Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the default value of EXPECTED_BLOCKS_PER_SEC #693

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading