Skip to content

Commit

Permalink
Merge branch 'development' of https://github.com/AXErunners/axe into …
Browse files Browse the repository at this point in the history
…development
  • Loading branch information
charlesrocket committed Mar 16, 2019
2 parents bb14df6 + 88667f8 commit 3eb6a9d
Show file tree
Hide file tree
Showing 16 changed files with 189 additions and 100 deletions.
3 changes: 2 additions & 1 deletion doc/man/axe-cli.1
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ Timeout during HTTP requests (default: 900)
Read extra arguments from standard input, one per line until EOF/Ctrl\-D
(recommended for sensitive information such as passphrases)
.SH COPYRIGHT
Copyright (C) 2014-2018 The Axe Core developers
Copyright (C) 2017-2019 The Axe Core developers
Copyright (C) 2014-2018 The Dash Core developers
Copyright (C) 2009-2018 The Bitcoin Core developers

Please contribute if you find Axe Core useful. Visit <https://axerunners.com> for
Expand Down
3 changes: 2 additions & 1 deletion doc/man/axe-tx.1
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ set=NAME:JSON\-STRING
.IP
Set register NAME to given JSON\-STRING
.SH COPYRIGHT
Copyright (C) 2014-2018 The Axe Core developers
Copyright (C) 2017-2019 The Axe Core developers
Copyright (C) 2014-2018 The Dash Core developers
Copyright (C) 2009-2018 The Bitcoin Core developers

Please contribute if you find Axe Core useful. Visit <https://axerunners.com> for
Expand Down
2 changes: 1 addition & 1 deletion qa/rpc-tests/test_framework/util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
# Copyright (c) 2014-2016 The Bitcoin Core developers
# Copyright (c) 2014-2017 The Axe Core developers
# Copyright (c) 2014-2017 The Dash Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.

Expand Down
2 changes: 1 addition & 1 deletion share/qt/Info.plist.in
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<string>APPL</string>

<key>CFBundleGetInfoString</key>
<string>@CLIENT_VERSION_MAJOR@.@CLIENT_VERSION_MINOR@.@CLIENT_VERSION_REVISION@, Copyright © 2009-@COPYRIGHT_YEAR@ The Bitcoin Core developers, 2014-@COPYRIGHT_YEAR@ @COPYRIGHT_HOLDERS_FINAL@</string>
<string>@CLIENT_VERSION_MAJOR@.@CLIENT_VERSION_MINOR@.@CLIENT_VERSION_REVISION@.@CLIENT_VERSION_BUILD@, Copyright © 2009-@COPYRIGHT_YEAR@ The Bitcoin Core developers, 2014-@COPYRIGHT_YEAR@ @COPYRIGHT_HOLDERS_FINAL@</string>

<key>CFBundleShortVersionString</key>
<string>@CLIENT_VERSION_MAJOR@.@CLIENT_VERSION_MINOR@.@CLIENT_VERSION_REVISION@</string>
Expand Down
2 changes: 2 additions & 0 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,8 @@ class CTestNetParams : public CChainParams {
assert(genesis.hashMerkleRoot == uint256S("0x987a08c31d7f04f47f1aeccdffc73ca4336e32a6615f619b94cc7109e7c2a7ac"));

vFixedSeeds.clear();
vFixedSeeds = std::vector<SeedSpec6>(pnSeed6_test, pnSeed6_test + ARRAYLEN(pnSeed6_test));

vSeeds.clear();
// nodes with support for servicebits filtering should be at the top
vSeeds.push_back(CDNSSeedData("seed1.0313370.xyz", "seed2.0313370.xyz"));
Expand Down
89 changes: 54 additions & 35 deletions src/dbwrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -344,14 +344,16 @@ class CDBWrapper

};

template<typename Parent, typename CommitTarget>
class CDBTransaction {
private:
CDBWrapper &db;
protected:
Parent &parent;
CommitTarget &commitTarget;

struct KeyHolder {
virtual ~KeyHolder() = default;
virtual bool Less(const KeyHolder &b) const = 0;
virtual void Erase(CDBBatch &batch) = 0;
virtual void Erase(CommitTarget &commitTarget) = 0;
};
typedef std::unique_ptr<KeyHolder> KeyHolderPtr;

Expand All @@ -364,15 +366,15 @@ class CDBTransaction {
auto *b2 = dynamic_cast<const KeyHolderImpl<K>*>(&b);
return key < b2->key;
}
virtual void Erase(CDBBatch &batch) {
batch.Erase(key);
virtual void Erase(CommitTarget &commitTarget) {
commitTarget.Erase(key);
}
K key;
};

struct KeyValueHolder {
virtual ~KeyValueHolder() = default;
virtual void Write(CDBBatch &batch) = 0;
virtual void Write(CommitTarget &parent) = 0;
};
typedef std::unique_ptr<KeyValueHolder> KeyValueHolderPtr;

Expand All @@ -381,8 +383,13 @@ class CDBTransaction {
KeyValueHolderImpl(const KeyHolderImpl<K> &_key, const V &_value)
: key(_key),
value(_value) { }
virtual void Write(CDBBatch &batch) {
batch.Write(key.key, value);
KeyValueHolderImpl(const KeyHolderImpl<K> &_key, V &&_value)
: key(_key),
value(std::forward<V>(_value)) { }
virtual void Write(CommitTarget &commitTarget) {
// we're moving the value instead of copying it. This means that Write() can only be called once per
// KeyValueHolderImpl instance. Commit() clears the write maps, so this ok.
commitTarget.Write(key.key, std::move(value));
}
const KeyHolderImpl<K> &key;
V value;
Expand Down Expand Up @@ -422,22 +429,34 @@ class CDBTransaction {
return getMapForType<K>(deletes, create);
}

public:
CDBTransaction(CDBWrapper &_db) : db(_db) {}

template <typename K, typename V>
void Write(const K& key, const V& value) {
KeyHolderPtr k(new KeyHolderImpl<K>(key));
KeyHolderImpl<K>* k2 = dynamic_cast<KeyHolderImpl<K>*>(k.get());
KeyValueHolderPtr kv(new KeyValueHolderImpl<K,V>(*k2, value));
template <typename K, typename KV>
void writeImpl(KeyHolderImpl<K>* k, KV&& kv) {
auto k2 = KeyHolderPtr(k);

KeyValueMap *ds = getDeletesMap<K>(false);
if (ds)
ds->erase(k);
ds->erase(k2);

KeyValueMap *ws = getWritesMap<K>(true);
ws->erase(k);
ws->emplace(std::make_pair(std::move(k), std::move(kv)));
ws->erase(k2);
ws->emplace(std::make_pair(std::move(k2), std::forward<KV>(kv)));
}

public:
CDBTransaction(Parent &_parent, CommitTarget &_commitTarget) : parent(_parent), commitTarget(_commitTarget) {}

template <typename K, typename V>
void Write(const K& key, const V& v) {
auto k = new KeyHolderImpl<K>(key);
auto kv = std::make_unique<KeyValueHolderImpl<K, V>>(*k, v);
writeImpl(k, std::move(kv));
}

template <typename K, typename V>
void Write(const K& key, V&& v) {
auto k = new KeyHolderImpl<K>(key);
auto kv = std::make_unique<KeyValueHolderImpl<K, typename std::remove_reference<V>::type>>(*k, std::forward<V>(v));
writeImpl(k, std::move(kv));
}

template <typename K, typename V>
Expand All @@ -450,7 +469,7 @@ class CDBTransaction {

KeyValueMap *ws = getWritesMap<K>(false);
if (ws) {
KeyValueMap::iterator it = ws->find(k);
auto it = ws->find(k);
if (it != ws->end()) {
auto *impl = dynamic_cast<KeyValueHolderImpl<K, V> *>(it->second.get());
if (!impl)
Expand All @@ -460,7 +479,7 @@ class CDBTransaction {
}
}

return db.Read(key, value);
return parent.Read(key, value);
}

template <typename K>
Expand All @@ -475,7 +494,7 @@ class CDBTransaction {
if (ws && ws->count(k))
return true;

return db.Exists(key);
return parent.Exists(key);
}

template <typename K>
Expand All @@ -494,48 +513,48 @@ class CDBTransaction {
deletes.clear();
}

bool Commit() {
CDBBatch batch(db);
void Commit() {
for (auto &p : deletes) {
for (auto &p2 : p.second) {
p2.first->Erase(batch);
p2.first->Erase(commitTarget);
}
}
for (auto &p : writes) {
for (auto &p2 : p.second) {
p2.second->Write(batch);
p2.second->Write(commitTarget);
}
}
bool ret = db.WriteBatch(batch, true);
Clear();
return ret;
}

bool IsClean() {
return writes.empty() && deletes.empty();
}
};

template<typename Parent, typename CommitTarget>
class CScopedDBTransaction {
public:
typedef CDBTransaction<Parent, CommitTarget> Transaction;

private:
CDBTransaction &dbTransaction;
Transaction &dbTransaction;
std::function<void ()> commitHandler;
std::function<void ()> rollbackHandler;
bool didCommitOrRollback{};

public:
CScopedDBTransaction(CDBTransaction &dbTx) : dbTransaction(dbTx) {}
CScopedDBTransaction(Transaction &dbTx) : dbTransaction(dbTx) {}
~CScopedDBTransaction() {
if (!didCommitOrRollback)
Rollback();
}
bool Commit() {
void Commit() {
assert(!didCommitOrRollback);
didCommitOrRollback = true;
bool result = dbTransaction.Commit();
dbTransaction.Commit();
if (commitHandler)
commitHandler();
return result;
}
void Rollback() {
assert(!didCommitOrRollback);
Expand All @@ -545,9 +564,9 @@ class CScopedDBTransaction {
rollbackHandler();
}

static std::unique_ptr<CScopedDBTransaction> Begin(CDBTransaction &dbTx) {
static std::unique_ptr<CScopedDBTransaction<Parent, CommitTarget>> Begin(Transaction &dbTx) {
assert(dbTx.IsClean());
return std::unique_ptr<CScopedDBTransaction>(new CScopedDBTransaction(dbTx));
return std::make_unique<CScopedDBTransaction<Parent, CommitTarget>>(dbTx);
}

void SetCommitHandler(const std::function<void ()> &h) {
Expand Down
18 changes: 17 additions & 1 deletion src/evo/deterministicmns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ void CDeterministicMN::ToJson(UniValue& obj) const
obj.push_back(Pair("proTxHash", proTxHash.ToString()));
obj.push_back(Pair("collateralHash", collateralOutpoint.hash.ToString()));
obj.push_back(Pair("collateralIndex", (int)collateralOutpoint.n));

Coin coin;
if (GetUTXOCoin(collateralOutpoint, coin)) {
CTxDestination dest;
if (ExtractDestination(coin.out.scriptPubKey, dest)) {
obj.push_back(Pair("collateralAddress", CBitcoinAddress(dest).ToString()));
}
}

obj.push_back(Pair("operatorReward", (double)nOperatorReward / 100));
obj.push_back(Pair("state", stateObj));
}
Expand Down Expand Up @@ -438,6 +447,13 @@ CDeterministicMNManager::CDeterministicMNManager(CEvoDB& _evoDb) :

bool CDeterministicMNManager::ProcessBlock(const CBlock& block, const CBlockIndex* pindex, CValidationState& _state)
{
AssertLockHeld(cs_main);

bool fDIP0003Active = VersionBitsState(pindex->pprev, Params().GetConsensus(), Consensus::DEPLOYMENT_DIP0003, versionbitscache) == THRESHOLD_ACTIVE;
if (!fDIP0003Active) {
return true;
}

LOCK(cs);

int nHeight = pindex->nHeight;
Expand All @@ -457,7 +473,7 @@ bool CDeterministicMNManager::ProcessBlock(const CBlock& block, const CBlockInde
CDeterministicMNListDiff diff = oldList.BuildDiff(newList);

evoDb.Write(std::make_pair(DB_LIST_DIFF, diff.blockHash), diff);
if ((nHeight % SNAPSHOT_LIST_PERIOD) == 0) {
if ((nHeight % SNAPSHOT_LIST_PERIOD) == 0 || oldList.GetHeight() == -1) {
evoDb.Write(std::make_pair(DB_LIST_SNAPSHOT, diff.blockHash), newList);
LogPrintf("CDeterministicMNManager::%s -- Wrote snapshot. nHeight=%d, mapCurMNs.allMNsCount=%d\n",
__func__, nHeight, newList.GetAllMNsCount());
Expand Down
13 changes: 12 additions & 1 deletion src/evo/evodb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,21 @@ CEvoDB* evoDb;

CEvoDB::CEvoDB(size_t nCacheSize, bool fMemory, bool fWipe) :
db(fMemory ? "" : (GetDataDir() / "evodb"), nCacheSize, fMemory, fWipe),
dbTransaction(db)
rootBatch(db),
rootDBTransaction(db, rootBatch),
curDBTransaction(rootDBTransaction, rootDBTransaction)
{
}

bool CEvoDB::CommitRootTransaction()
{
assert(curDBTransaction.IsClean());
rootDBTransaction.Commit();
bool ret = db.WriteBatch(rootBatch);
rootBatch.Clear();
return ret;
}

bool CEvoDB::VerifyBestBlock(const uint256& hash)
{
// Make sure evodb is consistent.
Expand Down
23 changes: 16 additions & 7 deletions src/evo/evodb.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,51 +16,60 @@ class CEvoDB
private:
CCriticalSection cs;
CDBWrapper db;
CDBTransaction dbTransaction;

typedef CDBTransaction<CDBWrapper, CDBBatch> RootTransaction;
typedef CDBTransaction<RootTransaction, RootTransaction> CurTransaction;
typedef CScopedDBTransaction<RootTransaction, RootTransaction> ScopedTransaction;

CDBBatch rootBatch;
RootTransaction rootDBTransaction;
CurTransaction curDBTransaction;

public:
CEvoDB(size_t nCacheSize, bool fMemory = false, bool fWipe = false);

std::unique_ptr<CScopedDBTransaction> BeginTransaction()
std::unique_ptr<ScopedTransaction> BeginTransaction()
{
LOCK(cs);
auto t = CScopedDBTransaction::Begin(dbTransaction);
auto t = ScopedTransaction::Begin(curDBTransaction);
return t;
}

template <typename K, typename V>
bool Read(const K& key, V& value)
{
LOCK(cs);
return dbTransaction.Read(key, value);
return curDBTransaction.Read(key, value);
}

template <typename K, typename V>
void Write(const K& key, const V& value)
{
LOCK(cs);
dbTransaction.Write(key, value);
curDBTransaction.Write(key, value);
}

template <typename K>
bool Exists(const K& key)
{
LOCK(cs);
return dbTransaction.Exists(key);
return curDBTransaction.Exists(key);
}

template <typename K>
void Erase(const K& key)
{
LOCK(cs);
dbTransaction.Erase(key);
curDBTransaction.Erase(key);
}

CDBWrapper& GetRawDB()
{
return db;
}

bool CommitRootTransaction();

bool VerifyBestBlock(const uint256& hash);
void WriteBestBlock(const uint256& hash);
};
Expand Down
Loading

0 comments on commit 3eb6a9d

Please sign in to comment.