From ce5f8c83973efcaa0e2e2e3c4a0777d5e4463f14 Mon Sep 17 00:00:00 2001 From: Dylan Wilson Date: Wed, 8 Aug 2018 14:14:01 -0700 Subject: [PATCH] Bump gas estimate percentile to 20% --- .../test_time_based_gas_price_strategy.py | 14 +++++++------- web3/gas_strategies/time_based.py | 2 +- web3/utils/math.py | 3 ++- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/tests/core/gas-strategies/test_time_based_gas_price_strategy.py b/tests/core/gas-strategies/test_time_based_gas_price_strategy.py index c2f3ba996e..8678485286 100644 --- a/tests/core/gas-strategies/test_time_based_gas_price_strategy.py +++ b/tests/core/gas-strategies/test_time_based_gas_price_strategy.py @@ -118,20 +118,20 @@ def _get_block_by_something(method, params): ( # 120 second wait times (dict(max_wait_seconds=80, sample_size=5, probability=98), 70), - (dict(max_wait_seconds=80, sample_size=5, probability=90), 23), - (dict(max_wait_seconds=80, sample_size=5, probability=50), 7), + (dict(max_wait_seconds=80, sample_size=5, probability=90), 25), + (dict(max_wait_seconds=80, sample_size=5, probability=50), 11), # 60 second wait times (dict(max_wait_seconds=60, sample_size=5, probability=98), 92), - (dict(max_wait_seconds=60, sample_size=5, probability=90), 48), - (dict(max_wait_seconds=60, sample_size=5, probability=50), 7), + (dict(max_wait_seconds=60, sample_size=5, probability=90), 49), + (dict(max_wait_seconds=60, sample_size=5, probability=50), 11), # 40 second wait times (dict(max_wait_seconds=40, sample_size=5, probability=98), 100), (dict(max_wait_seconds=40, sample_size=5, probability=90), 81), - (dict(max_wait_seconds=40, sample_size=5, probability=50), 7), + (dict(max_wait_seconds=40, sample_size=5, probability=50), 11), # 20 second wait times (dict(max_wait_seconds=20, sample_size=5, probability=98), 100), (dict(max_wait_seconds=20, sample_size=5, probability=90), 100), - (dict(max_wait_seconds=20, sample_size=5, probability=50), 34), + (dict(max_wait_seconds=20, sample_size=5, probability=50), 36), ), ) def test_time_based_gas_price_strategy(strategy_params, expected): @@ -150,7 +150,7 @@ def test_time_based_gas_price_strategy(strategy_params, expected): ) w3.eth.setGasPriceStrategy(time_based_gas_price_strategy) actual = w3.eth.generateGasPrice() - assert actual == expected + assert int(actual) == expected @pytest.mark.parametrize( diff --git a/web3/gas_strategies/time_based.py b/web3/gas_strategies/time_based.py index 61a4c7e14b..6f4df07bb4 100644 --- a/web3/gas_strategies/time_based.py +++ b/web3/gas_strategies/time_based.py @@ -62,7 +62,7 @@ def _aggregate_miner_data(raw_data): for miner, miner_data in data_by_miner.items(): _, block_hashes, gas_prices = map(set, zip(*miner_data)) try: - price_percentile = percentile(gas_prices, percentile=15) + price_percentile = percentile(gas_prices, percentile=20) except InsufficientData: price_percentile = min(gas_prices) yield MinerData( diff --git a/web3/utils/math.py b/web3/utils/math.py index 1f741d6012..130f67a03f 100644 --- a/web3/utils/math.py +++ b/web3/utils/math.py @@ -7,7 +7,8 @@ def percentile(values=None, percentile=None): """Calculates a simplified weighted average percentile """ if values in [None, tuple(), []] or len(values) < 1: - raise InsufficientData("Expected a sequence of at least 1 integers, got {0}".format(values)) + raise InsufficientData( + "Expected a sequence of at least 1 integers, got {0!r}".format(values)) if percentile is None: raise ValueError("Expected a percentile choice, got {0}".format(percentile))