Skip to content

Commit

Permalink
Merge pull request #1583 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 f5d4c65 + 6e62410 commit 1cc7c18
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
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

0 comments on commit 1cc7c18

Please sign in to comment.