Skip to content

Commit 562d467

Browse files
authored
Merge pull request #712 from evoskuil/master
Call set_block_unconfirmable on populate() errors.
2 parents a33a9c7 + 0185357 commit 562d467

File tree

2 files changed

+68
-25
lines changed

2 files changed

+68
-25
lines changed

include/bitcoin/node/chasers/chaser_validate.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,13 @@ class BCN_API chaser_validate
5252
virtual void do_checked(height_t height) NOEXCEPT;
5353
virtual void do_bump(height_t height) NOEXCEPT;
5454

55-
virtual void validate_block(const database::header_link& link) NOEXCEPT;
55+
virtual void validate_block(const database::header_link& link,
56+
bool bypass) NOEXCEPT;
57+
virtual code validate(bool bypass, const system::chain::block& block,
58+
const database::header_link& link,
59+
const system::chain::context& ctx) NOEXCEPT;
60+
virtual code populate(bool bypass, const system::chain::block& block,
61+
const system::chain::context& ctx) NOEXCEPT;
5662
virtual void complete_block(const code& ec,
5763
const database::header_link& link, size_t height) NOEXCEPT;
5864

@@ -77,6 +83,7 @@ class BCN_API chaser_validate
7783
const uint64_t initial_subsidy_;
7884
const size_t maximum_backlog_;
7985
const bool concurrent_;
86+
const bool filter_;
8087
};
8188

8289
} // namespace node

src/chasers/chaser_validate.cpp

Lines changed: 60 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ chaser_validate::chaser_validate(full_node& node) NOEXCEPT
4848
subsidy_interval_(node.config().bitcoin.subsidy_interval_blocks),
4949
initial_subsidy_(node.config().bitcoin.initial_subsidy()),
5050
maximum_backlog_(node.config().node.maximum_concurrency_()),
51-
concurrent_(node.config().node.concurrent_validation)
51+
concurrent_(node.config().node.concurrent_validation),
52+
filter_(node.archive().neutrino_enabled())
5253
{
5354
}
5455

@@ -187,20 +188,24 @@ void chaser_validate::do_bump(height_t) NOEXCEPT
187188

188189
set_position(height);
189190

190-
if ((ec == database::error::block_valid) ||
191+
const auto bypass =
192+
(ec == database::error::block_valid) ||
191193
(ec == database::error::block_confirmable) ||
192-
is_under_checkpoint(height) || query.is_milestone(link))
194+
is_under_checkpoint(height) || query.is_milestone(link);
195+
196+
if (bypass && !filter_)
193197
{
194198
complete_block(error::success, link, height);
195199
continue;
196200
}
197201

198-
PARALLEL(validate_block, link);
202+
PARALLEL(validate_block, link, bypass);
199203
}
200204
}
201205

202206
// Unstranded (concurrent by block).
203-
void chaser_validate::validate_block(const header_link& link) NOEXCEPT
207+
void chaser_validate::validate_block(const header_link& link,
208+
bool bypass) NOEXCEPT
204209
{
205210
if (closed())
206211
return;
@@ -218,44 +223,75 @@ void chaser_validate::validate_block(const header_link& link) NOEXCEPT
218223
{
219224
ec = error::validate2;
220225
}
221-
else if (!block->populate(ctx))
222-
{
223-
ec = system::error::relative_time_locked;
224-
}
225-
else if (!query.populate(*block))
226-
{
227-
ec = system::error::missing_previous_output;
228-
}
229-
else if ((ec = block->accept(ctx, subsidy_interval_, initial_subsidy_)))
226+
else if ((ec = populate(bypass, *block, ctx)))
230227
{
231228
if (!query.set_block_unconfirmable(link))
232229
ec = error::validate3;
233230
}
234-
else if ((ec = block->connect(ctx)))
231+
else if ((ec = validate(bypass, *block, link, ctx)))
235232
{
236233
if (!query.set_block_unconfirmable(link))
237234
ec = error::validate4;
238235
}
239-
else if (!query.set_block_valid(link, block->fees()))
236+
else if (!query.set_filter_body(link, *block))
240237
{
241238
ec = error::validate5;
242239
}
243-
else if (!query.set_prevouts(link, *block))
240+
else
244241
{
245-
ec = error::validate6;
242+
fire(events::block_validated, ctx.height);
246243
}
247-
else if (!query.set_filter_body(link, *block))
244+
245+
// Return to strand to handle result.
246+
POST(complete_block, ec, link, ctx.height);
247+
}
248+
249+
code chaser_validate::populate(bool bypass, const system::chain::block& block,
250+
const system::chain::context& ctx) NOEXCEPT
251+
{
252+
const auto& query = archive();
253+
254+
// Relative locktime check is unnecessary under bypass, but cheap.
255+
if (!block.populate(ctx))
256+
return system::error::relative_time_locked;
257+
258+
if (bypass)
248259
{
249-
// TODO: this should not bypass checkpoint/milestone if enabled.
250-
ec = error::validate7;
260+
if (!query.populate_without_metadata(block))
261+
return system::error::missing_previous_output;
251262
}
252263
else
253264
{
254-
fire(events::block_validated, ctx.height);
265+
if (!query.populate(block))
266+
return system::error::missing_previous_output;
255267
}
268+
269+
return error::success;
270+
}
256271

257-
// Return to strand to handle result.
258-
POST(complete_block, ec, link, ctx.height);
272+
code chaser_validate::validate(bool bypass, const system::chain::block& block,
273+
const database::header_link& link,
274+
const system::chain::context& ctx) NOEXCEPT
275+
{
276+
code ec{};
277+
if (bypass)
278+
return ec;
279+
280+
auto& query = archive();
281+
282+
if ((ec = block.accept(ctx, subsidy_interval_, initial_subsidy_)))
283+
return ec;
284+
285+
if ((ec = block.connect(ctx)))
286+
return ec;
287+
288+
if (!query.set_block_valid(link, block.fees()))
289+
return error::validate6;
290+
291+
if (!query.set_prevouts(link, block))
292+
return error::validate7;
293+
294+
return ec;
259295
}
260296

261297
void chaser_validate::complete_block(const code& ec, const header_link& link,

0 commit comments

Comments
 (0)