Skip to content

Commit

Permalink
Add a CMerkleBlock to store merkle branches of filtered txes.
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBlueMatt committed Jan 16, 2013
1 parent 587f0f8 commit 9fb106e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<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));
}
}
}








bool CheckDiskSpace(uint64 nAdditionalBytes)
{
uint64 nFreeBytesAvailable = filesystem::space(GetDataDir()).available;
Expand Down
30 changes: 30 additions & 0 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -2039,4 +2039,34 @@ struct CBlockTemplate
std::vector<int64_t> vTxSigOps;
};






/** Used to relay blocks as header + vector<merkle branch>
* 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<boost::tuple<unsigned int, uint256, std::vector<uint256> > > 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

0 comments on commit 9fb106e

Please sign in to comment.