Skip to content

Round Robin Proposer with Epochs#591

Merged
GalRogozinski merged 3 commits intoboolefrom
round-robin-with-epochs
Jan 1, 2026
Merged

Round Robin Proposer with Epochs#591
GalRogozinski merged 3 commits intoboolefrom
round-robin-with-epochs

Conversation

@MatheusFranco99
Copy link
Contributor

Overview

This PR adds epochs into the Round Robin proposer computation in order to generate variance through epochs.

More precisely, the previous round robin function rotated only through slots and rounds.
Because there are 32 slots in an epoch and 32%4=0, for committees with 4 operators every epoch had the same profile of proposers.

@MatheusFranco99 MatheusFranco99 self-assigned this Dec 13, 2025
Copilot AI review requested due to automatic review settings December 13, 2025 03:03
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR modifies the Round Robin proposer selection algorithm to incorporate epoch-based variance. The change adds an epoch offset (calculated as height/32) to the proposer index calculation, which introduces variation across epochs and prevents the same proposer pattern from repeating every epoch when the number of operators evenly divides 32.

Key changes:

  • Modified the RoundRobinProposer function to add an epoch offset based on height/32
  • Updated test cases for committees with 4, 7, 10, and 13 operators to reflect the new algorithm
  • Regenerated test data JSON files to match expected proposer sequences under the new algorithm

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
qbft/round_robin_proposer.go Core algorithm change: adds epoch-based offset (height/32) to the proposer index calculation
qbft/round_robin_proposer_test.go Removes empty test file (contained only package declaration)
qbft/spectest/tests/proposer/four_operators.go Updates test to use new formula (h+h/32)%4 for 4-operator committee
qbft/spectest/tests/proposer/seven_operators.go Updates test to use new formula (h+h/32)%7 for 7-operator committee
qbft/spectest/tests/proposer/ten_operators.go Updates test to use new formula (h+h/32)%10 for 10-operator committee
qbft/spectest/tests/proposer/thirteen_operators.go Updates test to use new formula (h+h/32)%13 for 13-operator committee
qbft/spectest/generate/tests/tests.RoundRobinSpecTest_qbft_round_robin_4_member_committee.json Regenerated test data reflecting new proposer sequences for 4-member committee
qbft/spectest/generate/tests/tests.RoundRobinSpecTest_qbft_round_robin_7_member_committee.json Regenerated test data reflecting new proposer sequences for 7-member committee
qbft/spectest/generate/tests/tests.RoundRobinSpecTest_qbft_round_robin_10_member_committee.json Regenerated test data reflecting new proposer sequences for 10-member committee
qbft/spectest/generate/tests/tests.RoundRobinSpecTest_qbft_round_robin_13_member_committee.json Regenerated test data reflecting new proposer sequences for 13-member committee

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Dec 13, 2025

Greptile Overview

Greptile Summary

This PR adds epoch-based variance to the round-robin proposer selection algorithm by incorporating Ethereum epochs (calculated as height/32) into the proposer index calculation.

Key Changes

  • Modified RoundRobinProposer function to add ethEpoch term: index = (firstRoundIndex + round - 1 + ethEpoch) % committeeSize
  • Addresses the issue where committees with 4 operators had identical proposer profiles every epoch (since 32 slots per epoch and 32%4=0)
  • Updated all test cases (4, 7, 10, and 13 member committees) to reflect the new formula: (h+h/32)%n instead of h%n
  • Regenerated test data JSON files for all committee sizes

Implementation Notes

  • The logic correctly matches between implementation and tests
  • The change provides better rotation variance across epochs without breaking the round-robin guarantees
  • Function documentation should be updated to reflect the new epoch-aware behavior

Confidence Score: 4/5

  • Safe to merge with minor documentation improvement recommended
  • The implementation is mathematically correct and well-tested across multiple committee sizes. The epoch-based variance solves the stated problem elegantly. Only concern is outdated function documentation that should be updated to reflect the new behavior.
  • Pay attention to qbft/round_robin_proposer.go - function comment should be updated to reflect epoch-aware calculation

Important Files Changed

File Analysis

Filename Score Overview
qbft/round_robin_proposer.go 4/5 Added epoch-based variance to round-robin proposer calculation by including ethEpoch term in the index formula, but the function comment is now outdated
qbft/spectest/tests/proposer/four_operators.go 5/5 Updated test formula to match new epoch-aware proposer calculation: (h+h/32)%4 instead of h%4
qbft/spectest/tests/proposer/seven_operators.go 5/5 Updated test formula to match new epoch-aware proposer calculation: (h+h/32)%7 instead of h%7
qbft/spectest/tests/proposer/ten_operators.go 5/5 Updated test formula to match new epoch-aware proposer calculation: (h+h/32)%10 instead of h%10
qbft/spectest/tests/proposer/thirteen_operators.go 5/5 Updated test formula to match new epoch-aware proposer calculation: (h+h/32)%13 instead of h%13

Sequence Diagram

sequenceDiagram
    participant Caller
    participant RoundRobinProposer
    participant State
    participant Committee

    Caller->>RoundRobinProposer: RoundRobinProposer(state, round)
    RoundRobinProposer->>RoundRobinProposer: Initialize firstRoundIndex = 0
    
    alt Height != FirstHeight (0)
        RoundRobinProposer->>State: Get Height
        State-->>RoundRobinProposer: Height value
        RoundRobinProposer->>Committee: Get Committee length
        Committee-->>RoundRobinProposer: Committee size
        RoundRobinProposer->>RoundRobinProposer: firstRoundIndex = Height % Committee size
    end
    
    RoundRobinProposer->>State: Get Height
    State-->>RoundRobinProposer: Height value
    RoundRobinProposer->>RoundRobinProposer: ethEpoch = Height / 32
    
    Note over RoundRobinProposer: NEW: Epoch-based variance added
    
    RoundRobinProposer->>RoundRobinProposer: index = (firstRoundIndex + round - FirstRound + ethEpoch) % Committee size
    
    RoundRobinProposer->>Committee: Get operator at index
    Committee-->>RoundRobinProposer: OperatorID
    RoundRobinProposer-->>Caller: Return OperatorID
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Additional Comments (1)

  1. qbft/round_robin_proposer.go, line 5-8 (link)

    style: update comment to reflect epoch-based calculation - the proposer no longer simply increments by 1 from the previous height, it now includes epoch variance

10 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Copy link
Contributor

@GalRogozinski GalRogozinski left a comment

Choose a reason for hiding this comment

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

Great!

@GalRogozinski GalRogozinski changed the base branch from main to boole December 21, 2025 17:30
Copy link
Collaborator

@dknopik dknopik left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@GalRogozinski GalRogozinski left a comment

Choose a reason for hiding this comment

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

We just need to make a SIP

Copy link
Contributor

@y0sher y0sher left a comment

Choose a reason for hiding this comment

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

lgtm

@GalRogozinski GalRogozinski merged commit a908b7f into boole Jan 1, 2026
2 checks passed
@GalRogozinski GalRogozinski deleted the round-robin-with-epochs branch January 1, 2026 10:11
GalRogozinski pushed a commit that referenced this pull request Jan 29, 2026
* SPEC - add topic assignment (#595)

* Round Robin Proposer with Epochs (#591)

* include epoch in round robin proposer calculation

* align tests

* add explanation comment on epoch variability

* ensure sorting in round robin function
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.

5 participants