Skip to content

Commit 1cc7c18

Browse files
authored
Merge pull request #1583 from evoskuil/master
Add context to block.populate for bip68 check.
2 parents f5d4c65 + 6e62410 commit 1cc7c18

2 files changed

Lines changed: 8 additions & 7 deletions

File tree

include/bitcoin/system/chain/block.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ class BC_API block
137137
code confirm(const context& ctx) const NOEXCEPT;
138138

139139
/// Populate previous outputs (and metadata.locked) internal to the block.
140-
bool populate() const NOEXCEPT;
140+
/// False if one or more populated prevouts is locked in the block context.
141+
bool populate(const context& ctx) const NOEXCEPT;
141142

142143
protected:
143144
block(const chain::header::cptr& header,

src/chain/block.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -702,24 +702,24 @@ bool block::is_unspent_coinbase_collision() const NOEXCEPT
702702
}
703703

704704
// Search is not ordered, forward references are caught by block.check.
705-
bool block::populate() const NOEXCEPT
705+
bool block::populate(const chain::context& ctx) const NOEXCEPT
706706
{
707707
if (txs_->empty())
708708
return true;
709709

710+
const auto start = std::next(txs_->begin());
711+
const auto bip68 = ctx.is_enabled(chain::flags::bip68_rule);
710712
unordered_map_of_cref_point_to_output_cptr_cref points{};
711-
const auto second = std::next(txs_->begin());
712-
const auto last = txs_->end();
713713
uint32_t index{};
714714

715715
// Populate outputs hash table.
716-
for (auto tx = second; tx != last; ++tx, index = 0)
716+
for (auto tx = start; tx != txs_->end(); ++tx, index = 0)
717717
for (const auto& out: *(*tx)->outputs_ptr())
718718
points.emplace(cref_point{ (*tx)->get_hash(false), index++ }, out);
719719

720720
// Populate input prevouts from hash table and obtain locked state.
721721
auto locked = false;
722-
for (auto tx = second; tx != last; ++tx)
722+
for (auto tx = start; tx != txs_->end(); ++tx)
723723
{
724724
for (const auto& in: *(*tx)->inputs_ptr())
725725
{
@@ -730,7 +730,7 @@ bool block::populate() const NOEXCEPT
730730
if (point != points.end())
731731
{
732732
in->prevout = point->second;
733-
in->metadata.locked = in->is_internally_locked();
733+
in->metadata.locked = bip68 && in->is_internally_locked();
734734
locked |= in->metadata.locked;
735735
}
736736
}

0 commit comments

Comments
 (0)