mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-02-03 22:03:01 +01:00
Merge bitcoin/bitcoin#34376: bench/test: clarify merkle bench and witness test intent
8b9d30e3fabench/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: ACK8b9d30e3famaflcko: lgtm ACK8b9d30e3faachow101: ACK8b9d30e3faw0xlt: ACK8b9d30e3fadanielabrozzoni: tACK8b9d30e3faTree-SHA512: 6efca7c19ebf96bb8d0def4217ed30d3b74b58a7be15566967e98aba9b03aaddd0e0ebb3b8f43130b5f397a7d9eed0470a48a55438f440e0bceefb87edd16b27
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user