diff --git a/src/merkleblock.h b/src/merkleblock.h --- a/src/merkleblock.h +++ b/src/merkleblock.h @@ -76,14 +76,14 @@ * txid's themselves) */ uint256 CalcHash(int height, unsigned int pos, - const std::vector &vTxid); + const std::vector &vTxid); /** * Recursive function that traverses tree nodes, storing the data as bits * and hashes. */ void TraverseAndBuild(int height, unsigned int pos, - const std::vector &vTxid, + const std::vector &vTxid, const std::vector &vMatch); /** @@ -93,7 +93,7 @@ */ uint256 TraverseAndExtract(int height, unsigned int pos, unsigned int &nBitsUsed, unsigned int &nHashUsed, - std::vector &vMatch, + std::vector &vMatch, std::vector &vnIndex); public: @@ -126,7 +126,7 @@ * Construct a partial merkle tree from a list of transaction ids, and a * mask that selects a subset of them. */ - CPartialMerkleTree(const std::vector &vTxid, + CPartialMerkleTree(const std::vector &vTxid, const std::vector &vMatch); 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 &vMatch, std::vector &vnIndex); }; @@ -152,7 +152,7 @@ public: /** Public only for unit testing and relay testing (not relayed) */ - std::vector> vMatchedTxn; + std::vector> vMatchedTxn; /** * Create from a CBlock, filtering transactions according to filter. Note diff --git a/src/merkleblock.cpp b/src/merkleblock.cpp --- a/src/merkleblock.cpp +++ b/src/merkleblock.cpp @@ -13,14 +13,14 @@ header = block.GetBlockHeader(); std::vector vMatch; - std::vector vHashes; + std::vector vTxids; vMatch.reserve(block.vtx.size()); - vHashes.reserve(block.vtx.size()); + vTxids.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(); + const TxId &txid = tx->GetId(); if (filter.IsRelevantAndUpdate(*tx)) { vMatch.push_back(true); vMatchedTxn.push_back(std::make_pair(i, txid)); @@ -28,32 +28,32 @@ vMatch.push_back(false); } - vHashes.push_back(txid); + vTxids.push_back(txid); } - txn = CPartialMerkleTree(vHashes, vMatch); + txn = CPartialMerkleTree(vTxids, vMatch); } CMerkleBlock::CMerkleBlock(const CBlock &block, const std::set &txids) { header = block.GetBlockHeader(); std::vector vMatch; - std::vector vHashes; + std::vector vTxids; vMatch.reserve(block.vtx.size()); - vHashes.reserve(block.vtx.size()); + vTxids.reserve(block.vtx.size()); for (const auto &tx : block.vtx) { const TxId &txid = tx->GetId(); vMatch.push_back(txids.count(txid)); - vHashes.push_back(txid); + vTxids.push_back(txid); } - txn = CPartialMerkleTree(vHashes, vMatch); + txn = CPartialMerkleTree(vTxids, vMatch); } uint256 CPartialMerkleTree::CalcHash(int height, unsigned int pos, - const std::vector &vTxid) { + const std::vector &vTxid) { if (height == 0) { // hash at height 0 is the txids themself. return vTxid[pos]; @@ -74,7 +74,7 @@ } void CPartialMerkleTree::TraverseAndBuild(int height, unsigned int pos, - const std::vector &vTxid, + const std::vector &vTxid, const std::vector &vMatch) { // Determine whether this node is the parent of at least one matched txid. bool fParentOfMatch = false; @@ -99,7 +99,7 @@ uint256 CPartialMerkleTree::TraverseAndExtract( int height, unsigned int pos, unsigned int &nBitsUsed, - unsigned int &nHashUsed, std::vector &vMatch, + unsigned int &nHashUsed, std::vector &vMatch, 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); + vMatch.push_back(TxId(hash)); vnIndex.push_back(pos); } return hash; @@ -145,7 +145,7 @@ return Hash(BEGIN(left), END(left), BEGIN(right), END(right)); } -CPartialMerkleTree::CPartialMerkleTree(const std::vector &vTxid, +CPartialMerkleTree::CPartialMerkleTree(const std::vector &vTxid, const std::vector &vMatch) : nTransactions(vTxid.size()), fBad(false) { // reset state @@ -164,7 +164,7 @@ CPartialMerkleTree::CPartialMerkleTree() : nTransactions(0), fBad(true) {} -uint256 CPartialMerkleTree::ExtractMatches(std::vector &vMatch, +uint256 CPartialMerkleTree::ExtractMatches(std::vector &vMatch, std::vector &vnIndex) { vMatch.clear(); diff --git a/src/net_processing.cpp b/src/net_processing.cpp --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -1249,7 +1249,7 @@ // allows for us to provide duplicate txn here, // however we MUST always provide at least what the // remote peer needs. - typedef std::pair PairType; + typedef std::pair PairType; for (PairType &pair : merkleBlock.vMatchedTxn) { connman.PushMessage( pfrom, diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -393,7 +393,7 @@ UniValue res(UniValue::VARR); - std::vector vMatch; + std::vector vMatch; std::vector vIndex; if (merkleBlock.txn.ExtractMatches(vMatch, vIndex) != merkleBlock.header.hashMerkleRoot) { @@ -408,8 +408,8 @@ "Block not found in chain"); } - for (const uint256 &hash : vMatch) { - res.push_back(hash.GetHex()); + for (const TxId &txid : vMatch) { + res.push_back(txid.GetHex()); } return res; diff --git a/src/test/bloom_tests.cpp b/src/test/bloom_tests.cpp --- a/src/test/bloom_tests.cpp +++ b/src/test/bloom_tests.cpp @@ -377,14 +377,14 @@ BOOST_CHECK(merkleBlock.header.GetHash() == block.GetHash()); BOOST_CHECK(merkleBlock.vMatchedTxn.size() == 1); - std::pair pair = merkleBlock.vMatchedTxn[0]; + std::pair pair = merkleBlock.vMatchedTxn[0]; BOOST_CHECK(merkleBlock.vMatchedTxn[0].second == uint256S("0x74d681e0e03bafa802c8aa084379aa98d9fcd632ddc2ed9782b" "586ec87451f20")); BOOST_CHECK(merkleBlock.vMatchedTxn[0].first == 8); - std::vector vMatched; + std::vector vMatched; std::vector vIndex; BOOST_CHECK(merkleBlock.txn.ExtractMatches(vMatched, vIndex) == block.hashMerkleRoot); @@ -475,14 +475,14 @@ BOOST_CHECK(merkleBlock.header.GetHash() == block.GetHash()); BOOST_CHECK(merkleBlock.vMatchedTxn.size() == 1); - std::pair pair = merkleBlock.vMatchedTxn[0]; + std::pair pair = merkleBlock.vMatchedTxn[0]; BOOST_CHECK(merkleBlock.vMatchedTxn[0].second == uint256S("0xe980fe9f792d014e73b95203dc1335c5f9ce19ac537a419e6df" "5b47aecb93b70")); BOOST_CHECK(merkleBlock.vMatchedTxn[0].first == 0); - std::vector vMatched; + std::vector vMatched; std::vector vIndex; BOOST_CHECK(merkleBlock.txn.ExtractMatches(vMatched, vIndex) == block.hashMerkleRoot); @@ -589,14 +589,14 @@ BOOST_CHECK(merkleBlock.header.GetHash() == block.GetHash()); BOOST_CHECK(merkleBlock.vMatchedTxn.size() == 1); - std::pair pair = merkleBlock.vMatchedTxn[0]; + std::pair pair = merkleBlock.vMatchedTxn[0]; BOOST_CHECK(merkleBlock.vMatchedTxn[0].second == uint256S("0xe980fe9f792d014e73b95203dc1335c5f9ce19ac537a419e6df" "5b47aecb93b70")); BOOST_CHECK(merkleBlock.vMatchedTxn[0].first == 0); - std::vector vMatched; + std::vector vMatched; std::vector vIndex; BOOST_CHECK(merkleBlock.txn.ExtractMatches(vMatched, vIndex) == block.hashMerkleRoot); @@ -670,7 +670,7 @@ "3a3d669c00cb5")); BOOST_CHECK(merkleBlock.vMatchedTxn[0].first == 0); - std::vector vMatched; + std::vector vMatched; std::vector vIndex; BOOST_CHECK(merkleBlock.txn.ExtractMatches(vMatched, vIndex) == block.hashMerkleRoot); @@ -792,14 +792,14 @@ BOOST_CHECK(merkleBlock.header.GetHash() == block.GetHash()); BOOST_CHECK(merkleBlock.vMatchedTxn.size() == 1); - std::pair pair = merkleBlock.vMatchedTxn[0]; + std::pair pair = merkleBlock.vMatchedTxn[0]; BOOST_CHECK(merkleBlock.vMatchedTxn[0].second == uint256S("0x0a2a92f0bda4727d0a13eaddf4dd9ac6b5c61a1429e6b2b818f" "19b15df0ac154")); BOOST_CHECK(merkleBlock.vMatchedTxn[0].first == 6); - std::vector vMatched; + std::vector vMatched; std::vector vIndex; BOOST_CHECK(merkleBlock.txn.ExtractMatches(vMatched, vIndex) == block.hashMerkleRoot); diff --git a/src/test/pmt_tests.cpp b/src/test/pmt_tests.cpp --- a/src/test/pmt_tests.cpp +++ b/src/test/pmt_tests.cpp @@ -47,7 +47,7 @@ // calculate actual merkle root and height uint256 merkleRoot1 = BlockMerkleRoot(block); - std::vector vTxid(nTx, uint256()); + std::vector vTxid(nTx, TxId()); for (unsigned int j = 0; j < nTx; j++) vTxid[j] = block.vtx[j]->GetId(); int nHeight = 1, nTx_ = nTx; @@ -61,7 +61,7 @@ for (int att = 1; att < 15; att++) { // build random subset of txid's std::vector vMatch(nTx, false); - std::vector vMatchTxid1; + std::vector vMatchTxid1; for (unsigned int j = 0; j < nTx; j++) { bool fInclude = InsecureRandBits(att / 2) == 0; vMatch[j] = fInclude; @@ -85,7 +85,7 @@ ss >> pmt2; // extract merkle root and matched txids from copy - std::vector vMatchTxid2; + std::vector vMatchTxid2; std::vector vIndex; uint256 merkleRoot2 = pmt2.ExtractMatches(vMatchTxid2, vIndex); @@ -102,7 +102,7 @@ for (int j = 0; j < 4; j++) { CPartialMerkleTreeTester pmt3(pmt2); pmt3.Damage(); - std::vector vMatchTxid3; + std::vector vMatchTxid3; uint256 merkleRoot3 = pmt3.ExtractMatches(vMatchTxid3, vIndex); BOOST_CHECK(merkleRoot3 != merkleRoot1); } @@ -111,11 +111,13 @@ } BOOST_AUTO_TEST_CASE(pmt_malleability) { - std::vector vTxid = { - ArithToUint256(1), ArithToUint256(2), ArithToUint256(3), - ArithToUint256(4), ArithToUint256(5), ArithToUint256(6), - ArithToUint256(7), ArithToUint256(8), ArithToUint256(9), - ArithToUint256(10), ArithToUint256(9), ArithToUint256(10)}; + std::vector vTxid = { + TxId(ArithToUint256(1)), TxId(ArithToUint256(2)), + TxId(ArithToUint256(3)), TxId(ArithToUint256(4)), + TxId(ArithToUint256(5)), TxId(ArithToUint256(6)), + TxId(ArithToUint256(7)), TxId(ArithToUint256(8)), + TxId(ArithToUint256(9)), TxId(ArithToUint256(10)), + TxId(ArithToUint256(9)), TxId(ArithToUint256(10))}; std::vector vMatch = {false, false, false, false, false, false, false, false, false, true, true, false}; diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -334,7 +334,7 @@ // Search partial merkle tree in proof for our transaction and index in // valid block - std::vector vMatch; + std::vector vMatch; std::vector vIndex; unsigned int txnIndex = 0; if (merkleBlock.txn.ExtractMatches(vMatch, vIndex) == @@ -349,7 +349,7 @@ "Block not found in chain"); } - std::vector::const_iterator it; + std::vector::const_iterator it; if ((it = std::find(vMatch.begin(), vMatch.end(), txid)) == vMatch.end()) { throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY,