From 21c03f19b3ea39c14b83212b9454fd95b50903ae Mon Sep 17 00:00:00 2001 From: evoskuil Date: Mon, 13 Jan 2025 00:34:22 -0500 Subject: [PATCH] Add context to block.populate for bip68 check. --- include/bitcoin/node/chasers/chaser_block.hpp | 3 ++- src/chasers/chaser_block.cpp | 16 ++++++++++++---- src/chasers/chaser_validate.cpp | 2 +- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/include/bitcoin/node/chasers/chaser_block.hpp b/include/bitcoin/node/chasers/chaser_block.hpp index 668aeb66..ffac3b0e 100644 --- a/include/bitcoin/node/chasers/chaser_block.hpp +++ b/include/bitcoin/node/chasers/chaser_block.hpp @@ -68,7 +68,8 @@ class BCN_API chaser_block private: void set_prevout(const system::chain::input& input) const NOEXCEPT; - void populate(const system::chain::block& block) const NOEXCEPT; + bool populate(const system::chain::block& block, + const system::chain::context& ctx) const NOEXCEPT; }; } // namespace node diff --git a/src/chasers/chaser_block.cpp b/src/chasers/chaser_block.cpp index 53993203..530efb94 100644 --- a/src/chasers/chaser_block.cpp +++ b/src/chasers/chaser_block.cpp @@ -117,8 +117,11 @@ code chaser_block::validate(const block& block, return ec; } - // Populate prevouts from self/tree/store (metadata not required). - populate(block); + // Populate prevouts from self/tree (metadata not required). + if (!populate(block, ctx)) + return system::error::relative_time_locked; + + // Populate prevouts from store (metadata not required). if (!archive().populate(block)) return network::error::protocol_violation; @@ -178,15 +181,20 @@ void chaser_block::set_prevout(const input& input) const NOEXCEPT } // metadata is mutable so can be set on a const object. -void chaser_block::populate(const block& block) const NOEXCEPT +bool chaser_block::populate(const block& block, + const system::chain::context& ctx) const NOEXCEPT { - block.populate(); + if (!block.populate(ctx)) + return false; + const inputs_cptr ins{ block.inputs_ptr() }; std::for_each(ins->begin(), ins->end(), [&](const auto& in) NOEXCEPT { if (!in->prevout && !in->point().is_null()) set_prevout(*in); }); + + return true; } } // namespace node diff --git a/src/chasers/chaser_validate.cpp b/src/chasers/chaser_validate.cpp index 4d65b231..5fab9114 100644 --- a/src/chasers/chaser_validate.cpp +++ b/src/chasers/chaser_validate.cpp @@ -218,7 +218,7 @@ void chaser_validate::validate_block(const header_link& link) NOEXCEPT { ec = error::validate2; } - else if (!block->populate()) + else if (!block->populate(ctx)) { ec = system::error::relative_time_locked; }