Code refactor #291
6 changed files with 625 additions and 668 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -119,3 +119,5 @@ contrib/devtools/split-debug.sh
|
|||
|
||||
.idea
|
||||
cmake-build-*/
|
||||
|
||||
compile_commands\.json
|
||||
|
|
1050
src/claimtrie.cpp
1050
src/claimtrie.cpp
File diff suppressed because it is too large
Load diff
153
src/claimtrie.h
153
src/claimtrie.h
|
@ -39,9 +39,7 @@ struct CClaimValue
|
|||
int nHeight;
|
||||
int nValidAtHeight;
|
||||
|
||||
CClaimValue()
|
||||
{
|
||||
}
|
||||
CClaimValue() = default;
|
||||
|
||||
CClaimValue(const COutPoint& outPoint, const uint160& claimId, CAmount nAmount, int nHeight, int nValidAtHeight)
|
||||
: outPoint(outPoint), claimId(claimId), nAmount(nAmount), nEffectiveAmount(nAmount), nHeight(nHeight), nValidAtHeight(nValidAtHeight)
|
||||
|
@ -97,9 +95,7 @@ struct CSupportValue
|
|||
int nHeight;
|
||||
int nValidAtHeight;
|
||||
|
||||
CSupportValue()
|
||||
{
|
||||
}
|
||||
CSupportValue() = default;
|
||||
|
||||
CSupportValue(const COutPoint& outPoint, const uint160& supportedClaimId, CAmount nAmount, int nHeight, int nValidAtHeight)
|
||||
: outPoint(outPoint), supportedClaimId(supportedClaimId), nAmount(nAmount), nHeight(nHeight), nValidAtHeight(nValidAtHeight)
|
||||
|
@ -197,9 +193,7 @@ struct COutPointHeightType
|
|||
COutPoint outPoint;
|
||||
int nHeight;
|
||||
|
||||
COutPointHeightType()
|
||||
{
|
||||
}
|
||||
COutPointHeightType() = default;
|
||||
|
||||
COutPointHeightType(const COutPoint& outPoint, int nHeight)
|
||||
: outPoint(outPoint), nHeight(nHeight)
|
||||
|
@ -222,9 +216,7 @@ struct CNameOutPointHeightType
|
|||
COutPoint outPoint;
|
||||
int nHeight;
|
||||
|
||||
CNameOutPointHeightType()
|
||||
{
|
||||
}
|
||||
CNameOutPointHeightType() = default;
|
||||
|
||||
CNameOutPointHeightType(std::string name, const COutPoint& outPoint, int nHeight)
|
||||
: name(std::move(name)), outPoint(outPoint), nHeight(nHeight)
|
||||
|
@ -247,15 +239,18 @@ struct CNameOutPointType
|
|||
std::string name;
|
||||
COutPoint outPoint;
|
||||
|
||||
CNameOutPointType()
|
||||
{
|
||||
}
|
||||
CNameOutPointType() = default;
|
||||
|
||||
CNameOutPointType(std::string name, const COutPoint& outPoint)
|
||||
: name(std::move(name)), outPoint(outPoint)
|
||||
{
|
||||
}
|
||||
|
||||
bool operator==(const CNameOutPointType& other) const
|
||||
{
|
||||
return name == other.name && outPoint == other.outPoint;
|
||||
}
|
||||
|
||||
ADD_SERIALIZE_METHODS;
|
||||
|
||||
template <typename Stream, typename Operation>
|
||||
|
@ -268,6 +263,13 @@ struct CNameOutPointType
|
|||
|
||||
struct CClaimIndexElement
|
||||
{
|
||||
CClaimIndexElement() = default;
|
||||
|
||||
CClaimIndexElement(std::string name, CClaimValue claim)
|
||||
: name(std::move(name)), claim(std::move(claim))
|
||||
{
|
||||
}
|
||||
|
||||
ADD_SERIALIZE_METHODS;
|
||||
|
||||
template <typename Stream, typename Operation>
|
||||
|
@ -288,8 +290,8 @@ struct CClaimsForNameType
|
|||
int nLastTakeoverHeight;
|
||||
std::string name;
|
||||
|
||||
CClaimsForNameType(claimEntryType claims, supportEntryType supports, int nLastTakeoverHeight, const std::string& name)
|
||||
: claims(std::move(claims)), supports(std::move(supports)), nLastTakeoverHeight(nLastTakeoverHeight), name(name)
|
||||
CClaimsForNameType(claimEntryType claims, supportEntryType supports, int nLastTakeoverHeight, std::string name)
|
||||
: claims(std::move(claims)), supports(std::move(supports)), nLastTakeoverHeight(nLastTakeoverHeight), name(std::move(name))
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -322,9 +324,8 @@ public:
|
|||
friend class CClaimTrieCacheNormalizationFork;
|
||||
};
|
||||
|
||||
class CClaimTrieProofNode
|
||||
struct CClaimTrieProofNode
|
||||
{
|
||||
public:
|
||||
CClaimTrieProofNode(std::vector<std::pair<unsigned char, uint256>> children, bool hasValue, const uint256& valHash)
|
||||
: children(std::move(children)), hasValue(hasValue), valHash(valHash)
|
||||
{
|
||||
|
@ -340,12 +341,9 @@ public:
|
|||
uint256 valHash;
|
||||
};
|
||||
|
||||
class CClaimTrieProof
|
||||
struct CClaimTrieProof
|
||||
{
|
||||
public:
|
||||
CClaimTrieProof()
|
||||
{
|
||||
}
|
||||
CClaimTrieProof() = default;
|
||||
|
||||
CClaimTrieProof(std::vector<CClaimTrieProofNode> nodes, bool hasValue, const COutPoint& outPoint, int nHeightOfLastTakeover)
|
||||
: nodes(std::move(nodes)), hasValue(hasValue), outPoint(outPoint), nHeightOfLastTakeover(nHeightOfLastTakeover)
|
||||
|
@ -363,12 +361,13 @@ public:
|
|||
int nHeightOfLastTakeover;
|
||||
};
|
||||
|
||||
typedef std::pair<std::string, CClaimValue> claimQueueEntryType;
|
||||
typedef std::vector<claimQueueEntryType> claimQueueRowType;
|
||||
template <typename T>
|
||||
using queueEntryType = std::pair<std::string, T>;
|
||||
|
||||
typedef std::vector<queueEntryType<CClaimValue>> claimQueueRowType;
|
||||
typedef std::map<int, claimQueueRowType> claimQueueType;
|
||||
|
||||
typedef std::pair<std::string, CSupportValue> supportQueueEntryType;
|
||||
typedef std::vector<supportQueueEntryType> supportQueueRowType;
|
||||
typedef std::vector<queueEntryType<CSupportValue>> supportQueueRowType;
|
||||
typedef std::map<int, supportQueueRowType> supportQueueType;
|
||||
|
||||
typedef std::vector<COutPointHeightType> queueNameRowType;
|
||||
|
@ -389,7 +388,7 @@ public:
|
|||
virtual ~CClaimTrieCacheBase() = default;
|
||||
|
||||
uint256 getMerkleHash();
|
||||
bool checkConsistency(int minimumHeight = 1) const;
|
||||
bool checkConsistency() const;
|
||||
|
||||
bool getClaimById(const uint160& claimId, std::string& name, CClaimValue& claim) const;
|
||||
|
||||
|
@ -450,8 +449,8 @@ public:
|
|||
|
||||
protected:
|
||||
CClaimTrie* base;
|
||||
CClaimTrie cache;
|
||||
std::unordered_set<std::string> namesToCheckForTakeover;
|
||||
CClaimTrie nodesToAddOrUpdate; // nodes pulled in from base (and possibly modified thereafter), written to base on flush
|
||||
std::unordered_set<std::string> namesToCheckForTakeover; // takeover numbers are updated on increment
|
||||
|
||||
uint256 recursiveComputeMerkleHash(CClaimTrie::iterator& it);
|
||||
|
||||
|
@ -461,29 +460,21 @@ protected:
|
|||
virtual bool insertSupportIntoMap(const std::string& name, const CSupportValue& support, bool fCheckTakeover);
|
||||
virtual bool removeSupportFromMap(const std::string& name, const COutPoint& outPoint, CSupportValue& support, bool fCheckTakeover);
|
||||
|
||||
virtual bool addClaimToQueues(const std::string& name, const CClaimValue& claim);
|
||||
|
||||
virtual bool addSupportToQueues(const std::string& name, const CSupportValue& support);
|
||||
virtual bool removeSupportFromQueue(const std::string& name, const COutPoint& outPoint, CSupportValue& support);
|
||||
|
||||
virtual std::string adjustNameForValidHeight(const std::string& name, int validHeight) const;
|
||||
|
||||
void addToExpirationQueue(int nExpirationHeight, CNameOutPointType& entry);
|
||||
void removeFromExpirationQueue(const std::string& name, const COutPoint& outPoint, int nHeight);
|
||||
|
||||
void addSupportToExpirationQueue(int nExpirationHeight, CNameOutPointType& entry);
|
||||
void removeSupportFromExpirationQueue(const std::string& name, const COutPoint& outPoint, int nHeight);
|
||||
|
||||
supportEntryType getSupportsForName(const std::string& name) const;
|
||||
|
||||
int getDelayForName(const std::string& name);
|
||||
virtual int getDelayForName(const std::string& name, const uint160& claimId);
|
||||
int getDelayForName(const std::string& name) const;
|
||||
virtual int getDelayForName(const std::string& name, const uint160& claimId) const;
|
||||
|
||||
CClaimTrie::iterator cacheData(const std::string& name, bool create = true);
|
||||
|
||||
bool getLastTakeoverForName(const std::string& name, uint160& claimId, int& takeoverHeight) const;
|
||||
|
||||
int getNumBlocksOfContinuousOwnership(const std::string& name);
|
||||
int getNumBlocksOfContinuousOwnership(const std::string& name) const;
|
||||
|
||||
void reactivateClaim(const expirationQueueRowType& row, int height, bool increment);
|
||||
void reactivateSupport(const expirationQueueRowType& row, int height, bool increment);
|
||||
|
||||
expirationQueueType expirationQueueCache;
|
||||
expirationQueueType supportExpirationQueueCache;
|
||||
|
@ -498,16 +489,16 @@ private:
|
|||
|
||||
bool fRequireTakeoverHeights;
|
||||
|
||||
claimQueueType claimQueueCache;
|
||||
claimQueueType claimQueueCache; // claims not active yet: to be written to disk on flush
|
||||
queueNameType claimQueueNameCache;
|
||||
supportQueueType supportQueueCache;
|
||||
supportQueueType supportQueueCache; // supports not active yet: to be written to disk on flush
|
||||
queueNameType supportQueueNameCache;
|
||||
claimIndexElementListType claimsToAdd;
|
||||
claimIndexClaimListType claimsToDelete;
|
||||
claimIndexElementListType claimsToAddToByIdIndex; // written to index on flush
|
||||
claimIndexClaimListType claimsToDeleteFromByIdIndex;
|
||||
|
||||
std::unordered_map<std::string, supportEntryType> cacheSupports;
|
||||
std::unordered_set<std::string> nodesToDelete;
|
||||
std::unordered_set<std::string> alreadyCachedNodes;
|
||||
std::unordered_map<std::string, supportEntryType> supportCache; // to be added/updated to base (and disk) on flush
|
||||
std::unordered_set<std::string> nodesToDelete; // to be removed from base (and disk) on flush
|
||||
std::unordered_set<std::string> nodesAlreadyCached; // set of nodes already pulled into cache from base
|
||||
std::unordered_map<std::string, bool> takeoverWorkaround;
|
||||
std::unordered_set<std::string> removalWorkaround;
|
||||
|
||||
|
@ -520,14 +511,51 @@ private:
|
|||
void markAsDirty(const std::string& name, bool fCheckTakeover);
|
||||
bool removeSupport(const std::string& name, const COutPoint& outPoint, int nHeight, int& nValidAtHeight, bool fCheckTakeover);
|
||||
bool removeClaim(const std::string& name, const COutPoint& outPoint, int nHeight, int& nValidAtHeight, bool fCheckTakeover);
|
||||
bool removeClaimFromQueue(const std::string& name, const COutPoint& outPoint, CClaimValue& claim);
|
||||
|
||||
typename claimQueueType::value_type* getQueueCacheRow(int nHeight, bool createIfNotExists = false);
|
||||
template <typename T>
|
||||
std::pair<const int, std::vector<queueEntryType<T>>>* getQueueCacheRow(int nHeight, bool createIfNotExists = false);
|
||||
|
||||
template <typename T>
|
||||
typename queueNameType::value_type* getQueueCacheNameRow(const std::string& name, bool createIfNotExists = false);
|
||||
|
||||
template <typename T>
|
||||
typename expirationQueueType::value_type* getExpirationQueueCacheRow(int nHeight, bool createIfNotExists = false);
|
||||
typename supportQueueType::value_type* getSupportQueueCacheRow(int nHeight, bool createIfNotExists = false);
|
||||
typename queueNameType::value_type* getSupportQueueCacheNameRow(const std::string& name, bool createIfNotExists = false);
|
||||
typename expirationQueueType::value_type* getSupportExpirationQueueCacheRow(int nHeight, bool createIfNotExists = false);
|
||||
|
||||
template <typename T>
|
||||
bool haveInQueue(const std::string& name, const COutPoint& outPoint, int& nValidAtHeight);
|
||||
|
||||
template <typename T>
|
||||
T add(const std::string& name, const COutPoint& outPoint, const uint160& claimId, CAmount nAmount, int nHeight);
|
||||
|
||||
template <typename T>
|
||||
bool remove(T& value, const std::string& name, const COutPoint& outPoint, int nHeight, int& nValidAtHeight, bool fCheckTakeover = false);
|
||||
|
||||
template <typename T>
|
||||
bool addToQueue(const std::string& name, const T& value);
|
||||
|
||||
template <typename T>
|
||||
bool removeFromQueue(const std::string& name, const COutPoint& outPoint, T& value);
|
||||
|
||||
template <typename T>
|
||||
bool addToCache(const std::string& name, const T& value, bool fCheckTakeover = false);
|
||||
|
||||
template <typename T>
|
||||
bool removeFromCache(const std::string& name, const COutPoint& outPoint, T& value, bool fCheckTakeover = false);
|
||||
|
||||
template <typename T>
|
||||
bool undoSpend(const std::string& name, const T& value, int nValidAtHeight);
|
||||
|
||||
template <typename T>
|
||||
void undoIncrement(insertUndoType& insertUndo, std::vector<queueEntryType<T>>& expireUndo, std::set<T>* deleted = nullptr);
|
||||
|
||||
template <typename T>
|
||||
void undoDecrement(insertUndoType& insertUndo, std::vector<queueEntryType<T>>& expireUndo, std::vector<CClaimIndexElement>* added = nullptr, std::set<T>* deleted = nullptr);
|
||||
|
||||
template <typename T>
|
||||
void undoIncrement(const std::string& name, insertUndoType& insertUndo, std::vector<queueEntryType<T>>& expireUndo);
|
||||
|
||||
template <typename T>
|
||||
void reactivate(const expirationQueueRowType& row, int height, bool increment);
|
||||
|
||||
// for unit test
|
||||
friend struct ClaimTrieChainFixture;
|
||||
|
@ -558,8 +586,6 @@ public:
|
|||
private:
|
||||
int nExpirationTime;
|
||||
bool forkForExpirationChange(bool increment);
|
||||
void removeAndAddSupportToExpirationQueue(expirationQueueRowType& row, int height, bool increment);
|
||||
void removeAndAddToExpirationQueue(expirationQueueRowType& row, int height, bool increment);
|
||||
};
|
||||
|
||||
class CClaimTrieCacheNormalizationFork : public CClaimTrieCacheExpirationFork
|
||||
|
@ -592,16 +618,13 @@ public:
|
|||
CClaimsForNameType getClaimsForName(const std::string& name) const override;
|
||||
|
||||
protected:
|
||||
bool insertClaimIntoTrie(const std::string& name, const CClaimValue& claim, bool fCheckTakeover = false) override;
|
||||
bool removeClaimFromTrie(const std::string& name, const COutPoint& outPoint, CClaimValue& claim, bool fCheckTakeover = false) override;
|
||||
bool insertClaimIntoTrie(const std::string& name, const CClaimValue& claim, bool fCheckTakeover) override;
|
||||
bool removeClaimFromTrie(const std::string& name, const COutPoint& outPoint, CClaimValue& claim, bool fCheckTakeover) override;
|
||||
|
||||
bool insertSupportIntoMap(const std::string& name, const CSupportValue& support, bool fCheckTakeover) override;
|
||||
bool removeSupportFromMap(const std::string& name, const COutPoint& outPoint, CSupportValue& support, bool fCheckTakeover) override;
|
||||
|
||||
int getDelayForName(const std::string& name, const uint160& claimId) override;
|
||||
|
||||
bool addClaimToQueues(const std::string& name, const CClaimValue& claim) override;
|
||||
bool addSupportToQueues(const std::string& name, const CSupportValue& support) override;
|
||||
int getDelayForName(const std::string& name, const uint160& claimId) const override;
|
||||
|
||||
std::string adjustNameForValidHeight(const std::string& name, int validHeight) const override;
|
||||
|
||||
|
|
|
@ -49,30 +49,6 @@ void CClaimTrieCacheExpirationFork::expirationForkActive(int nHeight, bool incre
|
|||
forkForExpirationChange(increment);
|
||||
}
|
||||
|
||||
void CClaimTrieCacheExpirationFork::removeAndAddToExpirationQueue(expirationQueueRowType& row, int height, bool increment)
|
||||
{
|
||||
for (auto e = row.begin(); e != row.end(); ++e) {
|
||||
// remove and insert with new expiration time
|
||||
removeFromExpirationQueue(e->name, e->outPoint, height);
|
||||
int extend_expiration = Params().GetConsensus().nExtendedClaimExpirationTime - Params().GetConsensus().nOriginalClaimExpirationTime;
|
||||
int new_expiration_height = increment ? height + extend_expiration : height - extend_expiration;
|
||||
CNameOutPointType entry(e->name, e->outPoint);
|
||||
addToExpirationQueue(new_expiration_height, entry);
|
||||
}
|
||||
}
|
||||
|
||||
void CClaimTrieCacheExpirationFork::removeAndAddSupportToExpirationQueue(expirationQueueRowType& row, int height, bool increment)
|
||||
{
|
||||
for (auto e = row.begin(); e != row.end(); ++e) {
|
||||
// remove and insert with new expiration time
|
||||
removeSupportFromExpirationQueue(e->name, e->outPoint, height);
|
||||
int extend_expiration = Params().GetConsensus().nExtendedClaimExpirationTime - Params().GetConsensus().nOriginalClaimExpirationTime;
|
||||
int new_expiration_height = increment ? height + extend_expiration : height - extend_expiration;
|
||||
CNameOutPointType entry(e->name, e->outPoint);
|
||||
addSupportToExpirationQueue(new_expiration_height, entry);
|
||||
}
|
||||
}
|
||||
|
||||
bool CClaimTrieCacheExpirationFork::forkForExpirationChange(bool increment)
|
||||
{
|
||||
/*
|
||||
|
@ -93,14 +69,14 @@ bool CClaimTrieCacheExpirationFork::forkForExpirationChange(bool increment)
|
|||
if (key.first == EXP_QUEUE_ROW) {
|
||||
expirationQueueRowType row;
|
||||
if (pcursor->GetValue(row)) {
|
||||
removeAndAddToExpirationQueue(row, height, increment);
|
||||
reactivateClaim(row, height, increment);
|
||||
} else {
|
||||
return error("%s(): error reading expiration queue rows from disk", __func__);
|
||||
}
|
||||
} else if (key.first == SUPPORT_EXP_QUEUE_ROW) {
|
||||
expirationQueueRowType row;
|
||||
if (pcursor->GetValue(row)) {
|
||||
removeAndAddSupportToExpirationQueue(row, height, increment);
|
||||
reactivateSupport(row, height, increment);
|
||||
} else {
|
||||
return error("%s(): error reading support expiration queue rows from disk", __func__);
|
||||
}
|
||||
|
@ -190,14 +166,13 @@ bool CClaimTrieCacheNormalizationFork::normalizeAllNamesInTrieIfNecessary(insert
|
|||
continue;
|
||||
|
||||
auto supports = getSupportsForName(it.key());
|
||||
for (auto& support : supports) {
|
||||
for (auto support : supports) {
|
||||
// if it's already going to expire just skip it
|
||||
if (support.nHeight + expirationTime() <= nNextHeight)
|
||||
continue;
|
||||
|
||||
CSupportValue removed;
|
||||
assert(removeSupportFromMap(it.key(), support.outPoint, removed, false));
|
||||
expireSupportUndo.emplace_back(it.key(), removed);
|
||||
assert(removeSupportFromMap(it.key(), support.outPoint, support, false));
|
||||
expireSupportUndo.emplace_back(it.key(), support);
|
||||
assert(insertSupportIntoMap(normalized, support, false));
|
||||
insertSupportUndo.emplace_back(it.key(), support.outPoint, -1);
|
||||
}
|
||||
|
@ -205,17 +180,16 @@ bool CClaimTrieCacheNormalizationFork::normalizeAllNamesInTrieIfNecessary(insert
|
|||
namesToCheckForTakeover.insert(normalized);
|
||||
|
||||
auto cached = cacheData(it.key(), false);
|
||||
if (!cached || cached->claims.empty())
|
||||
if (!cached || cached->empty())
|
||||
continue;
|
||||
|
||||
for (auto& claim : it->claims) {
|
||||
for (auto claim : it->claims) {
|
||||
if (claim.nHeight + expirationTime() <= nNextHeight)
|
||||
continue;
|
||||
|
||||
![]() Actually it isn't, because we know that we remove same support then re-add it under new name, no changes in value. Actually it isn't, because we know that we remove same support then re-add it under new name, no changes in value.
![]() But better to iterate through copy rather than reference. But better to iterate through copy rather than reference.
|
||||
CClaimValue removed;
|
||||
assert(removeClaimFromTrie(it.key(), claim.outPoint, removed, false));
|
||||
removeUndo.emplace_back(it.key(), removed);
|
||||
assert(insertClaimIntoTrie(normalized, claim, false));
|
||||
assert(removeClaimFromTrie(it.key(), claim.outPoint, claim, false));
|
||||
removeUndo.emplace_back(it.key(), claim);
|
||||
assert(insertClaimIntoTrie(normalized, claim, true));
|
||||
insertUndo.emplace_back(it.key(), claim.outPoint, -1);
|
||||
}
|
||||
|
||||
|
@ -255,21 +229,11 @@ CClaimsForNameType CClaimTrieCacheNormalizationFork::getClaimsForName(const std:
|
|||
return CClaimTrieCacheExpirationFork::getClaimsForName(normalizeClaimName(name));
|
||||
}
|
||||
|
||||
int CClaimTrieCacheNormalizationFork::getDelayForName(const std::string& name, const uint160& claimId)
|
||||
int CClaimTrieCacheNormalizationFork::getDelayForName(const std::string& name, const uint160& claimId) const
|
||||
{
|
||||
return CClaimTrieCacheExpirationFork::getDelayForName(normalizeClaimName(name), claimId);
|
||||
}
|
||||
|
||||
bool CClaimTrieCacheNormalizationFork::addClaimToQueues(const std::string& name, const CClaimValue& claim)
|
||||
{
|
||||
return CClaimTrieCacheExpirationFork::addClaimToQueues(normalizeClaimName(name, claim.nValidAtHeight > Params().GetConsensus().nNormalizedNameForkHeight), claim);
|
||||
}
|
||||
|
||||
bool CClaimTrieCacheNormalizationFork::addSupportToQueues(const std::string& name, const CSupportValue& support)
|
||||
{
|
||||
return CClaimTrieCacheExpirationFork::addSupportToQueues(normalizeClaimName(name, support.nValidAtHeight > Params().GetConsensus().nNormalizedNameForkHeight), support);
|
||||
}
|
||||
|
||||
std::string CClaimTrieCacheNormalizationFork::adjustNameForValidHeight(const std::string& name, int validHeight) const
|
||||
{
|
||||
return normalizeClaimName(name, validHeight > Params().GetConsensus().nNormalizedNameForkHeight);
|
||||
|
|
|
@ -356,11 +356,11 @@ struct ClaimTrieChainFixture: public CClaimTrieCacheExpirationFork
|
|||
|
||||
bool supportEmpty()
|
||||
{
|
||||
for (const auto& entry: cacheSupports) {
|
||||
for (const auto& entry: supportCache) {
|
||||
if (!entry.second.empty())
|
||||
return false;
|
||||
}
|
||||
return cacheSupports.empty() && keyTypeEmpty<std::string>(SUPPORT);
|
||||
return supportCache.empty() && keyTypeEmpty<std::string>(SUPPORT);
|
||||
}
|
||||
|
||||
bool supportQueueEmpty()
|
||||
|
|
|
@ -23,22 +23,22 @@ public:
|
|||
|
||||
void insert(const std::string& key, CClaimTrieData&& data)
|
||||
{
|
||||
cache.insert(key, std::move(data));
|
||||
nodesToAddOrUpdate.insert(key, std::move(data));
|
||||
}
|
||||
|
||||
bool erase(const std::string& key)
|
||||
{
|
||||
return cache.erase(key);
|
||||
return nodesToAddOrUpdate.erase(key);
|
||||
}
|
||||
|
||||
int cacheSize()
|
||||
{
|
||||
return cache.height();
|
||||
return nodesToAddOrUpdate.height();
|
||||
}
|
||||
|
||||
CClaimTrie::iterator getCache(const std::string& key)
|
||||
{
|
||||
return cache.find(key);
|
||||
return nodesToAddOrUpdate.find(key);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -124,7 +124,7 @@ BOOST_AUTO_TEST_CASE(merkle_hash_multiple_test)
|
|||
|
||||
BOOST_CHECK(!pclaimTrie->empty());
|
||||
BOOST_CHECK_EQUAL(ntState.getMerkleHash(), hash2);
|
||||
BOOST_CHECK(ntState.checkConsistency(0));
|
||||
BOOST_CHECK(ntState.checkConsistency());
|
||||
|
||||
CClaimTrieCacheTest ntState1(pclaimTrie);
|
||||
ntState1.removeClaimFromTrie(std::string("test"), tx1OutPoint, unused, true);
|
||||
|
@ -144,7 +144,7 @@ BOOST_AUTO_TEST_CASE(merkle_hash_multiple_test)
|
|||
|
||||
BOOST_CHECK(!pclaimTrie->empty());
|
||||
BOOST_CHECK_EQUAL(ntState2.getMerkleHash(), hash3);
|
||||
BOOST_CHECK(ntState2.checkConsistency(0));
|
||||
BOOST_CHECK(ntState2.checkConsistency());
|
||||
|
||||
CClaimTrieCacheTest ntState3(pclaimTrie);
|
||||
ntState3.insertClaimIntoTrie(std::string("test"), CClaimValue(tx1OutPoint, hash160, 50, 100, 200), true);
|
||||
|
@ -152,7 +152,7 @@ BOOST_AUTO_TEST_CASE(merkle_hash_multiple_test)
|
|||
ntState3.flush();
|
||||
BOOST_CHECK(!pclaimTrie->empty());
|
||||
BOOST_CHECK_EQUAL(ntState3.getMerkleHash(), hash4);
|
||||
BOOST_CHECK(ntState3.checkConsistency(0));
|
||||
BOOST_CHECK(ntState3.checkConsistency());
|
||||
|
||||
CClaimTrieCacheTest ntState4(pclaimTrie);
|
||||
ntState4.removeClaimFromTrie(std::string("abab"), tx6OutPoint, unused, true);
|
||||
|
@ -160,7 +160,7 @@ BOOST_AUTO_TEST_CASE(merkle_hash_multiple_test)
|
|||
ntState4.flush();
|
||||
BOOST_CHECK(!pclaimTrie->empty());
|
||||
BOOST_CHECK_EQUAL(ntState4.getMerkleHash(), hash2);
|
||||
BOOST_CHECK(ntState4.checkConsistency(0));
|
||||
BOOST_CHECK(ntState4.checkConsistency());
|
||||
|
||||
CClaimTrieCacheTest ntState5(pclaimTrie);
|
||||
ntState5.removeClaimFromTrie(std::string("test"), tx3OutPoint, unused, true);
|
||||
|
@ -169,7 +169,7 @@ BOOST_AUTO_TEST_CASE(merkle_hash_multiple_test)
|
|||
ntState5.flush();
|
||||
BOOST_CHECK(!pclaimTrie->empty());
|
||||
BOOST_CHECK_EQUAL(ntState5.getMerkleHash(), hash2);
|
||||
BOOST_CHECK(ntState5.checkConsistency(0));
|
||||
BOOST_CHECK(ntState5.checkConsistency());
|
||||
|
||||
CClaimTrieCacheTest ntState6(pclaimTrie);
|
||||
ntState6.insertClaimIntoTrie(std::string("test"), CClaimValue(tx3OutPoint, hash160, 50, 101, 201), true);
|
||||
|
@ -178,7 +178,7 @@ BOOST_AUTO_TEST_CASE(merkle_hash_multiple_test)
|
|||
ntState6.flush();
|
||||
BOOST_CHECK(!pclaimTrie->empty());
|
||||
BOOST_CHECK_EQUAL(ntState6.getMerkleHash(), hash2);
|
||||
BOOST_CHECK(ntState6.checkConsistency(0));
|
||||
BOOST_CHECK(ntState6.checkConsistency());
|
||||
|
||||
CClaimTrieCacheTest ntState7(pclaimTrie);
|
||||
ntState7.removeClaimFromTrie(std::string("test"), tx3OutPoint, unused, true);
|
||||
|
@ -190,7 +190,7 @@ BOOST_AUTO_TEST_CASE(merkle_hash_multiple_test)
|
|||
ntState7.flush();
|
||||
BOOST_CHECK(pclaimTrie->empty());
|
||||
BOOST_CHECK_EQUAL(ntState7.getMerkleHash(), hash0);
|
||||
BOOST_CHECK(ntState7.checkConsistency(0));
|
||||
BOOST_CHECK(ntState7.checkConsistency());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(basic_insertion_info_test)
|
||||
|
@ -337,13 +337,13 @@ BOOST_AUTO_TEST_CASE(trie_stays_consistent_test)
|
|||
BOOST_CHECK(cache.insertClaimIntoTrie(name, value, false));
|
||||
|
||||
cache.flush();
|
||||
BOOST_CHECK(cache.checkConsistency(0));
|
||||
BOOST_CHECK(cache.checkConsistency());
|
||||
|
||||
for (auto& name: names) {
|
||||
CClaimValue temp;
|
||||
BOOST_CHECK(cache.removeClaimFromTrie(name, COutPoint(), temp, false));
|
||||
cache.flush();
|
||||
BOOST_CHECK(cache.checkConsistency(0));
|
||||
BOOST_CHECK(cache.checkConsistency());
|
||||
}
|
||||
BOOST_CHECK_EQUAL(trie.height(), 0);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue
This has a bug in that it modifies the item we're about to insert. That other variable was there on purpose.