Skip to content

Commit 247503b

Browse files
committed
Adapt to chain and database block population changes.
1 parent 5d0991d commit 247503b

File tree

3 files changed

+21
-21
lines changed

3 files changed

+21
-21
lines changed

include/bitcoin/node/chasers/chaser_block.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ class BCN_API chaser_block
6868

6969
private:
7070
void set_prevout(const system::chain::input& input) const NOEXCEPT;
71-
bool populate(const system::chain::block& block,
72-
const system::chain::context& ctx) const NOEXCEPT;
71+
bool populate(const system::chain::block& block) const NOEXCEPT;
7372
};
7473

7574
} // namespace node

src/chasers/chaser_block.cpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,11 @@ code chaser_block::validate(const block& block,
117117
return ec;
118118
}
119119

120-
// Populate prevouts from self/tree (metadata not required).
121-
if (!populate(block, ctx))
122-
return system::error::relative_time_locked;
120+
// Populate prevouts from self/tree (no metadata for accept/connect).
121+
populate(block);
123122

124-
// Populate prevouts from store (metadata not required).
125-
if (!archive().populate(block))
123+
// Populate prevouts from store (no metadata for accept/connect).
124+
if (!archive().populate_without_metadata(block))
126125
return network::error::protocol_violation;
127126

128127
if ((ec = block.accept(ctx,
@@ -156,6 +155,8 @@ void chaser_block::update_milestone(const header&, size_t, size_t) NOEXCEPT
156155
void chaser_block::set_prevout(const input& input) const NOEXCEPT
157156
{
158157
const auto& point = input.point();
158+
if (input.prevout || point.is_null())
159+
return;
159160

160161
// Scan all tree blocks for matching tx (linear :/ but legacy scenario)
161162
std::for_each(tree().begin(), tree().end(), [&](const auto& item) NOEXCEPT
@@ -173,25 +174,22 @@ void chaser_block::set_prevout(const input& input) const NOEXCEPT
173174
const outputs_cptr outs{ tx->outputs_ptr() };
174175
if (point.index() < outs->size())
175176
{
177+
// prevout is mutable so can be set on a const object.
176178
input.prevout = outs->at(point.index());
177179
return;
178180
}
179181
}
180182
});
181183
}
182184

183-
// metadata is mutable so can be set on a const object.
184-
bool chaser_block::populate(const block& block,
185-
const system::chain::context& ctx) const NOEXCEPT
185+
bool chaser_block::populate(const block& block) const NOEXCEPT
186186
{
187-
if (!block.populate(ctx))
188-
return false;
187+
block.populate();
189188

190-
const inputs_cptr ins{ block.inputs_ptr() };
191-
std::for_each(ins->begin(), ins->end(), [&](const auto& in) NOEXCEPT
189+
const auto& ins = *block.inputs_ptr();
190+
std::for_each(ins.begin(), ins.end(), [&](const auto& in) NOEXCEPT
192191
{
193-
if (!in->prevout && !in->point().is_null())
194-
set_prevout(*in);
192+
set_prevout(*in);
195193
});
196194

197195
return true;

src/chasers/chaser_validate.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,18 +238,21 @@ code chaser_validate::populate(bool bypass, const chain::block& block,
238238
{
239239
const auto& query = archive();
240240

241-
// Relative locktime check is unnecessary under bypass, but cheap.
242-
if (!block.populate(ctx))
243-
return system::error::relative_time_locked;
244-
245241
if (bypass)
246242
{
243+
block.populate();
247244
if (!query.populate_without_metadata(block))
248245
return system::error::missing_previous_output;
249246
}
250247
else
251248
{
252-
if (!query.populate(block))
249+
// Internal maturity and time locks are verified here because they are
250+
// the only necessary confirmation checks for internal spends.
251+
if (const auto ec = block.populate_with_metadata(ctx))
252+
return ec;
253+
254+
// Metadata identifies internal spends alowing confirmation bypass.
255+
if (!query.populate_with_metadata(block))
253256
return system::error::missing_previous_output;
254257
}
255258

0 commit comments

Comments
 (0)