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
5 changes: 3 additions & 2 deletions include/bitcoin/node/chasers/chaser_header.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ class BCN_API chaser_header
virtual void organize_compact(const system::chain::header::cptr& header,
organize_handler&& handler) NOEXCEPT;

/// Organize a submitted (proven) header, prioritized (a tie wins).
/// Organize a submitted (proven) header, prioritized (a tie wins),
/// milestone set if trusted.
virtual void organize_submitted(const system::chain::header::cptr& header,
organize_handler&& handler) NOEXCEPT;
bool milestone, organize_handler&& handler) NOEXCEPT;

/// Reorganize to the branch of an archived block of at least equal work.
virtual void prioritize(const system::hash_digest& hash,
Expand Down
7 changes: 7 additions & 0 deletions include/bitcoin/node/chasers/chaser_transaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ class BCN_API chaser_transaction
virtual void get_confirmable_fees(
confirmable_fees_handler&& handler) NOEXCEPT;

/// Least and greatest value of receipts not spent, over conflict outcomes.
virtual void get_unconfirmed_range(const database::pool_receipts& receipts,
unconfirmed_range_handler&& handler) NOEXCEPT;

/// Count of changes to the pool (thread safe).
uint64_t pool_generation() const NOEXCEPT override;

Expand Down Expand Up @@ -141,6 +145,9 @@ class BCN_API chaser_transaction
const confirmable_txs_handler& handler) NOEXCEPT;
virtual void do_get_confirmable_fees(
const confirmable_fees_handler& handler) NOEXCEPT;
virtual void do_get_unconfirmed_range(
const database::pool_receipts& receipts,
const unconfirmed_range_handler& handler) NOEXCEPT;

/// Recompute pool context and sweep index by it if due, closing pool if not
/// current or context not reusable, and map scan starts: built once
Expand Down
9 changes: 7 additions & 2 deletions include/bitcoin/node/full_node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ class BCN_API full_node
virtual void organize_compact(const system::chain::header::cptr& header,
organize_handler&& handler) NOEXCEPT;

/// Organize a submitted (proven) header, prioritized (a tie wins).
/// Organize a submitted (proven) header, prioritized (a tie wins),
/// milestone set if trusted.
virtual void organize_submitted(const system::chain::header::cptr& header,
organize_handler&& handler) NOEXCEPT;
bool milestone, organize_handler&& handler) NOEXCEPT;

/// Reorganize to the branch of an archived block of at least equal work.
virtual void prioritize(const system::hash_digest& hash,
Expand Down Expand Up @@ -235,6 +236,10 @@ class BCN_API full_node
/// Fee rate tuples of the confirmable txs, in pool order.
void get_confirmable_fees(confirmable_fees_handler&& handler) NOEXCEPT;

/// Least and greatest value of receipts not spent, over conflict outcomes.
void get_unconfirmed_range(const database::pool_receipts& receipts,
unconfirmed_range_handler&& handler) NOEXCEPT;

/// Handle performance, base returns false (implied terminate).
virtual void performance(object_key channel, uint64_t speed,
result_handler&& handler) NOEXCEPT;
Expand Down
9 changes: 7 additions & 2 deletions include/bitcoin/node/protocols/protocol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ class BCN_API protocol
/// Fee rate tuples of the confirmable txs, in pool order.
void get_confirmable_fees(confirmable_fees_handler&& handler) NOEXCEPT;

/// Least and greatest value of receipts not spent, over conflict outcomes.
void get_unconfirmed_range(const database::pool_receipts& receipts,
unconfirmed_range_handler&& handler) NOEXCEPT;

/// Suspensions.
/// -----------------------------------------------------------------------

Expand All @@ -135,9 +139,10 @@ class BCN_API protocol
virtual void organize_compact(const system::chain::header::cptr& header,
organize_handler&& handler) NOEXCEPT;

/// Organize a submitted (proven) header, prioritized (a tie wins).
/// Organize a submitted (proven) header, prioritized (a tie wins),
/// milestone set if trusted.
virtual void organize_submitted(const system::chain::header::cptr& header,
organize_handler&& handler) NOEXCEPT;
bool milestone, organize_handler&& handler) NOEXCEPT;

/// Reorganize to the branch of an archived block of at least equal work.
virtual void prioritize(const system::hash_digest& hash,
Expand Down
9 changes: 7 additions & 2 deletions include/bitcoin/node/sessions/session.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ class BCN_API session
virtual void organize_compact(const system::chain::header::cptr& header,
organize_handler&& handler) NOEXCEPT;

/// Organize a submitted (proven) header, prioritized (a tie wins).
/// Organize a submitted (proven) header, prioritized (a tie wins),
/// milestone set if trusted.
virtual void organize_submitted(const system::chain::header::cptr& header,
organize_handler&& handler) NOEXCEPT;
bool milestone, organize_handler&& handler) NOEXCEPT;

/// Reorganize to the branch of an archived block of at least equal work.
virtual void prioritize(const system::hash_digest& hash,
Expand Down Expand Up @@ -164,6 +165,10 @@ class BCN_API session
/// Fee rate tuples of the confirmable txs, in pool order.
void get_confirmable_fees(confirmable_fees_handler&& handler) NOEXCEPT;

/// Least and greatest value of receipts not spent, over conflict outcomes.
void get_unconfirmed_range(const database::pool_receipts& receipts,
unconfirmed_range_handler&& handler) NOEXCEPT;

/// Handle performance, base returns false (implied terminate).
virtual void performance(object_key channel, uint64_t speed,
network::result_handler&& handler) NOEXCEPT;
Expand Down
2 changes: 2 additions & 0 deletions include/bitcoin/node/types/type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ typedef std::function<void(const code&,
const database::tx_links&)> confirmable_txs_handler;
typedef std::function<void(const code&,
const database::fee_rates&)> confirmable_fees_handler;
typedef std::function<void(const code&, uint64_t,
uint64_t)> unconfirmed_range_handler;

/// Event desubscriber.
typedef network::desubscriber<object_key, event_value> event_subscriber;
Expand Down
5 changes: 3 additions & 2 deletions src/chasers/chaser_header.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,13 @@ void chaser_header::organize_compact(const header::cptr& header,
}

void chaser_header::organize_submitted(const header::cptr& header,
organize_handler&& handler) NOEXCEPT
bool milestone, organize_handler&& handler) NOEXCEPT
{
if (closed())
return;

POST(do_organize, header, true, false, true, false, std::move(handler));
POST(do_organize, header, true, milestone, true, false,
std::move(handler));
}

void chaser_header::prioritize(const hash_digest& hash,
Expand Down
31 changes: 31 additions & 0 deletions src/chasers/chaser_transaction_query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,16 @@ void chaser_transaction::get_confirmable_fees(
POST(do_get_confirmable_fees, std::move(handler));
}

void chaser_transaction::get_unconfirmed_range(
const database::pool_receipts& receipts,
unconfirmed_range_handler&& handler) NOEXCEPT
{
if (closed())
return;

POST(do_get_unconfirmed_range, receipts, std::move(handler));
}

// private
void chaser_transaction::do_build_template(
const template_handler& handler) NOEXCEPT
Expand Down Expand Up @@ -302,6 +312,27 @@ void chaser_transaction::do_get_confirmable_fees(
handler(ec, rates);
}

// private
void chaser_transaction::do_get_unconfirmed_range(
const database::pool_receipts& receipts,
const unconfirmed_range_handler& handler) NOEXCEPT
{
BC_ASSERT(stranded());

if (closed())
{
handler(network::error::service_stopped, {}, {});
return;
}

uint64_t worst{};
uint64_t best{};
const auto& settings = node_settings().pool;
const auto ec = archive().get_unconfirmed_range(worst, best, receipts,
settings.maximum_outcomes);
handler(ec, worst, best);
}

BC_POP_WARNING()
BC_POP_WARNING()

Expand Down
10 changes: 8 additions & 2 deletions src/full_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ void full_node::organize_compact(const system::chain::header::cptr& header,
}

void full_node::organize_submitted(const system::chain::header::cptr& header,
organize_handler&& handler) NOEXCEPT
bool milestone, organize_handler&& handler) NOEXCEPT
{
chaser_header_.organize_submitted(header, std::move(handler));
chaser_header_.organize_submitted(header, milestone, std::move(handler));
}

void full_node::prioritize(const system::hash_digest& hash,
Expand Down Expand Up @@ -605,6 +605,12 @@ void full_node::get_confirmable_fees(
chaser_transaction_.get_confirmable_fees(std::move(handler));
}

void full_node::get_unconfirmed_range(const database::pool_receipts& receipts,
unconfirmed_range_handler&& handler) NOEXCEPT
{
chaser_transaction_.get_unconfirmed_range(receipts, std::move(handler));
}

void full_node::performance(object_key key, uint64_t speed,
result_handler&& handler) NOEXCEPT
{
Expand Down
10 changes: 8 additions & 2 deletions src/protocols/protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ void protocol::get_confirmable_fees(confirmable_fees_handler&& handler) NOEXCEPT
session_->get_confirmable_fees(std::move(handler));
}

void protocol::get_unconfirmed_range(const database::pool_receipts& receipts,
unconfirmed_range_handler&& handler) NOEXCEPT
{
session_->get_unconfirmed_range(receipts, std::move(handler));
}

// Events subscription.
// ----------------------------------------------------------------------------

Expand Down Expand Up @@ -182,9 +188,9 @@ void protocol::organize_compact(const system::chain::header::cptr& header,
}

void protocol::organize_submitted(const system::chain::header::cptr& header,
organize_handler&& handler) NOEXCEPT
bool milestone, organize_handler&& handler) NOEXCEPT
{
session_->organize_submitted(header, std::move(handler));
session_->organize_submitted(header, milestone, std::move(handler));
}

void protocol::prioritize(const system::hash_digest& hash,
Expand Down
10 changes: 8 additions & 2 deletions src/sessions/session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ void session::organize_compact(const header::cptr& header,
}

void session::organize_submitted(const header::cptr& header,
organize_handler&& handler) NOEXCEPT
bool milestone, organize_handler&& handler) NOEXCEPT
{
node_.organize_submitted(header, std::move(handler));
node_.organize_submitted(header, milestone, std::move(handler));
}

void session::prioritize(const hash_digest& hash,
Expand Down Expand Up @@ -233,6 +233,12 @@ void session::get_confirmable_fees(confirmable_fees_handler&& handler) NOEXCEPT
node_.get_confirmable_fees(std::move(handler));
}

void session::get_unconfirmed_range(const database::pool_receipts& receipts,
unconfirmed_range_handler&& handler) NOEXCEPT
{
node_.get_unconfirmed_range(receipts, std::move(handler));
}

void session::performance(object_key key, uint64_t speed,
result_handler&& handler) NOEXCEPT
{
Expand Down
18 changes: 15 additions & 3 deletions test/chasers/chaser_header.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,13 @@ struct chaser_header_setup_fixture
return future.get();
}

/// Organize a submitted header.
result organize_submitted(const system::chain::header::cptr& header)
/// Organize a submitted header, milestone set if trusted.
result organize_submitted(const system::chain::header::cptr& header,
bool milestone=false)
{
const auto promise = std::make_shared<std::promise<result>>();
auto future = promise->get_future();
header_.organize_submitted(header, [promise](const code& ec,
header_.organize_submitted(header, milestone, [promise](const code& ec,
size_t height) NOEXCEPT
{
promise->set_value({ ec, height });
Expand Down Expand Up @@ -933,6 +934,17 @@ BC_FIXTURE_TEST_CASE(chaser_header__organize_submitted__block1__compact_candidat
BC_REQUIRE_EQUAL(result.second, 1u);
BC_REQUIRE(candidate(1, header->hash()));
BC_REQUIRE(query_.is_compact(query_.to_header(header->hash())));
BC_REQUIRE(!query_.is_milestone(query_.to_header(header->hash())));
}

BC_FIXTURE_TEST_CASE(chaser_header__organize_submitted__trusted_block1__archived_milestone, chaser_header_setup_fixture)
{
const auto header = block1();
const auto result = organize_submitted(header, true);
BC_REQUIRE_EQUAL(result.first, error::success);
BC_REQUIRE_EQUAL(result.second, 1u);
BC_REQUIRE(candidate(1, header->hash()));
BC_REQUIRE(query_.is_milestone(query_.to_header(header->hash())));
}

BC_FIXTURE_TEST_CASE(chaser_header__organize__tied_block1__cached, chaser_header_setup_fixture)
Expand Down
30 changes: 30 additions & 0 deletions test/chasers/chaser_transaction_query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,36 @@ BC_FIXTURE_TEST_CASE(chaser_transaction__get_confirmable_fees__relay_off_pooled_
BC_REQUIRE(rates.empty());
}

// get_unconfirmed_range

BC_FIXTURE_TEST_CASE(chaser_transaction__get_unconfirmed_range__no_receipts__zeros, chaser_transaction_pooling_setup_fixture)
{
const auto [ec, worst, best] = get_unconfirmed_range({});
BC_REQUIRE_EQUAL(ec, database::error::success);
BC_REQUIRE_EQUAL(worst, 0u);
BC_REQUIRE_EQUAL(best, 0u);
}

BC_FIXTURE_TEST_CASE(chaser_transaction__get_unconfirmed_range__pooled_tx__its_value, chaser_transaction_pooling_setup_fixture)
{
const auto tx = spend(parent_value - 1'000);
const auto result = submit(package({ tx }));
const auto row = query_.to_pool_row(query_.to_tx(tx->hash(false)));
const auto [ec, worst, best] = get_unconfirmed_range({ { row.value, 42u, {} } });
BC_REQUIRE_EQUAL(result.first, node::error::success);
BC_REQUIRE_EQUAL(ec, database::error::success);
BC_REQUIRE_EQUAL(worst, 42u);
BC_REQUIRE_EQUAL(best, 42u);
}

BC_FIXTURE_TEST_CASE(chaser_transaction__get_unconfirmed_range__row_not_pooled__zeros, chaser_transaction_pooling_setup_fixture)
{
const auto [ec, worst, best] = get_unconfirmed_range({ { 0u, 42u, {} } });
BC_REQUIRE_EQUAL(ec, database::error::success);
BC_REQUIRE_EQUAL(worst, 0u);
BC_REQUIRE_EQUAL(best, 0u);
}

// estimate

BC_FIXTURE_TEST_CASE(chaser_transaction__estimate__relay_disabled__estimate_disabled, chaser_transaction_setup_fixture)
Expand Down
13 changes: 13 additions & 0 deletions test/chasers/chaser_transaction_setup_fixture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,19 @@ struct chaser_transaction_setup_fixture
return promise.get_future().get();
}

using ranged = std::tuple<code, uint64_t, uint64_t>;
ranged get_unconfirmed_range(const database::pool_receipts& receipts)
{
std::promise<ranged> promise{};
node_.get_unconfirmed_range(receipts, [&](const code& ec,
uint64_t worst, uint64_t best) NOEXCEPT
{
promise.set_value({ ec, worst, best });
});

return promise.get_future().get();
}

// Confirm a block of a coinbase, and the tx if any, and notify of it.
database::header_link confirm(const chain::transaction::cptr& tx={})
{
Expand Down
Loading