Skip to content

Commit

Permalink
Change chaser::close to ::fault, comments, style.
Browse files Browse the repository at this point in the history
  • Loading branch information
evoskuil committed Apr 12, 2024
1 parent 16ec878 commit e7b2115
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 72 deletions.
6 changes: 3 additions & 3 deletions include/bitcoin/node/chasers/chaser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ class BCN_API chaser
/// Close.
/// -----------------------------------------------------------------------

/// Close the node after logging the code.
void close(const code& ec) const NOEXCEPT;
/// There was a fault in the node.
void fault(const code& ec) const NOEXCEPT;

/// Node threadpool is stopped and may still be joining.
bool closed() const NOEXCEPT;
Expand All @@ -80,7 +80,7 @@ class BCN_API chaser
code subscribe_events(event_handler&& handler) NOEXCEPT;

/// Set event (does not require node strand).
void notify(const code& ec, chase event_, event_link value) NOEXCEPT;
void notify(const code& ec, chase event_, event_link value) const NOEXCEPT;

/// Properties.
/// -----------------------------------------------------------------------
Expand Down
37 changes: 21 additions & 16 deletions include/bitcoin/node/impl/chasers/chaser_organize.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ void CLASS::handle_event(const code&, chase event_, event_link value) NOEXCEPT
POST(do_disorganize, possible_narrow_cast<header_t>(value));
break;
}
case chase::stop:
{
// TODO: handle fault.
break;
}
case chase::start:
case chase::pause:
case chase::resume:
Expand All @@ -118,7 +123,7 @@ void CLASS::handle_event(const code&, chase event_, event_link value) NOEXCEPT
case chase::malleated:
case chase::transaction:
case chase::template_:
case chase::stop:
////case chase::stop:
{
break;
}
Expand Down Expand Up @@ -161,7 +166,7 @@ void CLASS::do_organize(typename Block::cptr& block_ptr,
if (!query.get_height(height, id))
{
handler(error::store_integrity, {});
close(error::store_integrity); // <= deadlock
fault(error::store_integrity);
return;
}

Expand Down Expand Up @@ -256,15 +261,15 @@ void CLASS::do_organize(typename Block::cptr& block_ptr,
if (!get_branch_work(work, branch_point, tree_branch, store_branch, header))
{
handler(error::store_integrity, height);
close(error::store_integrity); // <= deadlock
fault(error::store_integrity);
return;
}

bool strong{};
if (!get_is_strong(strong, work, branch_point))
{
handler(error::store_integrity, height);
close(error::store_integrity); // <= deadlock
fault(error::store_integrity);
return;
}

Expand All @@ -283,7 +288,7 @@ void CLASS::do_organize(typename Block::cptr& block_ptr,
if (top < branch_point)
{
handler(error::store_integrity, height);
close(error::store_integrity); // <= deadlock
fault(error::store_integrity);
return;
}

Expand All @@ -294,7 +299,7 @@ void CLASS::do_organize(typename Block::cptr& block_ptr,
if (!query.pop_candidate())
{
handler(error::store_integrity, height);
close(error::store_integrity); // <= deadlock
fault(error::store_integrity);
return;
}

Expand All @@ -310,7 +315,7 @@ void CLASS::do_organize(typename Block::cptr& block_ptr,
if (!query.push_candidate(link))
{
handler(error::store_integrity, height);
close(error::store_integrity); // <= deadlock
fault(error::store_integrity);
return;
}

Expand All @@ -323,7 +328,7 @@ void CLASS::do_organize(typename Block::cptr& block_ptr,
if (!push(key))
{
handler(error::store_integrity, height);
close(error::store_integrity); // <= deadlock
fault(error::store_integrity);
return;
}

Expand All @@ -336,7 +341,7 @@ void CLASS::do_organize(typename Block::cptr& block_ptr,
if (push(block, state->context()).is_terminal())
{
handler(error::store_integrity, height);
close(error::store_integrity); // <= deadlock
fault(error::store_integrity);
return;
}

Expand Down Expand Up @@ -379,15 +384,15 @@ void CLASS::do_disorganize(header_t link) NOEXCEPT
size_t height{};
if (!query.get_height(height, link) || is_zero(height))
{
close(error::store_integrity); // <= deadlock
fault(error::store_integrity);
return;
}

// Must reorganize down to fork point, since entire branch is now weak.
const auto fork_point = query.get_fork();
if (height <= fork_point)
{
close(error::store_integrity); // <= deadlock
fault(error::store_integrity);
return;
}

Expand All @@ -402,7 +407,7 @@ void CLASS::do_disorganize(header_t link) NOEXCEPT
{
if (!query.pop_candidate())
{
close(error::store_integrity); // <= deadlock
fault(error::store_integrity);
return;
}

Expand All @@ -418,7 +423,7 @@ void CLASS::do_disorganize(header_t link) NOEXCEPT
state_ = query.get_candidate_chain_state(settings_, fork_point);
if (!state_)
{
close(error::store_integrity); // <= deadlock
fault(error::store_integrity);
return;
}

Expand Down Expand Up @@ -454,7 +459,7 @@ void CLASS::do_disorganize(header_t link) NOEXCEPT
typename Block::cptr block{};
if (!get_block(block, index))
{
close(error::store_integrity); // <= deadlock
fault(error::store_integrity);
return;
}

Expand All @@ -477,7 +482,7 @@ void CLASS::do_disorganize(header_t link) NOEXCEPT

if (!query.pop_candidate())
{
close(error::store_integrity); // <= deadlock
fault(error::store_integrity);
return;
}

Expand All @@ -492,7 +497,7 @@ void CLASS::do_disorganize(header_t link) NOEXCEPT
{
if (!query.push_candidate(query.to_confirmed(index)))
{
close(error::store_integrity); // <= deadlock
fault(error::store_integrity);
return;
}

Expand Down
8 changes: 5 additions & 3 deletions src/chasers/chaser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ chaser::chaser(full_node& node) NOEXCEPT
// Close.
// ----------------------------------------------------------------------------

void chaser::close(const code& ec) const NOEXCEPT
void chaser::fault(const code& ec) const NOEXCEPT
{
LOGF("Chaser failed, " << ec.message());
LOGF("Detected fault: " << ec.message());
notify(ec, chase::stop, {});
}

bool chaser::closed() const NOEXCEPT
Expand All @@ -61,7 +62,8 @@ code chaser::subscribe_events(event_handler&& handler) NOEXCEPT
return node_.subscribe_events(std::move(handler));
}

void chaser::notify(const code& ec, chase event_, event_link value) NOEXCEPT
void chaser::notify(const code& ec, chase event_,
event_link value) const NOEXCEPT
{
// Posts to node strand, not chaser strand.
node_.notify(ec, event_, value);
Expand Down
9 changes: 3 additions & 6 deletions src/chasers/chaser_block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,20 @@ bool chaser_block::get_block(block::cptr& out, size_t index) const NOEXCEPT
return !is_null(out);
}

// Block validations are bypassed when under checkpoint.
code chaser_block::validate(const block& block,
const chain_state& state) const NOEXCEPT
{
code ec{};
const auto& header = block.header();

// block.check does not roll up to header.check.
// block.check does not invoke header.check.
if ((ec = header.check(
settings().timestamp_limit_seconds,
settings().proof_of_work_limit,
settings().forks.scrypt_proof_of_work)))
return ec;

// block.accept does not roll up to header.accept.
// block.accept does not invoke header.accept.
if ((ec = header.accept(state.context())))
return ec;

Expand All @@ -79,10 +78,8 @@ code chaser_block::validate(const block& block,
if ((ec = block.check(state.context())))
return ec;

// Populate prevouts from self/tree.
// Metadata population is only for confirmation, not required.
// Populate prevouts from self/tree/store (metadata not required).
populate(block);

if (!archive().populate(block))
return network::error::protocol_violation;

Expand Down
37 changes: 13 additions & 24 deletions src/chasers/chaser_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ namespace node {

using namespace system;
using namespace system::chain;
using namespace database;
using namespace network;
using namespace std::placeholders;

Expand All @@ -44,7 +45,7 @@ chaser_check::chaser_check(full_node& node) NOEXCEPT
: chaser(node),
connections_(node.network_settings().outbound_connections),
inventory_(system::lesser(node.config().node.maximum_inventory,
network::messages::max_inventory))
messages::max_inventory))
{
}

Expand Down Expand Up @@ -81,6 +82,11 @@ void chaser_check::handle_event(const code&, chase event_,
POST(do_malleated, possible_narrow_cast<header_t>(value));
break;
}
case chase::stop:
{
// TODO: handle fault.
break;
}
case chase::start:
case chase::pause:
case chase::resume:
Expand All @@ -103,7 +109,7 @@ void chaser_check::handle_event(const code&, chase event_,
////case chase::malleated:
case chase::transaction:
case chase::template_:
case chase::stop:
////case chase::stop:
{
break;
}
Expand Down Expand Up @@ -140,18 +146,6 @@ void chaser_check::do_purge_headers(height_t top) NOEXCEPT
// be purged, it simply means purge all hashes (reset all). All channels
// will get the purge notification before any subsequent download notify.
maps_.clear();

// It is possible for the previous candidate chain to have been stronger
// than confirmed (above fork point), given an unconfirmable block found
// more than one block above fork point. Yet this stronger candidate(s)
// will be popped, and all channels purged/dropped, once purge is handled.
// Subsequently there will be no progress on that stronger chain until a
// new stronger block is found upon channel restarts. In other words such a
// disorganization accepts a stall, not to exceed a singl block period. As
// a disorganization is an extrememly rare event: it requires relay of an
// invalid block with valid proof of work, on top of another strong block
// that was conicidentally not yet successfully confirmed. This is worth
// the higher complexity implementation to avoid.
notify(error::success, chase::purge, top);
}

Expand All @@ -166,7 +160,7 @@ void chaser_check::get_hashes(map_handler&& handler) NOEXCEPT
}

void chaser_check::put_hashes(const map_ptr& map,
network::result_handler&& handler) NOEXCEPT
result_handler&& handler) NOEXCEPT
{
boost::asio::post(strand(),
std::bind(&chaser_check::do_put_hashes,
Expand All @@ -185,7 +179,7 @@ void chaser_check::do_get_hashes(const map_handler& handler) NOEXCEPT
}

void chaser_check::do_put_hashes(const map_ptr& map,
const network::result_handler& handler) NOEXCEPT
const result_handler& handler) NOEXCEPT
{
BC_ASSERT(stranded());

Expand All @@ -206,19 +200,15 @@ void chaser_check::do_put_hashes(const map_ptr& map,
// The archived malleable block instance was found to be invalid (malleated).
// The block/header hash cannot be marked unconfirmable due to malleability, so
// disassociate the block and then add the block hash back to the current set.
// Upon restart/disorg the dissasociation causes the block hash to be mapped
// despite existing stored block instance(s). Storage can then invalidate found
// blocks that bitwise match stored-invalid-malleable (i.e. malleated) blocks.
void chaser_check::do_malleated(header_t link) NOEXCEPT
{
BC_ASSERT(stranded());
using namespace database;
auto& query = archive();

association out{};
if (!query.dissasociate(link) || !query.get_unassociated(out, link))
{
close(error::store_integrity); // <= deadlock
fault(error::store_integrity);
return;
}

Expand Down Expand Up @@ -257,14 +247,13 @@ 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<database::associations>(
return std::make_shared<associations>(
archive().get_unassociated_above(start, count));
}

map_ptr chaser_check::get_map(maps& table) NOEXCEPT
{
return table.empty() ? std::make_shared<database::associations>() :
pop_front(table);
return table.empty() ? std::make_shared<associations>() : pop_front(table);
}

BC_POP_WARNING()
Expand Down
Loading

0 comments on commit e7b2115

Please sign in to comment.