Skip to content

Commit

Permalink
Merge pull request #412 from BoostryJP/feature/#411
Browse files Browse the repository at this point in the history
feat: Variable block synchronization delay threshold
  • Loading branch information
YoshihitoAso authored Nov 2, 2022
2 parents c7aad01 + c479221 commit 24dd31b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
5 changes: 2 additions & 3 deletions batch/processor_monitor_block_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
WEB3_HTTP_PROVIDER_STANDBY,
BLOCK_SYNC_STATUS_SLEEP_INTERVAL,
BLOCK_SYNC_STATUS_CALC_PERIOD,
BLOCK_SYNC_REMAINING_THRESHOLD,
BLOCK_GENERATION_SPEED_THRESHOLD
)
from app.model.db import Node
Expand Down Expand Up @@ -161,9 +162,7 @@ def __process(self, db_session: Session, endpoint_uri: str):
syncing = web3.eth.syncing
if syncing:
remaining_blocks = syncing["highestBlock"] - syncing["currentBlock"]
# NOTE: If it is delayed by one block,
# it will be treated normally assuming that it will be updated immediately afterwards.
if remaining_blocks > 1:
if remaining_blocks > BLOCK_SYNC_REMAINING_THRESHOLD:
is_synced = False
errors.append(f"highestBlock={syncing['highestBlock']}, currentBlock={syncing['currentBlock']}")

Expand Down
3 changes: 3 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@
# number of monitoring data period
BLOCK_SYNC_STATUS_CALC_PERIOD = int(os.environ.get("BLOCK_SYNC_STATUS_CALC_PERIOD")) \
if os.environ.get("BLOCK_SYNC_STATUS_CALC_PERIOD") else 3
# Threshold for remaining block synchronization
# - Threshold for difference between highestBlock and currentBlock
BLOCK_SYNC_REMAINING_THRESHOLD = int(os.environ.get("BLOCK_SYNC_REMAINING_THRESHOLD", 1))
# Threshold of block generation speed for judging synchronous stop(%)
if APP_ENV == "local":
BLOCK_GENERATION_SPEED_THRESHOLD = int(os.environ.get("BLOCK_GENERATION_SPEED_THRESHOLD")) \
Expand Down
2 changes: 1 addition & 1 deletion tests/test_batch_processor_monitor_block_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def test_normal_1(self, processor, db):

time.sleep(BLOCK_SYNC_STATUS_SLEEP_INTERVAL)

# Run 2st: block generation speed down(same the previous)
# Run 2nd: block generation speed down(same the previous)
with mock.patch("batch.processor_monitor_block_sync.BLOCK_GENERATION_SPEED_THRESHOLD", 100):
processor.process()

Expand Down

0 comments on commit 24dd31b

Please sign in to comment.