-
Notifications
You must be signed in to change notification settings - Fork 28
refactor: use beacon chain deadlines for QBFT instance cleanup #719
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
base: unstable
Are you sure you want to change the base?
Changes from 1 commit
82eaa98
4767f9d
b2fc159
895c5c0
d181178
c1f7ff6
739902c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -902,6 +902,55 @@ mod manager_tests { | |
|
|
||
| context.verify_consensus().await; | ||
| } | ||
|
|
||
| #[tokio::test(start_paused = true)] | ||
| // Test that Committee instances can reach late rounds (9+) with max_round=12 configuration. | ||
| // This verifies that instances survive long enough to progress through many round changes | ||
| // as configured. Committee role has max_round=12, so instances should be able to reach | ||
| // round 10 before timing out at round 13. | ||
| // | ||
| // The test simulates network conditions where consensus cannot be reached early by keeping | ||
| // all but one operator offline, forcing round changes. We advance the slot to trigger | ||
| // cleanup and verify the instance survives to reach round 10. | ||
| async fn test_committee_can_reach_late_rounds() { | ||
| let setup = setup_test(1); | ||
| let clock = setup.clock.clone(); | ||
| let mut context = TestContext::<BeaconVote>::new( | ||
| setup.clock, | ||
| setup.executor, | ||
| CommitteeSize::Four, | ||
| setup.all_data, | ||
| ) | ||
| .await; | ||
|
|
||
| // Keep 3 operators offline initially to prevent consensus and force round changes. | ||
| // With only 1 operator online out of 4, we cannot reach quorum (need 3). | ||
| // This will cause the instance to go through multiple round changes. | ||
| context.set_operators_offline(&[2, 3, 4]); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test Design: Consider testing the actual cleanup boundary The test keeps 3 out of 4 operators offline to force round changes, which is good. However, it doesn't verify the specific failure mode mentioned in the PR description. Consider adding:
Example enhancement: // Keep 3 operators offline to force round changes
context.set_operators_offline(&[2, 3, 4]);
// Advance to slot 2 where cleanup happens (cutoff = slot 2 - 1 = slot 1)
// At this point, the instance starting at slot 0 should be removed
clock.set_slot(1);
tokio::time::sleep(slot_duration).await;
clock.set_slot(2);
tokio::time::sleep(slot_duration).await;
// TODO: Add assertion here to verify instance is still alive
// This is where the bug manifests - instance gets cleaned up too earlyThis would make the test more explicitly demonstrate the issue described in the PR. |
||
|
|
||
| // Advance time and slots to simulate reaching round 10 | ||
| // Instance starts at slot 0 | ||
| let slot_duration = Duration::from_secs(12); | ||
|
|
||
| // Advance through multiple slots while QBFT progresses | ||
| // This triggers cleanup logic which should NOT remove the active instance | ||
| for slot in 1..=50 { | ||
|
||
| clock.set_slot(slot); | ||
| tokio::time::sleep(slot_duration).await; | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mathematical Accuracy: Comment contains calculation error The comment states "Rounds 1-8: 16s" but this is incorrect:
Correct breakdown to round 10:
At 12s per slot:
Suggest updating comment to: // At slot 22 (264 seconds = 22 * 12s):
// - Rounds 1-8: 8 * 2s = 16s
// - Round 9: 120s
// - Total to complete round 9: 136s (11.33 slots)
// - Round 10 starts at 136s (slot 11), so at slot 22 (264s) we're 128s into round 10
if slot == 22 {This makes the test's timing expectations explicit and verifiable. |
||
| // At slot 22 (256 seconds = 16s + 240s), we should be around round 10 | ||
| // Rounds 1-8: 16s, Rounds 9-10: 240s = 256s total | ||
|
||
| if slot == 22 { | ||
| // Bring operators back online during round 10 to allow consensus | ||
| context.set_operators_online(&[2, 3, 4]); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| // Verify that consensus is reached successfully, proving the instance | ||
| // survived cleanup and was able to reach round 10 | ||
| context.verify_consensus().await; | ||
| } | ||
| } | ||
|
|
||
| // very important: set paused to true for deterministic timer | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documentation: Test expectations need clarification
The comment says "Currently fails" but doesn't specify:
#[should_panic]or#[ignore]?Recommendations:
#[ignore]or#[should_panic]:This prevents CI from failing and clearly communicates test intent to future developers.