diff options
author | Matt Corallo <git@bluematt.me> | 2012-11-08 16:26:25 -0500 |
---|---|---|
committer | Matt Corallo <git@bluematt.me> | 2013-01-16 14:34:06 -0500 |
commit | 21aaf255ff4553ae538fb90011b0185bc8039896 (patch) | |
tree | 5802725fb5756bac265ef7f7d4cef9d6083781a7 /src/main.cpp | |
parent | 4bedfa9223d38bbc322d19e28ca03417c216700b (diff) |
Use CPartialMerkleTree for CMerkleBlock transactions.
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/src/main.cpp b/src/main.cpp index 91fe6ba8fc..644c5d0e6d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2242,17 +2242,27 @@ bool ProcessBlock(CNode* pfrom, CBlock* pblock, CDiskBlockPos *dbp) CMerkleBlock::CMerkleBlock(const CBlock& block, CBloomFilter& filter) { header = block.GetBlockHeader(); - vtx.reserve(block.vtx.size()); - for(unsigned int i = 0; i < block.vtx.size(); i++) + vector<bool> vMatch; + vector<uint256> vHashes; + + vMatch.reserve(block.vtx.size()); + vHashes.reserve(block.vtx.size()); + + for (unsigned int i = 0; i < block.vtx.size(); i++) { - vector<uint256> branch = block.GetMerkleBranch(i); uint256 hash = block.vtx[i].GetHash(); if (filter.IsRelevantAndUpdate(block.vtx[i], hash)) { - vtx.push_back(make_tuple(i, hash, branch)); + vMatch.push_back(true); + vMatchedTxn.push_back(make_pair(i, hash)); } + else + vMatch.push_back(false); + vHashes.push_back(hash); } + + txn = CPartialMerkleTree(vHashes, vMatch); } @@ -3209,16 +3219,16 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) if (pfrom->pfilter) { CMerkleBlock merkleBlock(block, *pfrom->pfilter); - typedef boost::tuple<unsigned int, uint256, std::vector<uint256> > TupleType; // CMerkleBlock just contains hashes, so also push any transactions in the block the client did not see // This avoids hurting performance by pointlessly requiring a round-trip // Note that there is currently no way for a node to request any single transactions we didnt send here - // they must either disconnect and retry or request the full block. // Thus, the protocol spec specified allows for us to provide duplicate txn here, // however we MUST always provide at least what the remote peer needs - BOOST_FOREACH(TupleType& tuple, merkleBlock.vtx) - if (!pfrom->setInventoryKnown.count(CInv(MSG_TX, get<1>(tuple)))) - pfrom->PushMessage("tx", block.vtx[get<0>(tuple)]); + typedef std::pair<unsigned int, uint256> PairType; + BOOST_FOREACH(PairType& pair, merkleBlock.vMatchedTxn) + if (!pfrom->setInventoryKnown.count(CInv(MSG_TX, pair.second))) + pfrom->PushMessage("tx", block.vtx[pair.first]); pfrom->PushMessage("merkleblock", merkleBlock); } // else |