Skip to content

Commit 6e934ae

Browse files
authored
Merge pull request #724 from evoskuil/master
Remove mature_, concurrent_, and associated settings.
2 parents 0f86d1b + 7811690 commit 6e934ae

File tree

12 files changed

+87
-72
lines changed

12 files changed

+87
-72
lines changed

include/bitcoin/node/chasers/chaser_confirm.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,10 @@ class BCN_API chaser_confirm
8585
size_t fork_point) const NOEXCEPT;
8686

8787
// These are protected by strand.
88-
bool mature_{};
8988
network::threadpool threadpool_;
9089

9190
// These are thread safe.
9291
network::asio::strand independent_strand_;
93-
const bool concurrent_;
9492
bool prevout_;
9593
};
9694

include/bitcoin/node/chasers/chaser_validate.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ class BCN_API chaser_validate
7575
}
7676

7777
// These are protected by strand.
78-
bool mature_{};
7978
size_t backlog_{};
8079
network::threadpool threadpool_;
8180

@@ -84,7 +83,6 @@ class BCN_API chaser_validate
8483
const uint32_t subsidy_interval_;
8584
const uint64_t initial_subsidy_;
8685
const size_t maximum_backlog_;
87-
const bool concurrent_;
8886
const bool filter_;
8987
};
9088

include/bitcoin/node/error.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ enum error_t : uint8_t
6060

6161
/// faults (terminal, code error and store corruption assumed)
6262
protocol1,
63+
protocol2,
6364
header1,
6465
organize1,
6566
organize2,

include/bitcoin/node/settings.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,8 @@ class BCN_API settings
7272
settings(system::chain::selection context) NOEXCEPT;
7373

7474
/// Properties.
75+
bool priority;
7576
bool headers_first;
76-
bool priority_validation;
77-
bool concurrent_validation;
78-
bool concurrent_confirmation;
7977
float allowed_deviation;
8078
uint16_t allocation_multiple;
8179
uint64_t snapshot_bytes;

src/chasers/chaser_check.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,7 @@ size_t chaser_check::set_unassociated() NOEXCEPT
341341

342342
// Defer new work issuance until gaps filled and confirmation caught up.
343343
if (position() < requested_ ||
344-
requested_ >= maximum_height_
345-
/*||confirmed_ < requested_*/)
344+
confirmed_ < requested_)
346345
return {};
347346

348347
// Inventory size gets set only once.

src/chasers/chaser_confirm.cpp

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ chaser_confirm::chaser_confirm(full_node& node) NOEXCEPT
4444
: chaser(node),
4545
threadpool_(one, node.config().node.priority_()),
4646
independent_strand_(threadpool_.service().get_executor()),
47-
concurrent_(node.config().node.concurrent_confirmation),
4847
prevout_(node.archive().prevout_enabled())
4948
{
5049
}
@@ -92,34 +91,21 @@ bool chaser_confirm::handle_event(const code&, chase event_,
9291
////{
9392
//// BC_ASSERT(std::holds_alternative<height_t>(value));
9493
////
95-
//// if (concurrent_ || mature_)
96-
//// {
97-
//// // TODO: value is branch point.
98-
//// POST(do_validated, std::get<height_t>(value));
99-
//// }
100-
////
94+
//// // TODO: value is branch point.
95+
//// POST(do_validated, std::get<height_t>(value));
10196
//// break;
10297
////}
10398
case chase::start:
10499
case chase::bump:
105100
{
106-
if (concurrent_ || mature_)
107-
{
108-
POST(do_bump, height_t{});
109-
}
110-
101+
POST(do_bump, height_t{});
111102
break;
112103
}
113104
case chase::valid:
114105
{
115106
// value is validated block height.
116107
BC_ASSERT(std::holds_alternative<height_t>(value));
117-
118-
if (concurrent_ || mature_)
119-
{
120-
POST(do_validated, std::get<height_t>(value));
121-
}
122-
108+
POST(do_validated, std::get<height_t>(value));
123109
break;
124110
}
125111
case chase::regressed:
@@ -240,6 +226,13 @@ void chaser_confirm::do_bump(height_t) NOEXCEPT
240226
return;
241227
}
242228

229+
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
230+
// Failure here was previously result of bug in hashmap, which
231+
// caused both iteration across full prevout table and missing
232+
// prevout tx records intermittently in confirmation query.
233+
// This would prevent subsequent confirmation progress. This
234+
// has been resolved.
235+
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
243236
notify(ec, chase::unconfirmable, link);
244237
fire(events::block_unconfirmable, height);
245238
LOGR("Unconfirmable block [" << height << "] " << ec.message());

src/chasers/chaser_validate.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ chaser_validate::chaser_validate(full_node& node) NOEXCEPT
4848
subsidy_interval_(node.config().bitcoin.subsidy_interval_blocks),
4949
initial_subsidy_(node.config().bitcoin.initial_subsidy()),
5050
maximum_backlog_(node.config().node.maximum_concurrency_()),
51-
concurrent_(node.config().node.concurrent_validation),
5251
filter_(node.archive().neutrino_enabled())
5352
{
5453
}
@@ -95,23 +94,14 @@ bool chaser_validate::handle_event(const code&, chase event_,
9594
case chase::start:
9695
case chase::bump:
9796
{
98-
if (concurrent_ || mature_)
99-
{
100-
POST(do_bump, height_t{});
101-
}
102-
97+
POST(do_bump, height_t{});
10398
break;
10499
}
105100
case chase::checked:
106101
{
107102
// value is checked block height.
108103
BC_ASSERT(std::holds_alternative<height_t>(value));
109-
110-
if (concurrent_ || mature_)
111-
{
112-
POST(do_checked, std::get<height_t>(value));
113-
}
114-
104+
POST(do_checked, std::get<height_t>(value));
115105
break;
116106
}
117107
case chase::regressed:
@@ -316,6 +306,16 @@ void chaser_validate::complete_block(const code& ec, const header_link& link,
316306
notify(ec, chase::unvalid, link);
317307
fire(events::block_unconfirmable, height);
318308
LOGR("Invalid block [" << height << "] " << ec.message());
309+
310+
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
311+
// Stop the network in case of an unexpected invalidity (debugging).
312+
// This is considered a bug, not an invalid block arrival (for now).
313+
// This usually manifests as accept failure invalid_witness (!checked),
314+
// in which case the witness data is simply not present, but bip141 is
315+
// active and the output indicates a witness transaction.
316+
fault(ec);
317+
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
318+
319319
return;
320320
}
321321

src/error.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ DEFINE_ERROR_T_MESSAGE_MAP(error)
5050

5151
/// faults
5252
{ protocol1, "protocol1" },
53+
{ protocol2, "protocol2" },
5354
{ header1, "header1" },
5455
{ organize1, "organize1" },
5556
{ organize2, "organize2" },

src/parser.cpp

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -906,19 +906,9 @@ options_metadata parser::load_settings() THROWS
906906
"The number of threads in the validation threadpool, defaults to 16."
907907
)
908908
(
909-
"node.priority_validation",
910-
value<bool>(&configured.node.priority_validation),
911-
"Set the validation threadpool to high priority, defaults to false."
912-
)
913-
(
914-
"node.concurrent_validation",
915-
value<bool>(&configured.node.concurrent_validation),
916-
"Perform validation concurrently with download, defaults to false."
917-
)
918-
(
919-
"node.concurrent_confirmation",
920-
value<bool>(&configured.node.concurrent_confirmation),
921-
"Perform confirmation concurrently with download, defaults to false."
909+
"node.priority",
910+
value<bool>(&configured.node.priority),
911+
"Set the validation threadpool to high priority, defaults to true."
922912
)
923913
(
924914
"node.headers_first",

src/protocols/protocol_block_in_31800.cpp

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,21 @@ bool protocol_block_in_31800::handle_receive_block(const code& ec,
304304
const auto checked = is_under_checkpoint(height) ||
305305
query.is_milestone(link);
306306

307+
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
308+
// Failed on block [363353] with block_internal_double_spend (!checked).
309+
// The block object remains in scope during the call, but the pointer owns
310+
// the memory. There is a local pointer object copied above, but it may be
311+
// deleted once it is no longer referenced. This makes the block reference
312+
// below weak. The message pointer object is also held by the calling
313+
// closure, however it can be deleted by the compiler due to subsequent
314+
// non-use. The copied block pointer holds the block object, but it may be
315+
// also deleted if not referenced. Passing a block pointer into check,
316+
// allowing block->check() to be called would resolve that issue, but not
317+
// the issue of calling set_code (see below). But it's not clear how ~block
318+
// could have occured here with query.set_code(*block) pending below.
319+
// It hasn't failed when using a prevout table, which seems unrelated.
320+
// But if it's a race to overwrite freed block memory, it's very possible.
321+
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
307322
// Tx commitments and malleation are checked under bypass. Invalidity is
308323
// only stored when a strong header has been stored, later to be found out
309324
// as invalid and not malleable. Stored invalidity prevents repeat
@@ -315,6 +330,11 @@ bool protocol_block_in_31800::handle_receive_block(const code& ec,
315330
code == system::error::invalid_witness_commitment ||
316331
code == system::error::block_malleated)
317332
{
333+
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
334+
// These references to block didn't keep it in scope.
335+
// But because block is const they could precede the check. Could
336+
// be a compiler optimization as these are called by check(true).
337+
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
318338
LOGR("Uncommitted block [" << encode_hash(hash) << ":" << height
319339
<< "] from [" << authority() << "] " << code.message()
320340
<< " txs(" << block->transactions() << ")"
@@ -323,22 +343,12 @@ bool protocol_block_in_31800::handle_receive_block(const code& ec,
323343
return false;
324344
}
325345

326-
// TODO: why were we not setting this block as unconfirmable?
327-
////if (code == system::error::forward_reference)
328-
////{
329-
//// LOGR("Disordered block [" << encode_hash(hash) << ":" << height
330-
//// << " txs(" << block->transactions() << ")"
331-
//// << " segregated(" << block->is_segregated() << ").");
332-
//// stop(code);
333-
//// return false;
334-
////}
335-
336346
// Actual block represented by the hash is unconfirmable.
337347
if (!query.set_block_unconfirmable(link))
338348
{
339349
LOGF("Failure setting block unconfirmable [" << encode_hash(hash)
340350
<< ":" << height << "] from [" << authority() << "].");
341-
fault(error::protocol1);
351+
stop(fault(error::protocol1));
342352
return false;
343353
}
344354

@@ -353,6 +363,18 @@ bool protocol_block_in_31800::handle_receive_block(const code& ec,
353363
// Commit block.txs.
354364
// ........................................................................
355365

366+
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
367+
// For early segwit blocks this often fails to set the witness.
368+
// There is no failure code, the witness is just empty and stored empty.
369+
// That causes a validation failure with invalid_witness (!checked).
370+
// It may have also failed in a way that invalidates confirmation queries.
371+
// Passing a block pointer here would only hold the block in scope until
372+
// it iterates transactions, with no subsequent reference. Then transaction
373+
// pointers could hold themselves in scope, however block owns their memory
374+
// and ~block() frees that memory even if the transaction pointer is alive.
375+
// It hasn't failed when using a prevout table, which seems unrelated.
376+
// But if it's a race to overwrite freed block memory, it's very possible.
377+
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
356378
// This invokes set_strong when checked.
357379
if (const auto code = query.set_code(*block, link, checked))
358380
{
@@ -363,6 +385,23 @@ bool protocol_block_in_31800::handle_receive_block(const code& ec,
363385
return false;
364386
}
365387

388+
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
389+
// TODO: verify that ~block() free during contained object access is the
390+
// problem by switching to the default memory allocator w/non-prevout run
391+
// and the code below disabled.
392+
// TODO: pass shared_ptr in to check(block) and set_code(block) from here.
393+
// This may guarantee the pointer (vs. block&) lifetime until return.
394+
// This is an attempt to keep the shared pointer in scope.
395+
// Given that block is const this could also be reordered prior to check().
396+
// But this is not called in this scope, only by message deserialization.
397+
// Passing the block pointer through the store
398+
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
399+
if (!block->is_valid())
400+
{
401+
stop(fault(error::protocol2));
402+
return false;
403+
}
404+
366405
// Advance.
367406
// ........................................................................
368407

@@ -372,8 +411,10 @@ bool protocol_block_in_31800::handle_receive_block(const code& ec,
372411
notify(ec, chase::checked, height);
373412
fire(events::block_archived, height);
374413

414+
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
375415
// block->serialized_size may keep block in scope during set_code above.
376416
// However the compiler may reorder this calculation since block is const.
417+
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
377418
count(block->serialized_size(true));
378419
map_->erase(it);
379420
if (is_idle())

0 commit comments

Comments
 (0)