@@ -35,6 +35,11 @@ constexpr auto relaxed = std::memory_order_relaxed;
3535// public
3636// ----------------------------------------------------------------------------
3737
38+ estimator::ptr estimator::create () NOEXCEPT
39+ {
40+ return { new estimator{} ,[](estimator* ptr) NOEXCEPT { delete ptr; } };
41+ }
42+
3843uint64_t estimator::estimate (size_t target, mode mode) const NOEXCEPT
3944{
4045 // max_uint64 is failure sentinel (and unachievable/invalid as a fee).
@@ -128,6 +133,11 @@ size_t estimator::top_height() const NOEXCEPT
128133// protected
129134// ----------------------------------------------------------------------------
130135
136+ estimator::accumulator& estimator::history () NOEXCEPT
137+ {
138+ return fees_;
139+ }
140+
131141const estimator::accumulator& estimator::history () const NOEXCEPT
132142{
133143 return fees_;
@@ -139,11 +149,12 @@ bool estimator::initialize(const rate_sets& blocks) NOEXCEPT
139149 if (is_zero (count))
140150 return true ;
141151
142- const auto top = top_height ();
143- auto height = top - sub1 (count);
144- if (system::is_subtract_overflow (top, sub1 (count)))
152+ if (system::is_add_overflow (fees_.top_height , sub1 (count)))
145153 return false ;
146154
155+ auto height = fees_.top_height ;
156+ fees_.top_height += sub1 (count);
157+
147158 // TODO: could be parallel by block.
148159 for (const auto & block: blocks)
149160 if (!update (block, height++, true ))
@@ -162,8 +173,9 @@ bool estimator::push(const rates& block) NOEXCEPT
162173// Blocks must be pushed in order (but independent of chain index).
163174bool estimator::pop (const rates& block) NOEXCEPT
164175{
165- const auto result = update (block, fees_.top_height -- , false );
176+ const auto result = update (block, fees_.top_height , false );
166177 decay (false );
178+ --fees_.top_height ;
167179 return result;
168180}
169181
0 commit comments