Skip to content

Commit

Permalink
Merge pull request #693 from BoostryJP/feature/#685
Browse files Browse the repository at this point in the history
Change the default value of EXPECTED_BLOCKS_PER_SEC
  • Loading branch information
YoshihitoAso authored Sep 26, 2024
2 parents 5b70639 + 95f9e5a commit bcfca50
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion batch/processor_monitor_block_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ async def __process(self, db_session: AsyncSession, endpoint_uri: str):
old_data = history.peek_oldest()
elapsed_time = data["time"] - old_data["time"]
generated_block_count = data["block_number"] - old_data["block_number"]
generated_block_count_threshold = (elapsed_time / EXPECTED_BLOCKS_PER_SEC) * (
generated_block_count_threshold = (elapsed_time * EXPECTED_BLOCKS_PER_SEC) * (
BLOCK_GENERATION_SPEED_THRESHOLD / 100
) # count of block generation theoretical value
if generated_block_count < generated_block_count_threshold:
Expand Down
2 changes: 1 addition & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
else 20
)
# Average block generation interval
EXPECTED_BLOCKS_PER_SEC = float(os.environ.get("EXPECTED_BLOCKS_PER_SEC", 1))
EXPECTED_BLOCKS_PER_SEC = float(os.environ.get("EXPECTED_BLOCKS_PER_SEC", 0.1))


####################################################
Expand Down
23 changes: 13 additions & 10 deletions tests/batch/test_processor_monitor_block_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ class TestProcessor:
###########################################################################

# <Normal_1>
# Execute Batch Run 1st: synced
# Execute Batch Run 2nd: block generation speed down(same the previous)
# Execute Batch Run 3rd: synced
# Execute Batch Run 4th: node syncing(DIFF:over 2)
# Execute Batch Run 5th: node syncing(DIFF:2) == synced
# Run 1st: Normal state
# Run 2nd: Abnormal state - Setting BLOCK_GENERATION_SPEED_THRESHOLD to 100% will trigger an error.
# Run 3rd: Return to normal state
# Run 4th: Abnormal state - An error occurs when the difference between highestBlock and currentBlock exceeds a threshold.
# Run 5th: Return to normal state - Since the difference between highestBlock and currentBlock is within the threshold, no error occurs.
@mock.patch(
"batch.processor_monitor_block_sync.WEB3_HTTP_PROVIDER",
WEB3_HTTP_PROVIDER,
Expand All @@ -57,7 +57,7 @@ class TestProcessor:
async def test_normal_1(self, processor, db):
await processor.initial_setup()

# Run 1st: synced
# Run 1st: Normal state
await processor.process()

db.rollback()
Expand All @@ -67,7 +67,8 @@ async def test_normal_1(self, processor, db):
assert _node.priority == 0
assert _node.is_synced == True

# Run 2nd: block generation speed down(same the previous)
# Run 2nd: Abnormal state
# - Setting BLOCK_GENERATION_SPEED_THRESHOLD to 100% will trigger an error.
with mock.patch(
"batch.processor_monitor_block_sync.BLOCK_GENERATION_SPEED_THRESHOLD", 100
):
Expand All @@ -77,14 +78,15 @@ async def test_normal_1(self, processor, db):
_node = db.scalars(select(Node).limit(1)).first()
assert _node.is_synced == False

# Run 3rd: synced
# Run 3rd: Return to normal state
await processor.process()

db.rollback()
_node = db.scalars(select(Node).limit(1)).first()
assert _node.is_synced == True

# Run 4th: node syncing(DIFF:over 2)
# Run 4th: Abnormal state
# - An error occurs when the difference between highestBlock and currentBlock exceeds a threshold.
block_number = web3.eth.block_number
is_syncing_mock = AsyncMock()
is_syncing_mock.return_value = {
Expand All @@ -98,7 +100,8 @@ async def test_normal_1(self, processor, db):
_node = db.scalars(select(Node).limit(1)).first()
assert _node.is_synced == False

# Run 5th: node syncing(DIFF:2) == synced
# Run 5th: Return to normal state
# - Since the difference between highestBlock and currentBlock is within the threshold, no error occurs.
block_number = web3.eth.block_number
is_syncing_mock = AsyncMock()
is_syncing_mock.return_value = {
Expand Down

0 comments on commit bcfca50

Please sign in to comment.