Skip to content
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

Stateless proposer function #518

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions qbft/round_robin_proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import "github.com/ssvlabs/ssv-spec/types"
// Each new height starts with the first proposer and increments by 1 with each following round.
// Each new height has a different first round proposer which is +1 from the previous height.
// First height starts with index 0
func RoundRobinProposer(state *State, round Round) types.OperatorID {
// Assumption: the operators list is sorted.
func RoundRobinProposer(height Height, round Round, operators []types.OperatorID) types.OperatorID {
firstRoundIndex := 0
if state.Height != FirstHeight {
firstRoundIndex += int(state.Height) % len(state.CommitteeMember.Committee)
if height != FirstHeight {
firstRoundIndex += int(height) % len(operators)
}

index := (firstRoundIndex + int(round) - int(FirstRound)) % len(state.CommitteeMember.Committee)
return state.CommitteeMember.Committee[index].OperatorID
index := (firstRoundIndex + int(round) - int(FirstRound)) % len(operators)
return operators[index]
}
13 changes: 7 additions & 6 deletions qbft/spectest/tests/round_robin_spectest.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package tests

import (
"testing"

"github.com/ssvlabs/ssv-spec/qbft"
"github.com/ssvlabs/ssv-spec/types"
"github.com/stretchr/testify/require"
"testing"
)

type RoundRobinSpecTest struct {
Expand All @@ -19,13 +20,13 @@ func (test *RoundRobinSpecTest) Run(t *testing.T) {
require.True(t, len(test.Heights) > 0)
for i, h := range test.Heights {
r := test.Rounds[i]
s := &qbft.State{
Height: h,
Round: r,
CommitteeMember: test.Share,

operators := make([]types.OperatorID, 0)
for _, operator := range test.Share.Committee {
operators = append(operators, operator.OperatorID)
}

require.EqualValues(t, test.Proposers[i], qbft.RoundRobinProposer(s, r))
require.EqualValues(t, test.Proposers[i], qbft.RoundRobinProposer(h, r, operators))
}
}

Expand Down