From 77fb1cb53671d048b08a4e4d2cfc89bbcdc65154 Mon Sep 17 00:00:00 2001 From: Eric Voskuil Date: Mon, 23 Nov 2026 11:21:08 -0500 Subject: [PATCH 1/7] Pool a conflict past the outcome limit when its scored outcomes cover it. --- src/chasers/chaser_transaction_submit.cpp | 2 +- test/chasers/chaser_transaction_submit.cpp | 26 +++++++++++++++++----- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/chasers/chaser_transaction_submit.cpp b/src/chasers/chaser_transaction_submit.cpp index 4ff11585..4aefd6d4 100644 --- a/src/chasers/chaser_transaction_submit.cpp +++ b/src/chasers/chaser_transaction_submit.cpp @@ -91,7 +91,7 @@ static std::string describe_limit(const node::query& query, const auto ancestry = is_zero(component.contests) || algorithm::ancestry(sum, g, component, limit); const auto outcomes = algorithm::outcomes(component); - if (!ancestry || outcomes > maximum_outcomes) + if (!ancestry || is_zero(maximum_outcomes)) { out << "candidate " << at << (ancestry ? " outcomes " : " ancestry ") << "members " << component.count diff --git a/test/chasers/chaser_transaction_submit.cpp b/test/chasers/chaser_transaction_submit.cpp index a6b44b89..3ad8f530 100644 --- a/test/chasers/chaser_transaction_submit.cpp +++ b/test/chasers/chaser_transaction_submit.cpp @@ -203,12 +203,27 @@ BC_FIXTURE_TEST_CASE(chaser_transaction__submit__conflict_added_fee__success_arc BC_REQUIRE(query_.is_tx(second->hash(false))); } -BC_FIXTURE_TEST_CASE(chaser_transaction__submit__conflict_outcomes_over_limit__pool_limit, chaser_transaction_limit_setup_fixture) +BC_FIXTURE_TEST_CASE(chaser_transaction__submit__conflict_outcomes_over_limit__success, chaser_transaction_limit_setup_fixture) { const auto first = submit(package({ spend(parent_value) })); const auto second = submit(package({ spend(sub1(parent_value)) })); BC_REQUIRE_EQUAL(first.first, node::error::success); - BC_REQUIRE_EQUAL(second.first, database::error::pool_limit); + BC_REQUIRE_EQUAL(second.first, node::error::success); +} + +BC_FIXTURE_TEST_CASE(chaser_transaction__submit__dominant_rival_over_outcome_limit__templated, chaser_transaction_limit_setup_fixture) +{ + const auto low = spend(parent_value); + const auto high = spend(parent_value - 50'000); + const auto first = submit(package({ low })); + const auto second = submit(package({ high })); + const auto built = build_template(); + const auto& links = std::get<2>(built); + + BC_REQUIRE_EQUAL(first.first, node::error::success); + BC_REQUIRE_EQUAL(second.first, node::error::success); + BC_REQUIRE_EQUAL(links.size(), one); + BC_REQUIRE_EQUAL(links.front(), query_.to_tx(high->hash(false))); } BC_FIXTURE_TEST_CASE(chaser_transaction__submit__conflict_over_block__pool_limit, chaser_transaction_single_setup_fixture) @@ -219,7 +234,7 @@ BC_FIXTURE_TEST_CASE(chaser_transaction__submit__conflict_over_block__pool_limit BC_REQUIRE_EQUAL(second.first, database::error::pool_limit); } -BC_FIXTURE_TEST_CASE(chaser_transaction__submit_announced__conflict_outcomes_over_limit__passed_over, chaser_transaction_limit_setup_fixture) +BC_FIXTURE_TEST_CASE(chaser_transaction__submit_announced__conflict_outcomes_over_limit__both_stored, chaser_transaction_limit_setup_fixture) { const auto first = spend(parent_value); const auto conflict = spend(sub1(parent_value)); @@ -227,9 +242,8 @@ BC_FIXTURE_TEST_CASE(chaser_transaction__submit_announced__conflict_outcomes_ove BC_REQUIRE_EQUAL(submit(package({ first })).first, node::error::success); const auto result = submit_announced(package({ conflict, child }), node_.reserve_relay(node::relay_tier::manual)); - BC_REQUIRE_EQUAL(result.first, database::error::pool_limit); - BC_REQUIRE_EQUAL(result.second, zero); - BC_REQUIRE(!query_.is_tx(conflict->hash(false))); + BC_REQUIRE_EQUAL(result.first, node::error::success); + BC_REQUIRE(query_.is_tx(conflict->hash(false))); BC_REQUIRE(query_.is_tx(child->hash(false))); } From a43e2250e53a6c3e2f217e637991e1d7685c935b Mon Sep 17 00:00:00 2001 From: Eric Voskuil Date: Mon, 23 Nov 2026 11:52:52 -0500 Subject: [PATCH 2/7] Mark chaser_transaction::pool_generation override. --- include/bitcoin/node/chasers/chaser_transaction.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/bitcoin/node/chasers/chaser_transaction.hpp b/include/bitcoin/node/chasers/chaser_transaction.hpp index 7caaf8cd..0d23ebdd 100644 --- a/include/bitcoin/node/chasers/chaser_transaction.hpp +++ b/include/bitcoin/node/chasers/chaser_transaction.hpp @@ -85,7 +85,7 @@ class BCN_API chaser_transaction confirmable_fees_handler&& handler) NOEXCEPT; /// Count of changes to the pool (thread safe). - virtual uint64_t pool_generation() const NOEXCEPT; + uint64_t pool_generation() const NOEXCEPT override; /// Subscribe to pool scans (notified on the strand). virtual void subscribe_pool(pool_notifier&& handler) NOEXCEPT; From ecb853f91410ef9bbd180f4ff16c70e64ce6f607 Mon Sep 17 00:00:00 2001 From: Eric Voskuil Date: Mon, 23 Nov 2026 12:44:42 -0500 Subject: [PATCH 3/7] Carry the pool context and previous hash in the block template. --- .../bitcoin/node/chasers/chaser_template.hpp | 16 +++++++------ .../node/chasers/chaser_transaction.hpp | 1 + include/bitcoin/node/types/block_template.hpp | 7 ++++-- include/bitcoin/node/types/type.hpp | 4 ++-- src/chasers/chaser_template.cpp | 23 +++++++++++-------- src/chasers/chaser_transaction.cpp | 1 + src/chasers/chaser_transaction_query.cpp | 6 ++--- test/chasers/chaser_template.cpp | 2 +- .../chaser_transaction_setup_fixture.hpp | 5 ++-- 9 files changed, 38 insertions(+), 27 deletions(-) diff --git a/include/bitcoin/node/chasers/chaser_template.hpp b/include/bitcoin/node/chasers/chaser_template.hpp index 8563fb48..96f47896 100644 --- a/include/bitcoin/node/chasers/chaser_template.hpp +++ b/include/bitcoin/node/chasers/chaser_template.hpp @@ -63,13 +63,15 @@ class BCN_API chaser_template private: void build() NOEXCEPT; - void handle_build(const code& ec, size_t height, - const database::tx_links& links, uint64_t generation, - size_t moves) NOEXCEPT; - void do_build(const code& ec, size_t height, - const database::tx_links& links, uint64_t generation, - size_t moves) NOEXCEPT; - code replace(size_t height, const database::tx_links& links) NOEXCEPT; + void handle_build(const code& ec, const system::chain::context& context, + const system::hash_digest& previous, const database::tx_links& links, + uint64_t generation, size_t moves) NOEXCEPT; + void do_build(const code& ec, const system::chain::context& context, + const system::hash_digest& previous, const database::tx_links& links, + uint64_t generation, size_t moves) NOEXCEPT; + code replace(const system::chain::context& context, + const system::hash_digest& previous, + const database::tx_links& links) NOEXCEPT; void complete(const code& ec) NOEXCEPT; void start_timer() NOEXCEPT; void handle_timer(const code& ec) NOEXCEPT; diff --git a/include/bitcoin/node/chasers/chaser_transaction.hpp b/include/bitcoin/node/chasers/chaser_transaction.hpp index 0d23ebdd..e370c206 100644 --- a/include/bitcoin/node/chasers/chaser_transaction.hpp +++ b/include/bitcoin/node/chasers/chaser_transaction.hpp @@ -313,6 +313,7 @@ class BCN_API chaser_transaction // These are protected by strand. pool_subscriber subscriber_{}; system::chain::context pool_{}; + system::hash_digest previous_{}; database::header_link top_{}; size_t floor_{}; bool due_{ true }; diff --git a/include/bitcoin/node/types/block_template.hpp b/include/bitcoin/node/types/block_template.hpp index c42f683c..0a95fb15 100644 --- a/include/bitcoin/node/types/block_template.hpp +++ b/include/bitcoin/node/types/block_template.hpp @@ -30,8 +30,11 @@ struct block_template { typedef std::shared_ptr cptr; - /// Height of the block. - size_t height; + /// Hash of the previous block. + system::hash_digest previous; + + /// Context of the block, as the pool validates under it. + system::chain::context context; /// Count of templates held to this one. uint64_t sequence; diff --git a/include/bitcoin/node/types/type.hpp b/include/bitcoin/node/types/type.hpp index 29adc9a4..5f6e9a11 100644 --- a/include/bitcoin/node/types/type.hpp +++ b/include/bitcoin/node/types/type.hpp @@ -44,8 +44,8 @@ typedef std::function map_handler; /// Mining types. -typedef std::function template_handler; +typedef std::function template_handler; typedef std::function block_template_handler; diff --git a/src/chasers/chaser_template.cpp b/src/chasers/chaser_template.cpp index b0280039..d0c6c8b1 100644 --- a/src/chasers/chaser_template.cpp +++ b/src/chasers/chaser_template.cpp @@ -190,20 +190,22 @@ void chaser_template::build() NOEXCEPT building_ = true; request_template( - BIND(handle_build, _1, _2, _3, pool_generation(), moves_)); + BIND(handle_build, _1, _2, _3, _4, pool_generation(), moves_)); } // private -void chaser_template::handle_build(const code& ec, size_t height, +void chaser_template::handle_build(const code& ec, + const chain::context& context, const hash_digest& previous, const database::tx_links& links, uint64_t generation, size_t moves) NOEXCEPT { - POST(do_build, ec, height, links, generation, moves); + POST(do_build, ec, context, previous, links, generation, moves); } // private // A build that the chain moved under is not of its top, so is built again. -void chaser_template::do_build(const code& ec, size_t height, +void chaser_template::do_build(const code& ec, + const chain::context& context, const hash_digest& previous, const database::tx_links& links, uint64_t generation, size_t moves) NOEXCEPT { @@ -237,7 +239,7 @@ void chaser_template::do_build(const code& ec, size_t height, } built_ = generation; - if (const auto failed = replace(height, links)) + if (const auto failed = replace(context, previous, links)) { complete(fault(failed)); return; @@ -250,8 +252,8 @@ void chaser_template::do_build(const code& ec, size_t height, // private // The template held is replaced when it is not of the chain top, or when the // fees of the build exceed its own by more than the configured increase. -code chaser_template::replace(size_t height, - const database::tx_links& links) NOEXCEPT +code chaser_template::replace(const chain::context& context, + const hash_digest& previous, const database::tx_links& links) NOEXCEPT { BC_ASSERT(stranded()); const auto& query = archive(); @@ -268,7 +270,7 @@ code chaser_template::replace(size_t height, const auto increase = node_settings().pool.template_fee_increase; const auto current = held_ && (moved_ == moves_) && - (held_->height == height); + (held_->previous == previous); if (current && (floored_subtract(fees, held_->fees) <= increase)) return error::success; @@ -292,7 +294,8 @@ code chaser_template::replace(size_t height, const auto sequence = add1(template_generation()); held_ = to_shared(block_template { - height, + previous, + context, sequence, fees, links, @@ -302,7 +305,7 @@ code chaser_template::replace(size_t height, generation_.store(sequence, std::memory_order_relaxed); fire(events::template_issued, links.size()); - notify(error::success, chases::template_{ height }); + notify(error::success, chases::template_{ context.height }); return error::success; } diff --git a/src/chasers/chaser_transaction.cpp b/src/chasers/chaser_transaction.cpp index 37fc4fa3..a9a1d4f0 100644 --- a/src/chasers/chaser_transaction.cpp +++ b/src/chasers/chaser_transaction.cpp @@ -211,6 +211,7 @@ void chaser_transaction::do_bump() NOEXCEPT // The context of the next block, in which a pool tx would confirm. const auto previous = pool_; pool_ = chain_state{ *state, system_settings() }.context(); + previous_ = query.get_header_key(top); // Row holds unless a flag changes or height or median time past falls. due_ = due_ || pool_.flags != previous.flags || diff --git a/src/chasers/chaser_transaction_query.cpp b/src/chasers/chaser_transaction_query.cpp index 85f818be..0dc29fd6 100644 --- a/src/chasers/chaser_transaction_query.cpp +++ b/src/chasers/chaser_transaction_query.cpp @@ -130,13 +130,13 @@ void chaser_transaction::do_build_template( if (closed()) { - handler(network::error::service_stopped, {}, {}); + handler(network::error::service_stopped, {}, {}, {}); return; } if (!pooling_) { - handler(error::pooling_disabled, {}, {}); + handler(error::pooling_disabled, {}, {}, {}); return; } @@ -150,7 +150,7 @@ void chaser_transaction::do_build_template( settings.bytes_per_sigop, settings.maximum_outcomes); report(pool_scan::template_, start); - handler(ec, pool_.height, links); + handler(ec, pool_, previous_, links); } // private diff --git a/test/chasers/chaser_template.cpp b/test/chasers/chaser_template.cpp index 72642da4..d6935f76 100644 --- a/test/chasers/chaser_template.cpp +++ b/test/chasers/chaser_template.cpp @@ -149,7 +149,7 @@ struct chaser_template_setup_fixture const node::block_template::cptr& held) NOEXCEPT { if (held) - promise.set_value({ ec, held->height, held->links }); + promise.set_value({ ec, held->context.height, held->links }); else promise.set_value({ ec, zero, {} }); }); diff --git a/test/chasers/chaser_transaction_setup_fixture.hpp b/test/chasers/chaser_transaction_setup_fixture.hpp index 79c5dd53..bd7f44a0 100644 --- a/test/chasers/chaser_transaction_setup_fixture.hpp +++ b/test/chasers/chaser_transaction_setup_fixture.hpp @@ -461,10 +461,11 @@ struct chaser_transaction_setup_fixture built build_template() { std::promise promise{}; - node_.build_template([&](const code& ec, size_t height, + node_.build_template([&](const code& ec, + const system::chain::context& context, const system::hash_digest&, const database::tx_links& links) NOEXCEPT { - promise.set_value({ ec, height, links }); + promise.set_value({ ec, context.height, links }); }); return promise.get_future().get(); From c583d24ef3b48533f617d886c51ba969f3a91027 Mon Sep 17 00:00:00 2001 From: Eric Voskuil Date: Mon, 23 Nov 2026 14:25:02 -0500 Subject: [PATCH 4/7] Hold the ids, totals and parent positions of template txs. --- include/bitcoin/node/types/block_template.hpp | 3 ++ src/chasers/chaser_template.cpp | 31 +++++++------------ 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/include/bitcoin/node/types/block_template.hpp b/include/bitcoin/node/types/block_template.hpp index 0a95fb15..b40c63da 100644 --- a/include/bitcoin/node/types/block_template.hpp +++ b/include/bitcoin/node/types/block_template.hpp @@ -50,6 +50,9 @@ struct block_template /// Merkle branch of the coinbase. system::hashes branch; + + /// Ids, totals and parent positions of the txs. + database::template_txs txs; }; } // namespace node diff --git a/src/chasers/chaser_template.cpp b/src/chasers/chaser_template.cpp index d0c6c8b1..74e2fdd1 100644 --- a/src/chasers/chaser_template.cpp +++ b/src/chasers/chaser_template.cpp @@ -256,17 +256,13 @@ code chaser_template::replace(const chain::context& context, const hash_digest& previous, const database::tx_links& links) NOEXCEPT { BC_ASSERT(stranded()); - const auto& query = archive(); + database::template_txs txs{}; + if (const auto ec = archive().get_template_txs(txs, links)) + return ec; uint64_t fees{}; - for (const auto& link: links) - { - query::pool_totals totals{}; - if (!query.get_pooled_totals(totals, link)) - return database::error::integrity; - - fees = ceilinged_add(fees, totals.fee); - } + for (const auto& tx: txs) + fees = ceilinged_add(fees, tx.fee); const auto increase = node_settings().pool.template_fee_increase; const auto current = held_ && (moved_ == moves_) && @@ -278,16 +274,12 @@ code chaser_template::replace(const chain::context& context, // Leaves of the coinbase are null, as it is not of the template. hashes txids{ null_hash }; hashes wtxids{ null_hash }; - txids.reserve(add1(links.size())); - wtxids.reserve(add1(links.size())); - for (const auto& link: links) + txids.reserve(add1(txs.size())); + wtxids.reserve(add1(txs.size())); + for (const auto& tx: txs) { - const auto row = query.to_pool_row(link); - if (row.is_terminal()) - return database::error::integrity; - - txids.push_back(query.get_tx_key(link)); - wtxids.push_back(query.get_wtxid_key(row)); + txids.push_back(tx.txid); + wtxids.push_back(tx.wtxid); } const auto root = merkle_root(std::move(wtxids)); @@ -300,7 +292,8 @@ code chaser_template::replace(const chain::context& context, fees, links, sha256::double_hash(root, null_hash), - chain::block::merkle_branch(zero, std::move(txids)) + chain::block::merkle_branch(zero, std::move(txids)), + std::move(txs) }); generation_.store(sequence, std::memory_order_relaxed); From 95464d1fd7d6ea12cad93cc5770bbcff69bb6445 Mon Sep 17 00:00:00 2001 From: Eric Voskuil Date: Mon, 23 Nov 2026 17:45:48 -0500 Subject: [PATCH 5/7] Bump the pool generation when the pool opens or closes. --- src/chasers/chaser_transaction.cpp | 9 ++++ test/chasers/chaser_transaction.cpp | 23 +++++++++++ .../chaser_transaction_setup_fixture.hpp | 41 +++++++++++++++++-- 3 files changed, 69 insertions(+), 4 deletions(-) diff --git a/src/chasers/chaser_transaction.cpp b/src/chasers/chaser_transaction.cpp index a9a1d4f0..519baa20 100644 --- a/src/chasers/chaser_transaction.cpp +++ b/src/chasers/chaser_transaction.cpp @@ -184,7 +184,12 @@ void chaser_transaction::do_bump() NOEXCEPT const auto opened = pooling_.load(); pooling_ = false; if (closed() || !is_current_chain(true)) + { + if (opened) + ++generation_; + return; + } // Pooling is a permanent store property, so it requires relay. auto& query = archive(); @@ -240,6 +245,10 @@ void chaser_transaction::do_bump() NOEXCEPT } } + // Opening or closing the pool changes its templates. + if (pooling_ != opened) + ++generation_; + // Scan starts are mapped after the latch, as pooled rows are unordered. if (!query.silent_enabled() || scanning_) return; diff --git a/test/chasers/chaser_transaction.cpp b/test/chasers/chaser_transaction.cpp index 9addafaa..309b1eeb 100644 --- a/test/chasers/chaser_transaction.cpp +++ b/test/chasers/chaser_transaction.cpp @@ -30,6 +30,29 @@ BC_FIXTURE_TEST_CASE(chaser_transaction__organized__invalid_confirmed_top__suspe BC_REQUIRE_EQUAL(submit(package({ spend(parent_value) })).first, node::error::pooling_disabled); } +BC_FIXTURE_TEST_CASE(chaser_transaction__start__pool_opened__generation_bumped, chaser_transaction_pooling_setup_fixture) +{ + BC_REQUIRE(!std::get<0>(build_template())); + BC_REQUIRE_EQUAL(node_.pool_generation(), 1u); +} + +BC_FIXTURE_TEST_CASE(chaser_transaction__start__pool_not_opened__generation_unchanged, chaser_transaction_inactive_setup_fixture) +{ + BC_REQUIRE_EQUAL(std::get<0>(build_template()), node::error::pooling_disabled); + BC_REQUIRE_EQUAL(node_.pool_generation(), 0u); +} + +BC_FIXTURE_TEST_CASE(chaser_transaction__organized__currency_lost__pool_closed_generation_bumped, chaser_transaction_currency_setup_fixture) +{ + BC_REQUIRE(!std::get<0>(build_template())); + const auto opened = node_.pool_generation(); + const auto link = push({}, 1); + node_.notify(node::error::success, chases::organized{ link }); + BC_REQUIRE(!link.is_terminal()); + BC_REQUIRE(pool_closed()); + BC_REQUIRE_EQUAL(node_.pool_generation(), opened + 2u); +} + // subscribe_pool BC_FIXTURE_TEST_CASE(chaser_transaction__subscribe_pool__submit__coverage_then_admission, chaser_transaction_single_setup_fixture) diff --git a/test/chasers/chaser_transaction_setup_fixture.hpp b/test/chasers/chaser_transaction_setup_fixture.hpp index bd7f44a0..e0a976c5 100644 --- a/test/chasers/chaser_transaction_setup_fixture.hpp +++ b/test/chasers/chaser_transaction_setup_fixture.hpp @@ -520,15 +520,17 @@ struct chaser_transaction_setup_fixture return link; } - // Confirm a block of a coinbase, and the tx if any, in the store only. - database::header_link push(const chain::transaction::cptr& tx={}) + // Confirm a block of a coinbase, and the tx if any, in the store only, + // timestamped as given, or after genesis by its height if zero. + database::header_link push(const chain::transaction::cptr& tx={}, + uint32_t timestamp=0) { const system::settings bitcoin{ chain::selection::mainnet }; const auto& genesis = bitcoin.genesis_block; const auto top = query_.get_top_confirmed(); const auto height = add1(top); - const auto time = genesis.header().timestamp() + - possible_narrow_cast(height); + const auto time = is_zero(timestamp) ? genesis.header().timestamp() + + possible_narrow_cast(height) : timestamp; const auto bits = genesis.header().bits(); const chain::transaction coinbase { @@ -558,6 +560,22 @@ struct chaser_transaction_setup_fixture return link; } + // True once a template build reports the pool closed. + bool pool_closed() + { + using namespace std::chrono; + const auto deadline = steady_clock::now() + seconds(10); + while (steady_clock::now() < deadline) + { + if (std::get<0>(build_template()) == node::error::pooling_disabled) + return true; + + std::this_thread::sleep_for(milliseconds(10)); + } + + return false; + } + // True once the pool context is of the height. bool bumped(size_t height) { @@ -1159,6 +1177,21 @@ struct chaser_transaction_unapplied_relative_setup_fixture } }; +// Current while the top is within twenty years of now, so the test chain is +// current until a block of the epoch is confirmed. +struct chaser_transaction_currency_setup_fixture + : chaser_transaction_setup_fixture +{ + inline chaser_transaction_currency_setup_fixture() + : chaser_transaction_setup_fixture([](configuration& config) + { + config.network.enable_relay = true; + config.node.currency_window_minutes = 20u * 365u * 24u * 60u; + }) + { + } +}; + struct chaser_transaction_relay_off_setup_fixture : chaser_transaction_setup_fixture { From 3a457513f29141fcfd3f725a18791f73d156b540 Mon Sep 17 00:00:00 2001 From: Eric Voskuil Date: Mon, 23 Nov 2026 17:38:10 -0500 Subject: [PATCH 6/7] Relay from the pooled ancestry of the pool columns. --- src/chasers/chaser_transaction_relay.cpp | 40 +++--------------------- 1 file changed, 4 insertions(+), 36 deletions(-) diff --git a/src/chasers/chaser_transaction_relay.cpp b/src/chasers/chaser_transaction_relay.cpp index 2f0a5be8..87bf7eaf 100644 --- a/src/chasers/chaser_transaction_relay.cpp +++ b/src/chasers/chaser_transaction_relay.cpp @@ -225,41 +225,9 @@ bool chaser_transaction::relay(const database::tx_links& links, { BC_ASSERT(stranded()); using algorithm = pool::algorithm; - struct relayable - { - size_t row; - database::tx_link link; - algorithm::totals_t totals; - }; - - const auto& query = archive(); - std::vector rows{}; - std::unordered_set seen{}; - const auto add = [&](const database::tx_link& link) NOEXCEPT - { - if (!seen.insert(link.value).second) - return true; - - algorithm::totals_t totals{}; - const auto row = query.to_pool_row(link); - if (row.is_terminal() || !query.get_pooled_totals(totals, link)) - return false; - - rows.push_back({ row.value, link, totals }); - return true; - }; - - for (const auto& link: links) - { - for (const auto& ancestor: query.to_confirmable_ancestors(link)) - if (!add(ancestor)) - return false; - - if (!add(link)) - return false; - } - - std::ranges::sort(rows, {}, &relayable::row); + database::pooled_rows rows{}; + if (archive().get_pooled_ancestry(rows, links)) + return false; const auto limit = block_limit().size; const auto bytes_per_sigop = node_settings().pool.bytes_per_sigop; @@ -302,7 +270,7 @@ bool chaser_transaction::relay(const database::tx_links& links, continue; mark = bit_or(mark, word); - const chases::relay event{ row.link.value, word }; + const chases::relay event{ row.tx, word }; if (is_zero(key)) notify(error::success, event); else From e162e88485d0e1071bd9e7b23cb28d2395580a11 Mon Sep 17 00:00:00 2001 From: Eric Voskuil Date: Mon, 23 Nov 2026 17:38:10 -0500 Subject: [PATCH 7/7] Count admission sigops once, from the candidate, and pool with them. --- .../node/chasers/chaser_transaction.hpp | 6 ++--- src/chasers/chaser_transaction_submit.cpp | 26 ++++++++++--------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/include/bitcoin/node/chasers/chaser_transaction.hpp b/include/bitcoin/node/chasers/chaser_transaction.hpp index e370c206..1c8f2eb2 100644 --- a/include/bitcoin/node/chasers/chaser_transaction.hpp +++ b/include/bitcoin/node/chasers/chaser_transaction.hpp @@ -199,6 +199,7 @@ class BCN_API chaser_transaction bool test; bool announced; std::vector stored{}; + std::vector sigops_of{}; std::unordered_set held{}; query::pool_graph graph{}; uint64_t bytes{}; @@ -221,8 +222,7 @@ class BCN_API chaser_transaction bool spends_held(const system::chain::transaction& tx) const NOEXCEPT; bool is_held(const system::chain::input& in) const NOEXCEPT; void pass_over(submission& set, size_t index, const code& ec) NOEXCEPT; - void count(submission& set, - const system::chain::transaction& tx) const NOEXCEPT; + void count(submission& set, size_t index) const NOEXCEPT; code extend(bool& covered, submission& set, size_t index) NOEXCEPT; code restore(submission& set, size_t index) NOEXCEPT; code clear(size_t& at, submission& set, size_t index) NOEXCEPT; @@ -232,7 +232,7 @@ class BCN_API chaser_transaction code accept(const system::chain::transaction& tx, const system::chain::context& ctx) NOEXCEPT; code admit(database::tx_link& out, const system::chain::transaction& tx, - uint32_t time) NOEXCEPT; + uint32_t time, size_t sigops) NOEXCEPT; code validate(bool& guarded, const system::chain::transaction& tx, const system::chain::context& ctx) NOEXCEPT; database::tx_link to_stored( diff --git a/src/chasers/chaser_transaction_submit.cpp b/src/chasers/chaser_transaction_submit.cpp index 4aefd6d4..ba8a9405 100644 --- a/src/chasers/chaser_transaction_submit.cpp +++ b/src/chasers/chaser_transaction_submit.cpp @@ -229,6 +229,7 @@ void chaser_transaction::hold(submission& set) NOEXCEPT { const auto& query = archive(); set.stored.resize(set.txs->size()); + set.sigops_of.resize(set.txs->size()); for (size_t index{}; index < set.txs->size(); ++index) { const auto& tx = *set.txs->at(index); @@ -293,14 +294,14 @@ void chaser_transaction::pass_over(submission& set, size_t index, } // private -void chaser_transaction::count(submission& set, - const chain::transaction& tx) const NOEXCEPT +// Totals of last candidate in graph, tx at index. +void chaser_transaction::count(submission& set, size_t index) const NOEXCEPT { - const auto bip16 = pool_.is_enabled(flags::bip16_rule); - const auto bip141 = pool_.is_enabled(flags::bip141_rule); - const auto sigops = tx.signature_operations(bip16, bip141); - set.bytes = ceilinged_add(set.bytes, tx.virtual_size()); - set.sigops = ceilinged_add(set.sigops, sigops); + using algorithm = pool::algorithm; + const auto totals = algorithm::from_column(set.graph.totals.back()); + set.sigops_of.at(index) = totals.sigops; + set.bytes = ceilinged_add(set.bytes, totals.size); + set.sigops = ceilinged_add(set.sigops, totals.sigops); } // private @@ -319,7 +320,7 @@ code chaser_transaction::extend(bool& covered, submission& set, set.first = index; set.running = true; - count(set, tx); + count(set, index); const auto limit = block_limit(); if (set.bytes > limit.size || set.sigops > limit.sigops) @@ -371,7 +372,7 @@ code chaser_transaction::restore(submission& set, size_t index) NOEXCEPT if (const auto ec = query.get_pool_candidate(set.graph, tx, ctx)) return fault(ec); - count(set, tx); + count(set, at); set.running = true; } @@ -409,7 +410,8 @@ code chaser_transaction::clear(size_t& at, submission& set, continue; database::tx_link link{}; - if (const auto ec = admit(link, *set.txs->at(at), set.time)) + const auto& tx = *set.txs->at(at); + if (const auto ec = admit(link, tx, set.time, set.sigops_of.at(at))) return ec; admitted.push_back(link); @@ -452,7 +454,7 @@ code chaser_transaction::check(const transaction_cptrs& txs, } code chaser_transaction::admit(database::tx_link& link, - const chain::transaction& tx, uint32_t time) NOEXCEPT + const chain::transaction& tx, uint32_t time, size_t sigops) NOEXCEPT { bool archived{}; auto& query = archive(); @@ -466,7 +468,7 @@ code chaser_transaction::admit(database::tx_link& link, size_t repooled{}; const auto start = now(); const auto admitted = query.set_pooled(repooled, link, tx, - database::context::from(pool_), time); + database::context::from(pool_), time, sigops, archived); report(pool_scan::admission, start); if (!admitted)