mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 06:58:57 +01:00
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.
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user