Skip to content

Commit e2b0cbe

Browse files
committed
Return code populate_with_metadata and short-circuit on
1 parent 70841e4 commit e2b0cbe

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

include/bitcoin/system/chain/block.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,9 @@ class BC_API block
142142
void populate() const NOEXCEPT;
143143

144144
/// Populate previous outputs and metadata.locked internal to the block.
145+
/// Execution is shortcircuited for error with that metadata.locked set.
145146
/// False if any populated prevout is immature in the block context.
146-
bool populate_with_metadata(const context& ctx) const NOEXCEPT;
147+
code populate_with_metadata(const context& ctx) const NOEXCEPT;
147148

148149
protected:
149150
block(const chain::header::cptr& header,

src/chain/block.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -738,10 +738,10 @@ void block::populate() const NOEXCEPT
738738
}
739739
}
740740

741-
bool block::populate_with_metadata(const chain::context& ctx) const NOEXCEPT
741+
code block::populate_with_metadata(const chain::context& ctx) const NOEXCEPT
742742
{
743743
if (txs_->empty())
744-
return true;
744+
return error::block_success;
745745

746746
const auto bip68 = ctx.is_enabled(chain::flags::bip68_rule);
747747
unordered_map_of_cref_point_to_output_cptr_cref points{ outputs() };
@@ -753,7 +753,6 @@ bool block::populate_with_metadata(const chain::context& ctx) const NOEXCEPT
753753
points.emplace(cref_point{ (*tx)->get_hash(false), index++ }, out);
754754

755755
// Populate input prevouts from hash table and obtain maturity.
756-
auto locked = false;
757756
for (auto tx = std::next(txs_->begin()); tx != txs_->end(); ++tx)
758757
{
759758
for (const auto& in: *(*tx)->inputs_ptr())
@@ -765,18 +764,22 @@ bool block::populate_with_metadata(const chain::context& ctx) const NOEXCEPT
765764
if (point != points.end())
766765
{
767766
// Zero maturity coinbase spend is immature.
768-
const auto lock = (bip68 && (*tx)->is_internal_lock(*in));
767+
const auto lock = (bip68 && (*tx)->is_internally_locked(*in));
769768
const auto immature = !is_zero(coinbase_maturity) &&
770769
(in->point().hash() == txs_->front()->get_hash(false));
771770

772771
in->prevout = point->second;
773-
in->metadata.locked = immature || lock;
774-
locked |= in->metadata.locked;
772+
if ((in->metadata.locked = (immature || lock)))
773+
{
774+
// Shortcircuit population and return above error.
775+
return immature ? error::coinbase_maturity :
776+
error::relative_time_locked;
777+
}
775778
}
776779
}
777780
}
778781

779-
return !locked;
782+
return error::block_success;
780783
}
781784

782785
// Delegated.

0 commit comments

Comments
 (0)