Skip to content

Commit

Permalink
Use updated chain head functions (#405)
Browse files Browse the repository at this point in the history
Signed-off-by: cyc60 <[email protected]>
  • Loading branch information
cyc60 authored Sep 4, 2024
1 parent 55b8024 commit b34a95b
Show file tree
Hide file tree
Showing 8 changed files with 626 additions and 570 deletions.
1,171 changes: 613 additions & 558 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ sentry-sdk = "==1.32.0"
py-ecc = "==6.0.0"
gql = {extras = ["aiohttp"], version = "==3.5.0"}
multiproof = { git = "https://github.com/stakewise/multiproof.git", rev = "v0.1.8" }
sw-utils = {git = "https://github.com/stakewise/sw-utils.git", rev = "v0.6.18"}
sw-utils = {git = "https://github.com/stakewise/sw-utils.git", rev = "v0.6.22"}
staking-deposit = { git = "https://github.com/ethereum/staking-deposit-cli.git", rev = "v2.4.0" }
pycryptodomex = "3.19.1"
click = "==8.1.7"
Expand Down
2 changes: 1 addition & 1 deletion src/commands/start_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async def start_base() -> None:
logger.info('Syncing network validator events...')
chain_state = await get_chain_finalized_head()
await wait_execution_catch_up_consensus(chain_state)
await network_validators_scanner.process_new_events(chain_state.execution_block)
await network_validators_scanner.process_new_events(chain_state.block_number)

logger.info('Updating oracles cache...')
await update_oracles_cache()
Expand Down
4 changes: 2 additions & 2 deletions src/common/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ async def wait_execution_catch_up_consensus(
return

execution_block_number = await execution_client.eth.get_block_number()
if execution_block_number >= chain_state.execution_block:
if execution_block_number >= chain_state.block_number:
return

logger.warning(
'The execution client is behind the consensus client: '
'execution block %d, consensus finalized block %d',
execution_block_number,
chain_state.execution_block,
chain_state.block_number,
)
sleep_time = float(settings.network_config.SECONDS_PER_BLOCK)

Expand Down
5 changes: 4 additions & 1 deletion src/common/consensus.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from sw_utils import get_chain_finalized_head as sw_get_chain_finalized_head
from sw_utils.typings import ChainHead

from src.common.clients import consensus_client
from src.config.settings import settings


async def get_chain_finalized_head() -> ChainHead:
return await consensus_client.get_chain_finalized_head(settings.network_config.SLOTS_PER_EPOCH)
return await sw_get_chain_finalized_head(
consensus_client=consensus_client, slots_per_epoch=settings.network_config.SLOTS_PER_EPOCH
)
2 changes: 1 addition & 1 deletion src/common/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@ async def process_block(self, interrupt_handler: InterruptHandler) -> None:

chain_state = await get_chain_finalized_head()
metrics.block_number.set(await execution_client.eth.get_block_number())
metrics.slot_number.set(chain_state.consensus_block)
metrics.slot_number.set(chain_state.slot)
8 changes: 3 additions & 5 deletions src/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from web3.exceptions import Web3Exception
from web3.types import Timestamp

from src.common.clients import consensus_client
from src.common.consensus import get_chain_finalized_head
from src.common.exceptions import (
InvalidOraclesRequestError,
NotEnoughOracleApprovalsError,
Expand Down Expand Up @@ -62,10 +62,8 @@ def format_error(e: Exception) -> str:


async def is_block_finalized(block_number: BlockNumber) -> bool:
chain_head = await consensus_client.get_chain_finalized_head(
settings.network_config.SLOTS_PER_EPOCH
)
return chain_head.execution_block >= block_number
chain_head = await get_chain_finalized_head()
return chain_head.block_number >= block_number


def get_current_timestamp() -> Timestamp:
Expand Down
2 changes: 1 addition & 1 deletion src/validators/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ async def process_block(self, interrupt_handler: InterruptHandler) -> None:
)

# process new network validators
await self.network_validators_scanner.process_new_events(chain_state.execution_block)
await self.network_validators_scanner.process_new_events(chain_state.block_number)

if self.keystore and self.deposit_data:
await update_unused_validator_keys_metric(
Expand Down

0 comments on commit b34a95b

Please sign in to comment.