test(consensus): fix flaky TestIsYourTurnConsensusV2CrossConfig - #2531
Open
gzliudan wants to merge 1 commit into
Open
test(consensus): fix flaky TestIsYourTurnConsensusV2CrossConfig #2531gzliudan wants to merge 1 commit into
gzliudan wants to merge 1 commit into
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
gzliudan
requested review from
AnilChinchawale,
anunay-xin,
benjamin202410,
liam-lai and
wanwiset25
August 21, 2026 23:32
wanwiset25
approved these changes
Aug 23, 2026
gzliudan
force-pushed
the
fix-TestIsYourTurnConsensusV2CrossConfig
branch
from
August 23, 2026 15:37
52d0214 to
21083e2
Compare
TestIsYourTurnConsensusV2CrossConfig was flaky in CI: the first YourTurn call could be rounded up to the switched-to config's mine period (round 10 -> 3s) because the check compares against Unix-second granularity, returning true and failing the assert.False. The second check also under-slept since UpdateParams only repoints the engine's CurrentConfig, so MinePeriod read from blockchain.Config() stayed at the pre-switch value (2s). Derive the effective mine period from Config(round 10), wait strictly inside it for the first check, and comfortably past it for the second.
gzliudan
force-pushed
the
fix-TestIsYourTurnConsensusV2CrossConfig
branch
from
August 24, 2026 10:44
21083e2 to
1d84a68
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed changes
TestIsYourTurnConsensusV2CrossConfigwas flaky in CI, intermittently failing on the firstassert.Falsewith "Should be false". The failure is a timing/rounding bug in the test, not a consensus-logic bug.https://github.com/XinFinOrg/XDPoSChain/actions/runs/32529339583/job/96918041990?pr=2520
Root cause
YourTurnderives the mine period viaConfig(currentRound). Once the test advances the round to 10, that resolves to the switched-to config (UnitTestV2Configs[10], MinePeriod = 3s) even beforeUpdateParamsruns. The check comparesnow.Unix() - parent.Timeagainst that period using Unix-second granularity, andparent.Timeis floor-rounded. On slower CI machinesInsertBlock(910)can straddle a second boundary, pushing the firstwaitedTimeup to 3 (>= MinePeriod), soYourTurnreturns true and theassert.Falsefails — matching the CI log[yourturn] Yes ... round=10. Separately,UpdateParamsonly repoints the engine'sCurrentConfig, so readingMinePeriodfromblockchain.Config()stays at the pre-switch value (2s), making the second sleep under-computed.Fix
Look up the switched-to mine period by round (
Config(10)-> 3s) and sanity-check it is larger than the previous one. SleepfirstMinePeriod - 1before the firstYourTurnsowaitedTimestays strictly below the new period (reports false), and sleepnewMinePeriodbefore the secondYourTurnsowaitedTimeis comfortably past it (reports true).Verification
The patched test passes consistently (ran multiple times), sibling tests
TestIsAuthorisedMNForConsensusV2andTestIsYourTurnConsensusV2pass, andgofmt,goimports,go vet,make tidy, andmake quick-testare all clean. The original CI failure was reproduced on unpatcheddev-upgradeby simulating the same second-boundary timing, confirming the fix addresses the real root cause.Compatibility
Test-only change; no consensus, RPC, or network-format impact.
Types of changes
What types of changes does your code introduce to XDC network?
Put an
✅in the boxes that applyImpacted Components
Which parts of the codebase does this PR touch?
Put an
✅in the boxes that applyChecklist
Put an
✅in the boxes once you have confirmed below actions (or provide reasons on not doing so) that