Skip to content

Commit

Permalink
Merge pull request libbitcoin#711 from evoskuil/master
Browse files Browse the repository at this point in the history
Add context to block.populate for bip68 check.
  • Loading branch information
evoskuil authored Jan 13, 2025
2 parents baa8955 + 21c03f1 commit a33a9c7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
3 changes: 2 additions & 1 deletion include/bitcoin/node/chasers/chaser_block.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 12 additions & 4 deletions src/chasers/chaser_block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/chasers/chaser_validate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit a33a9c7

Please sign in to comment.