@@ -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).
@@ -144,11 +149,12 @@ bool estimator::initialize(const rate_sets& blocks) NOEXCEPT
144149 if (is_zero (count))
145150 return true ;
146151
147- const auto top = top_height ();
148- auto height = top - sub1 (count);
149- if (system::is_subtract_overflow (top, sub1 (count)))
152+ if (system::is_add_overflow (fees_.top_height , sub1 (count)))
150153 return false ;
151154
155+ auto height = fees_.top_height ;
156+ fees_.top_height += sub1 (count);
157+
152158 // TODO: could be parallel by block.
153159 for (const auto & block: blocks)
154160 if (!update (block, height++, true ))
@@ -167,8 +173,9 @@ bool estimator::push(const rates& block) NOEXCEPT
167173// Blocks must be pushed in order (but independent of chain index).
168174bool estimator::pop (const rates& block) NOEXCEPT
169175{
170- const auto result = update (block, fees_.top_height -- , false );
176+ const auto result = update (block, fees_.top_height , false );
171177 decay (false );
178+ --fees_.top_height ;
172179 return result;
173180}
174181
0 commit comments