From 2194641961f631ea1bc1dc84fa227bed4183e3c4 Mon Sep 17 00:00:00 2001 From: Evgeny Gusarov Date: Sun, 10 Mar 2024 22:32:56 +0300 Subject: [PATCH] Del max_priority_fee_per_gas_gwei setting --- src/commands/start.py | 8 -------- src/commands/start_api.py | 8 -------- src/common/execution.py | 30 ++++++++++++++++++++++-------- src/config/settings.py | 3 --- 4 files changed, 22 insertions(+), 27 deletions(-) diff --git a/src/commands/start.py b/src/commands/start.py index 40e2003e..10cbf2b8 100644 --- a/src/commands/start.py +++ b/src/commands/start.py @@ -45,12 +45,6 @@ f'Default is {DEFAULT_MAX_FEE_PER_GAS_GWEI} Gwei.', default=DEFAULT_MAX_FEE_PER_GAS_GWEI, ) -@click.option( - '--max-priority-fee-per-gas-gwei', - type=int, - envvar='MAX_PRIORITY_FEE_PER_GAS_GWEI', - help='Maximum priority fee per gas for transactions.', -) @click.option( '--hot-wallet-password-file', type=click.Path(exists=True, file_okay=True, dir_okay=False), @@ -222,7 +216,6 @@ def start( hot_wallet_file: str | None, hot_wallet_password_file: str | None, max_fee_per_gas_gwei: int, - max_priority_fee_per_gas_gwei: int | None, database_dir: str | None, pool_size: int | None, ) -> None: @@ -252,7 +245,6 @@ def start( hot_wallet_file=hot_wallet_file, hot_wallet_password_file=hot_wallet_password_file, max_fee_per_gas_gwei=max_fee_per_gas_gwei, - max_priority_fee_per_gas_gwei=max_priority_fee_per_gas_gwei, database_dir=database_dir, log_level=log_level, log_format=log_format, diff --git a/src/commands/start_api.py b/src/commands/start_api.py index 6194212e..acf31463 100644 --- a/src/commands/start_api.py +++ b/src/commands/start_api.py @@ -49,12 +49,6 @@ f'Default is {DEFAULT_MAX_FEE_PER_GAS_GWEI} Gwei.', default=DEFAULT_MAX_FEE_PER_GAS_GWEI, ) -@click.option( - '--max-priority-fee-per-gas-gwei', - type=int, - envvar='MAX_PRIORITY_FEE_PER_GAS_GWEI', - help='Maximum priority fee per gas for transactions.', -) @click.option( '--hot-wallet-password-file', type=click.Path(exists=True, file_okay=True, dir_okay=False), @@ -193,7 +187,6 @@ def start_api( hot_wallet_file: str | None, hot_wallet_password_file: str | None, max_fee_per_gas_gwei: int, - max_priority_fee_per_gas_gwei: int | None, database_dir: str | None, api_host: str, api_port: int, @@ -220,7 +213,6 @@ def start_api( hot_wallet_file=hot_wallet_file, hot_wallet_password_file=hot_wallet_password_file, max_fee_per_gas_gwei=max_fee_per_gas_gwei, - max_priority_fee_per_gas_gwei=max_priority_fee_per_gas_gwei, database_dir=database_dir, log_level=log_level, log_format=log_format, diff --git a/src/common/execution.py b/src/common/execution.py index 7b2c6ed1..33c583a0 100644 --- a/src/common/execution.py +++ b/src/common/execution.py @@ -153,20 +153,34 @@ async def get_oracles() -> Oracles: async def get_tx_params() -> TxParams: tx_params: TxParams = {} - if settings.max_priority_fee_per_gas_gwei: - max_priority_fee_per_gas = Web3.to_wei(settings.max_priority_fee_per_gas_gwei, 'gwei') + max_priority_fee_per_gas = await _calc_priority_fee() - # Reference: `_max_fee_per_gas` in web3/_utils/async_transactions.py - block = await execution_client.eth.get_block('latest') - max_fee_per_gas = Wei(max_priority_fee_per_gas + (2 * block['baseFeePerGas'])) + # Reference: `_max_fee_per_gas` in web3/_utils/async_transactions.py + block = await execution_client.eth.get_block('latest') + max_fee_per_gas = Wei(max_priority_fee_per_gas + (2 * block['baseFeePerGas'])) - tx_params['maxPriorityFeePerGas'] = max_priority_fee_per_gas - tx_params['maxFeePerGas'] = max_fee_per_gas - logger.debug('tx_params %s', tx_params) + tx_params['maxPriorityFeePerGas'] = max_priority_fee_per_gas + tx_params['maxFeePerGas'] = max_fee_per_gas + logger.debug('tx_params %s', tx_params) return tx_params +async def _calc_priority_fee() -> Wei: + """ + reference: "high" priority value from https://etherscan.io/gastracker + """ + num_blocks = 10 + percentile = 80.0 + history = await execution_client.eth.fee_history(num_blocks, 'pending', [percentile]) + validator_rewards = [r[0] for r in history['reward']] + logger.info( + 'validator_rewards %s', sorted([round(Web3.from_wei(r, 'gwei')) for r in validator_rewards]) + ) + mean_reward = int(sum(validator_rewards) / len(validator_rewards)) + return Wei(mean_reward) + + async def check_gas_price(custom_priority_fee: bool = False) -> bool: if custom_priority_fee: # custom gas-price logic diff --git a/src/config/settings.py b/src/config/settings.py index b2d546ca..d0bc9305 100644 --- a/src/config/settings.py +++ b/src/config/settings.py @@ -57,7 +57,6 @@ class Settings(metaclass=Singleton): hot_wallet_file: Path hot_wallet_password_file: Path max_fee_per_gas_gwei: int - max_priority_fee_per_gas_gwei: int | None database: Path log_level: str @@ -92,7 +91,6 @@ def set( metrics_port: int = DEFAULT_METRICS_PORT, metrics_host: str = DEFAULT_METRICS_HOST, max_fee_per_gas_gwei: int = DEFAULT_MAX_FEE_PER_GAS_GWEI, - max_priority_fee_per_gas_gwei: int | None = None, deposit_data_file: str | None = None, keystores_dir: str | None = None, keystores_password_file: str | None = None, @@ -123,7 +121,6 @@ def set( self.metrics_host = metrics_host self.metrics_port = metrics_port self.max_fee_per_gas_gwei = max_fee_per_gas_gwei - self.max_priority_fee_per_gas_gwei = max_priority_fee_per_gas_gwei self.deposit_data_file = ( Path(deposit_data_file) if deposit_data_file else vault_dir / 'deposit_data.json'