Skip to content

Commit e9eda82

Browse files
committed
Make chaser strand() and stranded() virtual, update neutrino.
1 parent d0f3fb9 commit e9eda82

File tree

4 files changed

+137
-123
lines changed

4 files changed

+137
-123
lines changed

include/bitcoin/node/chasers/chaser_confirm.hpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,20 @@ class BCN_API chaser_confirm
5959
////virtual void do_organize(header_links& fork, const header_links& popped,
6060
//// size_t fork_point) NOEXCEPT;
6161

62+
// Override base class strand because it sits on the network thread pool.
63+
network::asio::strand& strand() NOEXCEPT override;
64+
bool stranded() const NOEXCEPT override;
65+
6266
private:
67+
struct neutrino_header
68+
{
69+
system::hash_digest head{};
70+
database::header_link link{};
71+
};
72+
73+
void reset_position(size_t confirmed_height) NOEXCEPT;
74+
bool update_neutrino(const database::header_link& link) NOEXCEPT;
75+
6376
bool set_organized(const database::header_link& link,
6477
height_t height) NOEXCEPT;
6578
bool reset_organized(const database::header_link& link,
@@ -74,12 +87,13 @@ class BCN_API chaser_confirm
7487
bool get_is_strong(bool& strong, const uint256_t& fork_work,
7588
size_t fork_point) const NOEXCEPT;
7689

77-
// This is thread safe.
90+
// These are thread safe.
7891
const bool concurrent_;
92+
network::asio::strand independent_strand_;
7993

8094
// These are protected by strand.
8195
network::threadpool threadpool_;
82-
network::asio::strand strand_;
96+
neutrino_header neutrino_{};
8397
bool mature_{};
8498
};
8599

include/bitcoin/node/chasers/chaser_validate.hpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,25 +56,24 @@ class BCN_API chaser_validate
5656
virtual void complete_block(const code& ec,
5757
const database::header_link& link, size_t height) NOEXCEPT;
5858

59+
// Override base class strand because it sits on the network thread pool.
60+
network::asio::strand& strand() NOEXCEPT override;
61+
bool stranded() const NOEXCEPT override;
62+
5963
private:
60-
// neutrino
61-
void update_position(size_t height) NOEXCEPT;
62-
system::hash_digest get_neutrino(size_t height) const NOEXCEPT;
63-
bool update_neutrino(const database::header_link& link) NOEXCEPT;
64-
bool update_neutrino(const database::header_link& link,
64+
bool set_neutrino(const database::header_link& link,
6565
const system::chain::block& block) NOEXCEPT;
6666

6767
// These are thread safe.
6868
const bool concurrent_;
6969
const size_t maximum_backlog_;
7070
const uint64_t initial_subsidy_;
7171
const uint32_t subsidy_interval_;
72+
network::asio::strand independent_strand_;
7273

7374
// These are protected by strand.
7475
network::threadpool threadpool_;
75-
network::asio::strand strand_;
76-
system::hash_digest neutrino_{};
77-
size_t validation_backlog_{};
76+
size_t backlog_{};
7877
bool mature_{};
7978
};
8079

src/chasers/chaser_confirm.cpp

Lines changed: 61 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,14 @@ BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)
4242
chaser_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

5150
code chaser_confirm::start() NOEXCEPT
5251
{
53-
set_position(archive().get_fork());
52+
reset_position(archive().get_fork());
5453
SUBSCRIBE_EVENTS(handle_event, _1, _2, _3);
5554
return error::success;
5655
}
@@ -106,9 +105,7 @@ bool chaser_confirm::handle_event(const code&, chase event_,
106105
{
107106
if (concurrent_ || mature_)
108107
{
109-
////POST(do_bump, height_t{});
110-
boost::asio::post(strand_,
111-
BIND(do_bump, height_t{}));
108+
POST(do_bump, height_t{});
112109
}
113110

114111
break;
@@ -120,27 +117,21 @@ bool chaser_confirm::handle_event(const code&, chase event_,
120117

121118
if (concurrent_ || mature_)
122119
{
123-
////POST(do_validated, std::get<height_t>(value));
124-
boost::asio::post(strand_,
125-
BIND(do_validated, std::get<height_t>(value)));
120+
POST(do_validated, std::get<height_t>(value));
126121
}
127122

128123
break;
129124
}
130125
case chase::regressed:
131126
{
132127
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)));
128+
POST(do_regressed, std::get<height_t>(value));
136129
break;
137130
}
138131
case chase::disorganized:
139132
{
140133
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)));
134+
POST(do_regressed, std::get<height_t>(value));
144135
break;
145136
}
146137
case chase::stop:
@@ -170,7 +161,7 @@ void chaser_confirm::do_regressed(height_t branch_point) NOEXCEPT
170161
}
171162
}
172163

173-
set_position(branch_point);
164+
reset_position(branch_point);
174165
}
175166

176167
void chaser_confirm::do_validated(height_t height) NOEXCEPT
@@ -244,9 +235,8 @@ void chaser_confirm::do_bump(height_t) NOEXCEPT
244235
<< ec.message());
245236
return;
246237
}
247-
248-
// TODO: fees.
249-
if (!query.set_block_confirmable(link, {}))
238+
239+
if (!query.set_block_confirmable(link))
250240
{
251241
fault(error::confirm6);
252242
return;
@@ -283,6 +273,7 @@ void chaser_confirm::do_bump(height_t) NOEXCEPT
283273
return;
284274
}
285275

276+
update_neutrino(link);
286277
set_position(height);
287278
}
288279
}
@@ -617,6 +608,56 @@ bool chaser_confirm::get_is_strong(bool& strong, const uint256_t& fork_work,
617608
return true;
618609
}
619610

611+
// neutrino
612+
// ----------------------------------------------------------------------------
613+
614+
// This can only fail if prevouts are not fully populated.
615+
bool chaser_confirm::update_neutrino(const header_link& link) NOEXCEPT
616+
{
617+
// neutrino_.link is only used for this assertion, should compile away.
618+
BC_ASSERT(archive().get_height(link) ==
619+
add1(archive().get_height(neutrino_.link)));
620+
621+
auto& query = archive();
622+
if (!query.neutrino_enabled())
623+
return true;
624+
625+
data_chunk filter{};
626+
if (!query.get_filter_body(filter, link))
627+
return false;
628+
629+
neutrino_.link = link;
630+
neutrino_.head = neutrino::compute_filter_header(neutrino_.head, filter);
631+
return query.set_filter_head(link, neutrino_.head);
632+
}
633+
634+
// Expects confirmed height.
635+
// Use for startup and regression, to read current filter header from store.
636+
void chaser_confirm::reset_position(size_t confirmed_height) NOEXCEPT
637+
{
638+
set_position(confirmed_height);
639+
640+
const auto& query = archive();
641+
if (query.neutrino_enabled())
642+
{
643+
neutrino_.link = query.to_confirmed(confirmed_height);
644+
query.get_filter_head(neutrino_.head, neutrino_.link);
645+
}
646+
}
647+
648+
// Strand.
649+
// ----------------------------------------------------------------------------
650+
651+
network::asio::strand& chaser_confirm::strand() NOEXCEPT
652+
{
653+
return independent_strand_;
654+
}
655+
656+
bool chaser_confirm::stranded() const NOEXCEPT
657+
{
658+
return independent_strand_.running_in_this_thread();
659+
}
660+
620661
BC_POP_WARNING()
621662

622663
} // namespace node

0 commit comments

Comments
 (0)