From 9fb106e7579831b4ab682d2e6f588662d0f445d0 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Sat, 18 Aug 2012 23:40:00 -0400 Subject: [PATCH] Add a CMerkleBlock to store merkle branches of filtered txes. --- src/main.cpp | 23 +++++++++++++++++++++++ src/main.h | 30 ++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 93079693c..bd5b2408a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2239,6 +2239,29 @@ 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 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)); + } + } +} + + + + + + + + bool CheckDiskSpace(uint64 nAdditionalBytes) { uint64 nFreeBytesAvailable = filesystem::space(GetDataDir()).available; diff --git a/src/main.h b/src/main.h index d2329af09..77aac71d2 100644 --- a/src/main.h +++ b/src/main.h @@ -2039,4 +2039,34 @@ struct CBlockTemplate std::vector vTxSigOps; }; + + + + + +/** Used to relay blocks as header + vector + * to filtered nodes. + */ +class CMerkleBlock +{ +public: + CBlockHeader header; + + // We could optimize this a bit to deduplicate partial branches, + // but it's not worth much unless a node has a ton of txes in a single block + // tx index , tx hash, merkle branch + std::vector > > vtx; + + // Create from a CBlock, filtering transactions according to filter + // Note that this will call IsRelevantAndUpdate on the filter for each transaction, + // thus the filter will likely be modified. + CMerkleBlock(const CBlock& block, CBloomFilter& filter); + + IMPLEMENT_SERIALIZE + ( + READWRITE(header); + READWRITE(vtx); + ) +}; + #endif