From 223390e34858b2f77254860d1150447a0e6022eb Mon Sep 17 00:00:00 2001 From: Evgeny Gusarov Date: Wed, 25 Oct 2023 20:29:21 +0300 Subject: [PATCH 1/3] Fix check gas price message --- src/common/execution.py | 16 +--------------- src/harvest/execution.py | 15 +++++++++++++++ src/harvest/tasks.py | 8 +++++--- src/validators/execution.py | 15 +++++++++++++++ src/validators/tasks.py | 5 +++-- 5 files changed, 39 insertions(+), 20 deletions(-) diff --git a/src/common/execution.py b/src/common/execution.py index 97aab3ca..1c80743e 100644 --- a/src/common/execution.py +++ b/src/common/execution.py @@ -95,21 +95,7 @@ async def get_oracles() -> Oracles: ) -async def check_gas_price() -> bool: - max_fee_per_gas = await _get_max_fee_per_gas() - if max_fee_per_gas >= Web3.to_wei(settings.max_fee_per_gas_gwei, 'gwei'): - logging.warning( - 'Current gas price (%s gwei) is too high. ' - 'Will try to harvest on the next block if the gas ' - 'price is acceptable.', - Web3.from_wei(max_fee_per_gas, 'gwei'), - ) - return False - - return True - - -async def _get_max_fee_per_gas() -> Wei: +async def get_max_fee_per_gas() -> Wei: try: priority_fee = await execution_client.eth.max_priority_fee except MethodUnavailable: diff --git a/src/harvest/execution.py b/src/harvest/execution.py index d9d6a854..c546c57b 100644 --- a/src/harvest/execution.py +++ b/src/harvest/execution.py @@ -5,6 +5,7 @@ from src.common.clients import execution_client from src.common.contracts import vault_contract +from src.common.execution import get_max_fee_per_gas from src.common.typings import HarvestParams from src.common.utils import format_error from src.config.networks import ETH_NETWORKS @@ -37,3 +38,17 @@ async def submit_harvest_transaction(harvest_params: HarvestParams) -> HexStr | logger.info('Waiting for transaction %s confirmation', tx_hash) await execution_client.eth.wait_for_transaction_receipt(tx, timeout=300) return tx_hash + + +async def check_gas_price_for_harvest() -> bool: + max_fee_per_gas = await get_max_fee_per_gas() + if max_fee_per_gas >= Web3.to_wei(settings.max_fee_per_gas_gwei, 'gwei'): + logging.warning( + 'Current gas price (%s gwei) is too high. ' + 'Will try to harvest on the next block if the gas ' + 'price is acceptable.', + Web3.from_wei(max_fee_per_gas, 'gwei'), + ) + return False + + return True diff --git a/src/harvest/tasks.py b/src/harvest/tasks.py index 032bface..3989685f 100644 --- a/src/harvest/tasks.py +++ b/src/harvest/tasks.py @@ -1,10 +1,12 @@ import logging from src.common.contracts import keeper_contract -from src.common.execution import check_gas_price from src.common.ipfs import fetch_harvest_params from src.config.settings import settings -from src.harvest.execution import submit_harvest_transaction +from src.harvest.execution import ( + check_gas_price_for_harvest, + submit_harvest_transaction, +) logger = logging.getLogger(__name__) @@ -16,7 +18,7 @@ async def harvest_vault() -> None: return # check current gas prices - if not await check_gas_price(): + if not await check_gas_price_for_harvest(): return last_rewards = await keeper_contract.get_last_rewards_update() diff --git a/src/validators/execution.py b/src/validators/execution.py index 311492e6..6d6d3665 100644 --- a/src/validators/execution.py +++ b/src/validators/execution.py @@ -15,6 +15,7 @@ validators_registry_contract, vault_contract, ) +from src.common.execution import get_max_fee_per_gas from src.common.ipfs import fetch_harvest_params from src.common.metrics import metrics from src.common.typings import OraclesApproval @@ -341,3 +342,17 @@ async def register_multiple_validator( logger.info('Waiting for transaction %s confirmation', tx_hash) await execution_client.eth.wait_for_transaction_receipt(tx, timeout=300) return tx_hash + + +async def check_gas_price_for_validator_registration() -> bool: + max_fee_per_gas = await get_max_fee_per_gas() + if max_fee_per_gas >= Web3.to_wei(settings.max_fee_per_gas_gwei, 'gwei'): + logging.warning( + 'Current gas price (%s gwei) is too high. ' + 'Will try to register validator on the next block if the gas ' + 'price is acceptable.', + Web3.from_wei(max_fee_per_gas, 'gwei'), + ) + return False + + return True diff --git a/src/validators/tasks.py b/src/validators/tasks.py index 4ab709d6..3b4a9343 100644 --- a/src/validators/tasks.py +++ b/src/validators/tasks.py @@ -9,7 +9,7 @@ from src.common.clients import ipfs_fetch_client from src.common.contracts import validators_registry_contract from src.common.exceptions import NotEnoughOracleApprovalsError -from src.common.execution import check_gas_price, get_oracles +from src.common.execution import get_oracles from src.common.metrics import metrics from src.common.typings import Oracles from src.common.utils import MGNO_RATE, WAD, get_current_timestamp @@ -17,6 +17,7 @@ from src.config.settings import DEPOSIT_AMOUNT, settings from src.validators.database import NetworkValidatorCrud from src.validators.execution import ( + check_gas_price_for_validator_registration, get_available_validators, get_latest_network_validator_public_keys, get_withdrawable_assets, @@ -67,7 +68,7 @@ async def register_validators( # not enough balance to register validators return - if not await check_gas_price(): + if not await check_gas_price_for_validator_registration(): return validators: list[Validator] = await get_available_validators( From 923d3a5befebe7687ecccfc195b873fa888d718d Mon Sep 17 00:00:00 2001 From: Evgeny Gusarov Date: Thu, 26 Oct 2023 11:32:30 +0300 Subject: [PATCH 2/3] Revert "Fix check gas price message" This reverts commit 054531b3c0aa07dfd9f4e92773dba92025d31ddc. --- src/common/execution.py | 16 +++++++++++++++- src/harvest/execution.py | 15 --------------- src/harvest/tasks.py | 8 +++----- src/validators/execution.py | 15 --------------- src/validators/tasks.py | 5 ++--- 5 files changed, 20 insertions(+), 39 deletions(-) diff --git a/src/common/execution.py b/src/common/execution.py index 1c80743e..97aab3ca 100644 --- a/src/common/execution.py +++ b/src/common/execution.py @@ -95,7 +95,21 @@ async def get_oracles() -> Oracles: ) -async def get_max_fee_per_gas() -> Wei: +async def check_gas_price() -> bool: + max_fee_per_gas = await _get_max_fee_per_gas() + if max_fee_per_gas >= Web3.to_wei(settings.max_fee_per_gas_gwei, 'gwei'): + logging.warning( + 'Current gas price (%s gwei) is too high. ' + 'Will try to harvest on the next block if the gas ' + 'price is acceptable.', + Web3.from_wei(max_fee_per_gas, 'gwei'), + ) + return False + + return True + + +async def _get_max_fee_per_gas() -> Wei: try: priority_fee = await execution_client.eth.max_priority_fee except MethodUnavailable: diff --git a/src/harvest/execution.py b/src/harvest/execution.py index c546c57b..d9d6a854 100644 --- a/src/harvest/execution.py +++ b/src/harvest/execution.py @@ -5,7 +5,6 @@ from src.common.clients import execution_client from src.common.contracts import vault_contract -from src.common.execution import get_max_fee_per_gas from src.common.typings import HarvestParams from src.common.utils import format_error from src.config.networks import ETH_NETWORKS @@ -38,17 +37,3 @@ async def submit_harvest_transaction(harvest_params: HarvestParams) -> HexStr | logger.info('Waiting for transaction %s confirmation', tx_hash) await execution_client.eth.wait_for_transaction_receipt(tx, timeout=300) return tx_hash - - -async def check_gas_price_for_harvest() -> bool: - max_fee_per_gas = await get_max_fee_per_gas() - if max_fee_per_gas >= Web3.to_wei(settings.max_fee_per_gas_gwei, 'gwei'): - logging.warning( - 'Current gas price (%s gwei) is too high. ' - 'Will try to harvest on the next block if the gas ' - 'price is acceptable.', - Web3.from_wei(max_fee_per_gas, 'gwei'), - ) - return False - - return True diff --git a/src/harvest/tasks.py b/src/harvest/tasks.py index 3989685f..032bface 100644 --- a/src/harvest/tasks.py +++ b/src/harvest/tasks.py @@ -1,12 +1,10 @@ import logging from src.common.contracts import keeper_contract +from src.common.execution import check_gas_price from src.common.ipfs import fetch_harvest_params from src.config.settings import settings -from src.harvest.execution import ( - check_gas_price_for_harvest, - submit_harvest_transaction, -) +from src.harvest.execution import submit_harvest_transaction logger = logging.getLogger(__name__) @@ -18,7 +16,7 @@ async def harvest_vault() -> None: return # check current gas prices - if not await check_gas_price_for_harvest(): + if not await check_gas_price(): return last_rewards = await keeper_contract.get_last_rewards_update() diff --git a/src/validators/execution.py b/src/validators/execution.py index 6d6d3665..311492e6 100644 --- a/src/validators/execution.py +++ b/src/validators/execution.py @@ -15,7 +15,6 @@ validators_registry_contract, vault_contract, ) -from src.common.execution import get_max_fee_per_gas from src.common.ipfs import fetch_harvest_params from src.common.metrics import metrics from src.common.typings import OraclesApproval @@ -342,17 +341,3 @@ async def register_multiple_validator( logger.info('Waiting for transaction %s confirmation', tx_hash) await execution_client.eth.wait_for_transaction_receipt(tx, timeout=300) return tx_hash - - -async def check_gas_price_for_validator_registration() -> bool: - max_fee_per_gas = await get_max_fee_per_gas() - if max_fee_per_gas >= Web3.to_wei(settings.max_fee_per_gas_gwei, 'gwei'): - logging.warning( - 'Current gas price (%s gwei) is too high. ' - 'Will try to register validator on the next block if the gas ' - 'price is acceptable.', - Web3.from_wei(max_fee_per_gas, 'gwei'), - ) - return False - - return True diff --git a/src/validators/tasks.py b/src/validators/tasks.py index 3b4a9343..4ab709d6 100644 --- a/src/validators/tasks.py +++ b/src/validators/tasks.py @@ -9,7 +9,7 @@ from src.common.clients import ipfs_fetch_client from src.common.contracts import validators_registry_contract from src.common.exceptions import NotEnoughOracleApprovalsError -from src.common.execution import get_oracles +from src.common.execution import check_gas_price, get_oracles from src.common.metrics import metrics from src.common.typings import Oracles from src.common.utils import MGNO_RATE, WAD, get_current_timestamp @@ -17,7 +17,6 @@ from src.config.settings import DEPOSIT_AMOUNT, settings from src.validators.database import NetworkValidatorCrud from src.validators.execution import ( - check_gas_price_for_validator_registration, get_available_validators, get_latest_network_validator_public_keys, get_withdrawable_assets, @@ -68,7 +67,7 @@ async def register_validators( # not enough balance to register validators return - if not await check_gas_price_for_validator_registration(): + if not await check_gas_price(): return validators: list[Validator] = await get_available_validators( From 176b728c3e0c928533f6352fec479a80496b650e Mon Sep 17 00:00:00 2001 From: Evgeny Gusarov Date: Thu, 26 Oct 2023 11:33:48 +0300 Subject: [PATCH 3/3] Fix check_gas_price just message --- src/common/execution.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/execution.py b/src/common/execution.py index 97aab3ca..169d2c17 100644 --- a/src/common/execution.py +++ b/src/common/execution.py @@ -100,7 +100,7 @@ async def check_gas_price() -> bool: if max_fee_per_gas >= Web3.to_wei(settings.max_fee_per_gas_gwei, 'gwei'): logging.warning( 'Current gas price (%s gwei) is too high. ' - 'Will try to harvest on the next block if the gas ' + 'Will try to submit transaction on the next block if the gas ' 'price is acceptable.', Web3.from_wei(max_fee_per_gas, 'gwei'), )