Skip to content

Keep block period on the current epoch during resync - #5

Open
Frozen wants to merge 2 commits into
devfrom
fix/block-period-current-epoch
Open

Keep block period on the current epoch during resync#5
Frozen wants to merge 2 commits into
devfrom
fix/block-period-current-epoch

Conversation

@Frozen

@Frozen Frozen commented Aug 12, 2026

Copy link
Copy Markdown
Owner

Summary

  • compute BlockPeriod from the current epoch during startup and mid-epoch resync
  • switch to the next epoch cadence only for consensus following the last block of the current epoch
  • schedule NextBlockDue and a newly rotated leader with that next-consensus cadence
  • cover both 5s-to-2s and 2s-to-1s activation boundaries

Root cause

updateConsensusInformation always checked nextEpoch when selecting BlockPeriod. A validator that restarted or resynced during the epoch immediately before a timing fork therefore adopted the faster cadence one epoch early.

The first implementation corrected resync but exposed an ordering issue at epoch boundaries: NextBlockDue and the rotated-leader delay could capture the old period before consensus information was updated. The final change derives the period from the epoch of the consensus being scheduled.

Behavior

  • startup/resync within an epoch uses currentEpoch
  • consensus after a non-final block keeps the current cadence
  • consensus after the last block uses nextEpoch
  • the first block at 5s-to-2s and 2s-to-1s activation is scheduled with the new cadence

[Test]

  • go test -mod=readonly ./consensus/... -count=1
  • go test -mod=readonly -race ./consensus -run '^(TestBlockPeriodForConsensusUpdate|TestSetNextBlockDueUsesPeriodForNextConsensusEpoch)$' -count=1
  • go vet -mod=readonly ./consensus/...
  • make test
  • git diff --check
  • independent consensus-sensitive review: passed; no security, logic, race, aliasing, or consensus-regression findings

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your trial has ended. Reactivate Greptile to resume code reviews.

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your trial has ended. Reactivate Greptile to resume code reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant