Skip to content

Commit 470a474

Browse files
authored
Merge pull request #714 from evoskuil/master
Confirmation and validation updates.
2 parents 66a7516 + 2250d80 commit 470a474

File tree

5 files changed

+72
-114
lines changed

5 files changed

+72
-114
lines changed

console/executor_test_reader.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ using namespace system;
4040
using namespace std::chrono;
4141
using namespace std::placeholders;
4242

43+
// arbitrary testing (const).
4344
void executor::read_test(bool dump) const
4445
{
4546
using namespace database;
@@ -273,7 +274,14 @@ void executor::read_test(bool dump) const
273274

274275
#if defined(UNDEFINED)
275276

276-
// arbitrary testing (const).
277+
void executor::read_test(bool) const
278+
{
279+
database::header_link link{ 350'017_u32 };
280+
const auto ec = query_.block_confirmable(link);
281+
logger(format("block_confirmable [%1%] at height [%2%].") % ec.message() %
282+
query_.get_height(link));
283+
}
284+
277285
void executor::read_test(bool dump) const
278286
{
279287
logger("Wire size computation.");

include/bitcoin/node/chasers/chaser_confirm.hpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,6 @@ class BCN_API chaser_confirm
7070
database::header_link link{};
7171
};
7272

73-
void reset_position(size_t confirmed_height) NOEXCEPT;
74-
bool update_neutrino(const database::header_link& link) NOEXCEPT;
75-
7673
bool set_organized(const database::header_link& link,
7774
height_t height) NOEXCEPT;
7875
bool reset_organized(const database::header_link& link,
@@ -89,8 +86,6 @@ class BCN_API chaser_confirm
8986

9087
// These are protected by strand.
9188
bool mature_{};
92-
bool filters_{};
93-
neutrino_header neutrino_{};
9489
network::threadpool threadpool_;
9590

9691
// These are thread safe.

include/bitcoin/node/chasers/chaser_validate.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ class BCN_API chaser_validate
5959
const system::chain::context& ctx) NOEXCEPT;
6060
virtual code populate(bool bypass, const system::chain::block& block,
6161
const system::chain::context& ctx) NOEXCEPT;
62+
virtual void tracked_complete_block(const code& ec,
63+
const database::header_link& link, size_t height) NOEXCEPT;
6264
virtual void complete_block(const code& ec,
6365
const database::header_link& link, size_t height) NOEXCEPT;
6466

src/chasers/chaser_confirm.cpp

Lines changed: 34 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ chaser_confirm::chaser_confirm(full_node& node) NOEXCEPT
5050
code chaser_confirm::start() NOEXCEPT
5151
{
5252
const auto& query = archive();
53-
filters_ = query.neutrino_enabled();
54-
reset_position(query.get_fork());
53+
set_position(query.get_fork());
5554
SUBSCRIBE_EVENTS(handle_event, _1, _2, _3);
5655
return error::success;
5756
}
@@ -163,7 +162,7 @@ void chaser_confirm::do_regressed(height_t branch_point) NOEXCEPT
163162
}
164163
}
165164

166-
reset_position(branch_point);
165+
set_position(branch_point);
167166
}
168167

169168
// Candidate block validated at given height, if next then confirm/advance.
@@ -189,108 +188,93 @@ void chaser_confirm::do_bump(height_t) NOEXCEPT
189188
const auto link = query.to_candidate(height);
190189
auto ec = query.get_block_state(link);
191190

192-
// Don't report bypassed block is confirmable until associated.
193191
if (ec == database::error::unassociated)
192+
{
193+
// Wait until the gap is filled.
194194
return;
195-
196-
if (is_under_checkpoint(height) || query.is_milestone(link))
195+
}
196+
else if (is_under_checkpoint(height) || query.is_milestone(link))
197197
{
198-
notify(error::success, chase::confirmable, height);
199-
fire(events::confirm_bypassed, height);
200-
LOGV("Block confirmation bypassed: " << height);
201-
////return;
198+
// Fall through (report confirmed).
199+
}
200+
else if (ec == database::error::unvalidated)
201+
{
202+
// Wait until this block is validated.
203+
return;
202204
}
203205
else if (ec == database::error::block_valid)
204206
{
205-
if (!query.set_strong(link))
206-
{
207-
fault(error::confirm2);
208-
return;
209-
}
210-
211-
//////////////////////////////////////////
212207
// Confirmation query.
213-
// This will pull from new prevouts table.
214-
//////////////////////////////////////////
215208
if ((ec = query.block_confirmable(link)))
216209
{
217210
if (ec == database::error::integrity)
218211
{
219-
fault(error::confirm3);
212+
fault(error::confirm2);
220213
return;
221214
}
222215

223216
if (!query.set_block_unconfirmable(link))
224217
{
225-
fault(error::confirm4);
226-
return;
227-
}
228-
229-
if (!query.set_unstrong(link))
230-
{
231-
fault(error::confirm5);
218+
fault(error::confirm3);
232219
return;
233220
}
234221

235-
// Blocks between link and fork point will be set_unstrong
236-
// by header reorganization, picked up by do_regressed.
237222
notify(ec, chase::unconfirmable, link);
238223
fire(events::block_unconfirmable, height);
239-
LOGR("Unconfirmable block [" << height << "] "
240-
<< ec.message());
224+
LOGR("Unconfirmable block [" << height << "] " << ec.message());
241225
return;
242226
}
243227

244228
if (!query.set_block_confirmable(link))
245229
{
246-
fault(error::confirm6);
230+
fault(error::confirm4);
247231
return;
248232
}
249233

250-
if (!set_organized(link, height))
234+
if (!query.set_strong(link))
251235
{
252-
fault(error::confirm7);
236+
fault(error::confirm5);
253237
return;
254238
}
255-
256-
notify(error::success, chase::confirmable, height);
257-
fire(events::block_confirmed, height);
258-
LOGV("Block confirmed: " << height);
259-
////return;
260239
}
261240
else if (ec == database::error::block_confirmable)
262241
{
263242
if (!query.set_strong(link))
264243
{
265-
fault(error::confirm8);
244+
fault(error::confirm6);
266245
return;
267246
}
268-
269-
notify(error::success, chase::confirmable, height);
270-
fire(events::confirm_bypassed, height);
271-
LOGV("Block previously confirmable: " << height);
272-
////return;
273247
}
274248
else
275249
{
276250
// With or without an error code, shouldn't be here.
251+
// database::error::unassociated [wait state ]
252+
// database::error::unvalidated [wait state ]
277253
// database::error::block_valid [canonical state ]
278254
// database::error::block_confirmable [resurrected state]
279255
// database::error::block_unconfirmable [shouldn't be here]
280256
// database::error::unknown_state [shouldn't be here]
281-
// database::error::unassociated [shouldn't be here]
282-
// database::error::unvalidated [shouldn't be here]
283-
fault(error::confirm9);
257+
fault(error::confirm7);
258+
return;
259+
}
260+
261+
if (!query.set_filter_head(link))
262+
{
263+
fault(error::confirm8);
284264
return;
285265
}
286266

287-
if (!update_neutrino(link))
267+
if (!set_organized(link, height))
288268
{
289-
fault(error::confirm10);
269+
fault(error::confirm9);
290270
return;
291271
}
292272

293273
set_position(height);
274+
275+
notify(error::success, chase::confirmable, height);
276+
fire(events::block_confirmed, height);
277+
////LOGV("Block confirmed: " << height);
294278
}
295279
}
296280

@@ -624,42 +608,6 @@ bool chaser_confirm::get_is_strong(bool& strong, const uint256_t& fork_work,
624608
return true;
625609
}
626610

627-
// neutrino
628-
// ----------------------------------------------------------------------------
629-
630-
bool chaser_confirm::update_neutrino(const header_link& link) NOEXCEPT
631-
{
632-
// neutrino_.link is only used for this assertion, should compile away.
633-
BC_ASSERT(archive().get_height(link) ==
634-
add1(archive().get_height(neutrino_.link)));
635-
636-
if (!filters_)
637-
return true;
638-
639-
data_chunk filter{};
640-
auto& query = archive();
641-
if (!query.get_filter_body(filter, link))
642-
return false;
643-
644-
neutrino_.link = link;
645-
neutrino_.head = neutrino::compute_filter_header(neutrino_.head, filter);
646-
return query.set_filter_head(link, neutrino_.head);
647-
}
648-
649-
// Expects confirmed height.
650-
// Use for startup and regression, to read current filter header from store.
651-
void chaser_confirm::reset_position(size_t confirmed_height) NOEXCEPT
652-
{
653-
set_position(confirmed_height);
654-
655-
if (filters_)
656-
{
657-
const auto& query = archive();
658-
neutrino_.link = query.to_confirmed(confirmed_height);
659-
query.get_filter_head(neutrino_.head, neutrino_.link);
660-
}
661-
}
662-
663611
// Strand.
664612
// ----------------------------------------------------------------------------
665613

src/chasers/chaser_validate.cpp

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -173,21 +173,17 @@ void chaser_validate::do_bump(height_t) NOEXCEPT
173173
const auto link = query.to_candidate(height);
174174
const auto ec = query.get_block_state(link);
175175

176-
// Wait until the gap is filled at a current height (or next top).
177176
if (ec == database::error::unassociated)
177+
{
178+
// Wait until the gap is filled.
178179
return;
179-
180-
// The size of the job is not relevant to the backlog cost.
181-
++backlog_;
182-
183-
if (ec == database::error::block_unconfirmable)
180+
}
181+
else if (ec == database::error::block_unconfirmable)
184182
{
185183
complete_block(ec, link, height);
186184
return;
187185
}
188186

189-
set_position(height);
190-
191187
const auto bypass =
192188
(ec == database::error::block_valid) ||
193189
(ec == database::error::block_confirmable) ||
@@ -196,10 +192,14 @@ void chaser_validate::do_bump(height_t) NOEXCEPT
196192
if (bypass && !filter_)
197193
{
198194
complete_block(error::success, link, height);
199-
continue;
195+
}
196+
else
197+
{
198+
++backlog_;
199+
PARALLEL(validate_block, link, bypass);
200200
}
201201

202-
PARALLEL(validate_block, link, bypass);
202+
set_position(height);
203203
}
204204
}
205205

@@ -237,13 +237,9 @@ void chaser_validate::validate_block(const header_link& link,
237237
{
238238
ec = error::validate5;
239239
}
240-
else
241-
{
242-
fire(events::block_validated, ctx.height);
243-
}
244240

245241
// Return to strand to handle result.
246-
POST(complete_block, ec, link, ctx.height);
242+
POST(tracked_complete_block, ec, link, ctx.height);
247243
}
248244

249245
code chaser_validate::populate(bool bypass, const system::chain::block& block,
@@ -285,22 +281,29 @@ code chaser_validate::validate(bool bypass, const system::chain::block& block,
285281
if ((ec = block.connect(ctx)))
286282
return ec;
287283

288-
if (!query.set_block_valid(link, block.fees()))
284+
if (!query.set_prevouts(link, block))
289285
return error::validate6;
290286

291-
if (!query.set_prevouts(link, block))
287+
if (!query.set_block_valid(link, block.fees()))
292288
return error::validate7;
293289

294290
return ec;
295291
}
296292

297-
void chaser_validate::complete_block(const code& ec, const header_link& link,
298-
size_t height) NOEXCEPT
293+
// The size of the job is not relevant to the backlog cost.
294+
void chaser_validate::tracked_complete_block(const code& ec,
295+
const header_link& link, size_t height) NOEXCEPT
299296
{
300297
BC_ASSERT(stranded());
301298

302-
// The size of the job is not relevant to the backlog cost.
303299
--backlog_;
300+
complete_block(ec, link, height);
301+
}
302+
303+
void chaser_validate::complete_block(const code& ec, const header_link& link,
304+
size_t height) NOEXCEPT
305+
{
306+
BC_ASSERT(stranded());
304307

305308
if (ec)
306309
{
@@ -317,13 +320,15 @@ void chaser_validate::complete_block(const code& ec, const header_link& link,
317320
return;
318321
}
319322

320-
LOGR("Unconfirmable block [" << height << "] " << ec.message());
321-
fire(events::block_unconfirmable, height);
322323
notify(ec, chase::unvalid, link);
324+
fire(events::block_unconfirmable, height);
325+
LOGR("Unconfirmable block [" << height << "] " << ec.message());
323326
return;
324327
}
325328

326329
notify(ec, chase::valid, possible_wide_cast<height_t>(height));
330+
fire(events::block_validated, height);
331+
////LOGV("Block validated: " << height);
327332

328333
// Prevent stall by posting internal event, avoid hitting external handlers.
329334
if (is_zero(backlog_))

0 commit comments

Comments
 (0)