diff --git a/src/merkleblock.h b/src/merkleblock.h --- a/src/merkleblock.h +++ b/src/merkleblock.h @@ -84,7 +84,7 @@ */ void TraverseAndBuild(int height, unsigned int pos, const std::vector &vTxid, - const std::vector &vMatch); + const std::vector &vTxIdMask); /** * Recursive function that traverses tree nodes, consuming the bits and @@ -93,7 +93,7 @@ */ uint256 TraverseAndExtract(int height, unsigned int pos, unsigned int &nBitsUsed, unsigned int &nHashUsed, - std::vector &vMatch, + std::vector &vMatchingTxHashes, std::vector &vnIndex); public: @@ -127,7 +127,7 @@ * mask that selects a subset of them. */ CPartialMerkleTree(const std::vector &vTxid, - const std::vector &vMatch); + const std::vector &vTxIdMask); CPartialMerkleTree(); @@ -136,7 +136,7 @@ * their respective indices within the partial tree. Returns the merkle * root, or 0 in case of failure. */ - uint256 ExtractMatches(std::vector &vMatch, + uint256 ExtractMatches(std::vector &vMatchingTxHashes, std::vector &vnIndex); }; diff --git a/src/merkleblock.cpp b/src/merkleblock.cpp --- a/src/merkleblock.cpp +++ b/src/merkleblock.cpp @@ -12,44 +12,44 @@ CMerkleBlock::CMerkleBlock(const CBlock &block, CBloomFilter &filter) { header = block.GetBlockHeader(); - std::vector vMatch; + std::vector vTxIdMask; std::vector vHashes; - vMatch.reserve(block.vtx.size()); + vTxIdMask.reserve(block.vtx.size()); vHashes.reserve(block.vtx.size()); for (size_t i = 0; i < block.vtx.size(); i++) { const CTransaction *tx = block.vtx[i].get(); const uint256 &txid = tx->GetId(); if (filter.IsRelevantAndUpdate(*tx)) { - vMatch.push_back(true); + vTxIdMask.push_back(true); vMatchedTxn.push_back(std::make_pair(i, txid)); } else { - vMatch.push_back(false); + vTxIdMask.push_back(false); } vHashes.push_back(txid); } - txn = CPartialMerkleTree(vHashes, vMatch); + txn = CPartialMerkleTree(vHashes, vTxIdMask); } CMerkleBlock::CMerkleBlock(const CBlock &block, const std::set &txids) { header = block.GetBlockHeader(); - std::vector vMatch; + std::vector vTxIdMask; std::vector vHashes; - vMatch.reserve(block.vtx.size()); + vTxIdMask.reserve(block.vtx.size()); vHashes.reserve(block.vtx.size()); for (const auto &tx : block.vtx) { const TxId &txid = tx->GetId(); - vMatch.push_back(txids.count(txid)); + vTxIdMask.push_back(txids.count(txid)); vHashes.push_back(txid); } - txn = CPartialMerkleTree(vHashes, vMatch); + txn = CPartialMerkleTree(vHashes, vTxIdMask); } uint256 CPartialMerkleTree::CalcHash(int height, unsigned int pos, @@ -75,12 +75,12 @@ void CPartialMerkleTree::TraverseAndBuild(int height, unsigned int pos, const std::vector &vTxid, - const std::vector &vMatch) { + const std::vector &vTxIdMask) { // Determine whether this node is the parent of at least one matched txid. bool fParentOfMatch = false; for (unsigned int p = pos << height; p < (pos + 1) << height && p < nTransactions; p++) { - fParentOfMatch |= vMatch[p]; + fParentOfMatch |= vTxIdMask[p]; } // Store as flag bit. @@ -90,16 +90,16 @@ vHash.push_back(CalcHash(height, pos, vTxid)); } else { // Otherwise, don't store any hash, but descend into the subtrees. - TraverseAndBuild(height - 1, pos * 2, vTxid, vMatch); + TraverseAndBuild(height - 1, pos * 2, vTxid, vTxIdMask); if (pos * 2 + 1 < CalcTreeWidth(height - 1)) { - TraverseAndBuild(height - 1, pos * 2 + 1, vTxid, vMatch); + TraverseAndBuild(height - 1, pos * 2 + 1, vTxid, vTxIdMask); } } } uint256 CPartialMerkleTree::TraverseAndExtract( int height, unsigned int pos, unsigned int &nBitsUsed, - unsigned int &nHashUsed, std::vector &vMatch, + unsigned int &nHashUsed, std::vector &vMatchingTxHashes, std::vector &vnIndex) { if (nBitsUsed >= vBits.size()) { // Overflowed the bits array - failure @@ -119,7 +119,7 @@ const uint256 &hash = vHash[nHashUsed++]; // In case of height 0, we have a matched txid. if (height == 0 && fParentOfMatch) { - vMatch.push_back(hash); + vMatchingTxHashes.push_back(hash); vnIndex.push_back(pos); } return hash; @@ -127,11 +127,11 @@ // Otherwise, descend into the subtrees to extract matched txids and hashes. uint256 left = TraverseAndExtract(height - 1, pos * 2, nBitsUsed, nHashUsed, - vMatch, vnIndex), + vMatchingTxHashes, vnIndex), right; if (pos * 2 + 1 < CalcTreeWidth(height - 1)) { right = TraverseAndExtract(height - 1, pos * 2 + 1, nBitsUsed, - nHashUsed, vMatch, vnIndex); + nHashUsed, vMatchingTxHashes, vnIndex); if (right == left) { // The left and right branches should never be identical, as the // transaction hashes covered by them must each be unique. @@ -146,7 +146,7 @@ } CPartialMerkleTree::CPartialMerkleTree(const std::vector &vTxid, - const std::vector &vMatch) + const std::vector &vTxIdMask) : nTransactions(vTxid.size()), fBad(false) { // reset state vBits.clear(); @@ -159,14 +159,15 @@ } // traverse the partial tree - TraverseAndBuild(nHeight, 0, vTxid, vMatch); + TraverseAndBuild(nHeight, 0, vTxid, vTxIdMask); } CPartialMerkleTree::CPartialMerkleTree() : nTransactions(0), fBad(true) {} -uint256 CPartialMerkleTree::ExtractMatches(std::vector &vMatch, - std::vector &vnIndex) { - vMatch.clear(); +uint256 +CPartialMerkleTree::ExtractMatches(std::vector &vMatchingTxHashes, + std::vector &vnIndex) { + vMatchingTxHashes.clear(); // An empty set will not work if (nTransactions == 0) { @@ -195,8 +196,8 @@ // traverse the partial tree. unsigned int nBitsUsed = 0, nHashUsed = 0; - uint256 hashMerkleRoot = - TraverseAndExtract(nHeight, 0, nBitsUsed, nHashUsed, vMatch, vnIndex); + uint256 hashMerkleRoot = TraverseAndExtract( + nHeight, 0, nBitsUsed, nHashUsed, vMatchingTxHashes, vnIndex); // verify that no problems occurred during the tree traversal. if (fBad) {