Rename CClaimTrieCache to CClaimTrieUpdateBuffer and separate in own file #160

Closed
bvbfan wants to merge 4 commits from seperate_disk_claim into seperate_disk_claim
11 changed files with 1651 additions and 1623 deletions
Showing only changes of commit 4e48f81860 - Show all commits

View file

@ -120,6 +120,7 @@ BITCOIN_CORE_H = \
nameclaim.h \
claimtrie.h \
claimtriedb.h \
claimtrieupdatebuffer.h \
lbry.h \
net.h \
netbase.h \
@ -193,6 +194,7 @@ libbitcoin_server_a_SOURCES = \
miner.cpp \
claimtrie.cpp \
claimtriedb.cpp \
claimtrieupdatebuffer.cpp \
net.cpp \
noui.cpp \
policy/fees.cpp \

View file

@ -61,7 +61,7 @@ BITCOIN_TESTS =\
test/miner_tests.cpp \
test/multisig_tests.cpp \
test/claimtrie_tests.cpp \
test/claimtriecache_tests.cpp \
test/claimtrieupdatebuffer_tests.cpp \
test/claimtriebranching_tests.cpp \
test/claimtriedb_tests.cpp \
test/nameclaim_tests.cpp \

File diff suppressed because it is too large Load diff

View file

@ -345,7 +345,7 @@ struct claimsForNameType
: claims(claims), supports(supports), nLastTakeoverHeight(nLastTakeoverHeight) {}
};
class CClaimTrieCache;
class CClaimTrieUpdateBuffer;
class CClaimTrie
{
@ -400,7 +400,7 @@ public:
unsigned int getTotalClaimsInTrie() const;
CAmount getTotalValueOfClaimsInTrie(bool fControllingOnly) const;
friend class CClaimTrieCache;
friend class CClaimTrieUpdateBuffer;
int nCurrentHeight;
int nExpirationTime;
@ -436,185 +436,6 @@ private:
nodeCacheType dirtyNodes;
};
class CClaimTrieProofNode
{
public:
CClaimTrieProofNode() {};
CClaimTrieProofNode(std::vector<std::pair<unsigned char, uint256> > children,
bool hasValue, uint256 valHash)
: children(children), hasValue(hasValue), valHash(valHash)
{};
std::vector<std::pair<unsigned char, uint256> > children;
bool hasValue;
uint256 valHash;
};
class CClaimTrieProof
{
public:
CClaimTrieProof() {};
CClaimTrieProof(std::vector<CClaimTrieProofNode> nodes, bool hasValue, COutPoint outPoint, int nHeightOfLastTakeover) : nodes(nodes), hasValue(hasValue), outPoint(outPoint), nHeightOfLastTakeover(nHeightOfLastTakeover) {}
std::vector<CClaimTrieProofNode> nodes;
bool hasValue;
COutPoint outPoint;
int nHeightOfLastTakeover;
};
class CClaimTrieCache
{
public:
CClaimTrieCache(CClaimTrie* base, bool fRequireTakeoverHeights = true)
: base(base),
fRequireTakeoverHeights(fRequireTakeoverHeights)
{
assert(base);
hashBlock = base->hashBlock;
nCurrentHeight = base->nCurrentHeight;
}
uint256 getMerkleHash() const;
bool empty() const;
bool flush();
bool dirty() const;
bool addClaim(const std::string& name, const COutPoint& outPoint,
uint160 claimId, CAmount nAmount, int nHeight);
bool undoAddClaim(const std::string& name, const COutPoint& outPoint,
int nHeight);
bool spendClaim(const std::string& name, const COutPoint& outPoint,
int nHeight, int& nValidAtHeight);
bool undoSpendClaim(const std::string& name, const COutPoint& outPoint,
uint160 claimId, CAmount nAmount, int nHeight,
int nValidAtHeight);
bool addSupport(const std::string& name, const COutPoint& outPoint,
CAmount nAmount, uint160 supportedClaimId,
int nHeight);
bool undoAddSupport(const std::string& name, const COutPoint& outPoint,
int nHeight);
bool spendSupport(const std::string& name, const COutPoint& outPoint,
int nHeight, int& nValidAtHeight);
bool undoSpendSupport(const std::string& name, const COutPoint& outPoint,
uint160 supportedClaimId, CAmount nAmount,
int nHeight, int nValidAtHeight);
uint256 getBestBlock() const;
void setBestBlock(const uint256& hashBlock);
bool incrementBlock(insertUndoType& insertUndo,
claimQueueRowType& expireUndo,
insertUndoType& insertSupportUndo,
supportQueueRowType& expireSupportUndo,
std::vector<std::pair<std::string, int> >& takeoverHeightUndo);
bool decrementBlock(insertUndoType& insertUndo,
claimQueueRowType& expireUndo,
insertUndoType& insertSupportUndo,
supportQueueRowType& expireSupportUndo,
std::vector<std::pair<std::string, int> >& takeoverHeightUndo);
~CClaimTrieCache() { clear(); }
bool insertClaimIntoTrie(const std::string& name, CClaimValue claim,
bool fCheckTakeover = false);
bool removeClaimFromTrie(const std::string& name, const COutPoint& outPoint,
CClaimValue& claim,
bool fCheckTakeover = false);
CClaimTrieProof getProofForName(const std::string& name) const;
bool finalizeDecrement();
void removeAndAddSupportToExpirationQueue(supportExpirationQueueRowType &row, int height, bool increment);
void removeAndAddToExpirationQueue(expirationQueueRowType &row, int height, bool increment);
bool forkForExpirationChange(bool increment);
protected:
CClaimTrie* base;
bool fRequireTakeoverHeights;
nodeCacheType cache;
nodeCacheType block_originals;
claimQueueType claimQueueCache;
queueNameType claimQueueNameCache;
expirationQueueType expirationQueueCache;
supportMapType supportCache;
supportQueueType supportQueueCache;
supportQueueNameType supportQueueNameCache;
supportExpirationQueueType supportExpirationQueueCache;
std::set<std::string> namesToCheckForTakeover;
std::map<std::string, int> cacheTakeoverHeights;
int nCurrentHeight; // Height of the block that is being worked on, which is
// one greater than the height of the chain's tip
// used in merkle hash computing
mutable hashMapType cacheHashes;
mutable std::set<std::string> dirtyHashes;
uint256 hashBlock;
uint256 computeHash() const;
bool reorderTrieNode(const std::string& name, bool fCheckTakeover);
bool recursiveComputeMerkleHash(CClaimTrieNode* tnCurrent,
std::string sPos) const;
bool recursivePruneName(CClaimTrieNode* tnCurrent, unsigned int nPos,
std::string sName,
bool* pfNullified = NULL);
bool clear();
bool removeClaim(const std::string& name, const COutPoint& outPoint,
int nHeight, int& nValidAtHeight, bool fCheckTakeover);
bool addClaimToQueues(const std::string& name, CClaimValue& claim);
bool removeClaimFromQueue(const std::string& name, const COutPoint& outPoint,
CClaimValue& claim);
void addToExpirationQueue(int nExpirationHeight, nameOutPointType& entry);
void removeFromExpirationQueue(const std::string& name, const COutPoint& outPoint,
int nHeight);
bool removeSupport(const std::string& name, const COutPoint& outPoint,
int nHeight, int& nValidAtHeight,
bool fCheckTakeover);
bool removeSupportFromMap(const std::string& name, const COutPoint& outPoint,
CSupportValue& support,
bool fCheckTakeover);
bool insertSupportIntoMap(const std::string& name,
CSupportValue support,
bool fCheckTakeover);
bool addSupportToQueues(const std::string& name, CSupportValue& support);
bool removeSupportFromQueue(const std::string& name, const COutPoint& outPoint,
CSupportValue& support);
void addSupportToExpirationQueue(int nExpirationHeight,
nameOutPointType& entry);
void removeSupportFromExpirationQueue(const std::string& name,
const COutPoint& outPoint,
int nHeight);
bool getSupportsForName(const std::string& name,
supportMapEntryType& node) const;
bool getLastTakeoverForName(const std::string& name, int& lastTakeoverHeight) const;
int getDelayForName(const std::string& name) const;
uint256 getLeafHashForProof(const std::string& currentPosition, unsigned char nodeChar,
const CClaimTrieNode* currentNode) const;
CClaimTrieNode* addNodeToCache(const std::string& position, CClaimTrieNode* original);
bool getOriginalInfoForName(const std::string& name, CClaimValue& claim) const;
int getNumBlocksOfContinuousOwnership(const std::string& name) const;
template <typename K, typename V> void update(std::map<K, V> &map);
template <typename K, typename V> typename std::map<K, V>::iterator getQueueCacheRow(const K &key, std::map<K, V> &map, bool createIfNotExists);
};
const uint256 one = uint256S("0000000000000000000000000000000000000000000000000000000000000001");
#endif // BITCOIN_CLAIMTRIE_H

File diff suppressed because it is too large Load diff

186
src/claimtrieupdatebuffer.h Normal file
View file

@ -0,0 +1,186 @@
#ifndef BITCOIN_CLAIMTRIEUPDATEBUFFER_H
#define BITCOIN_CLAIMTRIEUPDATEBUFFER_H
#include "amount.h"
#include "claimtrie.h"
#include <string>
#include <vector>
#include <map>
#include <set>
class CClaimTrieProofNode
{
public:
CClaimTrieProofNode() {};
CClaimTrieProofNode(std::vector<std::pair<unsigned char, uint256> > children,
bool hasValue, uint256 valHash)
: children(children), hasValue(hasValue), valHash(valHash)
{};
std::vector<std::pair<unsigned char, uint256> > children;
bool hasValue;
uint256 valHash;
};
class CClaimTrieProof
{
public:
CClaimTrieProof() {};
CClaimTrieProof(std::vector<CClaimTrieProofNode> nodes, bool hasValue, COutPoint outPoint, int nHeightOfLastTakeover) : nodes(nodes), hasValue(hasValue), outPoint(outPoint), nHeightOfLastTakeover(nHeightOfLastTakeover) {}
std::vector<CClaimTrieProofNode> nodes;
bool hasValue;
COutPoint outPoint;
int nHeightOfLastTakeover;
};
class CClaimTrieUpdateBuffer
{
public:
CClaimTrieUpdateBuffer(CClaimTrie* base, bool fRequireTakeoverHeights = true);
~CClaimTrieUpdateBuffer();
uint256 getMerkleHash() const;
bool empty() const;
bool flush();
bool dirty() const;
bool addClaim(const std::string& name, const COutPoint& outPoint,
uint160 claimId, CAmount nAmount, int nHeight);
bool undoAddClaim(const std::string& name, const COutPoint& outPoint,
int nHeight);
bool spendClaim(const std::string& name, const COutPoint& outPoint,
int nHeight, int& nValidAtHeight);
bool undoSpendClaim(const std::string& name, const COutPoint& outPoint,
uint160 claimId, CAmount nAmount, int nHeight,
int nValidAtHeight);
bool addSupport(const std::string& name, const COutPoint& outPoint,
CAmount nAmount, uint160 supportedClaimId,
int nHeight);
bool undoAddSupport(const std::string& name, const COutPoint& outPoint,
int nHeight);
bool spendSupport(const std::string& name, const COutPoint& outPoint,
int nHeight, int& nValidAtHeight);
bool undoSpendSupport(const std::string& name, const COutPoint& outPoint,
uint160 supportedClaimId, CAmount nAmount,
int nHeight, int nValidAtHeight);
uint256 getBestBlock() const;
void setBestBlock(const uint256& hashBlock);
bool incrementBlock(insertUndoType& insertUndo,
claimQueueRowType& expireUndo,
insertUndoType& insertSupportUndo,
supportQueueRowType& expireSupportUndo,
std::vector<std::pair<std::string, int> >& takeoverHeightUndo);
bool decrementBlock(insertUndoType& insertUndo,
claimQueueRowType& expireUndo,
insertUndoType& insertSupportUndo,
supportQueueRowType& expireSupportUndo,
std::vector<std::pair<std::string, int> >& takeoverHeightUndo);
bool insertClaimIntoTrie(const std::string& name, CClaimValue claim,
bool fCheckTakeover = false);
bool removeClaimFromTrie(const std::string& name, const COutPoint& outPoint,
CClaimValue& claim,
bool fCheckTakeover = false);
CClaimTrieProof getProofForName(const std::string& name) const;
bool finalizeDecrement();
void removeAndAddSupportToExpirationQueue(supportExpirationQueueRowType &row, int height, bool increment);
void removeAndAddToExpirationQueue(expirationQueueRowType &row, int height, bool increment);
bool forkForExpirationChange(bool increment);
protected:
CClaimTrie* base;
bool fRequireTakeoverHeights;
nodeCacheType cache;
nodeCacheType block_originals;
claimQueueType claimQueueCache;
queueNameType claimQueueNameCache;
expirationQueueType expirationQueueCache;
supportMapType supportCache;
supportQueueType supportQueueCache;
supportQueueNameType supportQueueNameCache;
supportExpirationQueueType supportExpirationQueueCache;
std::set<std::string> namesToCheckForTakeover;
std::map<std::string, int> cacheTakeoverHeights;
int nCurrentHeight; // Height of the block that is being worked on, which is
// one greater than the height of the chain's tip
// used in merkle hash computing
mutable hashMapType cacheHashes;
mutable std::set<std::string> dirtyHashes;
uint256 hashBlock;
uint256 computeHash() const;
bool reorderTrieNode(const std::string& name, bool fCheckTakeover);
bool recursiveComputeMerkleHash(CClaimTrieNode* tnCurrent,
std::string sPos) const;
bool recursivePruneName(CClaimTrieNode* tnCurrent, unsigned int nPos,
std::string sName,
bool* pfNullified = NULL);
bool clear();
bool removeClaim(const std::string& name, const COutPoint& outPoint,
int nHeight, int& nValidAtHeight, bool fCheckTakeover);
bool addClaimToQueues(const std::string& name, CClaimValue& claim);
bool removeClaimFromQueue(const std::string& name, const COutPoint& outPoint,
CClaimValue& claim);
void addToExpirationQueue(int nExpirationHeight, nameOutPointType& entry);
void removeFromExpirationQueue(const std::string& name, const COutPoint& outPoint,
int nHeight);
bool removeSupport(const std::string& name, const COutPoint& outPoint,
int nHeight, int& nValidAtHeight,
bool fCheckTakeover);
bool removeSupportFromMap(const std::string& name, const COutPoint& outPoint,
CSupportValue& support,
bool fCheckTakeover);
bool insertSupportIntoMap(const std::string& name,
CSupportValue support,
bool fCheckTakeover);
bool addSupportToQueues(const std::string& name, CSupportValue& support);
bool removeSupportFromQueue(const std::string& name, const COutPoint& outPoint,
CSupportValue& support);
void addSupportToExpirationQueue(int nExpirationHeight,
nameOutPointType& entry);
void removeSupportFromExpirationQueue(const std::string& name,
const COutPoint& outPoint,
int nHeight);
bool getSupportsForName(const std::string& name,
supportMapEntryType& node) const;
bool getLastTakeoverForName(const std::string& name, int& lastTakeoverHeight) const;
int getDelayForName(const std::string& name) const;
uint256 getLeafHashForProof(const std::string& currentPosition, unsigned char nodeChar,
const CClaimTrieNode* currentNode) const;
CClaimTrieNode* addNodeToCache(const std::string& position, CClaimTrieNode* original);
bool getOriginalInfoForName(const std::string& name, CClaimValue& claim) const;
int getNumBlocksOfContinuousOwnership(const std::string& name) const;
template <typename K, typename V> void update(std::map<K, V> &map);
template <typename K, typename V> typename std::map<K, V>::iterator getQueueCacheRow(const K &key, std::map<K, V> &map, bool createIfNotExists);
};
#endif // BITCOIN_CLAIMTRIEUPDATEBUFFER_H

View file

@ -963,13 +963,13 @@ bool CheckTransaction(const CTransaction& tx, CValidationState &state)
if (!MoneyRange(nValueOut))
return state.DoS(100, false, REJECT_INVALID, "bad-txns-txouttotal-toolarge");
// check claimtrie transactions
// check claimtrie transactions
if (ClaimScriptSize(txout.scriptPubKey) > MAX_CLAIM_SCRIPT_SIZE)
return state.DoS(100, false, REJECT_INVALID, "bad-txns-claimscriptsize-toolarge");
if (ClaimNameSize(txout.scriptPubKey) > MAX_CLAIM_NAME_SIZE)
if (ClaimNameSize(txout.scriptPubKey) > MAX_CLAIM_NAME_SIZE)
return state.DoS(100, false, REJECT_INVALID, "bad-txns-claimscriptname-toolarge");
}
// Check for duplicate inputs
@ -2037,7 +2037,7 @@ bool AbortNode(CValidationState& state, const std::string& strMessage, const std
* @param out The out point that corresponds to the tx input.
* @return True on success.
*/
static bool ApplyTxInUndo(const CTxInUndo& undo, CCoinsViewCache& view, CClaimTrieCache& trieCache, const COutPoint& out)
static bool ApplyTxInUndo(const CTxInUndo& undo, CCoinsViewCache& view, CClaimTrieUpdateBuffer& trieBuffer, const COutPoint& out)
{
bool fClean = true;
@ -2082,7 +2082,7 @@ static bool ApplyTxInUndo(const CTxInUndo& undo, CCoinsViewCache& view, CClaimTr
if (nValidHeight > 0 && nValidHeight >= coins->nHeight)
{
LogPrintf("%s: (txid: %s, nOut: %d) Restoring %s to the claim trie due to a block being disconnected\n", __func__, out.hash.ToString(), out.n, name.c_str());
if (!trieCache.undoSpendClaim(name, COutPoint(out.hash, out.n), claimId, undo.txout.nValue, coins->nHeight, nValidHeight))
if (!trieBuffer.undoSpendClaim(name, COutPoint(out.hash, out.n), claimId, undo.txout.nValue, coins->nHeight, nValidHeight))
LogPrintf("%s: Something went wrong inserting the claim\n", __func__);
}
else
@ -2099,7 +2099,7 @@ static bool ApplyTxInUndo(const CTxInUndo& undo, CCoinsViewCache& view, CClaimTr
if (nValidHeight > 0 && nValidHeight >= coins->nHeight)
{
LogPrintf("%s: (txid: %s, nOut: %d) Restoring support for %s in claimid %s due to a block being disconnected\n", __func__, out.hash.ToString(), out.n, name, supportedClaimId.ToString());
if (!trieCache.undoSpendSupport(name, COutPoint(out.hash, out.n), supportedClaimId, undo.txout.nValue, coins->nHeight, nValidHeight))
if (!trieBuffer.undoSpendSupport(name, COutPoint(out.hash, out.n), supportedClaimId, undo.txout.nValue, coins->nHeight, nValidHeight))
LogPrintf("%s: Something went wrong inserting support for the claim\n", __func__);
}
else
@ -2114,10 +2114,10 @@ static bool ApplyTxInUndo(const CTxInUndo& undo, CCoinsViewCache& view, CClaimTr
return fClean;
}
bool DisconnectBlock(const CBlock& block, CValidationState& state, const CBlockIndex* pindex, CCoinsViewCache& view, CClaimTrieCache& trieCache, bool* pfClean)
bool DisconnectBlock(const CBlock& block, CValidationState& state, const CBlockIndex* pindex, CCoinsViewCache& view, CClaimTrieUpdateBuffer& trieBuffer, bool* pfClean)
{
assert(pindex->GetBlockHash() == view.GetBestBlock());
assert(pindex->GetBlockHash() == trieCache.getBestBlock());
assert(pindex->GetBlockHash() == trieBuffer.getBestBlock());
if (pfClean)
*pfClean = false;
@ -2134,7 +2134,7 @@ bool DisconnectBlock(const CBlock& block, CValidationState& state, const CBlockI
if (blockUndo.vtxundo.size() + 1 != block.vtx.size())
return error("DisconnectBlock(): block and undo data inconsistent");
assert(trieCache.decrementBlock(blockUndo.insertUndo, blockUndo.expireUndo, blockUndo.insertSupportUndo, blockUndo.expireSupportUndo, blockUndo.takeoverHeightUndo));
assert(trieBuffer.decrementBlock(blockUndo.insertUndo, blockUndo.expireUndo, blockUndo.insertSupportUndo, blockUndo.expireSupportUndo, blockUndo.takeoverHeightUndo));
// undo transactions in reverse order
for (int i = block.vtx.size() - 1; i >= 0; i--) {
@ -2190,7 +2190,7 @@ bool DisconnectBlock(const CBlock& block, CValidationState& state, const CBlockI
}
std::string name(vvchParams[0].begin(), vvchParams[0].end());
LogPrintf("%s: (txid: %s, nOut: %d) Trying to remove %s from the claim trie due to its block being disconnected\n", __func__, hash.ToString(), i, name.c_str());
if (!trieCache.undoAddClaim(name, COutPoint(hash, i), pindex->nHeight))
if (!trieBuffer.undoAddClaim(name, COutPoint(hash, i), pindex->nHeight))
{
LogPrintf("%s: Could not find the claim in the trie or the cache\n", __func__);
}
@ -2203,7 +2203,7 @@ bool DisconnectBlock(const CBlock& block, CValidationState& state, const CBlockI
LogPrintf("--- %s[%lu]: OP_SUPPORT_CLAIM \"%s\" with claimId %s and tx prevout %s at index %d\n",
__func__, pindex->nHeight, name, supportedClaimId.GetHex(), hash.ToString(), i);
LogPrintf("%s: (txid: %s, nOut: %d) Removing support for claim id %s on %s due to its block being disconnected\n", __func__, hash.ToString(), i, supportedClaimId.ToString(), name.c_str());
if (!trieCache.undoAddSupport(name, COutPoint(hash, i), pindex->nHeight))
if (!trieBuffer.undoAddSupport(name, COutPoint(hash, i), pindex->nHeight))
LogPrintf("%s: Something went wrong removing support for name %s in hash %s\n", __func__, name.c_str(), hash.ToString());
}
}
@ -2221,7 +2221,7 @@ bool DisconnectBlock(const CBlock& block, CValidationState& state, const CBlockI
for (unsigned int j = tx.vin.size(); j-- > 0;) {
const COutPoint &out = tx.vin[j].prevout;
const CTxInUndo &undo = txundo.vprevout[j];
if (!ApplyTxInUndo(undo, view, trieCache, out))
if (!ApplyTxInUndo(undo, view, trieBuffer, out))
fClean = false;
}
}
@ -2229,14 +2229,14 @@ bool DisconnectBlock(const CBlock& block, CValidationState& state, const CBlockI
// move best block pointer to prevout block
view.SetBestBlock(pindex->pprev->GetBlockHash());
assert(trieCache.finalizeDecrement());
trieCache.setBestBlock(pindex->pprev->GetBlockHash());
assert(trieCache.getMerkleHash() == pindex->pprev->hashClaimTrie);
assert(trieBuffer.finalizeDecrement());
trieBuffer.setBestBlock(pindex->pprev->GetBlockHash());
assert(trieBuffer.getMerkleHash() == pindex->pprev->hashClaimTrie);
if (pindex->nHeight == Params().GetConsensus().nExtendedClaimExpirationForkHeight)
{
LogPrintf("Decremented past the extended claim expiration hard fork height");
pclaimTrie->setExpirationTime(Params().GetConsensus().GetExpirationTime(pindex->nHeight-1));
trieCache.forkForExpirationChange(false);
trieBuffer.forkForExpirationChange(false);
}
@ -2395,7 +2395,7 @@ static int64_t nTimeIndex = 0;
static int64_t nTimeCallbacks = 0;
static int64_t nTimeTotal = 0;
bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& view, CClaimTrieCache& trieCache, bool fJustCheck)
bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& view, CClaimTrieUpdateBuffer& trieBuffer, bool fJustCheck)
{
const CChainParams& chainparams = Params();
AssertLockHeld(cs_main);
@ -2411,7 +2411,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
assert(hashPrevBlock == view.GetBestBlock());
// also verify that the trie cache's current state corresponds to the previous block
assert(hashPrevBlock == trieCache.getBestBlock());
assert(hashPrevBlock == trieBuffer.getBestBlock());
// Special case for the genesis block, skipping connection of its transactions
// (its coinbase is unspendable)
@ -2419,7 +2419,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
if (!fJustCheck)
{
view.SetBestBlock(pindex->GetBlockHash());
trieCache.setBestBlock(pindex->GetBlockHash());
trieBuffer.setBestBlock(pindex->GetBlockHash());
}
//return true;
}
@ -2499,13 +2499,13 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
flags |= SCRIPT_VERIFY_CHECKSEQUENCEVERIFY;
nLockTimeFlags |= LOCKTIME_VERIFY_SEQUENCE;
}
// v 13 LBRYcrd hard fork to extend expiration time
if (pindex->nHeight == Params().GetConsensus().nExtendedClaimExpirationForkHeight)
{
LogPrintf("Incremented past the extended claim expiration hard fork height");
pclaimTrie->setExpirationTime(chainparams.GetConsensus().GetExpirationTime(pindex->nHeight));
trieCache.forkForExpirationChange(true);
trieBuffer.forkForExpirationChange(true);
}
@ -2584,7 +2584,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
typedef std::vector<std::pair<std::string, uint160> > spentClaimsType;
spentClaimsType spentClaims;
for (unsigned int i = 0; i < tx.vin.size(); ++i)
{
const CTxIn& txin = tx.vin[i];
@ -2621,7 +2621,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
std::string name(vvchParams[0].begin(), vvchParams[0].end());
int nValidAtHeight;
LogPrintf("%s: Removing %s from the claim trie. Tx: %s, nOut: %d\n", __func__, name, txin.prevout.hash.GetHex(), txin.prevout.n);
if (trieCache.spendClaim(name, COutPoint(txin.prevout.hash, txin.prevout.n), coins->nHeight, nValidAtHeight))
if (trieBuffer.spendClaim(name, COutPoint(txin.prevout.hash, txin.prevout.n), coins->nHeight, nValidAtHeight))
{
mClaimUndoHeights[i] = nValidAtHeight;
std::pair<std::string, uint160> entry(name, claimId);
@ -2638,14 +2638,14 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
supportedClaimId.GetHex(), txin.prevout.hash.GetHex(), txin.prevout.n);
int nValidAtHeight;
LogPrintf("%s: Removing support for %s in %s. Tx: %s, nOut: %d, removed txid: %s\n", __func__, supportedClaimId.ToString(), name, txin.prevout.hash.ToString(), txin.prevout.n,tx.GetHash().ToString());
if (trieCache.spendSupport(name, COutPoint(txin.prevout.hash, txin.prevout.n), coins->nHeight, nValidAtHeight))
if (trieBuffer.spendSupport(name, COutPoint(txin.prevout.hash, txin.prevout.n), coins->nHeight, nValidAtHeight))
{
mClaimUndoHeights[i] = nValidAtHeight;
}
}
}
}
for (unsigned int i = 0; i < tx.vout.size(); ++i)
{
const CTxOut& txout = tx.vout[i];
@ -2659,7 +2659,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
assert(vvchParams.size() == 2);
std::string name(vvchParams[0].begin(), vvchParams[0].end());
LogPrintf("%s: Inserting %s into the claim trie. Tx: %s, nOut: %d\n", __func__, name, tx.GetHash().GetHex(), i);
if (!trieCache.addClaim(name, COutPoint(tx.GetHash(), i), ClaimIdHash(tx.GetHash(), i), txout.nValue, pindex->nHeight))
if (!trieBuffer.addClaim(name, COutPoint(tx.GetHash(), i), ClaimIdHash(tx.GetHash(), i), txout.nValue, pindex->nHeight))
{
LogPrintf("%s: Something went wrong inserting the claim\n", __func__);
}
@ -2681,7 +2681,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
if (itSpent != spentClaims.end())
{
spentClaims.erase(itSpent);
if (!trieCache.addClaim(name, COutPoint(tx.GetHash(), i), claimId, txout.nValue, pindex->nHeight))
if (!trieBuffer.addClaim(name, COutPoint(tx.GetHash(), i), claimId, txout.nValue, pindex->nHeight))
{
LogPrintf("%s: Something went wrong updating the claim\n", __func__);
}
@ -2692,7 +2692,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
assert(vvchParams.size() == 2);
std::string name(vvchParams[0].begin(), vvchParams[0].end());
uint160 supportedClaimId(vvchParams[1]);
if (!trieCache.addSupport(name, COutPoint(tx.GetHash(), i), txout.nValue, supportedClaimId, pindex->nHeight))
if (!trieBuffer.addSupport(name, COutPoint(tx.GetHash(), i), txout.nValue, supportedClaimId, pindex->nHeight))
{
LogPrintf("%s: Something went wrong inserting the support\n", __func__);
}
@ -2731,12 +2731,12 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
pos.nTxOffset += ::GetSerializeSize(tx, SER_DISK, CLIENT_VERSION);
}
assert(trieCache.incrementBlock(blockundo.insertUndo, blockundo.expireUndo, blockundo.insertSupportUndo, blockundo.expireSupportUndo, blockundo.takeoverHeightUndo));
assert(trieBuffer.incrementBlock(blockundo.insertUndo, blockundo.expireUndo, blockundo.insertSupportUndo, blockundo.expireSupportUndo, blockundo.takeoverHeightUndo));
if (trieCache.getMerkleHash() != block.hashClaimTrie)
if (trieBuffer.getMerkleHash() != block.hashClaimTrie)
return state.DoS(100,
error("ConnectBlock() : the merkle root of the claim trie does not match "
"(actual=%s vs block=%s)", trieCache.getMerkleHash().GetHex(),
"(actual=%s vs block=%s)", trieBuffer.getMerkleHash().GetHex(),
block.hashClaimTrie.GetHex()), REJECT_INVALID, "bad-claim-merkle-hash");
int64_t nTime3 = GetTimeMicros(); nTimeConnect += nTime3 - nTime2;
@ -2784,7 +2784,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
// add this block to the view's block chain
view.SetBestBlock(pindex->GetBlockHash());
trieCache.setBestBlock(pindex->GetBlockHash());
trieBuffer.setBestBlock(pindex->GetBlockHash());
int64_t nTime5 = GetTimeMicros(); nTimeIndex += nTime5 - nTime4;
LogPrint("bench", " - Index writing: %.2fms [%.2fs]\n", 0.001 * (nTime5 - nTime4), nTimeIndex * 0.000001);
@ -2995,12 +2995,12 @@ bool static DisconnectTip(CValidationState& state, const Consensus::Params& cons
int64_t nStart = GetTimeMicros();
{
CCoinsViewCache view(pcoinsTip);
CClaimTrieCache trieCache(pclaimTrie);
if (!DisconnectBlock(block, state, pindexDelete, view, trieCache))
CClaimTrieUpdateBuffer trieBuffer(pclaimTrie);
if (!DisconnectBlock(block, state, pindexDelete, view, trieBuffer))
return error("DisconnectTip(): DisconnectBlock %s failed", pindexDelete->GetBlockHash().ToString());
assert(view.Flush());
assert(trieCache.flush());
assert(pindexDelete->pprev->hashClaimTrie == trieCache.getMerkleHash());
assert(trieBuffer.flush());
assert(pindexDelete->pprev->hashClaimTrie == trieBuffer.getMerkleHash());
}
LogPrint("bench", "- Disconnect block: %.2fms\n", (GetTimeMicros() - nStart) * 0.001);
// Write the chain state to disk, if necessary.
@ -3061,8 +3061,8 @@ bool static ConnectTip(CValidationState& state, const CChainParams& chainparams,
LogPrint("bench", " - Load block from disk: %.2fms [%.2fs]\n", (nTime2 - nTime1) * 0.001, nTimeReadFromDisk * 0.000001);
{
CCoinsViewCache view(pcoinsTip);
CClaimTrieCache trieCache(pclaimTrie);
bool rv = ConnectBlock(*pblock, state, pindexNew, view, trieCache);
CClaimTrieUpdateBuffer trieBuffer(pclaimTrie);
bool rv = ConnectBlock(*pblock, state, pindexNew, view, trieBuffer);
GetMainSignals().BlockChecked(*pblock, state);
if (!rv) {
if (state.IsInvalid())
@ -3073,7 +3073,7 @@ bool static ConnectTip(CValidationState& state, const CChainParams& chainparams,
nTime3 = GetTimeMicros(); nTimeConnectTotal += nTime3 - nTime2;
LogPrint("bench", " - Connect total: %.2fms [%.2fs]\n", (nTime3 - nTime2) * 0.001, nTimeConnectTotal * 0.000001);
assert(view.Flush());
assert(trieCache.flush());
assert(trieBuffer.flush());
}
int64_t nTime4 = GetTimeMicros(); nTimeFlush += nTime4 - nTime3;
LogPrint("bench", " - Flush: %.2fms [%.2fs]\n", (nTime4 - nTime3) * 0.001, nTimeFlush * 0.000001);
@ -3872,7 +3872,7 @@ bool TestBlockValidity(CValidationState& state, const CChainParams& chainparams,
return error("%s: CheckIndexAgainstCheckpoint(): %s", __func__, state.GetRejectReason().c_str());
CCoinsViewCache viewNew(pcoinsTip);
CClaimTrieCache trieCache(pclaimTrie);
CClaimTrieUpdateBuffer trieBuffer(pclaimTrie);
CBlockIndex indexDummy(block);
indexDummy.pprev = pindexPrev;
indexDummy.nHeight = pindexPrev->nHeight + 1;
@ -3884,7 +3884,7 @@ bool TestBlockValidity(CValidationState& state, const CChainParams& chainparams,
return error("%s: Consensus::CheckBlock: %s", __func__, FormatStateMessage(state));
if (!ContextualCheckBlock(block, state, pindexPrev))
return error("%s: Consensus::ContextualCheckBlock: %s", __func__, FormatStateMessage(state));
if (!ConnectBlock(block, state, &indexDummy, viewNew, trieCache, true))
if (!ConnectBlock(block, state, &indexDummy, viewNew, trieBuffer, true))
return false;
assert(state.IsValid());
@ -4197,7 +4197,7 @@ bool CVerifyDB::VerifyDB(const CChainParams& chainparams, CCoinsView *coinsview,
nCheckLevel = std::max(0, std::min(4, nCheckLevel));
LogPrintf("Verifying last %i blocks at level %i\n", nCheckDepth, nCheckLevel);
CCoinsViewCache coins(coinsview);
CClaimTrieCache trieCache(pclaimTrie);
CClaimTrieUpdateBuffer trieBuffer(pclaimTrie);
CBlockIndex* pindexState = chainActive.Tip();
CBlockIndex* pindexFailure = NULL;
int nGoodTransactions = 0;
@ -4214,7 +4214,7 @@ bool CVerifyDB::VerifyDB(const CChainParams& chainparams, CCoinsView *coinsview,
return error("VerifyDB(): *** ReadBlockFromDisk failed at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString());
// check level 1: verify block validity
if (nCheckLevel >= 1 && !CheckBlock(block, state))
return error("%s: *** found bad block at %d, hash=%s (%s)\n", __func__,
return error("%s: *** found bad block at %d, hash=%s (%s)\n", __func__,
pindex->nHeight, pindex->GetBlockHash().ToString(), FormatStateMessage(state));
// check level 2: verify undo validity
if (nCheckLevel >= 2 && pindex) {
@ -4228,7 +4228,7 @@ bool CVerifyDB::VerifyDB(const CChainParams& chainparams, CCoinsView *coinsview,
// check level 3: check for inconsistencies during memory-only disconnect of tip blocks
if (nCheckLevel >= 3 && pindex == pindexState && (coins.DynamicMemoryUsage() + pcoinsTip->DynamicMemoryUsage()) <= nCoinCacheUsage) {
bool fClean = true;
if (!DisconnectBlock(block, state, pindex, coins, trieCache, &fClean))
if (!DisconnectBlock(block, state, pindex, coins, trieBuffer, &fClean))
return error("VerifyDB(): *** irrecoverable inconsistency in block data at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString());
pindexState = pindex->pprev;
if (!fClean) {
@ -4253,7 +4253,7 @@ bool CVerifyDB::VerifyDB(const CChainParams& chainparams, CCoinsView *coinsview,
CBlock block;
if (!ReadBlockFromDisk(block, pindex, chainparams.GetConsensus()))
return error("VerifyDB(): *** ReadBlockFromDisk failed at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString());
if (!ConnectBlock(block, state, pindex, coins, trieCache))
if (!ConnectBlock(block, state, pindex, coins, trieBuffer))
return error("VerifyDB(): *** found unconnectable block at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString());
}
}
@ -4271,7 +4271,7 @@ bool GetProofForName(const CBlockIndex* pindexProof, const std::string& name, CC
return false;
}
CCoinsViewCache coins(pcoinsTip);
CClaimTrieCache trieCache(pclaimTrie);
CClaimTrieUpdateBuffer trieBuffer(pclaimTrie);
CBlockIndex* pindexState = chainActive.Tip();
CValidationState state;
for (CBlockIndex *pindex = chainActive.Tip(); pindex && pindex->pprev && pindexState != pindexProof; pindex=pindex->pprev)
@ -4285,7 +4285,7 @@ bool GetProofForName(const CBlockIndex* pindexProof, const std::string& name, CC
if (pindex == pindexState && (coins.DynamicMemoryUsage() + pcoinsTip->DynamicMemoryUsage()) <= nCoinCacheUsage)
{
bool fClean = true;
if (!DisconnectBlock(block, state, pindex, coins, trieCache, &fClean))
if (!DisconnectBlock(block, state, pindex, coins, trieBuffer, &fClean))
{
return false;
}
@ -4295,7 +4295,7 @@ bool GetProofForName(const CBlockIndex* pindexProof, const std::string& name, CC
return false;
}
assert(pindexState == pindexProof);
proof = trieCache.getProofForName(name);
proof = trieBuffer.getProofForName(name);
return true;
}
@ -4341,7 +4341,7 @@ bool LoadBlockIndex()
return true;
}
bool InitBlockIndex(const CChainParams& chainparams)
bool InitBlockIndex(const CChainParams& chainparams)
{
LOCK(cs_main);

View file

@ -18,6 +18,7 @@
#include "script/script_error.h"
#include "sync.h"
#include "versionbits.h"
#include "claimtrieupdatebuffer.h"
#include <algorithm>
#include <exception>
@ -204,11 +205,11 @@ void RegisterNodeSignals(CNodeSignals& nodeSignals);
/** Unregister a network node */
void UnregisterNodeSignals(CNodeSignals& nodeSignals);
/**
/**
* Process an incoming block. This only returns after the best known valid
* block is made active. Note that it does not, however, guarantee that the
* specific block passed to it has been checked for validity!
*
*
* @param[out] state This may be set to an Error state if any error occurred processing it, including during validation/connection/etc of otherwise unrelated blocks during reorganisation; or it may be set to an Invalid state if pblock is itself invalid (but this is not guaranteed even when the block is checked). If you want to *possibly* get feedback on whether pblock is valid, you must also install a CValidationInterface (see validationinterface.h) - this will have its BlockChecked method called whenever *any* block completes validation.
* @param[in] pfrom The node which we are receiving the block from; it is added to mapBlockSource and may be penalised if the block is invalid.
* @param[in] pblock The block we want to process.
@ -339,7 +340,7 @@ struct CDiskTxPos : public CDiskBlockPos
};
/**
/**
* Count ECDSA signature operations the old-fashioned (pre-0.6) way
* @return number of sigops this transaction's outputs will produce when spent
* @see CTransaction::FetchInputs
@ -348,7 +349,7 @@ unsigned int GetLegacySigOpCount(const CTransaction& tx);
/**
* Count ECDSA signature operations in pay-to-script-hash inputs.
*
*
* @param[in] mapInputs Map of previous transactions that have outputs we're spending
* @return maximum number of sigops required to validate this transaction's inputs
* @see CTransaction::FetchInputs
@ -411,7 +412,7 @@ bool CheckSequenceLocks(const CTransaction &tx, int flags, LockPoints* lp = NULL
/**
* Closure representing one script verification
* Note that this stores references to the spending transaction
* Note that this stores references to the spending transaction
*/
class CScriptCheck
{
@ -464,13 +465,13 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIn
/** Apply the effects of this block (with given index) on the UTXO set represented by coins.
* Validity checks that depend on the UTXO set are also done; ConnectBlock()
* can fail if those validity checks fail (among other reasons). */
bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& coins, CClaimTrieCache& trieCache, bool fJustCheck = false);
bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& coins, CClaimTrieUpdateBuffer& trieBuffer, bool fJustCheck = false);
/** Undo the effects of this block (with given index) on the UTXO set represented by coins.
* In case pfClean is provided, operation will try to be tolerant about errors, and *pfClean
* will be true if no problems were found. Otherwise, the return value will be false in case
* of problems. Note that in any case, coins may be modified. */
bool DisconnectBlock(const CBlock& block, CValidationState& state, const CBlockIndex* pindex, CCoinsViewCache& coins, CClaimTrieCache& trieCache, bool* pfClean = NULL);
bool DisconnectBlock(const CBlock& block, CValidationState& state, const CBlockIndex* pindex, CCoinsViewCache& coins, CClaimTrieUpdateBuffer& trieBuffer, bool* pfClean = NULL);
/** Check a block is completely valid from start to finish (only works on top of our current best block, with cs_main held) */
bool TestBlockValidity(CValidationState& state, const CChainParams& chainparams, const CBlock& block, CBlockIndex* pindexPrev, bool fCheckPOW = true, bool fCheckMerkleRoot = true);

View file

@ -137,7 +137,7 @@ CBlockTemplate* CreateNewBlock(const CChainParams& chainparams, const CScript& s
{
return NULL;
}
CClaimTrieCache trieCache(pclaimTrie);
CClaimTrieUpdateBuffer trieBuffer(pclaimTrie);
const int64_t nMedianTimePast = pindexPrev->GetMedianTimePast();
pblock->nVersion = ComputeBlockVersion(pindexPrev, chainparams.GetConsensus());
@ -294,7 +294,7 @@ CBlockTemplate* CreateNewBlock(const CChainParams& chainparams, const CScript& s
}
std::string name(vvchParams[0].begin(), vvchParams[0].end());
int throwaway;
if (trieCache.spendClaim(name, COutPoint(txin.prevout.hash, txin.prevout.n), nTxinHeight, throwaway))
if (trieBuffer.spendClaim(name, COutPoint(txin.prevout.hash, txin.prevout.n), nTxinHeight, throwaway))
{
std::pair<std::string, uint160> entry(name, claimId);
spentClaims.push_back(entry);
@ -309,18 +309,18 @@ CBlockTemplate* CreateNewBlock(const CChainParams& chainparams, const CScript& s
assert(vvchParams.size() == 2);
std::string name(vvchParams[0].begin(), vvchParams[0].end());
int throwaway;
if (!trieCache.spendSupport(name, COutPoint(txin.prevout.hash, txin.prevout.n), nTxinHeight, throwaway))
if (!trieBuffer.spendSupport(name, COutPoint(txin.prevout.hash, txin.prevout.n), nTxinHeight, throwaway))
{
LogPrintf("%s(): The support was not found in the trie or queue\n", __func__);
}
}
}
}
for (unsigned int i = 0; i < tx.vout.size(); ++i)
{
const CTxOut& txout = tx.vout[i];
std::vector<std::vector<unsigned char> > vvchParams;
int op;
if (DecodeClaimScript(txout.scriptPubKey, op, vvchParams))
@ -329,7 +329,7 @@ CBlockTemplate* CreateNewBlock(const CChainParams& chainparams, const CScript& s
{
assert(vvchParams.size() == 2);
std::string name(vvchParams[0].begin(), vvchParams[0].end());
if (!trieCache.addClaim(name, COutPoint(tx.GetHash(), i), ClaimIdHash(tx.GetHash(), i), txout.nValue, nHeight))
if (!trieBuffer.addClaim(name, COutPoint(tx.GetHash(), i), ClaimIdHash(tx.GetHash(), i), txout.nValue, nHeight))
{
LogPrintf("%s: Something went wrong inserting the name\n", __func__);
}
@ -350,7 +350,7 @@ CBlockTemplate* CreateNewBlock(const CChainParams& chainparams, const CScript& s
if (itSpent != spentClaims.end())
{
spentClaims.erase(itSpent);
if (!trieCache.addClaim(name, COutPoint(tx.GetHash(), i), claimId, txout.nValue, nHeight))
if (!trieBuffer.addClaim(name, COutPoint(tx.GetHash(), i), claimId, txout.nValue, nHeight))
{
LogPrintf("%s: Something went wrong updating a claim\n", __func__);
}
@ -365,7 +365,7 @@ CBlockTemplate* CreateNewBlock(const CChainParams& chainparams, const CScript& s
assert(vvchParams.size() == 2);
std::string name(vvchParams[0].begin(), vvchParams[0].end());
uint160 supportedClaimId(vvchParams[1]);
if (!trieCache.addSupport(name, COutPoint(tx.GetHash(), i), txout.nValue, supportedClaimId, nHeight))
if (!trieBuffer.addSupport(name, COutPoint(tx.GetHash(), i), txout.nValue, supportedClaimId, nHeight))
{
LogPrintf("%s: Something went wrong inserting the claim support\n", __func__);
}
@ -443,8 +443,8 @@ CBlockTemplate* CreateNewBlock(const CChainParams& chainparams, const CScript& s
insertUndoType dummyInsertSupportUndo;
supportQueueRowType dummyExpireSupportUndo;
std::vector<std::pair<std::string, int> > dummyTakeoverHeightUndo;
trieCache.incrementBlock(dummyInsertUndo, dummyExpireUndo, dummyInsertSupportUndo, dummyExpireSupportUndo, dummyTakeoverHeightUndo);
pblock->hashClaimTrie = trieCache.getMerkleHash();
trieBuffer.incrementBlock(dummyInsertUndo, dummyExpireUndo, dummyInsertSupportUndo, dummyExpireSupportUndo, dummyTakeoverHeightUndo);
pblock->hashClaimTrie = trieBuffer.getMerkleHash();
CValidationState state;
if (!TestBlockValidity(state, chainparams, *pblock, pindexPrev, false, false)) {
@ -568,7 +568,7 @@ void static BitcoinMiner(const CChainParams& chainparams)
while (true)
{
unsigned int nHashesDone = 0;
// Check if something found
while (true)
{
@ -599,7 +599,7 @@ void static BitcoinMiner(const CChainParams& chainparams)
}
if (found)
break;
// Meter hashes/sec
static int64_t nHashCounter;
if (nHPSTimerStart == 0)

View file

@ -17,6 +17,7 @@
#include <boost/test/unit_test.hpp>
#include <iostream>
#include "test/test_bitcoin.h"
#include "claimtrieupdatebuffer.h"
using namespace std;
@ -187,19 +188,19 @@ BOOST_AUTO_TEST_CASE(claimtrie_merkle_hash)
uint256 hash1;
hash1.SetHex("71c7b8d35b9a3d7ad9a1272b68972979bbd18589f1efe6f27b0bf260a6ba78fa");
uint256 hash2;
hash2.SetHex("c4fc0e2ad56562a636a0a237a96a5f250ef53495c2cb5edd531f087a8de83722");
uint256 hash3;
hash3.SetHex("baf52472bd7da19fe1e35116cfb3bd180d8770ffbe3ae9243df1fb58a14b0975");
uint256 hash4;
hash4.SetHex("c73232a755bf015f22eaa611b283ff38100f2a23fb6222e86eca363452ba0c51");
BOOST_CHECK(pclaimTrie->empty());
CClaimTrieCache ntState(pclaimTrie, false);
CClaimTrieUpdateBuffer ntState(pclaimTrie, false);
ntState.insertClaimIntoTrie(std::string("test"), CClaimValue(tx1OutPoint, hash160, 50, 100, 200));
ntState.insertClaimIntoTrie(std::string("test2"), CClaimValue(tx2OutPoint, hash160, 50, 100, 200));
@ -220,7 +221,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_merkle_hash)
BOOST_CHECK(pclaimTrie->getMerkleHash() == hash2);
BOOST_CHECK(pclaimTrie->checkConsistency());
CClaimTrieCache ntState1(pclaimTrie, false);
CClaimTrieUpdateBuffer ntState1(pclaimTrie, false);
ntState1.removeClaimFromTrie(std::string("test"), tx1OutPoint, unused);
ntState1.removeClaimFromTrie(std::string("test2"), tx2OutPoint, unused);
ntState1.removeClaimFromTrie(std::string("test"), tx3OutPoint, unused);
@ -228,7 +229,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_merkle_hash)
BOOST_CHECK(ntState1.getMerkleHash() == hash0);
CClaimTrieCache ntState2(pclaimTrie, false);
CClaimTrieUpdateBuffer ntState2(pclaimTrie, false);
ntState2.insertClaimIntoTrie(std::string("abab"), CClaimValue(tx6OutPoint, hash160, 50, 100, 200));
ntState2.removeClaimFromTrie(std::string("test"), tx1OutPoint, unused);
@ -240,7 +241,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_merkle_hash)
BOOST_CHECK(pclaimTrie->getMerkleHash() == hash3);
BOOST_CHECK(pclaimTrie->checkConsistency());
CClaimTrieCache ntState3(pclaimTrie, false);
CClaimTrieUpdateBuffer ntState3(pclaimTrie, false);
ntState3.insertClaimIntoTrie(std::string("test"), CClaimValue(tx1OutPoint, hash160, 50, 100, 200));
BOOST_CHECK(ntState3.getMerkleHash() == hash4);
ntState3.flush();
@ -248,7 +249,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_merkle_hash)
BOOST_CHECK(pclaimTrie->getMerkleHash() == hash4);
BOOST_CHECK(pclaimTrie->checkConsistency());
CClaimTrieCache ntState4(pclaimTrie, false);
CClaimTrieUpdateBuffer ntState4(pclaimTrie, false);
ntState4.removeClaimFromTrie(std::string("abab"), tx6OutPoint, unused);
BOOST_CHECK(ntState4.getMerkleHash() == hash2);
ntState4.flush();
@ -256,7 +257,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_merkle_hash)
BOOST_CHECK(pclaimTrie->getMerkleHash() == hash2);
BOOST_CHECK(pclaimTrie->checkConsistency());
CClaimTrieCache ntState5(pclaimTrie, false);
CClaimTrieUpdateBuffer ntState5(pclaimTrie, false);
ntState5.removeClaimFromTrie(std::string("test"), tx3OutPoint, unused);
BOOST_CHECK(ntState5.getMerkleHash() == hash2);
@ -265,7 +266,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_merkle_hash)
BOOST_CHECK(pclaimTrie->getMerkleHash() == hash2);
BOOST_CHECK(pclaimTrie->checkConsistency());
CClaimTrieCache ntState6(pclaimTrie, false);
CClaimTrieUpdateBuffer ntState6(pclaimTrie, false);
ntState6.insertClaimIntoTrie(std::string("test"), CClaimValue(tx3OutPoint, hash160, 50, 101, 201));
BOOST_CHECK(ntState6.getMerkleHash() == hash2);
@ -274,12 +275,12 @@ BOOST_AUTO_TEST_CASE(claimtrie_merkle_hash)
BOOST_CHECK(pclaimTrie->getMerkleHash() == hash2);
BOOST_CHECK(pclaimTrie->checkConsistency());
CClaimTrieCache ntState7(pclaimTrie, false);
CClaimTrieUpdateBuffer ntState7(pclaimTrie, false);
ntState7.removeClaimFromTrie(std::string("test"), tx3OutPoint, unused);
ntState7.removeClaimFromTrie(std::string("test"), tx1OutPoint, unused);
ntState7.removeClaimFromTrie(std::string("tes"), tx4OutPoint, unused);
ntState7.removeClaimFromTrie(std::string("test2"), tx2OutPoint, unused);
BOOST_CHECK(ntState7.getMerkleHash() == hash0);
ntState7.flush();
BOOST_CHECK(pclaimTrie->empty());
@ -289,7 +290,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_merkle_hash)
BOOST_AUTO_TEST_CASE(claimtrie_insert_update_claim)
{
fRequireStandard = false;
BOOST_CHECK(pclaimTrie->nCurrentHeight == chainActive.Height() + 1);
LOCK(cs_main);
@ -314,7 +315,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_insert_update_claim)
uint256 hash0(uint256S("0000000000000000000000000000000000000000000000000000000000000001"));
BOOST_CHECK(pclaimTrie->getMerkleHash() == hash0);
CMutableTransaction tx1 = BuildTransaction(coinbases[0]);
tx1.vout[0].scriptPubKey = CScript() << OP_CLAIM_NAME << vchName1 << vchValue1 << OP_2DROP << OP_DROP << OP_TRUE;
uint160 tx1ClaimId = ClaimIdHash(tx1.GetHash(), 0);
@ -325,43 +326,43 @@ BOOST_AUTO_TEST_CASE(claimtrie_insert_update_claim)
tx2.vout[0].scriptPubKey = CScript() << OP_CLAIM_NAME << vchName2 << vchValue2 << OP_2DROP << OP_DROP << OP_TRUE;
tx2.vout[0].nValue = tx1.vout[0].nValue - 1;
COutPoint tx2OutPoint(tx2.GetHash(), 0);
CMutableTransaction tx3 = BuildTransaction(tx1);
tx3.vout[0].scriptPubKey = CScript() << OP_UPDATE_CLAIM << vchName1 << vchTx1ClaimId << vchValue1 << OP_2DROP << OP_2DROP << OP_TRUE;
tx3.vout[0].nValue -= 10000;
COutPoint tx3OutPoint(tx3.GetHash(), 0);
CMutableTransaction tx4 = BuildTransaction(tx2);
tx4.vout[0].scriptPubKey = CScript() << OP_TRUE;
COutPoint tx4OutPoint(tx4.GetHash(), 0);
CMutableTransaction tx5 = BuildTransaction(coinbases[2]);
tx5.vout[0].scriptPubKey = CScript() << OP_CLAIM_NAME << vchName2 << vchValue2 << OP_2DROP << OP_DROP << OP_TRUE;
COutPoint tx5OutPoint(tx5.GetHash(), 0);
CMutableTransaction tx6 = BuildTransaction(tx3);
tx6.vout[0].scriptPubKey = CScript() << OP_TRUE;
COutPoint tx6OutPoint(tx6.GetHash(), 0);
CMutableTransaction tx7 = BuildTransaction(coinbases[3]);
tx7.vout[0].scriptPubKey = CScript() << OP_CLAIM_NAME << vchName1 << vchValue2 << OP_2DROP << OP_DROP << OP_TRUE;
tx7.vout[0].nValue = tx1.vout[0].nValue - 10001;
uint160 tx7ClaimId = ClaimIdHash(tx7.GetHash(), 0);
std::vector<unsigned char> vchTx7ClaimId(tx7ClaimId.begin(), tx7ClaimId.end());
COutPoint tx7OutPoint(tx7.GetHash(), 0);
CMutableTransaction tx8 = BuildTransaction(tx3, 0, 2);
tx8.vout[0].scriptPubKey = CScript() << OP_UPDATE_CLAIM << vchName1 << vchTx1ClaimId << vchValue1 << OP_2DROP << OP_2DROP << OP_TRUE;
tx8.vout[0].nValue = tx8.vout[0].nValue - 1;
tx8.vout[1].scriptPubKey = CScript() << OP_CLAIM_NAME << vchName1 << vchValue2 << OP_2DROP << OP_DROP << OP_TRUE;
COutPoint tx8OutPoint0(tx8.GetHash(), 0);
COutPoint tx8OutPoint1(tx8.GetHash(), 1);
CMutableTransaction tx9 = BuildTransaction(tx7);
tx9.vout[0].scriptPubKey = CScript() << OP_UPDATE_CLAIM << vchName1 << vchTx7ClaimId << vchValue2 << OP_2DROP << OP_2DROP << OP_TRUE;
tx9.vout[0].nValue -= 10000;
COutPoint tx9OutPoint(tx9.GetHash(), 0);
CMutableTransaction tx10 = BuildTransaction(coinbases[4]);
tx10.vout[0].scriptPubKey = CScript() << OP_UPDATE_CLAIM << vchName1 << vchTx1ClaimId << vchValue1 << OP_2DROP << OP_2DROP << OP_TRUE;
COutPoint tx10OutPoint(tx10.GetHash(), 0);
@ -377,7 +378,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_insert_update_claim)
CMutableTransaction tx13 = BuildTransaction(coinbases[5]);
tx13.vout[0].scriptPubKey = CScript() << OP_CLAIM_NAME << vchName3 << vchValue3 << OP_2DROP << OP_DROP << OP_TRUE;
COutPoint tx13OutPoint(tx13.GetHash(), 0);
CClaimValue val;
int nThrowaway;
@ -390,7 +391,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_insert_update_claim)
BOOST_CHECK(CreateBlocks(1, 2));
blocks_to_invalidate.push_back(chainActive.Tip()->GetBlockHash());
BOOST_CHECK(pclaimTrie->getInfoForName(sName1, val));
BOOST_CHECK(val.outPoint == tx7OutPoint);
@ -413,7 +414,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_insert_update_claim)
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName1, val));
BOOST_CHECK(val.outPoint == tx1OutPoint);
// Verify updates to the best claim get inserted immediately, and others don't.
AddToMempool(tx3);
@ -434,7 +435,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_insert_update_claim)
//FlushStateToDisk();
CCoinsViewCache coins(pcoinsTip);
CClaimTrieCache trieCache(pclaimTrie);
CClaimTrieUpdateBuffer trieCache(pclaimTrie);
CBlockIndex* pindexState = chainActive.Tip();
CValidationState state;
CBlockIndex* pindex;
@ -456,7 +457,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_insert_update_claim)
BOOST_CHECK(ReadBlockFromDisk(block, pindex, Params().GetConsensus()));
BOOST_CHECK(ConnectBlock(block, state, pindex, coins, trieCache));
}
// Roll back the last block, make sure tx1 and tx7 are put back in the trie
BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back()));
@ -472,7 +473,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_insert_update_claim)
BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back()));
blocks_to_invalidate.pop_back();
BOOST_CHECK(!pclaimTrie->getInfoForName(sName1, val));
BOOST_CHECK(pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->getMerkleHash() == hash0);
@ -481,7 +482,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_insert_update_claim)
// Test undoing a claim before the claim gets into the trie
// Put tx1 in the chain, then advance a few blocks.
AddToMempool(tx1);
BOOST_CHECK(CreateBlocks(1, 2));
@ -491,7 +492,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_insert_update_claim)
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(CreateBlocks(10, 1));
// Put tx7 in the chain, verify it goes into the queue
AddToMempool(tx7);
@ -547,35 +548,35 @@ BOOST_AUTO_TEST_CASE(claimtrie_insert_update_claim)
blocks_to_invalidate.push_back(chainActive.Tip()->GetBlockHash());
BOOST_CHECK(CreateBlocks(5, 1));
// Put tx2 into the chain, and then advance a few blocks but not far enough for it to get into the trie
AddToMempool(tx2);
BOOST_CHECK(CreateBlocks(1, 2));
BOOST_CHECK(pclaimTrie->haveClaimInQueue(sName2, tx2OutPoint, nThrowaway));
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(!pclaimTrie->queueEmpty());
BOOST_CHECK(CreateBlocks(3, 1));
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(!pclaimTrie->queueEmpty());
// Spend tx2 with tx4, and then advance to where tx2 would be inserted into the trie and verify it hasn't happened
AddToMempool(tx4);
BOOST_CHECK(CreateBlocks(1, 2));
blocks_to_invalidate.push_back(chainActive.Tip()->GetBlockHash());
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(CreateBlocks(5, 1));
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(!pclaimTrie->haveClaim(sName2, tx2OutPoint));
@ -584,16 +585,16 @@ BOOST_AUTO_TEST_CASE(claimtrie_insert_update_claim)
BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back()));
blocks_to_invalidate.pop_back();
BOOST_CHECK(CreateBlocks(1, 1));
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(!pclaimTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->haveClaimInQueue(sName2, tx2OutPoint, nThrowaway));
BOOST_CHECK(CreateBlocks(2, 1));
BOOST_CHECK(pclaimTrie->haveClaim(sName2, tx2OutPoint));
BOOST_CHECK(!pclaimTrie->empty());
@ -605,7 +606,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_insert_update_claim)
// Test undoing a spend which involves a claim in the trie
// spend tx2, which is in the trie, with tx4
AddToMempool(tx4);
BOOST_CHECK(CreateBlocks(1, 2));
@ -616,7 +617,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_insert_update_claim)
BOOST_CHECK(!pclaimTrie->haveClaim(sName2, tx2OutPoint));
// undo spending tx2 with tx4, and verify tx2 is back in the trie
BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back()));
blocks_to_invalidate.pop_back();
BOOST_CHECK(!pclaimTrie->empty());
@ -626,7 +627,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_insert_update_claim)
BOOST_CHECK(pclaimTrie->haveClaim(sName2, tx2OutPoint));
// roll back to the beginning
BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back()));
blocks_to_invalidate.pop_back();
BOOST_CHECK(pclaimTrie->empty());
@ -657,7 +658,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_insert_update_claim)
// move forward some, but not far enough for the claim to get into the trie
BOOST_CHECK(CreateBlocks(2, 1));
// update the original claim (tx3 spends tx1)
AddToMempool(tx3);
@ -732,28 +733,28 @@ BOOST_AUTO_TEST_CASE(claimtrie_insert_update_claim)
BOOST_CHECK(val.outPoint == tx1OutPoint);
// update the original claim (tx3 spends tx1)
AddToMempool(tx3);
BOOST_CHECK(CreateBlocks(1, 2));
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName1, val));
BOOST_CHECK(val.outPoint == tx3OutPoint);
// spend the update (tx6 spends tx3)
AddToMempool(tx6);
BOOST_CHECK(CreateBlocks(1, 2));
blocks_to_invalidate.push_back(chainActive.Tip()->GetBlockHash());
BOOST_CHECK(pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
// undo spending the update (undo tx6 spending tx3)
BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back()));
blocks_to_invalidate.pop_back();
BOOST_CHECK(!pclaimTrie->empty());
@ -764,14 +765,14 @@ BOOST_AUTO_TEST_CASE(claimtrie_insert_update_claim)
// Test having two updates to a claim in the same transaction
// Add both txouts (tx8 spends tx3)
AddToMempool(tx8);
BOOST_CHECK(CreateBlocks(1, 2));
blocks_to_invalidate.push_back(chainActive.Tip()->GetBlockHash());
// ensure txout 0 made it into the trie and txout 1 did not
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(!pclaimTrie->queueEmpty());
@ -852,9 +853,9 @@ BOOST_AUTO_TEST_CASE(claimtrie_insert_update_claim)
// update it
AddToMempool(tx11);
BOOST_CHECK(CreateBlocks(1, 2));
blocks_to_invalidate.push_back(chainActive.Tip()->GetBlockHash());
BOOST_CHECK(!pclaimTrie->haveClaimInQueue(sName1, tx11OutPoint, nThrowaway));
@ -878,7 +879,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_insert_update_claim)
BOOST_CHECK(pclaimTrie->queueEmpty());
// make sure tx10 would have gotten into the trie, then run tests again
BOOST_CHECK(CreateBlocks(10, 1));
BOOST_CHECK(!pclaimTrie->haveClaim(sName1, tx10OutPoint));
@ -986,7 +987,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_claim_expiration)
std::vector<unsigned char> vchValue(sValue.begin(), sValue.end());
std::vector<CTransaction> coinbases;
BOOST_CHECK(CreateCoinbases(2, coinbases));
CMutableTransaction tx1 = BuildTransaction(coinbases[0]);
@ -996,14 +997,14 @@ BOOST_AUTO_TEST_CASE(claimtrie_claim_expiration)
CMutableTransaction tx2 = BuildTransaction(tx1);
tx2.vout[0].scriptPubKey = CScript() << OP_TRUE;
COutPoint tx2OutPoint(tx2.GetHash(), 0);
CMutableTransaction tx3 = BuildTransaction(coinbases[1]);
tx3.vout[0].scriptPubKey = CScript() << OP_CLAIM_NAME << vchName << vchValue << OP_2DROP << OP_DROP << OP_TRUE;
tx3.vout[0].nValue = tx1.vout[0].nValue >> 1;
COutPoint tx3OutPoint(tx3.GetHash(), 0);
int nThrowaway;
std::vector<uint256> blocks_to_invalidate;
// set expiration time to 200 blocks after the block is created
@ -1021,7 +1022,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_claim_expiration)
BOOST_CHECK(!pclaimTrie->expirationQueueEmpty());
// advance until the expiration event occurs. verify the expiration event occurs on time.
BOOST_CHECK(CreateBlocks(100, 1));
blocks_to_invalidate.push_back(chainActive.Tip()->GetBlockHash());
@ -1037,7 +1038,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_claim_expiration)
BOOST_CHECK(pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->expirationQueueEmpty());
// roll forward a bit and then roll back to before the expiration event. verify the claim is reinserted. verify the expiration event is scheduled again.
BOOST_CHECK(CreateBlocks(100, 1));
@ -1051,9 +1052,9 @@ BOOST_AUTO_TEST_CASE(claimtrie_claim_expiration)
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(!pclaimTrie->expirationQueueEmpty());
// advance until the expiration event occurs. verify the expiration event occurs on time.
BOOST_CHECK(CreateBlocks(1, 1));
blocks_to_invalidate.push_back(chainActive.Tip()->GetBlockHash());
@ -1062,13 +1063,13 @@ BOOST_AUTO_TEST_CASE(claimtrie_claim_expiration)
BOOST_CHECK(pclaimTrie->expirationQueueEmpty());
// roll back to before the expiration event. verify the claim is reinserted. verify the expiration event is scheduled again.
BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back()));
blocks_to_invalidate.pop_back();
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(!pclaimTrie->expirationQueueEmpty());
// roll back some more.
BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back()));
@ -1078,7 +1079,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_claim_expiration)
BOOST_CHECK(!pclaimTrie->expirationQueueEmpty());
// spend the claim. verify the expiration event is removed.
AddToMempool(tx2);
BOOST_CHECK(CreateBlocks(1, 2));
@ -1087,17 +1088,17 @@ BOOST_AUTO_TEST_CASE(claimtrie_claim_expiration)
BOOST_CHECK(pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->expirationQueueEmpty());
// roll back the spend. verify the expiration event is returned.
BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back()));
blocks_to_invalidate.pop_back();
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(!pclaimTrie->expirationQueueEmpty());
// advance until the expiration event occurs. verify the event occurs on time.
BOOST_CHECK(CreateBlocks(100, 1));
BOOST_CHECK(!pclaimTrie->empty());
@ -1190,7 +1191,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_claim_expiration)
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(!pclaimTrie->queueEmpty());
BOOST_CHECK(!pclaimTrie->expirationQueueEmpty());
// advance until tx3 is valid, ensure tx1 is winning
BOOST_CHECK(CreateBlocks(4, 1));
@ -1201,7 +1202,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_claim_expiration)
BOOST_CHECK(CreateBlocks(1, 1));
blocks_to_invalidate.push_back(chainActive.Tip()->GetBlockHash());
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(!pclaimTrie->expirationQueueEmpty());
@ -1379,7 +1380,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims)
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(!pclaimTrie->queueEmpty());
BOOST_CHECK(CreateBlocks(1, 1));
blocks_to_invalidate.push_back(chainActive.Tip()->GetBlockHash());
@ -1391,12 +1392,12 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims)
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
BOOST_CHECK(val.outPoint == tx1OutPoint);
// spend tx3
AddToMempool(tx6);
BOOST_CHECK(CreateBlocks(1, 2));
blocks_to_invalidate.push_back(chainActive.Tip()->GetBlockHash());
@ -1409,7 +1410,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims)
BOOST_CHECK(pclaimTrie->supportQueueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
BOOST_CHECK(val.outPoint == tx2OutPoint);
// unspend tx3, verify tx1 regains control
BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back()));
@ -1438,13 +1439,13 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims)
BOOST_CHECK(val.outPoint == tx7OutPoint);
// roll back to before tx7 is inserted, verify tx1 has control
BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back()));
blocks_to_invalidate.pop_back();
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
BOOST_CHECK(val.outPoint == tx1OutPoint);
// roll back to before tx2 is valid
BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back()));
@ -1513,7 +1514,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims)
BOOST_CHECK(CreateBlocks(1, 3));
blocks_to_invalidate.push_back(chainActive.Tip()->GetBlockHash());
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->supportEmpty());
@ -1601,7 +1602,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims)
// advance until tx3 is valid again
BOOST_CHECK(CreateBlocks(1, 1));
BOOST_CHECK(!pclaimTrie->supportEmpty());
BOOST_CHECK(pclaimTrie->supportQueueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
@ -1666,24 +1667,24 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims2)
int nThrowaway;
CClaimValue val;
std::vector<uint256> blocks_to_invalidate;
// Test 2: create 1 LBC claim (tx1), create 5 LBC claim (tx2), create 5 LBC support (tx3)
// Verify that tx1 loses control when tx2 becomes valid, and then tx1 gains control when tx3 becomes valid
// Then, verify that tx2 regains control when A) tx3 is spent and B) tx3 is undone
AddToMempool(tx1);
BOOST_CHECK(CreateBlocks(1, 2));
blocks_to_invalidate.push_back(chainActive.Tip()->GetBlockHash());
BOOST_CHECK(pcoinsTip->HaveCoins(tx1.GetHash()));
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->supportEmpty());
BOOST_CHECK(pclaimTrie->supportQueueEmpty());
// advance a few blocks
BOOST_CHECK(CreateBlocks(4, 1));
// put tx2 into the blockchain
@ -1874,7 +1875,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims2)
BOOST_CHECK(CreateBlocks(1, 2));
blocks_to_invalidate.push_back(chainActive.Tip()->GetBlockHash());
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->supportEmpty());
@ -1900,7 +1901,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims2)
BOOST_CHECK(val.outPoint == tx2OutPoint);
// advance some
BOOST_CHECK(CreateBlocks(5, 1));
// insert tx3 into the block chain
@ -1908,7 +1909,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims2)
AddToMempool(tx3);
BOOST_CHECK(CreateBlocks(1, 2));
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(!pclaimTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->supportEmpty());
@ -1920,7 +1921,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims2)
BOOST_CHECK(CreateBlocks(4, 1));
BOOST_CHECK(CreateBlocks(1, 1));
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->supportEmpty());
@ -1933,7 +1934,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims2)
BOOST_CHECK(CreateBlocks(10, 1));
BOOST_CHECK(CreateBlocks(1, 1));
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(!pclaimTrie->supportEmpty());
@ -1945,7 +1946,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims2)
BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back()));
blocks_to_invalidate.pop_back();
BOOST_CHECK(pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->supportEmpty());
@ -1966,11 +1967,11 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims2)
BOOST_CHECK(pclaimTrie->supportQueueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
BOOST_CHECK(val.outPoint == tx1OutPoint);
// advance a few blocks
BOOST_CHECK(CreateBlocks(5, 1));
// insert tx2 into the blockchain
AddToMempool(tx2);
@ -1983,7 +1984,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims2)
BOOST_CHECK(pclaimTrie->supportQueueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
BOOST_CHECK(val.outPoint == tx1OutPoint);
// advance some, insert tx3
BOOST_CHECK(CreateBlocks(2, 1));
@ -1998,7 +1999,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims2)
BOOST_CHECK(pclaimTrie->supportQueueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
BOOST_CHECK(val.outPoint == tx1OutPoint);
// advance until tx2 is valid
BOOST_CHECK(CreateBlocks(2, 1));
@ -2011,7 +2012,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims2)
BOOST_CHECK(pclaimTrie->supportQueueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
BOOST_CHECK(val.outPoint == tx1OutPoint);
// spend tx1
AddToMempool(tx4);
@ -2025,7 +2026,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims2)
BOOST_CHECK(pclaimTrie->supportQueueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
BOOST_CHECK(val.outPoint == tx2OutPoint);
// undo spend of tx1
BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back()));
@ -2037,7 +2038,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims2)
BOOST_CHECK(pclaimTrie->supportQueueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
BOOST_CHECK(val.outPoint == tx1OutPoint);
// roll all the way back
BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back()));
@ -2047,7 +2048,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims2)
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->supportEmpty());
BOOST_CHECK(pclaimTrie->supportQueueEmpty());
// Test 7: create 1 LBC claim (tx1), wait till valid, create 5 LBC support (tx3), spend tx1
// Verify name trie is empty
@ -2061,7 +2062,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims2)
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->supportEmpty());
BOOST_CHECK(pclaimTrie->supportQueueEmpty());
// insert tx3 into blockchain
AddToMempool(tx3);
@ -2072,7 +2073,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims2)
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(!pclaimTrie->supportEmpty());
BOOST_CHECK(pclaimTrie->supportQueueEmpty());
// spent tx1
AddToMempool(tx4);
@ -2088,7 +2089,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims2)
BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back()));
blocks_to_invalidate.pop_back();
BOOST_CHECK(pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->supportEmpty());
@ -2161,9 +2162,9 @@ BOOST_AUTO_TEST_CASE(claimtrie_invalid_claimid)
// Create a 5 LBC claim (tx2)
AddToMempool(tx2);
BOOST_CHECK(CreateBlocks(1, 2));
BOOST_CHECK(pcoinsTip->HaveCoins(tx2.GetHash()));
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(!pclaimTrie->queueEmpty());
@ -2176,13 +2177,13 @@ BOOST_AUTO_TEST_CASE(claimtrie_invalid_claimid)
BOOST_CHECK(pcoinsTip->HaveCoins(tx3.GetHash()));
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->queueEmpty());
// Verify it's not in the claim trie
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
BOOST_CHECK(val.outPoint == tx1OutPoint);
BOOST_CHECK(!pclaimTrie->haveClaim(sName, tx4OutPoint));
// Update the tx with the bogus claimId
@ -2349,7 +2350,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_expiring_supports)
BOOST_CHECK(CreateBlocks(1, 1));
blocks_to_invalidate.push_back(chainActive.Tip()->GetBlockHash());
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->supportEmpty());
@ -2372,7 +2373,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_expiring_supports)
// redo the block, make sure it expires again
BOOST_CHECK(CreateBlocks(1, 1));
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(pclaimTrie->supportEmpty());
@ -2382,7 +2383,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_expiring_supports)
// roll back some, spend the support, and make sure nothing unexpected
// happens at the time the support should have expired
BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back()));
blocks_to_invalidate.pop_back();
@ -2414,7 +2415,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_expiring_supports)
BOOST_CHECK(pclaimTrie->supportQueueEmpty());
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
BOOST_CHECK(val.outPoint == tx2OutPoint);
//undo the spend, and make sure it still expires on time
BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back()));
@ -2466,7 +2467,7 @@ BOOST_AUTO_TEST_CASE(claimtrienode_serialize_unserialize)
CClaimTrieNode n1;
CClaimTrieNode n2;
CClaimValue throwaway;
ss << n1;
ss >> n2;
BOOST_CHECK(n1 == n2);
@ -2613,7 +2614,7 @@ BOOST_AUTO_TEST_CASE(claimtrievalue_proof)
std::string sName1("a");
std::string sValue1("testa");
std::string sName2("abc");
std::string sValue2("testabc");
@ -2648,15 +2649,15 @@ BOOST_AUTO_TEST_CASE(claimtrievalue_proof)
CMutableTransaction tx1 = BuildTransaction(coinbases[0]);
tx1.vout[0].scriptPubKey = CScript() << OP_CLAIM_NAME << vchName1 << vchValue1 << OP_2DROP << OP_DROP << OP_TRUE;
COutPoint tx1OutPoint(tx1.GetHash(), 0);
CMutableTransaction tx2 = BuildTransaction(coinbases[1]);
tx2.vout[0].scriptPubKey = CScript() << OP_CLAIM_NAME << vchName2 << vchValue2 << OP_2DROP << OP_DROP << OP_TRUE;
COutPoint tx2OutPoint(tx2.GetHash(), 0);
CMutableTransaction tx3 = BuildTransaction(coinbases[2]);
tx3.vout[0].scriptPubKey = CScript() << OP_CLAIM_NAME << vchName3 << vchValue3 << OP_2DROP << OP_DROP << OP_TRUE;
COutPoint tx3OutPoint(tx3.GetHash(), 0);
CMutableTransaction tx4 = BuildTransaction(coinbases[3]);
tx4.vout[0].scriptPubKey = CScript() << OP_CLAIM_NAME << vchName4 << vchValue4 << OP_2DROP << OP_DROP << OP_TRUE;
COutPoint tx4OutPoint(tx4.GetHash(), 0);
@ -2691,7 +2692,7 @@ BOOST_AUTO_TEST_CASE(claimtrievalue_proof)
BOOST_CHECK(pclaimTrie->getInfoForName(sName4, val));
BOOST_CHECK(val.outPoint == tx4OutPoint);
CClaimTrieCache cache(pclaimTrie);
CClaimTrieUpdateBuffer cache(pclaimTrie);
CClaimTrieProof proof;
@ -2722,15 +2723,15 @@ BOOST_AUTO_TEST_CASE(claimtrievalue_proof)
proof = cache.getProofForName(sName7);
BOOST_CHECK(verify_proof(proof, chainActive.Tip()->hashClaimTrie, sName7));
BOOST_CHECK(proof.hasValue == false);
AddToMempool(tx5);
BOOST_CHECK(CreateBlocks(1, 2));
BOOST_CHECK(pclaimTrie->getInfoForName(sName7, val));
BOOST_CHECK(val.outPoint == tx5OutPoint);
cache = CClaimTrieCache(pclaimTrie);
cache = CClaimTrieUpdateBuffer(pclaimTrie);
proof = cache.getProofForName(sName1);
BOOST_CHECK(verify_proof(proof, chainActive.Tip()->hashClaimTrie, sName1));
@ -2765,7 +2766,7 @@ BOOST_AUTO_TEST_CASE(claimtrievalue_proof)
BOOST_CHECK(pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->queueEmpty());
BOOST_CHECK(blocks_to_invalidate.empty());
}
// Check that blocks with bogus calimtrie hash is rejected
@ -2783,7 +2784,7 @@ BOOST_AUTO_TEST_CASE(bogus_claimtrie_hash)
std::vector<CTransaction> coinbases;
BOOST_CHECK(CreateCoinbases(3, coinbases));
int orig_chain_height = chainActive.Height();
CMutableTransaction tx1 = BuildTransaction(coinbases[0]);
@ -2801,14 +2802,14 @@ BOOST_AUTO_TEST_CASE(bogus_claimtrie_hash)
CMutableTransaction txCoinbase(pblockTemp->block.vtx[0]);
txCoinbase.vin[0].scriptSig = CScript() << CScriptNum(chainActive.Height());
txCoinbase.vout[0].nValue = GetBlockSubsidy(chainActive.Height() + 1, Params().GetConsensus());
pblockTemp->block.vtx[0] = CTransaction(txCoinbase);
pblockTemp->block.hashMerkleRoot = BlockMerkleRoot(pblockTemp->block);
//create bogus hash
pblockTemp->block.vtx[0] = CTransaction(txCoinbase);
pblockTemp->block.hashMerkleRoot = BlockMerkleRoot(pblockTemp->block);
//create bogus hash
uint256 bogusHashClaimTrie;
bogusHashClaimTrie.SetHex("aaa");
pblockTemp->block.hashClaimTrie = bogusHashClaimTrie;
bogusHashClaimTrie.SetHex("aaa");
pblockTemp->block.hashClaimTrie = bogusHashClaimTrie;
for (int i = 0; ; ++i)
{
pblockTemp->block.nNonce = i;
@ -2819,7 +2820,7 @@ BOOST_AUTO_TEST_CASE(bogus_claimtrie_hash)
}
CValidationState state;
bool success = ProcessNewBlock(state, Params(), NULL, &pblockTemp->block, true, NULL);
// will process , but will not be connected
// will process , but will not be connected
BOOST_CHECK(success);
BOOST_CHECK(state.IsValid());
BOOST_CHECK(pblockTemp->block.GetHash() != chainActive.Tip()->GetBlockHash());

View file

@ -3,24 +3,25 @@
#include "uint256.h"
#include "test/test_bitcoin.h"
#include "claimtrieupdatebuffer.h"
#include <boost/test/unit_test.hpp>
using namespace std;
class CClaimTrieCacheTest : public CClaimTrieCache {
class CClaimTrieCacheTest : public CClaimTrieUpdateBuffer {
public:
CClaimTrieCacheTest(CClaimTrie* base):
CClaimTrieCache(base, false){}
CClaimTrieUpdateBuffer(base, false){}
bool recursiveComputeMerkleHash(CClaimTrieNode* tnCurrent,
std::string sPos) const
{
return CClaimTrieCache::recursiveComputeMerkleHash(tnCurrent, sPos);
return CClaimTrieUpdateBuffer::recursiveComputeMerkleHash(tnCurrent, sPos);
}
bool recursivePruneName(CClaimTrieNode* tnCurrent, unsigned int nPos, std::string sName, bool* pfNullified)
{
return CClaimTrieCache::recursivePruneName(tnCurrent,nPos,sName, pfNullified);
return CClaimTrieUpdateBuffer::recursivePruneName(tnCurrent,nPos,sName, pfNullified);
}
int cacheSize()
{