@@ -42,15 +42,16 @@ BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)
4242chaser_confirm::chaser_confirm (full_node& node) NOEXCEPT
4343 : chaser(node),
4444 concurrent_ (node.config().node.concurrent_confirmation),
45- threadpool_(1_u32, node.config().node.priority_validation ?
46- network::thread_priority::high : network::thread_priority::normal),
47- strand_(threadpool_.service().get_executor())
45+ threadpool_(one, node.config().node.priority_()),
46+ independent_strand_(threadpool_.service().get_executor())
4847{
4948}
5049
5150code chaser_confirm::start () NOEXCEPT
5251{
53- set_position (archive ().get_fork ());
52+ const auto & query = archive ();
53+ filters_ = query.neutrino_enabled ();
54+ reset_position (query.get_fork ());
5455 SUBSCRIBE_EVENTS (handle_event, _1, _2, _3);
5556 return error::success;
5657}
@@ -71,9 +72,6 @@ void chaser_confirm::stop() NOEXCEPT
7172 }
7273}
7374
74- // Protected
75- // ----------------------------------------------------------------------------
76-
7775bool chaser_confirm::handle_event (const code&, chase event_,
7876 event_value value) NOEXCEPT
7977{
@@ -106,9 +104,7 @@ bool chaser_confirm::handle_event(const code&, chase event_,
106104 {
107105 if (concurrent_ || mature_)
108106 {
109- // //POST(do_bump, height_t{});
110- boost::asio::post (strand_,
111- BIND (do_bump, height_t {}));
107+ POST (do_bump, height_t {});
112108 }
113109
114110 break ;
@@ -120,27 +116,21 @@ bool chaser_confirm::handle_event(const code&, chase event_,
120116
121117 if (concurrent_ || mature_)
122118 {
123- // //POST(do_validated, std::get<height_t>(value));
124- boost::asio::post (strand_,
125- BIND (do_validated, std::get<height_t >(value)));
119+ POST (do_validated, std::get<height_t >(value));
126120 }
127121
128122 break ;
129123 }
130124 case chase::regressed:
131125 {
132126 BC_ASSERT (std::holds_alternative<height_t >(value));
133- // //POST(do_regressed, std::get<height_t>(value));
134- boost::asio::post (strand_,
135- BIND (do_regressed, std::get<height_t >(value)));
127+ POST (do_regressed, std::get<height_t >(value));
136128 break ;
137129 }
138130 case chase::disorganized:
139131 {
140132 BC_ASSERT (std::holds_alternative<height_t >(value));
141- // //POST(do_regressed, std::get<height_t>(value));
142- boost::asio::post (strand_,
143- BIND (do_regressed, std::get<height_t >(value)));
133+ POST (do_regressed, std::get<height_t >(value));
144134 break ;
145135 }
146136 case chase::stop:
@@ -156,6 +146,9 @@ bool chaser_confirm::handle_event(const code&, chase event_,
156146 return true ;
157147}
158148
149+ // track validation
150+ // ----------------------------------------------------------------------------
151+
159152void chaser_confirm::do_regressed (height_t branch_point) NOEXCEPT
160153{
161154 BC_ASSERT (stranded ());
@@ -170,14 +163,14 @@ void chaser_confirm::do_regressed(height_t branch_point) NOEXCEPT
170163 }
171164 }
172165
173- set_position (branch_point);
166+ reset_position (branch_point);
174167}
175168
169+ // Candidate block validated at given height, if next then confirm/advance.
176170void chaser_confirm::do_validated (height_t height) NOEXCEPT
177171{
178172 BC_ASSERT (stranded ());
179173
180- // Candidate block was validated at the given height, confirm/advance.
181174 if (height == add1 (position ()))
182175 do_bump (height);
183176}
@@ -244,9 +237,8 @@ void chaser_confirm::do_bump(height_t) NOEXCEPT
244237 << ec.message ());
245238 return ;
246239 }
247-
248- // TODO: fees.
249- if (!query.set_block_confirmable (link, {}))
240+
241+ if (!query.set_block_confirmable (link))
250242 {
251243 fault (error::confirm6);
252244 return ;
@@ -283,6 +275,7 @@ void chaser_confirm::do_bump(height_t) NOEXCEPT
283275 return ;
284276 }
285277
278+ update_neutrino (link);
286279 set_position (height);
287280 }
288281}
@@ -617,6 +610,56 @@ bool chaser_confirm::get_is_strong(bool& strong, const uint256_t& fork_work,
617610 return true ;
618611}
619612
613+ // neutrino
614+ // ----------------------------------------------------------------------------
615+
616+ // This can only fail if prevouts are not fully populated.
617+ bool chaser_confirm::update_neutrino (const header_link& link) NOEXCEPT
618+ {
619+ // neutrino_.link is only used for this assertion, should compile away.
620+ BC_ASSERT (archive ().get_height (link) ==
621+ add1 (archive ().get_height (neutrino_.link )));
622+
623+ if (!filters_)
624+ return true ;
625+
626+ data_chunk filter{};
627+ auto & query = archive ();
628+ if (!query.get_filter_body (filter, link))
629+ return false ;
630+
631+ neutrino_.link = link;
632+ neutrino_.head = neutrino::compute_filter_header (neutrino_.head , filter);
633+ return query.set_filter_head (link, neutrino_.head );
634+ }
635+
636+ // Expects confirmed height.
637+ // Use for startup and regression, to read current filter header from store.
638+ void chaser_confirm::reset_position (size_t confirmed_height) NOEXCEPT
639+ {
640+ set_position (confirmed_height);
641+
642+ if (filters_)
643+ {
644+ const auto & query = archive ();
645+ neutrino_.link = query.to_confirmed (confirmed_height);
646+ query.get_filter_head (neutrino_.head , neutrino_.link );
647+ }
648+ }
649+
650+ // Strand.
651+ // ----------------------------------------------------------------------------
652+
653+ network::asio::strand& chaser_confirm::strand () NOEXCEPT
654+ {
655+ return independent_strand_;
656+ }
657+
658+ bool chaser_confirm::stranded () const NOEXCEPT
659+ {
660+ return independent_strand_.running_in_this_thread ();
661+ }
662+
620663BC_POP_WARNING ()
621664
622665} // namespace node
0 commit comments