Skip to content

Commit

Permalink
Fix check gas price message
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeny-stakewise committed Oct 25, 2023
1 parent 09b809b commit 054531b
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 20 deletions.
16 changes: 1 addition & 15 deletions src/common/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 15 additions & 0 deletions src/harvest/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
8 changes: 5 additions & 3 deletions src/harvest/tasks.py
Original file line number Diff line number Diff line change
@@ -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__)

Expand All @@ -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()
Expand Down
15 changes: 15 additions & 0 deletions src/validators/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
5 changes: 3 additions & 2 deletions src/validators/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
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
from src.config.networks import GNOSIS
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,
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 054531b

Please sign in to comment.