Complete cache trie by merging base one in #300
4 changed files with 27 additions and 7 deletions
|
@ -579,6 +579,13 @@ bool CClaimTrieCacheBase::ReadFromDisk(const CBlockIndex* tip)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CClaimTrieCacheBase::mergeTrieIntoCache()
|
||||||
|
{
|
||||||
|
for (auto it = base->cbegin(); it != base->cend(); ++it)
|
||||||
|
if (!nodesAlreadyCached.count(it.key()))
|
||||||
|
nodesToAddOrUpdate.copy(it);
|
||||||
|
}
|
||||||
|
|
||||||
CClaimTrieCacheBase::CClaimTrieCacheBase(CClaimTrie* base) : base(base)
|
CClaimTrieCacheBase::CClaimTrieCacheBase(CClaimTrie* base) : base(base)
|
||||||
{
|
{
|
||||||
assert(base);
|
assert(base);
|
||||||
|
@ -721,11 +728,9 @@ bool CClaimTrieCacheBase::removeClaimFromTrie(const std::string& name, const COu
|
||||||
it->reorderClaims(supports);
|
it->reorderClaims(supports);
|
||||||
} else {
|
} else {
|
||||||
// in case we pull a child into our spot; we will then need their kids for hash
|
// in case we pull a child into our spot; we will then need their kids for hash
|
||||||
bool hasChild = false;
|
bool hasChild = it.hasChildren();
|
||||||
for (auto& child: it.children()) {
|
for (auto& child: it.children())
|
||||||
hasChild = true;
|
|
||||||
cacheData(child.key(), false);
|
cacheData(child.key(), false);
|
||||||
}
|
|
||||||
|
|
||||||
nodesToAddOrUpdate.erase(name);
|
nodesToAddOrUpdate.erase(name);
|
||||||
nodesToDelete.insert(name);
|
nodesToDelete.insert(name);
|
||||||
|
|
|
@ -445,6 +445,8 @@ public:
|
||||||
CClaimTrie::const_iterator end() const;
|
CClaimTrie::const_iterator end() const;
|
||||||
CClaimTrie::const_iterator find(const std::string& name) const;
|
CClaimTrie::const_iterator find(const std::string& name) const;
|
||||||
|
|
||||||
|
void mergeTrieIntoCache();
|
||||||
|
|
||||||
void dumpToLog(CClaimTrie::const_iterator it, bool diffFromBase = true) const;
|
void dumpToLog(CClaimTrie::const_iterator it, bool diffFromBase = true) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -182,6 +182,7 @@ static UniValue getclaimsintrie(const JSONRPCRequest& request)
|
||||||
if (!request.params.empty()) {
|
if (!request.params.empty()) {
|
||||||
CBlockIndex* blockIndex = BlockHashIndex(ParseHashV(request.params[0], "blockhash (optional parameter 1)"));
|
CBlockIndex* blockIndex = BlockHashIndex(ParseHashV(request.params[0], "blockhash (optional parameter 1)"));
|
||||||
RollBackTo(blockIndex, coinsCache, trieCache);
|
RollBackTo(blockIndex, coinsCache, trieCache);
|
||||||
|
trieCache.mergeTrieIntoCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
UniValue ret(UniValue::VARR);
|
UniValue ret(UniValue::VARR);
|
||||||
|
@ -266,6 +267,7 @@ static UniValue getnamesintrie(const JSONRPCRequest& request)
|
||||||
if (!request.params.empty()) {
|
if (!request.params.empty()) {
|
||||||
CBlockIndex* blockIndex = BlockHashIndex(ParseHashV(request.params[0], "blockhash (optional parameter 1)"));
|
CBlockIndex* blockIndex = BlockHashIndex(ParseHashV(request.params[0], "blockhash (optional parameter 1)"));
|
||||||
RollBackTo(blockIndex, coinsCache, trieCache);
|
RollBackTo(blockIndex, coinsCache, trieCache);
|
||||||
|
trieCache.mergeTrieIntoCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
UniValue ret(UniValue::VARR);
|
UniValue ret(UniValue::VARR);
|
||||||
|
|
|
@ -3908,11 +3908,17 @@ BOOST_AUTO_TEST_CASE(getnamesintrie_test)
|
||||||
{
|
{
|
||||||
ClaimTrieChainFixture fixture;
|
ClaimTrieChainFixture fixture;
|
||||||
std::string sName1("test");
|
std::string sName1("test");
|
||||||
|
std::string sName2("test2");
|
||||||
|
std::string sName3("guest");
|
||||||
std::string sValue1("test");
|
std::string sValue1("test");
|
||||||
|
|
||||||
|
fixture.MakeClaim(fixture.GetCoinbase(), sName1, sValue1, 42);
|
||||||
|
fixture.MakeClaim(fixture.GetCoinbase(), sName2, sValue1, 42);
|
||||||
|
fixture.IncrementBlocks(1);
|
||||||
|
|
||||||
uint256 blockHash = chainActive.Tip()->GetBlockHash();
|
uint256 blockHash = chainActive.Tip()->GetBlockHash();
|
||||||
|
|
||||||
fixture.MakeClaim(fixture.GetCoinbase(), sName1, sValue1, 42);
|
fixture.MakeClaim(fixture.GetCoinbase(), sName3, sValue1, 42);
|
||||||
fixture.IncrementBlocks(1);
|
fixture.IncrementBlocks(1);
|
||||||
|
|
||||||
rpcfn_type getnamesintrie = tableRPC["getnamesintrie"]->actor;
|
rpcfn_type getnamesintrie = tableRPC["getnamesintrie"]->actor;
|
||||||
|
@ -3920,12 +3926,17 @@ BOOST_AUTO_TEST_CASE(getnamesintrie_test)
|
||||||
req.params = UniValue(UniValue::VARR);
|
req.params = UniValue(UniValue::VARR);
|
||||||
|
|
||||||
UniValue results = getnamesintrie(req);
|
UniValue results = getnamesintrie(req);
|
||||||
BOOST_CHECK_EQUAL(results.size(), 1U);
|
BOOST_CHECK_EQUAL(results.size(), 3U);
|
||||||
|
BOOST_CHECK_EQUAL(results[0].get_str(), sName3);
|
||||||
|
BOOST_CHECK_EQUAL(results[1].get_str(), sName1);
|
||||||
|
BOOST_CHECK_EQUAL(results[2].get_str(), sName2);
|
||||||
|
|
||||||
req.params.push_back(blockHash.GetHex());
|
req.params.push_back(blockHash.GetHex());
|
||||||
|
|
||||||
results = getnamesintrie(req);
|
results = getnamesintrie(req);
|
||||||
BOOST_CHECK_EQUAL(results.size(), 0U);
|
BOOST_CHECK_EQUAL(results.size(), 2U);
|
||||||
|
BOOST_CHECK_EQUAL(results[0].get_str(), sName1);
|
||||||
|
BOOST_CHECK_EQUAL(results[1].get_str(), sName2);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(getvalueforname_test)
|
BOOST_AUTO_TEST_CASE(getvalueforname_test)
|
||||||
|
|
Loading…
Reference in a new issue