Skip to content

Commit

Permalink
Merge pull request #586 from evoskuil/master
Browse files Browse the repository at this point in the history
Add bump event to prevent preconfirm stall with no downloads.
  • Loading branch information
evoskuil committed Apr 16, 2024
2 parents 0c1d4ad + b3560e1 commit 36f103d
Show file tree
Hide file tree
Showing 14 changed files with 56 additions and 31 deletions.
4 changes: 2 additions & 2 deletions console/executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const std::unordered_map<uint8_t, std::string> executor::fired_

{ events::block_archived, "block_archived......" },
{ events::block_validated, "block_validated....." },
{ events::block_confirmable, "block_confirmable..." },
{ events::block_confirmed, "block_confirmed....." },
{ events::block_unconfirmable, "block_unconfirmable." },
{ events::validate_bypassed, "validate_bypassed..." },
{ events::confirm_bypassed, "confirm_bypassed...." },
Expand Down Expand Up @@ -1013,7 +1013,7 @@ void executor::write_test()
else if ((ec = query_.block_confirmable(link)))
{
// must set_strong before each (no push, verifies non-use).
console(format("Failure: block_confirmable, %1%") % ec.message());
console(format("Failure: block_confirmed, %1%") % ec.message());
break;
}
////if (!query_.set_txs_connected(link))
Expand Down
6 changes: 5 additions & 1 deletion include/bitcoin/node/chase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ enum class chase
/// Work shuffling.
/// -----------------------------------------------------------------------

/// Chaser is directed to start validating (height_t).
/// Chasers are directed to start operating (height_t).
/// Issued by 'full_node' and handled by 'preconfirm'.
start,

/// Chaser is directed to start when there are no downloads (height_t).
/// Issued by 'organize' and handled by 'preconfirm'.
bump,

/// Channels (all) are directed to pause reading (channel_t).
/// Issued by 'full_node' and handled by 'protocol'.
pause,
Expand Down
3 changes: 3 additions & 0 deletions include/bitcoin/node/chasers/chaser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ class BCN_API chaser
/// True if the current thread is on the chaser strand.
bool stranded() const NOEXCEPT;

/// Top candidate is within configured span from current time.
bool is_current() const NOEXCEPT;

/// Header timestamp is within configured span from current time.
bool is_current(uint32_t timestamp) const NOEXCEPT;

Expand Down
2 changes: 1 addition & 1 deletion include/bitcoin/node/events.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ enum events : uint8_t
/// Blocks.
block_archived, // block checked
block_validated, // block checked, accepted, connected
block_confirmable, // block checked, accepted, connected, confirmable
block_confirmed, // block checked, accepted, connected, confirmable
block_unconfirmable, // block invalid (after headers-first archive)
validate_bypassed, // block checked, accepted [assumed]
confirm_bypassed, // block checked, accepted, connected [assumed]
Expand Down
15 changes: 11 additions & 4 deletions include/bitcoin/node/impl/chasers/chaser_organize.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ void CLASS::handle_event(const code&, chase event_, event_link value) NOEXCEPT
break;
}
case chase::start:
case chase::bump:
case chase::pause:
case chase::resume:
case chase::starved:
Expand Down Expand Up @@ -366,12 +367,18 @@ void CLASS::do_organize(typename Block::cptr& block_ptr,

// Delay so headers can get current before block download starts.
// Checking currency before notify also avoids excessive work backlog.

// If all headers are previously associated then no blocks will be fed to
// preconfirmation, resulting in a stall...

if (is_block() || is_current(header.timestamp()))
{
// If at start the fork point is top of both chains, and next candidate
// is already downloaded, then new header will arrive and download will
// be skipped, resulting in stall until restart at which time the start
// event will advance through all downloaded candidates and progress on
// arrivals. This bumps preconfirmation for current strong headers.
notify(error::success, chase::bump, add1(branch_point));

// Start block downloads, which upon completion bumps preconfirmation.
notify(error::success, chase_object(), branch_point);
}

state_ = state;
handler(error::success, height);
Expand Down
5 changes: 5 additions & 0 deletions src/chasers/chaser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ bool chaser::stranded() const NOEXCEPT
return strand_.running_in_this_thread();
}

bool chaser::is_current() const NOEXCEPT
{
return node_.is_current();
}

bool chaser::is_current(uint32_t timestamp) const NOEXCEPT
{
return node_.is_current(timestamp);
Expand Down
10 changes: 4 additions & 6 deletions src/chasers/chaser_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ void chaser_check::handle_event(const code&, chase event_,
break;
}
case chase::start:
case chase::bump:
case chase::pause:
case chase::resume:
case chase::starved:
Expand Down Expand Up @@ -133,10 +134,8 @@ void chaser_check::do_add_headers(height_t branch_point) NOEXCEPT
LOGN("Branch point (" << branch_point << ") unassociated ("
<< added << ").");

if (is_zero(added))
return;

notify(error::success, chase::download, added);
if (!is_zero(added))
notify(error::success, chase::download, added);
}

// purge headers
Expand Down Expand Up @@ -247,8 +246,7 @@ size_t chaser_check::count_map(const maps& table) const NOEXCEPT
});
}

map_ptr chaser_check::make_map(size_t start,
size_t count) const NOEXCEPT
map_ptr chaser_check::make_map(size_t start, size_t count) const NOEXCEPT
{
// Known malleated blocks are disassociated and therefore appear here.
return std::make_shared<associations>(
Expand Down
26 changes: 15 additions & 11 deletions src/chasers/chaser_confirm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ void chaser_confirm::handle_event(const code&, chase event_,
break;
}
case chase::start:
case chase::bump:
case chase::pause:
case chase::resume:
case chase::starved:
Expand Down Expand Up @@ -179,21 +180,21 @@ void chaser_confirm::do_preconfirmed(height_t height) NOEXCEPT
// Advance and confirm.
notify(code, chase::confirmable, index);
fire(events::confirm_bypassed, index);

if (!set_confirmed(link, index++))
{
fault(error::store_integrity);
return;
}
continue;
}

if (code == error::store_integrity)
{
fault(error::store_integrity);
return;
}

if (query.is_malleable(link))
{
notify(code, chase::malleated, link);
Expand All @@ -206,17 +207,17 @@ void chaser_confirm::do_preconfirmed(height_t height) NOEXCEPT
fault(error::store_integrity);
return;
}

notify(code, chase::unconfirmable, link);
fire(events::block_unconfirmable, index);
}

if (!roll_back(popped, fork_point, sub1(index)))
{
fault(error::store_integrity);
return;
}

LOGR("Unconfirmable block [" << index << "] " << code.message());
return;
}
Expand All @@ -235,7 +236,7 @@ void chaser_confirm::do_preconfirmed(height_t height) NOEXCEPT
// ....................................................................

notify(error::success, chase::confirmable, index);
fire(events::block_confirmable, index);
fire(events::block_confirmed, index);

if (!set_confirmed(link, index++))
{
Expand All @@ -258,11 +259,14 @@ code chaser_confirm::confirm(const header_link& link,
ec == database::error::block_unconfirmable)
return ec;

if (ec == database::error::block_preconfirmable)
return query.block_confirmable(link);
// TODO: fix block_confirmable.
return error::success;

// Should not get here without a known block state.
return error::store_integrity;
////if (ec == database::error::block_preconfirmable)
//// return query.block_confirmable(link);
////
////// Should not get here without a known block state.
////return error::store_integrity;
}

// utility
Expand Down
10 changes: 4 additions & 6 deletions src/chasers/chaser_preconfirm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,7 @@ void chaser_preconfirm::handle_event(const code&, chase event_,
switch (event_)
{
case chase::start:
{
POST(do_checked, height_t{});
break;
}
case chase::header:
case chase::bump:
{
POST(do_checked, height_t{});
break;
Expand All @@ -81,6 +77,7 @@ void chaser_preconfirm::handle_event(const code&, chase event_,
break;
}
////case chase::start:
////case chase::bump:
case chase::pause:
case chase::resume:
case chase::starved:
Expand Down Expand Up @@ -240,7 +237,8 @@ code chaser_preconfirm::validate(const header_link& link,
{} // work_required
};

return ec = block.accept(ctx, subsidy_interval_blocks_, initial_subsidy_) ?
return
ec = block.accept(ctx, subsidy_interval_blocks_, initial_subsidy_) ?
ec : block.connect(ctx);
}

Expand Down
1 change: 1 addition & 0 deletions src/chasers/chaser_template.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ void chaser_template::handle_event(const code&, chase event_,
break;
}
case chase::start:
case chase::bump:
case chase::pause:
case chase::resume:
case chase::starved:
Expand Down
2 changes: 2 additions & 0 deletions src/chasers/chaser_transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ void chaser_transaction::handle_event(const code&, chase event_,
// TODO: handle fault.
break;
}

case chase::bump:
case chase::start:
case chase::pause:
case chase::resume:
Expand Down
1 change: 1 addition & 0 deletions src/protocols/protocol_block_in_31800.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ void protocol_block_in_31800::handle_event(const code&,
break;
}
case chase::start:
case chase::bump:
////case chase::pause:
////case chase::resume:
case chase::starved:
Expand Down
1 change: 1 addition & 0 deletions src/protocols/protocol_observer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ void protocol_observer::handle_event(const code&, chase event_,
break;
}
case chase::start:
case chase::bump:
////case chase::pause:
////case chase::resume:
case chase::starved:
Expand Down
1 change: 1 addition & 0 deletions src/sessions/session_outbound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ void session_outbound::handle_event(const code&,
break;
}
case chase::start:
case chase::bump:
case chase::pause:
case chase::resume:
////case chase::starved:
Expand Down

0 comments on commit 36f103d

Please sign in to comment.