Commit d02effc1 authored by Brannon King's avatar Brannon King
Browse files

added trie logging used for debugging

parent c123b774
......@@ -2566,4 +2566,46 @@ bool CClaimTrieCacheBase::getProofForName(const std::string& name, CClaimTriePro
proof = CClaimTrieProof(nodes, fNameHasValue, outPoint, nHeightOfLastTakeover);
return true;
\ No newline at end of file
void CClaimTrieCacheBase::dumpToLog() const {
class CClaimCallback : public CNodeCallback {
const CClaimTrieCacheBase* owner;
const hashMapType& cacheHashes;
const std::map<std::string, int>& cacheTakeoverHeights;
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))
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);
......@@ -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;
// Should be private: Do not use unless you know what you're doing.
CClaimTrieNode* addNodeToCache(const std::string& position, CClaimTrieNode* original) const;
......@@ -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 ...
return state.DoS(100,
error("ConnectBlock() : the merkle root of the claim trie does not match "
"(actual=%s vs block=%s)", trieCache.getMerkleHash().GetHex(),
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment