@@ -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,40 +223,19 @@ void chaser_validate::validate_block(const header_link& link) NOEXCEPT
218223 {
219224 ec = error::validate2;
220225 }
221- else if (!block-> populate (ctx))
226+ else if ((ec = populate (bypass, *block, ctx) ))
222227 {
223- ec = system::error::relative_time_locked;
224228 if (!query.set_block_unconfirmable (link))
225229 ec = error::validate3;
226230 }
227- else if (!query. populate ( *block))
231+ else if ((ec = validate (bypass, *block, link, ctx) ))
228232 {
229- ec = system::error::missing_previous_output;
230233 if (!query.set_block_unconfirmable (link))
231234 ec = error::validate4;
232235 }
233- else if ((ec = block->accept (ctx, subsidy_interval_, initial_subsidy_)))
234- {
235- if (!query.set_block_unconfirmable (link))
236- ec = error::validate5;
237- }
238- else if ((ec = block->connect (ctx)))
239- {
240- if (!query.set_block_unconfirmable (link))
241- ec = error::validate6;
242- }
243- else if (!query.set_block_valid (link, block->fees ()))
244- {
245- ec = error::validate7;
246- }
247- else if (!query.set_prevouts (link, *block))
248- {
249- ec = error::validate8;
250- }
251236 else if (!query.set_filter_body (link, *block))
252237 {
253- // TODO: this should not bypass checkpoint/milestone if enabled.
254- ec = error::validate9;
238+ ec = error::validate5;
255239 }
256240 else
257241 {
@@ -262,6 +246,54 @@ void chaser_validate::validate_block(const header_link& link) NOEXCEPT
262246 POST (complete_block, ec, link, ctx.height );
263247}
264248
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)
259+ {
260+ if (!query.populate_without_metadata (block))
261+ return system::error::missing_previous_output;
262+ }
263+ else
264+ {
265+ if (!query.populate (block))
266+ return system::error::missing_previous_output;
267+ }
268+
269+ return error::success;
270+ }
271+
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;
295+ }
296+
265297void chaser_validate::complete_block (const code& ec, const header_link& link,
266298 size_t height) NOEXCEPT
267299{
@@ -279,9 +311,7 @@ void chaser_validate::complete_block(const code& ec, const header_link& link,
279311 ec == error::validate4 ||
280312 ec == error::validate5 ||
281313 ec == error::validate6 ||
282- ec == error::validate7 ||
283- ec == error::validate8 ||
284- ec == error::validate9)
314+ ec == error::validate7)
285315 {
286316 fault (ec);
287317 return ;
0 commit comments