fixed issue with invalid usage of trie's root node in cache
This commit is contained in:
parent
bed577d9cf
commit
0830074e15
4 changed files with 42 additions and 27 deletions
|
@ -1229,11 +1229,8 @@ uint256 CClaimTrieCache::getMerkleHash() const
|
||||||
}
|
}
|
||||||
if (dirty())
|
if (dirty())
|
||||||
{
|
{
|
||||||
nodeCacheType::iterator cachedNode = cache.find("");
|
CClaimTrieNode* root = getRoot();
|
||||||
if (cachedNode != cache.end())
|
recursiveComputeMerkleHash(root, "");
|
||||||
recursiveComputeMerkleHash(cachedNode->second, "");
|
|
||||||
else
|
|
||||||
recursiveComputeMerkleHash(&(base->root), "");
|
|
||||||
}
|
}
|
||||||
hashMapType::iterator ithash = cacheHashes.find("");
|
hashMapType::iterator ithash = cacheHashes.find("");
|
||||||
if (ithash != cacheHashes.end())
|
if (ithash != cacheHashes.end())
|
||||||
|
@ -1285,11 +1282,8 @@ bool CClaimTrieCache::getOriginalInfoForName(const std::string& name, CClaimValu
|
||||||
bool CClaimTrieCache::insertClaimIntoTrie(const std::string& name, CClaimValue claim, bool fCheckTakeover) const
|
bool CClaimTrieCache::insertClaimIntoTrie(const std::string& name, CClaimValue claim, bool fCheckTakeover) const
|
||||||
{
|
{
|
||||||
assert(base);
|
assert(base);
|
||||||
CClaimTrieNode* currentNode = &(base->root);
|
CClaimTrieNode* currentNode = getRoot();
|
||||||
nodeCacheType::iterator cachedNode;
|
nodeCacheType::iterator cachedNode;
|
||||||
cachedNode = cache.find("");
|
|
||||||
if (cachedNode != cache.end())
|
|
||||||
currentNode = cachedNode->second;
|
|
||||||
for (std::string::const_iterator itCur = name.begin(); itCur != name.end(); ++itCur)
|
for (std::string::const_iterator itCur = name.begin(); itCur != name.end(); ++itCur)
|
||||||
{
|
{
|
||||||
std::string sCurrentSubstring(name.begin(), itCur);
|
std::string sCurrentSubstring(name.begin(), itCur);
|
||||||
|
@ -1374,11 +1368,8 @@ bool CClaimTrieCache::insertClaimIntoTrie(const std::string& name, CClaimValue c
|
||||||
bool CClaimTrieCache::removeClaimFromTrie(const std::string& name, const COutPoint& outPoint, CClaimValue& claim, bool fCheckTakeover) const
|
bool CClaimTrieCache::removeClaimFromTrie(const std::string& name, const COutPoint& outPoint, CClaimValue& claim, bool fCheckTakeover) const
|
||||||
{
|
{
|
||||||
assert(base);
|
assert(base);
|
||||||
CClaimTrieNode* currentNode = &(base->root);
|
CClaimTrieNode* currentNode = getRoot();
|
||||||
nodeCacheType::iterator cachedNode;
|
nodeCacheType::iterator cachedNode;
|
||||||
cachedNode = cache.find("");
|
|
||||||
if (cachedNode != cache.end())
|
|
||||||
currentNode = cachedNode->second;
|
|
||||||
assert(currentNode != NULL); // If there is no root in either the trie or the cache, how can there be any names to remove?
|
assert(currentNode != NULL); // If there is no root in either the trie or the cache, how can there be any names to remove?
|
||||||
for (std::string::const_iterator itCur = name.begin(); itCur != name.end(); ++itCur)
|
for (std::string::const_iterator itCur = name.begin(); itCur != name.end(); ++itCur)
|
||||||
{
|
{
|
||||||
|
@ -1448,10 +1439,7 @@ bool CClaimTrieCache::removeClaimFromTrie(const std::string& name, const COutPoi
|
||||||
if (fCheckTakeover)
|
if (fCheckTakeover)
|
||||||
namesToCheckForTakeover.insert(name);
|
namesToCheckForTakeover.insert(name);
|
||||||
}
|
}
|
||||||
CClaimTrieNode* rootNode = &(base->root);
|
CClaimTrieNode* rootNode = getRoot();
|
||||||
cachedNode = cache.find("");
|
|
||||||
if (cachedNode != cache.end())
|
|
||||||
rootNode = cachedNode->second;
|
|
||||||
return recursivePruneName(rootNode, 0, name);
|
return recursivePruneName(rootNode, 0, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1752,12 +1740,7 @@ bool CClaimTrieCache::reorderTrieNode(const std::string& name, bool fCheckTakeov
|
||||||
cachedNode = cache.find(name);
|
cachedNode = cache.find(name);
|
||||||
if (cachedNode == cache.end())
|
if (cachedNode == cache.end())
|
||||||
{
|
{
|
||||||
CClaimTrieNode* currentNode;
|
CClaimTrieNode* currentNode = getRoot();
|
||||||
cachedNode = cache.find("");
|
|
||||||
if(cachedNode == cache.end())
|
|
||||||
currentNode = &(base->root);
|
|
||||||
else
|
|
||||||
currentNode = cachedNode->second;
|
|
||||||
for (std::string::const_iterator itCur = name.begin(); itCur != name.end(); ++itCur)
|
for (std::string::const_iterator itCur = name.begin(); itCur != name.end(); ++itCur)
|
||||||
{
|
{
|
||||||
std::string sCurrentSubstring(name.begin(), itCur);
|
std::string sCurrentSubstring(name.begin(), itCur);
|
||||||
|
@ -2575,7 +2558,7 @@ void CClaimTrieCache::recursiveFlattenTrie(const std::string& name, const CClaim
|
||||||
std::vector<namedNodeType> CClaimTrieCache::flattenTrie() const
|
std::vector<namedNodeType> CClaimTrieCache::flattenTrie() const
|
||||||
{
|
{
|
||||||
std::vector<namedNodeType> nodes;
|
std::vector<namedNodeType> nodes;
|
||||||
recursiveFlattenTrie("", &(base->root), nodes);
|
recursiveFlattenTrie("", getRoot(), nodes);
|
||||||
return nodes;
|
return nodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2652,7 +2635,7 @@ bool CClaimTrieCache::getInfoForName(const std::string& name, CClaimValue& claim
|
||||||
if (dirty())
|
if (dirty())
|
||||||
getMerkleHash();
|
getMerkleHash();
|
||||||
|
|
||||||
CClaimTrieNode* current = &(base->root);
|
CClaimTrieNode* current = getRoot();
|
||||||
nodeCacheType::const_iterator cachedNode;
|
nodeCacheType::const_iterator cachedNode;
|
||||||
|
|
||||||
for (std::string::const_iterator itName = name.begin(); current; ++itName) {
|
for (std::string::const_iterator itName = name.begin(); current; ++itName) {
|
||||||
|
@ -2678,7 +2661,7 @@ bool CClaimTrieCache::getProofForName(const std::string& name, CClaimTrieProof&
|
||||||
getMerkleHash();
|
getMerkleHash();
|
||||||
|
|
||||||
std::vector<CClaimTrieProofNode> nodes;
|
std::vector<CClaimTrieProofNode> nodes;
|
||||||
CClaimTrieNode* current = &(base->root);
|
CClaimTrieNode* current = getRoot();
|
||||||
nodeCacheType::const_iterator cachedNode;
|
nodeCacheType::const_iterator cachedNode;
|
||||||
bool fNameHasValue = false;
|
bool fNameHasValue = false;
|
||||||
COutPoint outPoint;
|
COutPoint outPoint;
|
||||||
|
|
|
@ -476,6 +476,12 @@ public:
|
||||||
bool flush();
|
bool flush();
|
||||||
bool dirty() const { return !dirtyHashes.empty(); }
|
bool dirty() const { return !dirtyHashes.empty(); }
|
||||||
|
|
||||||
|
CClaimTrieNode* getRoot() const
|
||||||
|
{
|
||||||
|
nodeCacheType::iterator iter = cache.find("");
|
||||||
|
return iter == cache.end() ? &(base->root) : iter->second;
|
||||||
|
}
|
||||||
|
|
||||||
bool addClaim(const std::string& name, const COutPoint& outPoint,
|
bool addClaim(const std::string& name, const COutPoint& outPoint,
|
||||||
uint160 claimId, CAmount nAmount, int nHeight) const;
|
uint160 claimId, CAmount nAmount, int nHeight) const;
|
||||||
bool undoAddClaim(const std::string& name, const COutPoint& outPoint,
|
bool undoAddClaim(const std::string& name, const COutPoint& outPoint,
|
||||||
|
|
|
@ -36,7 +36,7 @@ static CBlockIndex* BlockHashIndex(const uint256& blockHash)
|
||||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Block not in main chain");
|
throw JSONRPCError(RPC_INTERNAL_ERROR, "Block not in main chain");
|
||||||
|
|
||||||
if (chainActive.Tip()->nHeight > (pblockIndex->nHeight + MAX_RPC_BLOCK_DECREMENTS))
|
if (chainActive.Tip()->nHeight > (pblockIndex->nHeight + MAX_RPC_BLOCK_DECREMENTS))
|
||||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Block too deep to regenerate it");
|
throw JSONRPCError(RPC_INTERNAL_ERROR, "Block is too deep");
|
||||||
|
|
||||||
return pblockIndex;
|
return pblockIndex;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3165,6 +3165,32 @@ BOOST_AUTO_TEST_CASE(getclaimsintrie_test)
|
||||||
BOOST_CHECK(results[0]["name"].get_str() == sName1);
|
BOOST_CHECK(results[0]["name"].get_str() == sName1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(getclaimsintrie_test2)
|
||||||
|
{
|
||||||
|
ClaimTrieChainFixture fixture;
|
||||||
|
std::string sName1("test");
|
||||||
|
std::string sValue1("test");
|
||||||
|
|
||||||
|
uint256 blockHash = chainActive.Tip()->GetBlockHash();
|
||||||
|
|
||||||
|
rpcfn_type getclaimsintrie = tableRPC["getclaimsintrie"]->actor;
|
||||||
|
rpcfn_type getclaimtrie = tableRPC["getclaimtrie"]->actor;
|
||||||
|
UniValue params(UniValue::VARR);
|
||||||
|
params.push_back(blockHash.GetHex());
|
||||||
|
UniValue results = getclaimsintrie(params, false);
|
||||||
|
BOOST_CHECK(results.size() == 0U);
|
||||||
|
results = getclaimtrie(params, false);
|
||||||
|
BOOST_CHECK(results.size() == 1U);
|
||||||
|
|
||||||
|
fixture.IncrementBlocks(10);
|
||||||
|
fixture.MakeClaim(fixture.GetCoinbase(), sName1, sValue1, 42);
|
||||||
|
fixture.IncrementBlocks(10);
|
||||||
|
results = getclaimsintrie(params, false);
|
||||||
|
BOOST_CHECK(results.size() == 0U);
|
||||||
|
results = getclaimtrie(params, false);
|
||||||
|
BOOST_CHECK(results.size() == 1U);
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(getclaimtrie_test)
|
BOOST_AUTO_TEST_CASE(getclaimtrie_test)
|
||||||
{
|
{
|
||||||
ClaimTrieChainFixture fixture;
|
ClaimTrieChainFixture fixture;
|
||||||
|
|
Loading…
Add table
Reference in a new issue