Skip to content

Commit 669f38e

Browse files
authored
Merge pull request #726 from evoskuil/master
Don't fire events for bypassed validate/confirm, shrink initial point table.
2 parents ba7fe2d + 53ca381 commit 669f38e

File tree

5 files changed

+34
-71
lines changed

5 files changed

+34
-71
lines changed

include/bitcoin/node/chasers/chaser_validate.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ class BCN_API chaser_validate
6060
virtual code populate(bool bypass, const system::chain::block& block,
6161
const system::chain::context& ctx) NOEXCEPT;
6262
virtual void tracked_complete_block(const code& ec,
63-
const database::header_link& link, size_t height) NOEXCEPT;
63+
const database::header_link& link, size_t height, bool bypassed) NOEXCEPT;
6464
virtual void complete_block(const code& ec,
65-
const database::header_link& link, size_t height) NOEXCEPT;
65+
const database::header_link& link, size_t height, bool bypassed) NOEXCEPT;
6666

6767
// Override base class strand because it sits on the network thread pool.
6868
network::asio::strand& strand() NOEXCEPT override;

src/chasers/chaser_confirm.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ void chaser_confirm::do_bump(height_t) NOEXCEPT
177177
{
178178
const auto link = query.to_candidate(height);
179179
auto ec = query.get_block_state(link);
180+
auto bypassed = true;
180181

181182
if (ec == database::error::unassociated)
182183
{
@@ -224,13 +225,6 @@ void chaser_confirm::do_bump(height_t) NOEXCEPT
224225
return;
225226
}
226227

227-
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
228-
// Failure here was previously result of bug in hashmap, which
229-
// caused both iteration across full prevout table and missing
230-
// prevout tx records intermittently in confirmation query.
231-
// This would prevent subsequent confirmation progress. This
232-
// has been resolved.
233-
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
234228
notify(ec, chase::unconfirmable, link);
235229
fire(events::block_unconfirmable, height);
236230
LOGR("Unconfirmable block [" << height << "] " << ec.message());
@@ -249,6 +243,9 @@ void chaser_confirm::do_bump(height_t) NOEXCEPT
249243
fault(error::confirm6);
250244
return;
251245
}
246+
247+
// Confirmable query executed successfully.
248+
bypassed = false;
252249
}
253250
else if (ec == database::error::block_confirmable)
254251
{
@@ -284,8 +281,12 @@ void chaser_confirm::do_bump(height_t) NOEXCEPT
284281
set_position(height);
285282

286283
notify(error::success, chase::confirmable, height);
287-
fire(events::block_confirmed, height);
288-
////LOGV("Block confirmed: " << height);
284+
285+
if (!bypassed)
286+
{
287+
fire(events::block_confirmed, height);
288+
////LOGV("Block confirmed: " << height);
289+
}
289290
}
290291
}
291292

src/chasers/chaser_validate.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ void chaser_validate::do_bump(height_t) NOEXCEPT
168168
}
169169
else if (ec == database::error::block_unconfirmable)
170170
{
171-
complete_block(ec, link, height);
171+
complete_block(ec, link, height, true);
172172
return;
173173
}
174174

@@ -179,7 +179,7 @@ void chaser_validate::do_bump(height_t) NOEXCEPT
179179

180180
if (bypass && !filter_)
181181
{
182-
complete_block(database::error::success, link, height);
182+
complete_block(database::error::success, link, height, true);
183183
}
184184
else
185185
{
@@ -227,7 +227,7 @@ void chaser_validate::validate_block(const header_link& link,
227227
}
228228

229229
// Return to strand to handle result.
230-
POST(tracked_complete_block, ec, link, ctx.height);
230+
POST(tracked_complete_block, ec, link, ctx.height, bypass);
231231
}
232232

233233
code chaser_validate::populate(bool bypass, const chain::block& block,
@@ -279,16 +279,16 @@ code chaser_validate::validate(bool bypass, const chain::block& block,
279279

280280
// The size of the job is not relevant to the backlog cost.
281281
void chaser_validate::tracked_complete_block(const code& ec,
282-
const header_link& link, size_t height) NOEXCEPT
282+
const header_link& link, size_t height, bool bypassed) NOEXCEPT
283283
{
284284
BC_ASSERT(stranded());
285285

286286
--backlog_;
287-
complete_block(ec, link, height);
287+
complete_block(ec, link, height, bypassed);
288288
}
289289

290290
void chaser_validate::complete_block(const code& ec, const header_link& link,
291-
size_t height) NOEXCEPT
291+
size_t height, bool bypassed) NOEXCEPT
292292
{
293293
BC_ASSERT(stranded());
294294

@@ -305,21 +305,20 @@ void chaser_validate::complete_block(const code& ec, const header_link& link,
305305
fire(events::block_unconfirmable, height);
306306
LOGR("Invalid block [" << height << "] " << ec.message());
307307

308-
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
309308
// Stop the network in case of an unexpected invalidity (debugging).
310309
// This is considered a bug, not an invalid block arrival (for now).
311-
// This usually manifests as accept failure invalid_witness (!checked),
312-
// in which case the witness data is simply not present, but bip141 is
313-
// active and the output indicates a witness transaction.
314-
fault(ec);
315-
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
310+
////fault(ec);
316311

317312
return;
318313
}
319314

320315
notify(ec, chase::valid, possible_wide_cast<height_t>(height));
321-
fire(events::block_validated, height);
322-
////LOGV("Block validated: " << height);
316+
317+
if (!bypassed)
318+
{
319+
fire(events::block_validated, height);
320+
////LOGV("Block validated: " << height);
321+
}
323322

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

src/parser.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,9 @@ parser::parser(system::chain::selection context) NOEXCEPT
8282
configured.database.output_size = 25'300'000'000;
8383
configured.database.output_rate = 5;
8484

85-
configured.database.point_buckets = 1'750'905'073;
86-
configured.database.point_size = 24'000'000'000;
85+
// Full size too big for mini, so reduced to compressed size.
86+
configured.database.point_buckets = 546'188'501;
87+
configured.database.point_size = 8'389'074'978;
8788
configured.database.point_rate = 5;
8889

8990
configured.database.puts_size = 6'300'000'000;
@@ -697,12 +698,12 @@ options_metadata parser::load_settings() THROWS
697698
(
698699
"database.point_buckets",
699700
value<uint32_t>(&configured.database.point_buckets),
700-
"The number of buckets in the point table head, defaults to '1750905073'."
701+
"The number of buckets in the point table head, defaults to '546188501'."
701702
)
702703
(
703704
"database.point_size",
704705
value<uint64_t>(&configured.database.point_size),
705-
"The minimum allocation of the point table body, defaults to '24000000000'."
706+
"The minimum allocation of the point table body, defaults to '8389074978'."
706707
)
707708
(
708709
"database.point_rate",

src/protocols/protocol_block_in_31800.cpp

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -304,21 +304,6 @@ 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-
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
322307
// Tx commitments and malleation are checked under bypass. Invalidity is
323308
// only stored when a strong header has been stored, later to be found out
324309
// as invalid and not malleable. Stored invalidity prevents repeat
@@ -330,11 +315,6 @@ bool protocol_block_in_31800::handle_receive_block(const code& ec,
330315
code == system::error::invalid_witness_commitment ||
331316
code == system::error::block_malleated)
332317
{
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-
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
338318
LOGR("Uncommitted block [" << encode_hash(hash) << ":" << height
339319
<< "] from [" << authority() << "] " << code.message()
340320
<< " txs(" << block->transactions() << ")"
@@ -363,18 +343,6 @@ bool protocol_block_in_31800::handle_receive_block(const code& ec,
363343
// Commit block.txs.
364344
// ........................................................................
365345

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-
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
378346
// This invokes set_strong when checked.
379347
if (const auto code = query.set_code(*block, link, checked))
380348
{
@@ -385,17 +353,11 @@ bool protocol_block_in_31800::handle_receive_block(const code& ec,
385353
return false;
386354
}
387355

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.
356+
// ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
394357
// This is an attempt to keep the shared pointer in scope.
395358
// Given that block is const this could also be reordered prior to check().
396359
// But this is not called in this scope, only by message deserialization.
397-
// Passing the block pointer through the store
398-
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
360+
// ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
399361
if (!block->is_valid())
400362
{
401363
stop(fault(error::protocol2));
@@ -411,10 +373,10 @@ bool protocol_block_in_31800::handle_receive_block(const code& ec,
411373
notify(ec, chase::checked, height);
412374
fire(events::block_archived, height);
413375

414-
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
376+
// ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
415377
// block->serialized_size may keep block in scope during set_code above.
416378
// However the compiler may reorder this calculation since block is const.
417-
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
379+
// ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
418380
count(block->serialized_size(true));
419381
map_->erase(it);
420382
if (is_idle())

0 commit comments

Comments
 (0)