Skip to content

new short term election algorithm#3270

Merged
pompon0 merged 30 commits into
release/v6.4from
gprusak-election2
Apr 21, 2026
Merged

new short term election algorithm#3270
pompon0 merged 30 commits into
release/v6.4from
gprusak-election2

Conversation

@pompon0

@pompon0 pompon0 commented Apr 17, 2026

Copy link
Copy Markdown
Contributor

The new algorithm is choosing leader of (height,round), based on hash(height,round) and weights of validators (public lottery). The new algorithm is enabled via config flag: Consensus.StatelessLeaderElection (false by default). It will be the only option in 6.5. Additional changes:

  • updated crypto package to include zeroize fix (otherwise it panics under a new compiler)
  • made consensus tests run against both stateful and stateless leader election. The caveat is that many of the consensus tests are very poor quality and they hardcode the expected leader schedule. To minimize the amount of work, these tests have been adjusted in one of the following ways: a) the test harness looks for a starting round which produces the leader schedule that the test expects; b) the test harness adjusts the weights so that the leader schedule matches what the test expects.
  • I have manually run the tests outside of the consensus module with StatelessLeaderElection = true, however these are not included in CI.

@pompon0 pompon0 changed the base branch from main to release/v6.4 April 17, 2026 12:46
@github-actions

github-actions Bot commented Apr 17, 2026

Copy link
Copy Markdown

The latest Buf updates on your PR. Results from workflow Buf / buf (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedApr 21, 2026, 3:50 PM

@codecov

codecov Bot commented Apr 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.39%. Comparing base (8149711) to head (4a25d84).
⚠️ Report is 1 commits behind head on release/v6.4.

Files with missing lines Patch % Lines
sei-tendermint/internal/consensus/state.go 91.66% 0 Missing and 1 partial ⚠️
...tendermint/internal/consensus/types/round_state.go 96.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@               Coverage Diff                @@
##           release/v6.4    #3270      +/-   ##
================================================
+ Coverage         58.33%   58.39%   +0.05%     
================================================
  Files              2091     2091              
  Lines            172978   172990      +12     
================================================
+ Hits             100914   101012      +98     
+ Misses            63050    62981      -69     
+ Partials           9014     8997      -17     
Flag Coverage Δ
sei-chain-pr 76.04% <95.00%> (?)
sei-db 70.41% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
sei-tendermint/config/config.go 70.29% <100.00%> (+0.06%) ⬆️
sei-tendermint/crypto/merkle/proof.go 88.61% <ø> (ø)
sei-tendermint/types/validator_set.go 93.13% <100.00%> (+0.03%) ⬆️
sei-tendermint/internal/consensus/state.go 75.67% <91.66%> (+1.56%) ⬆️
...tendermint/internal/consensus/types/round_state.go 86.03% <96.00%> (+0.75%) ⬆️

... and 27 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pompon0 pompon0 requested review from sei-will and wen-coding April 20, 2026 11:41
@pompon0 pompon0 marked this pull request as ready for review April 20, 2026 11:44
Comment thread sei-tendermint/config/config.go
Comment thread sei-tendermint/internal/consensus/types/round_state.go
// pos(height,round) := hash(height ++ round)
// Validators are assigned subintervals of [0,TotalVotingPower) of length
// equal to their voting poser.
// Validator i is the leader of (height,round) <=> pos(height,round)%TotalVotingPower \in validator_interval[i]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Are we planning to do per-height calculation later?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yup, for the long term solution. And I would like first to compute what is the actual impact on block latency if we intriduce it.

Comment thread sei-tendermint/types/validator_set.go Outdated
totalVotingPower int64
}

func (vals *ValidatorSet) All() iter.Seq[*Validator] {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: add comment why the returned set is deterministic? We might need to warn future AI agent that do not mutate Validators without sorting them by ValidatorsByVotingPower?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Renamed to Ordered and documented the function. If the ordering changes, it should be caught by the change detector test that I've added.

Comment thread sei-tendermint/internal/consensus/common_test.go
// If this validator is the proposer of this round, and the previous block time is later than
// our local clock time, wait to propose until our local clock time has passed the block time.
if key, ok := cs.privValidatorPubKey.Get(); ok && cs.isProposer(key.Address()) {
if key, ok := cs.privValidatorPubKey.Get(); ok && cs.roundState.Leader() == key {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: Would bytes.Equal(leader.Address(), key.Address()) be more future proof?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

why would it? Address is derived from public key. Honestly I don't understand why the concept of Address exists - to save space maybe?

Comment thread sei-tendermint/internal/consensus/types/round_state_test.go
@pompon0 pompon0 enabled auto-merge (squash) April 21, 2026 15:08
@pompon0 pompon0 disabled auto-merge April 21, 2026 15:10
@pompon0 pompon0 force-pushed the gprusak-election2 branch from f72a7e3 to e6b9338 Compare April 21, 2026 15:11
@pompon0 pompon0 enabled auto-merge (squash) April 21, 2026 15:14
@pompon0 pompon0 merged commit 7cb40a8 into release/v6.4 Apr 21, 2026
38 checks passed
@pompon0 pompon0 deleted the gprusak-election2 branch April 21, 2026 15:44
@pompon0 pompon0 added the backport release/v6.5 Backport to release v6.5 label Apr 21, 2026
@pompon0

pompon0 commented Apr 21, 2026

Copy link
Copy Markdown
Contributor Author

/backport

@seidroid

seidroid Bot commented Apr 21, 2026

Copy link
Copy Markdown

Successfully created backport PR for release/v6.5:

pompon0 added a commit that referenced this pull request Apr 21, 2026
Backport of #3270 to `release/v6.5`.

Co-authored-by: Grzegorz Prusak <pompon.pompon@gmail.com>
h45hc47 pushed a commit to h45hc47/sei-chain that referenced this pull request May 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants