Skip to content

Commit 1e8404d

Browse files
committed
Style, change estimator::initialize() to derive top block.
1 parent 03d8df4 commit 1e8404d

2 files changed

Lines changed: 25 additions & 17 deletions

File tree

include/bitcoin/server/estimator.hpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ class BCS_API estimator
4545
/// Pass zero to target next block for confirmation, range:0..1007.
4646
uint64_t estimate(size_t target, mode mode) const NOEXCEPT;
4747

48-
/// Populate accumulator.
48+
/// Populate accumulator with count blocks up to the top confirmed block.
4949
bool initialize(std::atomic_bool& cancel, const node::query& query,
50-
size_t top, size_t count) NOEXCEPT;
50+
size_t count) NOEXCEPT;
5151

5252
/// Update accumulator.
5353
bool push(const node::query& query) NOEXCEPT;
@@ -60,22 +60,14 @@ class BCS_API estimator
6060
using rates = database::fee_rates;
6161
using rate_sets = database::fee_rate_sets;
6262

63-
/// Bucket count sizing parameters.
63+
/// Bucket depth sizing parameters.
6464
enum horizon : size_t
6565
{
6666
small = 12,
6767
medium = 48,
6868
large = 1008
6969
};
7070

71-
/// Estimation confidences.
72-
struct confidence
73-
{
74-
static constexpr double low = 0.60;
75-
static constexpr double mid = 0.85;
76-
static constexpr double high = 0.95;
77-
};
78-
7971
/// Bucket count sizing parameters.
8072
struct sizing
8173
{
@@ -87,17 +79,25 @@ class BCS_API estimator
8779
static constexpr size_t count = 283;
8880
};
8981

82+
/// Estimation confidences.
83+
struct confidence
84+
{
85+
static constexpr double low = 0.60;
86+
static constexpr double mid = 0.85;
87+
static constexpr double high = 0.95;
88+
};
89+
9090
/// Accumulator (persistent, decay-weighted counters).
9191
struct accumulator
9292
{
93-
template <size_t Depth>
93+
template <size_t Horizon>
9494
struct bucket
9595
{
9696
/// Total scaled txs in bucket.
9797
std::atomic<size_t> total{};
9898

9999
/// confirmed[n]: scaled txs confirmed in > n blocks.
100-
std::array<std::atomic<size_t>, Depth> confirmed;
100+
std::array<std::atomic<size_t>, Horizon> confirmed;
101101
};
102102

103103
/// Current block height of accumulated state.

src/estimator.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,18 @@ uint64_t estimator::estimate(size_t target, mode mode) const NOEXCEPT
8585
}
8686

8787
bool estimator::initialize(std::atomic_bool& cancel, const node::query& query,
88-
size_t top, size_t count) NOEXCEPT
88+
size_t count) NOEXCEPT
8989
{
90+
if (is_zero(count))
91+
return true;
92+
93+
const auto top = query.get_top_confirmed();
94+
if (sub1(count) > top)
95+
return false;
96+
9097
rate_sets blocks{};
91-
return query.get_branch_fees(cancel, blocks, top, count) &&
98+
const auto start = top - sub1(count);
99+
return query.get_branch_fees(cancel, blocks, start, count) &&
92100
initialize(blocks);
93101
}
94102

@@ -269,7 +277,7 @@ bool estimator::update(const rates& block, size_t height, bool push) NOEXCEPT
269277
const auto call = [&](auto& buckets) NOEXCEPT
270278
{
271279
// The array count of the buckets element type.
272-
const auto depth = buckets.front().confirmed.size();
280+
const auto horizon = buckets.front().confirmed.size();
273281

274282
size_t bin{};
275283
for (const auto count: counts)
@@ -285,7 +293,7 @@ bool estimator::update(const rates& block, size_t height, bool push) NOEXCEPT
285293
const auto signed_term = push ? scaled : twos_complement(scaled);
286294

287295
bucket.total.fetch_add(signed_term, relaxed);
288-
for (auto target = age; target < depth; ++target)
296+
for (auto target = age; target < horizon; ++target)
289297
bucket.confirmed.at(target).fetch_add(signed_term, relaxed);
290298
}
291299
};

0 commit comments

Comments
 (0)