@@ -203,6 +203,11 @@ void chaser_confirm::do_bump(height_t) NOEXCEPT
203203 for (auto height = add1 (position ()); !closed (); ++height)
204204 {
205205 const auto link = query.to_candidate (height);
206+ auto ec = query.get_block_state (link);
207+
208+ // Don't report bypassed block is confirmable until associated.
209+ if (ec == database::error::unassociated)
210+ return ;
206211
207212 if (is_under_checkpoint (height) || query.is_milestone (link))
208213 {
@@ -211,85 +216,81 @@ void chaser_confirm::do_bump(height_t) NOEXCEPT
211216 LOGV (" Block confirmation bypassed: " << height);
212217 // //return;
213218 }
214- else
219+ else if (ec == database::error::block_valid)
215220 {
216- auto ec = query.get_block_state (link);
217- if (ec == database::error::block_valid)
221+ if (!query.set_strong (link))
218222 {
219- if (!query.set_strong (link))
220- {
221- fault (error::confirm2);
222- return ;
223- }
223+ fault (error::confirm2);
224+ return ;
225+ }
224226
225- if ((ec = query.block_confirmable (link)))
227+ if ((ec = query.block_confirmable (link)))
228+ {
229+ if (ec == database::error::integrity)
226230 {
227- if (ec == database::error::integrity)
228- {
229- fault (error::confirm3);
230- return ;
231- }
232-
233- if (!query.set_block_unconfirmable (link))
234- {
235- fault (error::confirm4);
236- return ;
237- }
238-
239- if (!query.set_unstrong (link))
240- {
241- fault (error::confirm5);
242- return ;
243- }
244-
245- // Blocks between link and fork point will be set_unstrong
246- // by header reorganization, picked up by do_regressed.
247- notify (ec, chase::unconfirmable, link);
248- fire (events::block_unconfirmable, height);
249- LOGR (" Unconfirmable block [" << height << " ] "
250- << ec.message ());
231+ fault (error::confirm3);
251232 return ;
252233 }
253-
254- // TODO: fees.
255- if (!query.set_block_confirmable (link, {}))
234+
235+ if (!query.set_block_unconfirmable (link))
256236 {
257- fault (error::confirm6 );
237+ fault (error::confirm4 );
258238 return ;
259239 }
260-
261- notify (error::success, chase::confirmable, height);
262- fire (events::block_confirmed, height);
263- LOGV (" Block confirmed: " << height);
264- // //return;
265- }
266- else if (ec == database::error::block_confirmable)
267- {
268- if (!query.set_strong (link))
240+
241+ if (!query.set_unstrong (link))
269242 {
270- fault (error::confirm7 );
243+ fault (error::confirm5 );
271244 return ;
272245 }
246+
247+ // Blocks between link and fork point will be set_unstrong
248+ // by header reorganization, picked up by do_regressed.
249+ notify (ec, chase::unconfirmable, link);
250+ fire (events::block_unconfirmable, height);
251+ LOGR (" Unconfirmable block [" << height << " ] "
252+ << ec.message ());
253+ return ;
254+ }
273255
274- notify (error::success, chase::confirmable, height);
275- fire (events::confirm_bypassed, height);
276- LOGV (" Block previously confirmable: " << height);
277- // //return;
256+ // TODO: fees.
257+ if (!query.set_block_confirmable (link, {}))
258+ {
259+ fault (error::confirm6);
260+ return ;
278261 }
279- else
262+
263+ notify (error::success, chase::confirmable, height);
264+ fire (events::block_confirmed, height);
265+ LOGV (" Block confirmed: " << height);
266+ // //return;
267+ }
268+ else if (ec == database::error::block_confirmable)
269+ {
270+ if (!query.set_strong (link))
280271 {
281- // With or without an error code, shouldn't be here.
282- // database::error::block_valid [canonical state ]
283- // database::error::block_confirmable [resurrected state]
284- // database::error::block_unconfirmable [shouldn't be here]
285- // database::error::unknown_state [shouldn't be here]
286- // database::error::unassociated [shouldn't be here]
287- // database::error::unvalidated [shouldn't be here]
272+ fault (error::confirm7);
288273 return ;
289274 }
290-
291- set_position (height);
275+
276+ notify (error::success, chase::confirmable, height);
277+ fire (events::confirm_bypassed, height);
278+ LOGV (" Block previously confirmable: " << height);
279+ // //return;
280+ }
281+ else
282+ {
283+ // With or without an error code, shouldn't be here.
284+ // database::error::block_valid [canonical state ]
285+ // database::error::block_confirmable [resurrected state]
286+ // database::error::block_unconfirmable [shouldn't be here]
287+ // database::error::unknown_state [shouldn't be here]
288+ // database::error::unassociated [shouldn't be here]
289+ // database::error::unvalidated [shouldn't be here]
290+ return ;
292291 }
292+
293+ set_position (height);
293294 }
294295}
295296
0 commit comments