From 7d072e6544cd904a07465f1e0e1b1872e38d4b58 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Thu, 26 Mar 2026 11:37:00 -0400 Subject: [PATCH] Overallocate get_tx_keys for common merkle scenario. --- include/bitcoin/database/impl/query/archive_read.ipp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/include/bitcoin/database/impl/query/archive_read.ipp b/include/bitcoin/database/impl/query/archive_read.ipp index b5ba3675..d54feeef 100644 --- a/include/bitcoin/database/impl/query/archive_read.ipp +++ b/include/bitcoin/database/impl/query/archive_read.ipp @@ -112,8 +112,12 @@ hashes CLASS::get_tx_keys(const header_link& link) const NOEXCEPT if (tx_fks.empty()) return {}; + // Overallocate as required for the common merkle scenario. + const auto count = tx_fks.size(); + const auto size = is_odd(count) && !is_one(count) ? add1(count) : count; + system::hashes hashes{}; - hashes.reserve(tx_fks.size()); + hashes.reserve(size); for (const auto& tx_fk: tx_fks) hashes.push_back(get_tx_key(tx_fk));