From f2c559fd1915a4ceacaf13478d5122141f504010 Mon Sep 17 00:00:00 2001 From: MatheusFranco99 <48058141+MatheusFranco99@users.noreply.github.com> Date: Thu, 30 Jan 2025 14:43:23 +0000 Subject: [PATCH 1/2] refactor proposer function --- qbft/round_robin_proposer.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/qbft/round_robin_proposer.go b/qbft/round_robin_proposer.go index 922d03445..6caa9a687 100644 --- a/qbft/round_robin_proposer.go +++ b/qbft/round_robin_proposer.go @@ -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] } From f5f6889dfb64234cd3df020da3df25ebd14c778b Mon Sep 17 00:00:00 2001 From: MatheusFranco99 <48058141+MatheusFranco99@users.noreply.github.com> Date: Thu, 30 Jan 2025 14:43:28 +0000 Subject: [PATCH 2/2] align tests --- qbft/spectest/tests/round_robin_spectest.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/qbft/spectest/tests/round_robin_spectest.go b/qbft/spectest/tests/round_robin_spectest.go index 94e9b0d35..7ecf7b0c9 100644 --- a/qbft/spectest/tests/round_robin_spectest.go +++ b/qbft/spectest/tests/round_robin_spectest.go @@ -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 { @@ -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)) } }