Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions include/bitcoin/node/chase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,15 @@ enum class chase
/// -----------------------------------------------------------------------

/// A current block has been organized (header_t).
/// Issued by 'transaction' and handled by 'protocol_header/block_out'.
/// Issued by 'confirm' and handled by 'protocol_header/block_out/estimator'.
block,

/// A confirmable block has been confirmed (header_t).
/// Issued by 'confirm' [and handled by 'transaction'].
/// Issued by 'confirm' and handled by 'transaction'.
organized,

/// A previously confirmed block has been unconfirmed (header_t).
/// Issued by 'confirm' [and handled by 'transaction'].
/// Issued by 'confirm' and handled by 'transaction'.
reorganized,

/// Mining.
Expand Down
2 changes: 1 addition & 1 deletion include/bitcoin/node/chasers/chaser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class BCN_API chaser
public:
DELETE_COPY_MOVE_DESTRUCT(chaser);

/// Must be called from node strand.
/// Should be called from node strand.
virtual code start() NOEXCEPT = 0;

/// Override to capture non-blocking stopping.
Expand Down
1 change: 1 addition & 0 deletions include/bitcoin/node/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ enum error_t : uint8_t
confirm10,
confirm11,
confirm12,
estimate_failed,
estimates_failed,
estimates_disabled,
estimates_premature
Expand Down
1 change: 0 additions & 1 deletion src/chasers/chaser_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ map_ptr chaser_check::split(const map_ptr& map) NOEXCEPT

code chaser_check::start() NOEXCEPT
{
BC_ASSERT(stranded());
start_tracking();
set_position(archive().get_fork());
requested_ = advanced_ = position();
Expand Down
1 change: 0 additions & 1 deletion src/chasers/chaser_confirm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ chaser_confirm::chaser_confirm(full_node& node) NOEXCEPT

code chaser_confirm::start() NOEXCEPT
{
BC_ASSERT(stranded());
const auto& query = archive();
set_position(query.get_fork());

Expand Down
40 changes: 21 additions & 19 deletions src/chasers/chaser_estimate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ chaser_estimate::chaser_estimate(full_node& node) NOEXCEPT

code chaser_estimate::start() NOEXCEPT
{
BC_ASSERT(stranded());

if (is_zero(node_settings().fee_estimate_enabled()))
if (node_settings().fee_estimate_enabled())
{
SUBSCRIBE_CHASE(handle_chase, _1, _2, _3);
}
Expand All @@ -72,12 +70,6 @@ void chaser_estimate::estimate(size_t target, estimator::mode mode,
return;
}

if (!initialized())
{
handler(error::estimates_premature, {});
return;
}

POST(do_estimate, target, mode, std::move(handler));
}

Expand All @@ -86,7 +78,20 @@ void chaser_estimate::do_estimate(size_t target, estimator::mode mode,
const estimate_handler& handler) NOEXCEPT
{
BC_ASSERT(stranded());
handler(error::success, estimator_->estimate(target, mode));

// Check this under strand so that chase can initialize first.
if (!initialized())
{
handler(error::estimates_premature, {});
return;
}

const auto value = estimator_->estimate(target, mode);
const auto ec = (value < to_unsigned(max_int64) ? error::success :
error::estimate_failed);

// Successful value is always castable to int64_t.
handler(ec, value);
}

size_t chaser_estimate::top_height() const NOEXCEPT
Expand All @@ -113,12 +118,10 @@ bool chaser_estimate::handle_chase(const code&, chase event_,
////if (suspended())
//// return true;

if (!is_current(true))
return true;

switch (event_)
{
case chase::organized:
// chase::block is only sent when current (may need to file gaps).
case chase::block:
{
BC_ASSERT(std::holds_alternative<header_t>(value));
POST(do_organized, std::get<header_t>(value));
Expand Down Expand Up @@ -147,15 +150,17 @@ void chaser_estimate::do_organized(header_t) NOEXCEPT
{
BC_ASSERT(stranded());

if (initialize())
// TODO: make gap safe (get estimator top and adjust).
if (initialized() || initialize())
estimator_->push(archive());
}

void chaser_estimate::do_reorganized(header_t) NOEXCEPT
{
BC_ASSERT(stranded());

if (initialize())
// TODO: make gap safe (get estimator top and adjust).
if (initialized())
estimator_->pop(archive());
}

Expand All @@ -167,9 +172,6 @@ bool chaser_estimate::initialize() NOEXCEPT
{
BC_ASSERT(stranded());

if (initialized())
return true;

// Preempt initialize fault when horizon exceeds chain length.
const auto horizon = node_settings().fee_estimate_horizon_();
if (horizon > add1(archive().get_top_confirmed()))
Expand Down
1 change: 0 additions & 1 deletion src/chasers/chaser_header.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ chaser_header::chaser_header(full_node& node) NOEXCEPT

code chaser_header::start() NOEXCEPT
{
BC_ASSERT(stranded());
if (!initialize_milestone())
return fault(error::header1);

Expand Down
2 changes: 0 additions & 2 deletions src/chasers/chaser_snapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ chaser_snapshot::chaser_snapshot(full_node& node) NOEXCEPT

code chaser_snapshot::start() NOEXCEPT
{
BC_ASSERT(stranded());

// Initial values assume all stops or starts are snapped.
// get_top_validated is an expensive scan.

Expand Down
2 changes: 0 additions & 2 deletions src/chasers/chaser_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ chaser_storage::chaser_storage(full_node& node) NOEXCEPT

code chaser_storage::start() NOEXCEPT
{
BC_ASSERT(stranded());

// Construct is too early to create the unstarted timer.
disk_timer_ = std::make_shared<deadline>(log, strand(), seconds{1});

Expand Down
1 change: 0 additions & 1 deletion src/chasers/chaser_template.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ chaser_template::chaser_template(full_node& node) NOEXCEPT
// TODO: initialize template state.
code chaser_template::start() NOEXCEPT
{
BC_ASSERT(stranded());
SUBSCRIBE_CHASE(handle_chase, _1, _2, _3);
return error::success;
}
Expand Down
1 change: 0 additions & 1 deletion src/chasers/chaser_transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ chaser_transaction::chaser_transaction(full_node& node) NOEXCEPT
// TODO: initialize tx graph from store, log and stop on error.
code chaser_transaction::start() NOEXCEPT
{
BC_ASSERT(stranded());
SUBSCRIBE_CHASE(handle_chase, _1, _2, _3);
return error::success;
}
Expand Down
1 change: 1 addition & 0 deletions src/error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ DEFINE_ERROR_T_MESSAGE_MAP(error)
{ confirm10, "confirm10" },
{ confirm11, "confirm11" },
{ confirm12, "confirm12" },
{ estimate_failed, "estimate_failed" },
{ estimates_failed, "estimates_failed" },
{ estimates_disabled, "estimates_disabled" },
{ estimates_premature, "estimates_premature" }
Expand Down
9 changes: 9 additions & 0 deletions test/error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,15 @@ BOOST_AUTO_TEST_CASE(error_t__code__confirm1__true_expected_message)
BOOST_REQUIRE_EQUAL(ec.message(), "confirm1");
}

BOOST_AUTO_TEST_CASE(error_t__code__estimate_failed__true_expected_message)
{
constexpr auto value = error::estimate_failed;
const auto ec = code(value);
BOOST_REQUIRE(ec);
BOOST_REQUIRE(ec == value);
BOOST_REQUIRE_EQUAL(ec.message(), "estimate_failed");
}

BOOST_AUTO_TEST_CASE(error_t__code__estimates_failed__true_expected_message)
{
constexpr auto value = error::estimates_failed;
Expand Down
Loading