diff options
author | dergoegge <n.goeggi@gmail.com> | 2024-02-06 10:07:18 +0000 |
---|---|---|
committer | dergoegge <n.goeggi@gmail.com> | 2024-02-27 14:19:15 +0000 |
commit | 1ec6bbeb8d27d31647d1433ccb87b362f6d81f90 (patch) | |
tree | c7e3a084274b9e13e0d68bd0e0f72d43b357c5f9 /src/validation.cpp | |
parent | 5bf4f5ba32da4627f152b54d266df9b2aa930457 (diff) |
[validation] Cache merkle root and witness commitment checks
Slight performance improvement by avoiding duplicate work.
Diffstat (limited to 'src/validation.cpp')
-rw-r--r-- | src/validation.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/validation.cpp b/src/validation.cpp index 120663bfc0..b03cc7f78a 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -3641,6 +3641,8 @@ static bool CheckBlockHeader(const CBlockHeader& block, BlockValidationState& st static bool CheckMerkleRoot(const CBlock& block, BlockValidationState& state) { + if (block.m_checked_merkle_root) return true; + bool mutated; uint256 merkle_root = BlockMerkleRoot(block, &mutated); if (block.hashMerkleRoot != merkle_root) { @@ -3660,6 +3662,7 @@ static bool CheckMerkleRoot(const CBlock& block, BlockValidationState& state) /*debug_message=*/"duplicate transaction"); } + block.m_checked_merkle_root = true; return true; } @@ -3672,6 +3675,8 @@ static bool CheckMerkleRoot(const CBlock& block, BlockValidationState& state) static bool CheckWitnessMalleation(const CBlock& block, bool expect_witness_commitment, BlockValidationState& state) { if (expect_witness_commitment) { + if (block.m_checked_witness_commitment) return true; + int commitpos = GetWitnessCommitmentIndex(block); if (commitpos != NO_WITNESS_COMMITMENT) { assert(!block.vtx.empty() && !block.vtx[0]->vin.empty()); @@ -3697,6 +3702,7 @@ static bool CheckWitnessMalleation(const CBlock& block, bool expect_witness_comm /*debug_message=*/strprintf("%s : witness merkle commitment mismatch", __func__)); } + block.m_checked_witness_commitment = true; return true; } } |