From 6e624107820298866b06036c399ad5c87512d333 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Mon, 13 Jan 2025 00:35:00 -0500 Subject: [PATCH] Add context to block.populate for bip68 check. --- include/bitcoin/system/chain/block.hpp | 3 ++- src/chain/block.cpp | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/include/bitcoin/system/chain/block.hpp b/include/bitcoin/system/chain/block.hpp index e51b3d504a..dd8748be88 100644 --- a/include/bitcoin/system/chain/block.hpp +++ b/include/bitcoin/system/chain/block.hpp @@ -137,7 +137,8 @@ class BC_API block code confirm(const context& ctx) const NOEXCEPT; /// Populate previous outputs (and metadata.locked) internal to the block. - bool populate() const NOEXCEPT; + /// False if one or more populated prevouts is locked in the block context. + bool populate(const context& ctx) const NOEXCEPT; protected: block(const chain::header::cptr& header, diff --git a/src/chain/block.cpp b/src/chain/block.cpp index 54b23f0fe0..963c74d1c6 100644 --- a/src/chain/block.cpp +++ b/src/chain/block.cpp @@ -702,24 +702,24 @@ bool block::is_unspent_coinbase_collision() const NOEXCEPT } // Search is not ordered, forward references are caught by block.check. -bool block::populate() const NOEXCEPT +bool block::populate(const chain::context& ctx) const NOEXCEPT { if (txs_->empty()) return true; + const auto start = std::next(txs_->begin()); + const auto bip68 = ctx.is_enabled(chain::flags::bip68_rule); unordered_map_of_cref_point_to_output_cptr_cref points{}; - const auto second = std::next(txs_->begin()); - const auto last = txs_->end(); uint32_t index{}; // Populate outputs hash table. - for (auto tx = second; tx != last; ++tx, index = 0) + for (auto tx = start; tx != txs_->end(); ++tx, index = 0) for (const auto& out: *(*tx)->outputs_ptr()) points.emplace(cref_point{ (*tx)->get_hash(false), index++ }, out); // Populate input prevouts from hash table and obtain locked state. auto locked = false; - for (auto tx = second; tx != last; ++tx) + for (auto tx = start; tx != txs_->end(); ++tx) { for (const auto& in: *(*tx)->inputs_ptr()) { @@ -730,7 +730,7 @@ bool block::populate() const NOEXCEPT if (point != points.end()) { in->prevout = point->second; - in->metadata.locked = in->is_internally_locked(); + in->metadata.locked = bip68 && in->is_internally_locked(); locked |= in->metadata.locked; } }