diff --git a/src/messages/block.cpp b/src/messages/block.cpp index 85b280dd1..0046b3221 100644 --- a/src/messages/block.cpp +++ b/src/messages/block.cpp @@ -49,16 +49,22 @@ 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()) { + // TODO: consider having tx cache serialized sizes. const auto true_size = tx->serialized_size(true); ////tx->set_witness_hash(bitcoin_hash(true_size, begin)); // 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 +72,7 @@ typename block::cptr block::deserialize(uint32_t version, tx->set_hash(bitcoin_hash(true_size, begin)); } + coinbase = false; std::advance(begin, true_size); }