diff --git a/nano/core_test/rate_limiting.cpp b/nano/core_test/rate_limiting.cpp index 0d547e41c0..b0debd70c7 100644 --- a/nano/core_test/rate_limiting.cpp +++ b/nano/core_test/rate_limiting.cpp @@ -24,7 +24,6 @@ TEST (rate, basic) // Allow time for the bucket to completely refill and do a full burst std::this_thread::sleep_for (1s); ASSERT_TRUE (bucket.try_consume (10)); - ASSERT_EQ (bucket.largest_burst (), 10); } TEST (rate, network) @@ -35,9 +34,7 @@ TEST (rate, network) // Initial burst of 10 mb/s over two calls ASSERT_TRUE (bucket.try_consume (5)); - ASSERT_EQ (bucket.largest_burst (), 5); ASSERT_TRUE (bucket.try_consume (5)); - ASSERT_EQ (bucket.largest_burst (), 10); ASSERT_FALSE (bucket.try_consume (5)); // After 200 ms, the 5 mb/s fillrate means we have 1 mb available @@ -84,13 +81,10 @@ TEST (rate, unlimited) { nano::rate::token_bucket bucket (0, 0); ASSERT_TRUE (bucket.try_consume (5)); - ASSERT_EQ (bucket.largest_burst (), 5); ASSERT_TRUE (bucket.try_consume (static_cast (1e9))); - ASSERT_EQ (bucket.largest_burst (), static_cast (1e9)); // With unlimited tokens, consuming always succeed ASSERT_TRUE (bucket.try_consume (static_cast (1e9))); - ASSERT_EQ (bucket.largest_burst (), static_cast (1e9)); } TEST (rate, busy_spin) diff --git a/nano/lib/rate_limiting.cpp b/nano/lib/rate_limiting.cpp index adc8950bf1..4076868c04 100644 --- a/nano/lib/rate_limiting.cpp +++ b/nano/lib/rate_limiting.cpp @@ -19,18 +19,12 @@ bool nano::rate::token_bucket::try_consume (unsigned tokens_required) refill (); - // Keep track of largest observed bucket size so burst size can be computed (for tests and stats) - largest_size = std::max (largest_size, current_size); - bool possible = current_size >= tokens_required; if (possible) { current_size -= tokens_required; } - // Keep track of smallest observed bucket size so burst size can be computed (for tests and stats) - smallest_size = std::min (smallest_size, current_size); - return possible || refill_rate == unlimited_rate_sentinel; } @@ -48,8 +42,7 @@ void nano::rate::token_bucket::refill () void nano::rate::token_bucket::reset (std::size_t max_token_count_a, std::size_t refill_rate_a) { - // A token count of 0 indicates unlimited capacity. We use 1e9 as - // a sentinel, allowing largest burst to still be computed. + // A token count of 0 indicates unlimited capacity. We use 1e9 as a sentinel, allowing largest burst to still be computed. if (max_token_count_a == 0) { // Unlimited capacity @@ -61,18 +54,12 @@ void nano::rate::token_bucket::reset (std::size_t max_token_count_a, std::size_t refill_rate_a = unlimited_rate_sentinel; } - max_token_count = smallest_size = max_token_count_a; + max_token_count = max_token_count_a; refill_rate = refill_rate_a; current_size = max_token_count < unlimited_rate_sentinel ? max_token_count : 0; last_refill = std::chrono::steady_clock::now (); } -std::size_t nano::rate::token_bucket::largest_burst () const -{ - debug_assert (largest_size >= smallest_size); - return largest_size - smallest_size; -} - std::size_t nano::rate::token_bucket::size () const { return current_size; diff --git a/nano/lib/rate_limiting.hpp b/nano/lib/rate_limiting.hpp index ba13475dca..a0820a4030 100644 --- a/nano/lib/rate_limiting.hpp +++ b/nano/lib/rate_limiting.hpp @@ -44,18 +44,12 @@ class token_bucket /** Returns the current number of tokens in the bucket */ std::size_t size () const; - /** Returns the largest burst observed */ - std::size_t largest_burst () const; - void refill (); private: std::size_t max_token_count{ 0 }; std::size_t refill_rate{ 0 }; - std::size_t current_size{ 0 }; - std::size_t smallest_size{ 0 }; // The minimum observed bucket size, from which the largest burst can be derived - std::size_t largest_size{ 0 }; // The largest observed bucket size, from which the largest burst can be derived std::chrono::steady_clock::time_point last_refill; static std::size_t constexpr unlimited_rate_sentinel{ static_cast (1e9) };