From 7d3e3d2a6b0ccae7153b0ff0a195a2948e2e8c4b Mon Sep 17 00:00:00 2001 From: evoskuil Date: Fri, 20 Feb 2026 23:09:47 -0500 Subject: [PATCH 1/2] Fix get_block_fees() inverted return. --- .../bitcoin/database/impl/query/estimate.ipp | 28 +++++-------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/include/bitcoin/database/impl/query/estimate.ipp b/include/bitcoin/database/impl/query/estimate.ipp index da976ee7..e29bfce7 100644 --- a/include/bitcoin/database/impl/query/estimate.ipp +++ b/include/bitcoin/database/impl/query/estimate.ipp @@ -30,10 +30,6 @@ namespace libbitcoin { namespace database { -// fee estimate -// ---------------------------------------------------------------------------- - -// protected TEMPLATE bool CLASS::get_block_fees(fee_rates& out, const header_link& link) const NOEXCEPT @@ -58,7 +54,6 @@ bool CLASS::get_block_fees(fee_rates& out, return true; } -// public TEMPLATE bool CLASS::get_block_fees(std::atomic_bool& cancel, fee_rate_sets& out, size_t top, size_t count) const NOEXCEPT @@ -78,31 +73,22 @@ bool CLASS::get_block_fees(std::atomic_bool& cancel, fee_rate_sets& out, std::vector offsets(count); std::iota(offsets.begin(), offsets.end(), zero); - std::atomic_bool failure{}; + std::atomic_bool fail{}; constexpr auto relaxed = std::memory_order_relaxed; std::for_each(poolstl::execution::par, offsets.begin(), offsets.end(), [&](const size_t& offset) NOEXCEPT { - if (failure.load(relaxed)) - return; - - if (cancel.load(relaxed)) - { - failure.store(true, relaxed); + if (fail.load(relaxed)) return; - } - const auto link = to_confirmed(start + offset); - if (!get_block_fees(out.at(offset), link)) - { - failure.store(false, relaxed); - return; - } + if (cancel.load(relaxed) || !get_block_fees(out.at(offset), + to_confirmed(start + offset))) + fail.store(true, relaxed); }); - const auto failed = failure.load(relaxed); + const auto failed = fail.load(relaxed); if (failed) out.clear(); - return failed; + return !failed; } } // namespace database From 8eaad905a84629e37309996eaa2fafaa763b0c28 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Fri, 20 Feb 2026 23:31:16 -0500 Subject: [PATCH 2/2] Add get_tx_fees, rename get_block_fees. --- include/bitcoin/database/impl/query/estimate.ipp | 14 +++++++++++++- include/bitcoin/database/impl/query/validate.ipp | 2 +- include/bitcoin/database/query.hpp | 10 ++++++---- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/include/bitcoin/database/impl/query/estimate.ipp b/include/bitcoin/database/impl/query/estimate.ipp index e29bfce7..aabea730 100644 --- a/include/bitcoin/database/impl/query/estimate.ipp +++ b/include/bitcoin/database/impl/query/estimate.ipp @@ -30,6 +30,18 @@ namespace libbitcoin { namespace database { +TEMPLATE +bool CLASS::get_tx_fees(fee_rate& out, const tx_link& link) const NOEXCEPT +{ + const auto tx = get_transaction(link, false); + if (!tx || !populate_without_metadata(*tx)) + return false; + + out.bytes = tx->virtual_size(); + out.fee = tx->fee(); + return true; +} + TEMPLATE bool CLASS::get_block_fees(fee_rates& out, const header_link& link) const NOEXCEPT @@ -55,7 +67,7 @@ bool CLASS::get_block_fees(fee_rates& out, } TEMPLATE -bool CLASS::get_block_fees(std::atomic_bool& cancel, fee_rate_sets& out, +bool CLASS::get_branch_fees(std::atomic_bool& cancel, fee_rate_sets& out, size_t top, size_t count) const NOEXCEPT { out.clear(); diff --git a/include/bitcoin/database/impl/query/validate.ipp b/include/bitcoin/database/impl/query/validate.ipp index dcd4aa9e..dfa1be95 100644 --- a/include/bitcoin/database/impl/query/validate.ipp +++ b/include/bitcoin/database/impl/query/validate.ipp @@ -141,7 +141,7 @@ code CLASS::get_block_state(const header_link& link) const NOEXCEPT } TEMPLATE -uint64_t CLASS::get_block_fees(const header_link& link) const NOEXCEPT +uint64_t CLASS::get_block_fee(const header_link& link) const NOEXCEPT { // TODO: optimize. const auto block = get_block(link, false); diff --git a/include/bitcoin/database/query.hpp b/include/bitcoin/database/query.hpp index 217b4772..865ffee4 100644 --- a/include/bitcoin/database/query.hpp +++ b/include/bitcoin/database/query.hpp @@ -401,9 +401,13 @@ class query /// Services. /// ----------------------------------------------------------------------- - /// Gether fee rate tuples by block or set of blocks. + uint64_t get_tx_fee(const tx_link& link) const NOEXCEPT; + uint64_t get_block_fee(const header_link& link) const NOEXCEPT; + + /// Gether fee rate tuples by tx, block or branch. + bool get_tx_fees(fee_rate& out, const tx_link& link) const NOEXCEPT; bool get_block_fees(fee_rates& out, const header_link& link) const NOEXCEPT; - bool get_block_fees(std::atomic_bool& cancel, fee_rate_sets& out, + bool get_branch_fees(std::atomic_bool& cancel, fee_rate_sets& out, size_t top, size_t count) const NOEXCEPT; /// Merkle computations over the index of confirmed headers. @@ -476,8 +480,6 @@ class query /// States. bool is_validateable(size_t height) const NOEXCEPT; - uint64_t get_tx_fee(const tx_link& link) const NOEXCEPT; - uint64_t get_block_fees(const header_link& link) const NOEXCEPT; code get_block_state(const header_link& link) const NOEXCEPT; code get_header_state(const header_link& link) const NOEXCEPT; code get_tx_state(const tx_link& link, const context& ctx) const NOEXCEPT;