@@ -710,7 +710,35 @@ bool block::is_unspent_coinbase_collision() const NOEXCEPT
710710}
711711
712712// Search is unordered, forward refs (and duplicates) caught by block.check.
713- bool block::populate (const chain::context& ctx) const NOEXCEPT
713+ void block::populate () const NOEXCEPT
714+ {
715+ if (txs_->empty ())
716+ return ;
717+
718+ unordered_map_of_cref_point_to_output_cptr_cref points{ outputs () };
719+ uint32_t index{};
720+
721+ // Populate outputs hash table (coinbase included).
722+ for (auto tx = txs_->begin (); tx != txs_->end (); ++tx, index = 0 )
723+ for (const auto & out: *(*tx)->outputs_ptr ())
724+ points.emplace (cref_point{ (*tx)->get_hash (false ), index++ }, out);
725+
726+ // Populate input prevouts from hash table.
727+ for (auto tx = std::next (txs_->begin ()); tx != txs_->end (); ++tx)
728+ {
729+ for (const auto & in: *(*tx)->inputs_ptr ())
730+ {
731+ // Map chain::point to cref_point for search, should optimize away.
732+ const auto point = points.find ({ in->point ().hash (),
733+ in->point ().index () });
734+
735+ if (point != points.end ())
736+ in->prevout = point->second ;
737+ }
738+ }
739+ }
740+
741+ bool block::populate_with_metadata (const chain::context& ctx) const NOEXCEPT
714742{
715743 if (txs_->empty ())
716744 return true ;
@@ -724,7 +752,7 @@ bool block::populate(const chain::context& ctx) const NOEXCEPT
724752 for (const auto & out: *(*tx)->outputs_ptr ())
725753 points.emplace (cref_point{ (*tx)->get_hash (false ), index++ }, out);
726754
727- // Populate input prevouts from hash table and obtain locked state .
755+ // Populate input prevouts from hash table and obtain maturity .
728756 auto locked = false ;
729757 for (auto tx = std::next (txs_->begin ()); tx != txs_->end (); ++tx)
730758 {
@@ -736,7 +764,7 @@ bool block::populate(const chain::context& ctx) const NOEXCEPT
736764
737765 if (point != points.end ())
738766 {
739- // Zero maturity coinbase spend is treated as locked .
767+ // Zero maturity coinbase spend is immature .
740768 const auto lock = (bip68 && (*tx)->is_internal_lock (*in));
741769 const auto immature = !is_zero (coinbase_maturity) &&
742770 (in->point ().hash () == txs_->front ()->get_hash (false ));
0 commit comments