Skip to content
This repository has been archived by the owner on Jul 1, 2021. It is now read-only.

Commit

Permalink
Pivot when beam sync lag is more than 30 blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
gsalgado committed Dec 1, 2020
1 parent d501485 commit e351542
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
5 changes: 3 additions & 2 deletions trinity/sync/beam/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
BEAM_PIVOT_BUFFER_FRACTION,
BLOCK_BACKFILL_IDLE_TIME,
BLOCK_IMPORT_MISSING_STATE_TIMEOUT,
ESTIMATED_BEAMABLE_SECONDS,
FULL_BLOCKS_NEEDED_TO_START_BEAM,
MAX_BEAM_SYNC_LAG,
PAUSE_BACKFILL_AT_LAG,
RESUME_BACKFILL_AT_LAG,
PREDICTED_BLOCK_TIME,
Expand Down Expand Up @@ -655,7 +655,8 @@ async def run(self) -> None:

def _is_header_eligible_to_beam_sync(self, header: BlockHeaderAPI) -> bool:
time_gap = time.time() - header.timestamp
return time_gap < (ESTIMATED_BEAMABLE_SECONDS * (1 - BEAM_PIVOT_BUFFER_FRACTION))
estimated_max_lag_seconds = MAX_BEAM_SYNC_LAG * PREDICTED_BLOCK_TIME
return time_gap < (estimated_max_lag_seconds * (1 - BEAM_PIVOT_BUFFER_FRACTION))

async def _persist_headers_if_tip_too_old(self) -> None:
tip = await self._db.coro_get_canonical_head()
Expand Down
5 changes: 5 additions & 0 deletions trinity/sync/beam/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@
# It's also useful to estimate the amount of time covered by those beamable blocks.
ESTIMATED_BEAMABLE_SECONDS = ESTIMATED_BEAMABLE_BLOCKS * PREDICTED_BLOCK_TIME

# Maximum number of blocks we can lag behind the current chain head before we pivot.
# This is a relatively low value because on mainnet, as soon as we are lagging behind 20-30
# blocks, we're very unlikely to catch up given our block import times are high.
MAX_BEAM_SYNC_LAG = 30

# To make up for clients that are configured with unusually low block times,
# and other surprises, we pivot earlier than we think we need to.
# For example, if the BEAM_PIVOT_BUFFER_FRACTION is ~1/4, then pivot about 25%
Expand Down
8 changes: 4 additions & 4 deletions trinity/sync/beam/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from trinity.db.eth1.chain import BaseAsyncChainDB
from trinity.protocol.eth.peer import ETHPeerPool
from trinity.sync.beam.constants import (
ESTIMATED_BEAMABLE_BLOCKS,
MAX_BEAM_SYNC_LAG,
PREDICTED_BLOCK_TIME,
)
from trinity.sync.common.checkpoint import Checkpoint
Expand Down Expand Up @@ -99,15 +99,15 @@ async def _monitor_for_pivot(self, beam_syncer: BeamSyncer) -> bool:
return False
else:
lag = beam_syncer.get_block_count_lag()
if lag > ESTIMATED_BEAMABLE_BLOCKS:
if lag > MAX_BEAM_SYNC_LAG:
self.logger.warning(
"Beam Sync is lagging by %d blocks. Pivoting...",
lag,
)
beam_syncer.get_manager().cancel()
return True
else:
if lag >= ESTIMATED_BEAMABLE_BLOCKS * 0.8:
if lag >= MAX_BEAM_SYNC_LAG * 0.8:
# Start showing the lag in info, if lagging behind a lot
logger = self.logger.info
else:
Expand All @@ -118,7 +118,7 @@ async def _monitor_for_pivot(self, beam_syncer: BeamSyncer) -> bool:
" will pivot above %d"
),
lag,
ESTIMATED_BEAMABLE_BLOCKS,
MAX_BEAM_SYNC_LAG,
)

# Keep monitoring
Expand Down

0 comments on commit e351542

Please sign in to comment.