Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions include/bitcoin/server/estimator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -60,22 +60,14 @@ 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,
medium = 48,
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
{
Expand All @@ -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 <size_t Depth>
template <size_t Horizon>
struct bucket
{
/// Total scaled txs in bucket.
std::atomic<size_t> total{};

/// confirmed[n]: scaled txs confirmed in > n blocks.
std::array<std::atomic<size_t>, Depth> confirmed;
std::array<std::atomic<size_t>, Horizon> confirmed;
};

/// Current block height of accumulated state.
Expand Down
16 changes: 12 additions & 4 deletions src/estimator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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)
Expand All @@ -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);
}
};
Expand Down
Loading