From 1e8404d624e3124c460c26cac0631f9082f3433d Mon Sep 17 00:00:00 2001 From: evoskuil Date: Sat, 21 Feb 2026 13:55:22 -0500 Subject: [PATCH] Style, change estimator::initialize() to derive top block. --- include/bitcoin/server/estimator.hpp | 26 +++++++++++++------------- src/estimator.cpp | 16 ++++++++++++---- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/include/bitcoin/server/estimator.hpp b/include/bitcoin/server/estimator.hpp index bdde3cef..9f4a773b 100644 --- a/include/bitcoin/server/estimator.hpp +++ b/include/bitcoin/server/estimator.hpp @@ -45,9 +45,9 @@ class BCS_API estimator /// Pass zero to target next block for confirmation, range:0..1007. uint64_t estimate(size_t target, mode mode) const NOEXCEPT; - /// Populate accumulator. + /// Populate accumulator with count blocks up to the top confirmed block. bool initialize(std::atomic_bool& cancel, const node::query& query, - size_t top, size_t count) NOEXCEPT; + size_t count) NOEXCEPT; /// Update accumulator. bool push(const node::query& query) NOEXCEPT; @@ -60,7 +60,7 @@ class BCS_API estimator using rates = database::fee_rates; using rate_sets = database::fee_rate_sets; - /// Bucket count sizing parameters. + /// Bucket depth sizing parameters. enum horizon : size_t { small = 12, @@ -68,14 +68,6 @@ class BCS_API estimator large = 1008 }; - /// Estimation confidences. - struct confidence - { - static constexpr double low = 0.60; - static constexpr double mid = 0.85; - static constexpr double high = 0.95; - }; - /// Bucket count sizing parameters. struct sizing { @@ -87,17 +79,25 @@ class BCS_API estimator static constexpr size_t count = 283; }; + /// Estimation confidences. + struct confidence + { + static constexpr double low = 0.60; + static constexpr double mid = 0.85; + static constexpr double high = 0.95; + }; + /// Accumulator (persistent, decay-weighted counters). struct accumulator { - template + template struct bucket { /// Total scaled txs in bucket. std::atomic total{}; /// confirmed[n]: scaled txs confirmed in > n blocks. - std::array, Depth> confirmed; + std::array, Horizon> confirmed; }; /// Current block height of accumulated state. diff --git a/src/estimator.cpp b/src/estimator.cpp index 88107e04..310d64ee 100644 --- a/src/estimator.cpp +++ b/src/estimator.cpp @@ -85,10 +85,18 @@ uint64_t estimator::estimate(size_t target, mode mode) const NOEXCEPT } bool estimator::initialize(std::atomic_bool& cancel, const node::query& query, - size_t top, size_t count) NOEXCEPT + size_t count) NOEXCEPT { + if (is_zero(count)) + return true; + + const auto top = query.get_top_confirmed(); + if (sub1(count) > top) + return false; + rate_sets blocks{}; - return query.get_branch_fees(cancel, blocks, top, count) && + const auto start = top - sub1(count); + return query.get_branch_fees(cancel, blocks, start, count) && initialize(blocks); } @@ -269,7 +277,7 @@ bool estimator::update(const rates& block, size_t height, bool push) NOEXCEPT const auto call = [&](auto& buckets) NOEXCEPT { // The array count of the buckets element type. - const auto depth = buckets.front().confirmed.size(); + const auto horizon = buckets.front().confirmed.size(); size_t bin{}; for (const auto count: counts) @@ -285,7 +293,7 @@ bool estimator::update(const rates& block, size_t height, bool push) NOEXCEPT const auto signed_term = push ? scaled : twos_complement(scaled); bucket.total.fetch_add(signed_term, relaxed); - for (auto target = age; target < depth; ++target) + for (auto target = age; target < horizon; ++target) bucket.confirmed.at(target).fetch_add(signed_term, relaxed); } };