mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-04 18:56:16 +00:00
Merge bitcoin/bitcoin#34376: bench/test: clarify merkle bench and witness test intent
8b9d30e3facff0cd132dc3faf6282d75b1f9b532 bench/test: clarify merkle bench and witness test intent (Lőrinc)
Pull request description:
Follow-up to #32497.
Clarify why the witness merkle test uses an odd leaf count (it exercises leaf duplication in `ComputeMerkleRoot()`), and make the coinbase witness hash initialization explicit.
Also simplify the leaf-copy loop in the `MerkleRoot` benchmark for readability.
No production code is changed in this follow-up, for simplicity and safety.
ACKs for top commit:
optout21:
ACK 8b9d30e3facff0cd132dc3faf6282d75b1f9b532
maflcko:
lgtm ACK 8b9d30e3facff0cd132dc3faf6282d75b1f9b532
achow101:
ACK 8b9d30e3facff0cd132dc3faf6282d75b1f9b532
w0xlt:
ACK 8b9d30e3fa
danielabrozzoni:
tACK 8b9d30e3facff0cd132dc3faf6282d75b1f9b532
Tree-SHA512: 6efca7c19ebf96bb8d0def4217ed30d3b74b58a7be15566967e98aba9b03aaddd0e0ebb3b8f43130b5f397a7d9eed0470a48a55438f440e0bceefb87edd16b27
This commit is contained in:
commit
7b48b09b7f
@ -25,8 +25,8 @@ static void MerkleRoot(benchmark::Bench& bench)
|
||||
bench.name(mutate ? "MerkleRootWithMutation" : "MerkleRoot").batch(hashes.size()).unit("leaf").run([&] {
|
||||
std::vector<uint256> leaves;
|
||||
leaves.reserve((hashes.size() + 1) & ~1ULL); // capacity rounded up to even
|
||||
for (size_t s = 0; s < hashes.size(); s++) {
|
||||
leaves.push_back(hashes[s]);
|
||||
for (const auto& hash : hashes) {
|
||||
leaves.push_back(hash);
|
||||
}
|
||||
|
||||
bool mutated{false};
|
||||
|
||||
@ -243,7 +243,8 @@ BOOST_AUTO_TEST_CASE(merkle_test_BlockWitness)
|
||||
uint256 blockWitness = BlockWitnessMerkleRoot(block);
|
||||
|
||||
std::vector<uint256> hashes;
|
||||
hashes.resize(vtx_count); // Note: leaving odd count to exercise old behavior
|
||||
hashes.resize(vtx_count); // Odd count exercises leaf duplication in ComputeMerkleRoot (which can append one extra hash).
|
||||
hashes[0] = uint256::ZERO; // The witness hash of the coinbase is 0.
|
||||
for (size_t pos{1}; pos < vtx_count; ++pos) {
|
||||
hashes[pos] = block.vtx[pos]->GetWitnessHash().ToUint256();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user