]> Git Repo - VerusCoin.git/commitdiff
Add anchor to output of getblock
authorJack Grigg <[email protected]>
Fri, 10 Mar 2017 07:04:14 +0000 (20:04 +1300)
committerJack Grigg <[email protected]>
Fri, 10 Mar 2017 07:09:40 +0000 (20:09 +1300)
Closes #2164.

src/chain.h
src/main.cpp
src/rpcblockchain.cpp

index 2abb23c5abb009a3ef42049b6b69bc5e90a3681d..e4076e00aa97b3ec488a380fa76e8df10930f54c 100644 (file)
@@ -141,6 +141,9 @@ public:
     //! The anchor for the tree state up to the start of this block
     uint256 hashAnchor;
 
+    //! (memory only) The anchor for the tree state up to the end of this block
+    uint256 hashAnchorEnd;
+
     //! block header
     int nVersion;
     uint256 hashMerkleRoot;
@@ -167,6 +170,7 @@ public:
         nChainTx = 0;
         nStatus = 0;
         hashAnchor = uint256();
+        hashAnchorEnd = uint256();
         nSequenceId = 0;
 
         nVersion       = 0;
index 52e8ca4c6a8334c4fe008b65c93eaa32c36f7273..a430ec275467511f7757ef9e2231c24cfa531e6c 100644 (file)
@@ -2061,6 +2061,8 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
             // Before the genesis block, there was an empty tree
             ZCIncrementalMerkleTree tree;
             pindex->hashAnchor = tree.root();
+            // The genesis block contained no JoinSplits
+            pindex->hashAnchorEnd = pindex->hashAnchor;
         }
         return true;
     }
@@ -2175,6 +2177,9 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
     }
 
     view.PushAnchor(tree);
+    if (!fJustCheck) {
+        pindex->hashAnchorEnd = tree.root();
+    }
     blockundo.old_tree_root = old_tree_root;
 
     int64_t nTime1 = GetTimeMicros(); nTimeConnect += nTime1 - nTimeStart;
@@ -3579,11 +3584,27 @@ bool static LoadBlockIndexDB()
     pblocktree->ReadFlag("txindex", fTxIndex);
     LogPrintf("%s: transaction index %s\n", __func__, fTxIndex ? "enabled" : "disabled");
 
+    // Fill in-memory data
+    BOOST_FOREACH(const PAIRTYPE(uint256, CBlockIndex*)& item, mapBlockIndex)
+    {
+        CBlockIndex* pindex = item.second;
+        // - This relationship will always be true even if pprev has multiple
+        //   children, because hashAnchor is technically a property of pprev,
+        //   not its children.
+        // - This will miss chain tips; we handle the best tip below, and other
+        //   tips will be handled by ConnectTip during a re-org.
+        if (pindex->pprev) {
+            pindex->pprev->hashAnchorEnd = pindex->hashAnchor;
+        }
+    }
+
     // Load pointer to end of best chain
     BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock());
     if (it == mapBlockIndex.end())
         return true;
     chainActive.SetTip(it->second);
+    // Set hashAnchorEnd for the end of best chain
+    it->second->hashAnchorEnd = pcoinsTip->GetBestAnchor();
 
     PruneBlockIndexCandidates();
 
index 24bff3f4888b9610ac9f01a6a1af9dd9525793ec..0936640c23b887d32f55784b19e267d7280e3ff1 100644 (file)
@@ -131,6 +131,7 @@ UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool tx
     result.push_back(Pair("bits", strprintf("%08x", block.nBits)));
     result.push_back(Pair("difficulty", GetDifficulty(blockindex)));
     result.push_back(Pair("chainwork", blockindex->nChainWork.GetHex()));
+    result.push_back(Pair("anchor", blockindex->hashAnchorEnd.GetHex()));
 
     if (blockindex->pprev)
         result.push_back(Pair("previousblockhash", blockindex->pprev->GetBlockHash().GetHex()));
This page took 0.038535 seconds and 4 git commands to generate.