From 3f8592a7d90788095f2684f37ae574e41610b5a1 Mon Sep 17 00:00:00 2001 From: Eric Voskuil Date: Sat, 28 Nov 2026 14:37:42 -0500 Subject: [PATCH] Query unconfirmed totals on tx chaser. --- .../node/chasers/chaser_transaction.hpp | 10 +++---- include/bitcoin/node/full_node.hpp | 6 ++--- include/bitcoin/node/protocols/protocol.hpp | 6 ++--- include/bitcoin/node/sessions/session.hpp | 6 ++--- include/bitcoin/node/types/type.hpp | 4 +-- src/chasers/chaser_transaction_query.cpp | 16 ++++++------ src/full_node.cpp | 6 ++--- src/protocols/protocol.cpp | 6 ++--- src/sessions/session.cpp | 6 ++--- test/chasers/chaser_transaction_query.cpp | 26 +++++++++---------- .../chaser_transaction_setup_fixture.hpp | 11 ++++---- 11 files changed, 52 insertions(+), 51 deletions(-) diff --git a/include/bitcoin/node/chasers/chaser_transaction.hpp b/include/bitcoin/node/chasers/chaser_transaction.hpp index e2a48fe2..954cff7b 100644 --- a/include/bitcoin/node/chasers/chaser_transaction.hpp +++ b/include/bitcoin/node/chasers/chaser_transaction.hpp @@ -84,9 +84,9 @@ 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; + /// Totals of receipts, in conflict outcomes of least and greatest value. + virtual void get_unconfirmed_totals(const database::pool_receipts& receipts, + unconfirmed_totals_handler&& handler) NOEXCEPT; /// Count of changes to the pool (thread safe). uint64_t pool_generation() const NOEXCEPT override; @@ -145,9 +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( + virtual void do_get_unconfirmed_totals( const database::pool_receipts& receipts, - const unconfirmed_range_handler& handler) NOEXCEPT; + const unconfirmed_totals_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 diff --git a/include/bitcoin/node/full_node.hpp b/include/bitcoin/node/full_node.hpp index ca0cd3d7..f75fc108 100644 --- a/include/bitcoin/node/full_node.hpp +++ b/include/bitcoin/node/full_node.hpp @@ -236,9 +236,9 @@ 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; + /// Totals of receipts, in conflict outcomes of least and greatest value. + void get_unconfirmed_totals(const database::pool_receipts& receipts, + unconfirmed_totals_handler&& handler) NOEXCEPT; /// Handle performance, base returns false (implied terminate). virtual void performance(object_key channel, uint64_t speed, diff --git a/include/bitcoin/node/protocols/protocol.hpp b/include/bitcoin/node/protocols/protocol.hpp index 1cf7e8f5..66f518a0 100644 --- a/include/bitcoin/node/protocols/protocol.hpp +++ b/include/bitcoin/node/protocols/protocol.hpp @@ -113,9 +113,9 @@ 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; + /// Totals of receipts, in conflict outcomes of least and greatest value. + void get_unconfirmed_totals(const database::pool_receipts& receipts, + unconfirmed_totals_handler&& handler) NOEXCEPT; /// Suspensions. /// ----------------------------------------------------------------------- diff --git a/include/bitcoin/node/sessions/session.hpp b/include/bitcoin/node/sessions/session.hpp index 6968ee87..b3606e42 100644 --- a/include/bitcoin/node/sessions/session.hpp +++ b/include/bitcoin/node/sessions/session.hpp @@ -165,9 +165,9 @@ 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; + /// Totals of receipts, in conflict outcomes of least and greatest value. + void get_unconfirmed_totals(const database::pool_receipts& receipts, + unconfirmed_totals_handler&& handler) NOEXCEPT; /// Handle performance, base returns false (implied terminate). virtual void performance(object_key channel, uint64_t speed, diff --git a/include/bitcoin/node/types/type.hpp b/include/bitcoin/node/types/type.hpp index b57641fd..224aa45d 100644 --- a/include/bitcoin/node/types/type.hpp +++ b/include/bitcoin/node/types/type.hpp @@ -54,8 +54,8 @@ typedef std::function confirmable_txs_handler; typedef std::function confirmable_fees_handler; -typedef std::function unconfirmed_range_handler; +typedef std::function unconfirmed_totals_handler; /// Event desubscriber. typedef network::desubscriber event_subscriber; diff --git a/src/chasers/chaser_transaction_query.cpp b/src/chasers/chaser_transaction_query.cpp index 25387173..3b77d8fe 100644 --- a/src/chasers/chaser_transaction_query.cpp +++ b/src/chasers/chaser_transaction_query.cpp @@ -122,14 +122,14 @@ void chaser_transaction::get_confirmable_fees( POST(do_get_confirmable_fees, std::move(handler)); } -void chaser_transaction::get_unconfirmed_range( +void chaser_transaction::get_unconfirmed_totals( const database::pool_receipts& receipts, - unconfirmed_range_handler&& handler) NOEXCEPT + unconfirmed_totals_handler&& handler) NOEXCEPT { if (closed()) return; - POST(do_get_unconfirmed_range, receipts, std::move(handler)); + POST(do_get_unconfirmed_totals, receipts, std::move(handler)); } // private @@ -313,9 +313,9 @@ void chaser_transaction::do_get_confirmable_fees( } // private -void chaser_transaction::do_get_unconfirmed_range( +void chaser_transaction::do_get_unconfirmed_totals( const database::pool_receipts& receipts, - const unconfirmed_range_handler& handler) NOEXCEPT + const unconfirmed_totals_handler& handler) NOEXCEPT { BC_ASSERT(stranded()); @@ -325,10 +325,10 @@ void chaser_transaction::do_get_unconfirmed_range( return; } - uint64_t worst{}; - uint64_t best{}; + database::address_totals worst{}; + database::address_totals best{}; const auto& settings = node_settings().pool; - const auto ec = archive().get_unconfirmed_range(worst, best, receipts, + const auto ec = archive().get_unconfirmed_totals(worst, best, receipts, settings.maximum_outcomes); handler(ec, worst, best); } diff --git a/src/full_node.cpp b/src/full_node.cpp index 701baf04..76e53495 100644 --- a/src/full_node.cpp +++ b/src/full_node.cpp @@ -605,10 +605,10 @@ 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 +void full_node::get_unconfirmed_totals(const database::pool_receipts& receipts, + unconfirmed_totals_handler&& handler) NOEXCEPT { - chaser_transaction_.get_unconfirmed_range(receipts, std::move(handler)); + chaser_transaction_.get_unconfirmed_totals(receipts, std::move(handler)); } void full_node::performance(object_key key, uint64_t speed, diff --git a/src/protocols/protocol.cpp b/src/protocols/protocol.cpp index 5b277197..a3a65082 100644 --- a/src/protocols/protocol.cpp +++ b/src/protocols/protocol.cpp @@ -126,10 +126,10 @@ 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 +void protocol::get_unconfirmed_totals(const database::pool_receipts& receipts, + unconfirmed_totals_handler&& handler) NOEXCEPT { - session_->get_unconfirmed_range(receipts, std::move(handler)); + session_->get_unconfirmed_totals(receipts, std::move(handler)); } // Events subscription. diff --git a/src/sessions/session.cpp b/src/sessions/session.cpp index e8472f0a..a8695281 100644 --- a/src/sessions/session.cpp +++ b/src/sessions/session.cpp @@ -233,10 +233,10 @@ 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 +void session::get_unconfirmed_totals(const database::pool_receipts& receipts, + unconfirmed_totals_handler&& handler) NOEXCEPT { - node_.get_unconfirmed_range(receipts, std::move(handler)); + node_.get_unconfirmed_totals(receipts, std::move(handler)); } void session::performance(object_key key, uint64_t speed, diff --git a/test/chasers/chaser_transaction_query.cpp b/test/chasers/chaser_transaction_query.cpp index 07a5b4bb..6da7489a 100644 --- a/test/chasers/chaser_transaction_query.cpp +++ b/test/chasers/chaser_transaction_query.cpp @@ -165,34 +165,34 @@ BC_FIXTURE_TEST_CASE(chaser_transaction__get_confirmable_fees__relay_off_pooled_ BC_REQUIRE(rates.empty()); } -// get_unconfirmed_range +// get_unconfirmed_totals -BC_FIXTURE_TEST_CASE(chaser_transaction__get_unconfirmed_range__no_receipts__zeros, chaser_transaction_pooling_setup_fixture) +BC_FIXTURE_TEST_CASE(chaser_transaction__get_unconfirmed_totals__no_receipts__zeros, chaser_transaction_pooling_setup_fixture) { - const auto [ec, worst, best] = get_unconfirmed_range({}); + const auto [ec, worst, best] = get_unconfirmed_totals({}); BC_REQUIRE_EQUAL(ec, database::error::success); - BC_REQUIRE_EQUAL(worst, 0u); - BC_REQUIRE_EQUAL(best, 0u); + BC_REQUIRE_EQUAL(worst.funded_count, 0u); + BC_REQUIRE_EQUAL(best.funded_count, 0u); } -BC_FIXTURE_TEST_CASE(chaser_transaction__get_unconfirmed_range__pooled_tx__its_value, chaser_transaction_pooling_setup_fixture) +BC_FIXTURE_TEST_CASE(chaser_transaction__get_unconfirmed_totals__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, {} } }); + const auto [ec, worst, best] = get_unconfirmed_totals({ { 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_REQUIRE_EQUAL(worst.funded_value, 42u); + BC_REQUIRE_EQUAL(best.funded_value, 42u); } -BC_FIXTURE_TEST_CASE(chaser_transaction__get_unconfirmed_range__row_not_pooled__zeros, chaser_transaction_pooling_setup_fixture) +BC_FIXTURE_TEST_CASE(chaser_transaction__get_unconfirmed_totals__row_not_pooled__zeros, chaser_transaction_pooling_setup_fixture) { - const auto [ec, worst, best] = get_unconfirmed_range({ { 0u, 42u, {} } }); + const auto [ec, worst, best] = get_unconfirmed_totals({ { 0u, 42u, {} } }); BC_REQUIRE_EQUAL(ec, database::error::success); - BC_REQUIRE_EQUAL(worst, 0u); - BC_REQUIRE_EQUAL(best, 0u); + BC_REQUIRE_EQUAL(worst.funded_count, 0u); + BC_REQUIRE_EQUAL(best.funded_count, 0u); } // estimate diff --git a/test/chasers/chaser_transaction_setup_fixture.hpp b/test/chasers/chaser_transaction_setup_fixture.hpp index 98d5746f..dabbccc5 100644 --- a/test/chasers/chaser_transaction_setup_fixture.hpp +++ b/test/chasers/chaser_transaction_setup_fixture.hpp @@ -526,12 +526,13 @@ struct chaser_transaction_setup_fixture return promise.get_future().get(); } - using ranged = std::tuple; - ranged get_unconfirmed_range(const database::pool_receipts& receipts) + using totals = database::address_totals; + using totaled = std::tuple; + totaled get_unconfirmed_totals(const database::pool_receipts& receipts) { - std::promise promise{}; - node_.get_unconfirmed_range(receipts, [&](const code& ec, - uint64_t worst, uint64_t best) NOEXCEPT + std::promise promise{}; + node_.get_unconfirmed_totals(receipts, [&](const code& ec, + const totals& worst, const totals& best) NOEXCEPT { promise.set_value({ ec, worst, best }); });