From 322fa373187592bf72065b4163d19cbf8970e933 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Fri, 24 Mar 2023 01:38:33 -0700 Subject: [PATCH 1/2] Don't cache witness coinbase hash. --- src/messages/block.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/messages/block.cpp b/src/messages/block.cpp index 85b280dd1..b2cd5df50 100644 --- a/src/messages/block.cpp +++ b/src/messages/block.cpp @@ -49,6 +49,7 @@ typename block::cptr block::deserialize(uint32_t version, header.set_hash(bitcoin_hash(header_size, data.data())); auto begin = std::next(data.data(), header_size); + auto coinbase = true; for (const auto& tx: *message->block_ptr->transactions_ptr()) { const auto true_size = tx->serialized_size(true); @@ -57,8 +58,12 @@ typename block::cptr block::deserialize(uint32_t version, // If segregated the hashes are distinct, cache both. if (tx->is_segregated()) { - const auto end = std::next(begin, tx->serialized_size(false)); - tx->set_hash(transaction::desegregated_hash({ begin, end })); + // Coinbase witness hash is null_hash, do not cache. + if (!coinbase) + { + const auto end = std::next(begin, tx->serialized_size(false)); + tx->set_hash(transaction::desegregated_hash({ begin, end })); + } } else { @@ -66,6 +71,7 @@ typename block::cptr block::deserialize(uint32_t version, tx->set_hash(bitcoin_hash(true_size, begin)); } + coinbase = false; std::advance(begin, true_size); } From 220ae2ea781ab772c31d340035b4e5f5d75cead6 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Fri, 24 Mar 2023 03:50:56 -0700 Subject: [PATCH 2/2] Comment. --- src/messages/block.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/messages/block.cpp b/src/messages/block.cpp index b2cd5df50..0046b3221 100644 --- a/src/messages/block.cpp +++ b/src/messages/block.cpp @@ -52,6 +52,7 @@ typename block::cptr block::deserialize(uint32_t version, auto coinbase = true; for (const auto& tx: *message->block_ptr->transactions_ptr()) { + // TODO: consider having tx cache serialized sizes. const auto true_size = tx->serialized_size(true); ////tx->set_witness_hash(bitcoin_hash(true_size, begin));