Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add context to block.populate for bip68 check. #1583

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/bitcoin/system/chain/block.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 6 additions & 6 deletions src/chain/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand All @@ -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;
}
}
Expand Down
Loading