@@ -31,7 +31,6 @@ namespace node {
3131#define CLASS chaser_confirm
3232
3333using namespace system ;
34- using namespace database ;
3534using namespace std ::placeholders;
3635
3736BC_PUSH_WARNING (NO_THROW_IN_NOEXCEPT)
@@ -155,25 +154,26 @@ void chaser_confirm::do_bump(height_t) NOEXCEPT
155154void chaser_confirm::do_bumped (height_t height) NOEXCEPT
156155{
157156 BC_ASSERT (stranded ());
157+ const auto & query = archive ();
158158
159159 if (closed ())
160160 return ;
161161
162162 // If empty height is not on a candidate fork (may have been reorganized).
163- auto fork = get_fork (height);
163+ auto fork = query. get_candidate_fork (height);
164164 if (fork.empty ())
165165 return ;
166166
167167 uint256_t work{};
168- if (!get_work (work, fork))
168+ if (!query. get_work (work, fork))
169169 {
170170 fault (error::confirm1);
171171 return ;
172172 }
173173
174174 bool strong{};
175175 const auto fork_point = height - fork.size ();
176- if (!get_strong (strong, work, fork_point))
176+ if (!query. get_strong (strong, work, fork_point))
177177 {
178178 fault (error::confirm2);
179179 return ;
@@ -195,12 +195,12 @@ void chaser_confirm::do_bumped(height_t height) NOEXCEPT
195195void chaser_confirm::reorganize (header_links& fork, size_t fork_point) NOEXCEPT
196196{
197197 BC_ASSERT (stranded ());
198-
199198 const auto & query = archive ();
199+
200200 auto height = query.get_top_confirmed ();
201201 if (height < fork_point)
202202 {
203- fault (error::confirm4 );
203+ fault (error::confirm3 );
204204 return ;
205205 }
206206
@@ -210,14 +210,14 @@ void chaser_confirm::reorganize(header_links& fork, size_t fork_point) NOEXCEPT
210210 const auto link = query.to_confirmed (height);
211211 if (link.is_terminal ())
212212 {
213- fault (error::confirm5 );
213+ fault (error::confirm4 );
214214 return ;
215215 }
216216
217217 popped.push_back (link);
218218 if (!set_reorganized (link, height--))
219219 {
220- fault (error::confirm6 );
220+ fault (error::confirm5 );
221221 return ;
222222 }
223223 }
@@ -253,7 +253,7 @@ void chaser_confirm::organize(header_links& fork, const header_links& popped,
253253 {
254254 if (!query.set_filter_head (link))
255255 {
256- fault (error::confirm3 );
256+ fault (error::confirm6 );
257257 return ;
258258 }
259259
@@ -274,15 +274,15 @@ void chaser_confirm::organize(header_links& fork, const header_links& popped,
274274 }
275275 default :
276276 {
277- fault (error::confirm4 );
277+ fault (error::confirm7 );
278278 return ;
279279 }
280280 }
281281
282282 // After set_block_confirmable.
283283 if (!set_organized (link, height++))
284284 {
285- fault (error::confirm5 );
285+ fault (error::confirm8 );
286286 return ;
287287 }
288288
@@ -304,19 +304,19 @@ bool chaser_confirm::confirm_block(const header_link& link,
304304 {
305305 if (!query.set_unstrong (link))
306306 {
307- fault (error::confirm6 );
307+ fault (error::confirm9 );
308308 return false ;
309309 }
310310
311311 if (!query.set_block_unconfirmable (link))
312312 {
313- fault (error::confirm7 );
313+ fault (error::confirm10 );
314314 return false ;
315315 }
316316
317317 if (!roll_back (popped, fork_point, sub1 (height)))
318318 {
319- fault (error::confirm8 );
319+ fault (error::confirm11 );
320320 return false ;
321321 }
322322
@@ -327,13 +327,13 @@ bool chaser_confirm::confirm_block(const header_link& link,
327327 // Before set_block_confirmable.
328328 if (!query.set_filter_head (link))
329329 {
330- fault (error::confirm9 );
330+ fault (error::confirm12 );
331331 return false ;
332332 }
333333
334334 if (!query.set_block_confirmable (link))
335335 {
336- fault (error::confirm10 );
336+ fault (error::confirm13 );
337337 return false ;
338338 }
339339
@@ -367,7 +367,7 @@ void chaser_confirm::complete_block(const code& ec, const header_link& link,
367367 LOGV (" Block confirmable: " << height);
368368}
369369
370- // Private setters
370+ // private
371371// ----------------------------------------------------------------------------
372372// Checkpointed blocks are set strong by archiver, and cannot be reorganized.
373373
@@ -421,84 +421,6 @@ bool chaser_confirm::roll_back(const header_links& popped, size_t fork_point,
421421 return true ;
422422}
423423
424- // Private getters
425- // ----------------------------------------------------------------------------
426-
427- // TODO: move into database library with internal lock.
428- chaser_confirm::header_links chaser_confirm::get_fork (
429- height_t fork_top) const NOEXCEPT
430- {
431- BC_ASSERT (stranded ());
432- const auto & query = archive ();
433- header_link link{};
434- header_links out{};
435-
436- // Prevents organizer from popping candidates (does not block push).
437- get_reorganization_lock ();
438-
439- // Walk down candidates from fork_top to fork point (highest common).
440- for (link = query.to_candidate (fork_top);
441- !link.is_terminal () && !query.is_confirmed_block (link);
442- link = query.to_candidate (--fork_top))
443- {
444- out.push_back (link);
445- }
446-
447- // Terminal candidate from previously valid height implies regression.
448- // This is ok, it just means that the fork is no longer a candidate.
449- if (link.is_terminal ())
450- out.clear ();
451-
452- return out;
453- }
454-
455- bool chaser_confirm::get_work (uint256_t & fork_work,
456- const header_links& fork) const NOEXCEPT
457- {
458- BC_ASSERT (stranded ());
459- const auto & query = archive ();
460-
461- // Walk down candidates from fork_top to fork point (highest common).
462- for (const auto & link: fork)
463- {
464- uint32_t bits{};
465- if (!query.get_bits (bits, link))
466- return false ;
467-
468- fork_work += chain::header::proof (bits);
469- }
470-
471- return true ;
472- }
473-
474- // A fork with greater work will cause confirmed reorganization.
475- bool chaser_confirm::get_strong (bool & strong, const uint256_t & fork_work,
476- size_t fork_point) const NOEXCEPT
477- {
478- BC_ASSERT (stranded ());
479- uint256_t confirmed_work{};
480- const auto & query = archive ();
481-
482- for (auto height = query.get_top_confirmed (); height > fork_point;
483- --height)
484- {
485- uint32_t bits{};
486- if (!query.get_bits (bits, query.to_confirmed (height)))
487- return false ;
488-
489- // Not strong when confirmed_work equals or exceeds fork_work.
490- confirmed_work += chain::header::proof (bits);
491- if (confirmed_work >= fork_work)
492- {
493- strong = false ;
494- return true ;
495- }
496- }
497-
498- strong = true ;
499- return true ;
500- }
501-
502424BC_POP_WARNING ()
503425
504426} // namespace node
0 commit comments