diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2014-09-16 00:30:05 +0200 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2014-09-24 19:17:02 +0200 |
commit | 584a358997e52a87e8c5402269c7fb3784ed2065 (patch) | |
tree | 72cb1589072c23bded2737f1fdf9b9fb0c3e0680 /src/core.h | |
parent | 7a04f3d708faab4af1f1a6aeddc5a6a4db3849a5 (diff) |
Do merkle root and txid duplicates check simultaneously
Move the txid duplicates check into BuildMerkleTree, where it can be done
much more efficiently (without needing to build a full txid set to detect
duplicates).
The previous version (using the std::set<uint256> to detect duplicates) was
also slightly too weak. A block mined with actual duplicate transactions
(which is invalid, due to the inputs of the duplicated transactions being
seen as double spends) would trigger the duplicates logic, resulting in the
block not being stored on disk, and rerequested. This change fixes that by
only triggering in the case of duplicated transactions that can actually
result in an identical merkle root.
Diffstat (limited to 'src/core.h')
-rw-r--r-- | src/core.h | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/core.h b/src/core.h index 9a2ac47487..de41b8621b 100644 --- a/src/core.h +++ b/src/core.h @@ -528,7 +528,11 @@ public: return block; } - uint256 BuildMerkleTree() const; + // Build the in-memory merkle tree for this block and return the merkle root. + // If non-NULL, *mutated is set to whether mutation was detected in the merkle + // tree (a duplication of transactions in the block leading to an identical + // merkle root). + uint256 BuildMerkleTree(bool* mutated = NULL) const; std::vector<uint256> GetMerkleBranch(int nIndex) const; static uint256 CheckMerkleBranch(uint256 hash, const std::vector<uint256>& vMerkleBranch, int nIndex); |