added trie logging used for debugging

This commit is contained in:
Brannon King 2019-08-21 14:25:56 -06:00
parent c123b77419
commit d02effc12f
3 changed files with 55 additions and 2 deletions

View file

@ -2566,4 +2566,46 @@ bool CClaimTrieCacheBase::getProofForName(const std::string& name, CClaimTriePro
}
proof = CClaimTrieProof(nodes, fNameHasValue, outPoint, nHeightOfLastTakeover);
return true;
}
}
void CClaimTrieCacheBase::dumpToLog() const {
class CClaimCallback : public CNodeCallback {
const CClaimTrieCacheBase* owner;
const hashMapType& cacheHashes;
const std::map<std::string, int>& cacheTakeoverHeights;
public:
CClaimCallback(const CClaimTrieCacheBase* owner, const hashMapType& cacheHashes, const std::map<std::string, int>& cacheTakeoverHeights)
: owner(owner), cacheHashes(cacheHashes), cacheTakeoverHeights(cacheTakeoverHeights) {}
void visit(const std::string &name, const CClaimTrieNode *node) {
if (!owner->cacheContains(name))
return;
const nodeMapType& children = node->children;
if (children.size() == 1 && node->claims.empty())
return; // don't clutter output with interior nodes
hashMapType::const_iterator hit = cacheHashes.find(name);
uint256 hash = node->hash;
if (hit != cacheHashes.end())
hash = hit->second;
int takeover = node->nHeightOfLastTakeover;
std::map<std::string, int>::const_iterator hit2 = cacheTakeoverHeights.find(name);
if (hit2 != cacheTakeoverHeights.end())
takeover = hit2->second;
LogPrintf("%s, %s, hash: %s, take: %d, kids: %zu\n", name, HexStr(name.begin(), name.end()),
hash.ToString(), takeover, children.size());
for (std::vector<CClaimValue>::const_iterator it = node->claims.begin(); it != node->claims.end(); ++it)
LogPrintf(" claim: %s, %ld, %ld, %d, %d\n", it->claimId.ToString(), it->nAmount, it->nEffectiveAmount, it->nHeight, it->nValidAtHeight);
supportMapEntryType supports = owner->getSupports(name);
for (supportMapEntryType::const_iterator it = supports.begin(); it != supports.end(); ++it)
LogPrintf(" suprt: %s, %ld, %d, %d\n", it->supportedClaimId.ToString(), it->nAmount, it->nHeight, it->nValidAtHeight);
}
};
CClaimCallback cc(this, cacheHashes, cacheTakeoverHeights);
iterateTrie(cc);
}

View file

@ -544,6 +544,16 @@ public:
CAmount getEffectiveAmountForClaim(const std::string& name, const uint160& claimId, std::vector<CSupportValue>* supports = NULL) const;
CAmount getEffectiveAmountForClaim(const claimsForNameType& claims, const uint160& claimId, std::vector<CSupportValue>* supports = NULL) const;
bool cacheContains(const std::string& name) const { return cache.find(name) != cache.end(); }
supportMapEntryType getSupports(const std::string& name) const {
supportMapEntryType ret;
if (getSupportsForName(name, ret))
return ret;
return supportMapEntryType();
}
void dumpToLog() const;
protected:
// Should be private: Do not use unless you know what you're doing.
CClaimTrieNode* addNodeToCache(const std::string& position, CClaimTrieNode* original) const;

View file

@ -2740,7 +2740,8 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
assert(trieCache.incrementBlock(blockUndo.insertUndo, blockUndo.expireUndo, blockUndo.insertSupportUndo, blockUndo.expireSupportUndo, blockUndo.takeoverHeightUndo));
if (trieCache.getMerkleHash() != block.hashClaimTrie) {
if (trieCache.getMerkleHash() != block.hashClaimTrie) { // || pindex->nHeight == ... where we want to stop ...
trieCache.dumpToLog();
return state.DoS(100,
error("ConnectBlock() : the merkle root of the claim trie does not match "
"(actual=%s vs block=%s)", trieCache.getMerkleHash().GetHex(),