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

Round change according to duty start time #352

Open
wants to merge 30 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
1f37484
dynamic timeout
GalRogozinski Jan 17, 2024
3956935
rename timeout test
GalRogozinski Jan 18, 2024
410647d
add round timer
GalRogozinski Jan 18, 2024
b04a934
fix timeout.go
GalRogozinski Jan 19, 2024
853677e
revert timer.go
GalRogozinski Jan 19, 2024
8d44801
fix timeout.go
GalRogozinski Jan 20, 2024
f5dea9a
rename tests
GalRogozinski Jan 20, 2024
aaf32ab
timeout duration tests
GalRogozinski Jan 20, 2024
298998c
round_1_duration comments
GalRogozinski Jan 21, 2024
5f15c26
fix timeout.go
GalRogozinski Jan 21, 2024
0d5e0bf
more duration tests
GalRogozinski Jan 21, 2024
98268fc
more round tests
GalRogozinski Jan 21, 2024
d3db487
future current_time fix
GalRogozinski Jan 21, 2024
9200969
refactoring
GalRogozinski Jan 21, 2024
6cc8200
refactoring
GalRogozinski Jan 21, 2024
d6dac1a
fix alltests and run test
GalRogozinski Jan 21, 2024
c6cbeba
add multispectest
GalRogozinski Jan 21, 2024
7cba6ce
all tests
GalRogozinski Jan 21, 2024
75f8ea4
tests.json
GalRogozinski Jan 21, 2024
777c009
Merge branch 'main' into dynamic-roundchange
GalRogozinski Jan 21, 2024
06abcae
fix multispectest marshalling
GalRogozinski Jan 21, 2024
a5eb874
fix multispectest marshalling
GalRogozinski Jan 21, 2024
8456002
remove cast
GalRogozinski Jan 23, 2024
f00fbe5
add comment
GalRogozinski Jan 25, 2024
a24af7f
fix round 8 -> 6
GalRogozinski Mar 24, 2024
68ece9e
fix round 9 -> 7
GalRogozinski Mar 24, 2024
4e42906
quickTimeoutThreshold on 6 now
GalRogozinski Mar 24, 2024
450e3a8
round14 -> 13
GalRogozinski Mar 24, 2024
9a139cb
round14 -> 13
GalRogozinski Mar 24, 2024
54dc3a5
Update qbft/timeout.go
GalRogozinski Oct 30, 2024
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
6 changes: 5 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ require (
github.com/stretchr/testify v1.8.4
)

require (
github.com/google/go-cmp v0.5.9
golang.org/x/exp v0.0.0-20230321023759-10a507213a29
)

require (
github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.2 // indirect
github.com/holiman/uint256 v1.2.2 // indirect
github.com/ipfs/go-cid v0.4.1 // indirect
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU
golang.org/x/crypto v0.10.0 h1:LKqV2xt9+kDzSTfOhx4FrkEBcMrAgHSYgzywV9zcGmM=
golang.org/x/crypto v0.10.0/go.mod h1:o4eNf7Ede1fv+hwOwZsTHl9EsPFO6q6ZvYR8vYfY45I=
golang.org/x/exp v0.0.0-20230321023759-10a507213a29 h1:ooxPy7fPvB4kwsA2h+iBNHkAbp/4JxTSwCmvdjEYmug=
golang.org/x/exp v0.0.0-20230321023759-10a507213a29/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
Expand Down
12 changes: 12 additions & 0 deletions qbft/spectest/all_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/bloxapp/ssv-spec/qbft/spectest/tests/roundchange"
"github.com/bloxapp/ssv-spec/qbft/spectest/tests/startinstance"
"github.com/bloxapp/ssv-spec/qbft/spectest/tests/timeout"
"github.com/bloxapp/ssv-spec/qbft/spectest/tests/timeout/timeoutduration"
)

var AllTests = []tests.TestF{
Expand All @@ -23,6 +24,17 @@ var AllTests = []tests.TestF{
timeout.Round5,
timeout.Round15,

timeoutduration.Round1Duration,
timeoutduration.Round3Duration,
timeoutduration.Round6Duration,
timeoutduration.Round7Duration,
timeoutduration.Round13Duration,
timeoutduration.Round1DurationFutureCurrentTime,
timeoutduration.Round3DurationOnDutyStartTime,
timeoutduration.Round5DurationOnRound3Time,
timeoutduration.Round7DurationOnDutyStartTime,
timeoutduration.Round13DurationOnRound12Time,

decided.Valid,
decided.HasQuorum,
decided.LateDecided,
Expand Down
2 changes: 1 addition & 1 deletion qbft/spectest/generate/tests.json

Large diffs are not rendered by default.

20 changes: 18 additions & 2 deletions qbft/spectest/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package spectest
import (
"encoding/json"
"github.com/bloxapp/ssv-spec/qbft/spectest/tests/timeout"
"github.com/bloxapp/ssv-spec/qbft/spectest/tests/timeout/timeoutduration"
"os"
"path/filepath"
"reflect"
Expand Down Expand Up @@ -96,10 +97,25 @@ func TestJson(t *testing.T) {

tests[testName] = typedTest
typedTest.Run(t)
case reflect.TypeOf(&timeout.SpecTest{}).String():
case reflect.TypeOf(&timeoutduration.MultiSpecTest{}).String():
byts, err := json.Marshal(test)
require.NoError(t, err)
typedTest := &timeout.SpecTest{}
typedTest := timeoutduration.MultiSpecTest{}
require.NoError(t, json.Unmarshal(byts, &typedTest))

typedTest.Run(t)
case reflect.TypeOf(timeoutduration.TimeoutDurationTest{}).String():
byts, err := json.Marshal(test)
require.NoError(t, err)
typedTest := &timeoutduration.TimeoutDurationTest{}
require.NoError(t, json.Unmarshal(byts, &typedTest))

tests[testName] = typedTest
typedTest.Run(t)
case reflect.TypeOf(&timeout.UponTimeoutTest{}).String():
byts, err := json.Marshal(test)
require.NoError(t, err)
typedTest := &timeout.UponTimeoutTest{}
require.NoError(t, json.Unmarshal(byts, &typedTest))

// a little trick we do to instantiate all the internal instance params
Expand Down
2 changes: 1 addition & 1 deletion qbft/spectest/tests/timeout/round_1.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func Round1() tests.SpecTest {
pre := testingutils.BaseInstance()
pre.State.ProposalAcceptedForCurrentRound = testingutils.TestingProposalMessage(ks.Shares[1], types.OperatorID(1))

return &SpecTest{
return &UponTimeoutTest{
Name: "round 1",
Pre: pre,
PostRoot: sc.Root(),
Expand Down
2 changes: 1 addition & 1 deletion qbft/spectest/tests/timeout/round_15.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func Round15() tests.SpecTest {
pre.State.ProposalAcceptedForCurrentRound = testingutils.TestingProposalMessageWithRound(ks.Shares[1],
types.OperatorID(1), 15)

return &SpecTest{
return &UponTimeoutTest{
Name: "round 15",
Pre: pre,
PostRoot: sc.Root(),
Expand Down
2 changes: 1 addition & 1 deletion qbft/spectest/tests/timeout/round_2.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func Round2() tests.SpecTest {
pre.State.Round = 2
pre.State.ProposalAcceptedForCurrentRound = testingutils.TestingProposalMessageWithRound(ks.Shares[1], types.OperatorID(1), 2)

return &SpecTest{
return &UponTimeoutTest{
Name: "round 2",
Pre: pre,
PostRoot: sc.Root(),
Expand Down
2 changes: 1 addition & 1 deletion qbft/spectest/tests/timeout/round_3.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func Round3() tests.SpecTest {
pre.State.Round = 3
pre.State.ProposalAcceptedForCurrentRound = testingutils.TestingProposalMessageWithRound(ks.Shares[1], types.OperatorID(1), 3)

return &SpecTest{
return &UponTimeoutTest{
Name: "round 3",
Pre: pre,
PostRoot: sc.Root(),
Expand Down
2 changes: 1 addition & 1 deletion qbft/spectest/tests/timeout/round_5.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func Round5() tests.SpecTest {
pre.State.Round = 5
pre.State.ProposalAcceptedForCurrentRound = testingutils.TestingProposalMessageWithRound(ks.Shares[1], types.OperatorID(1), 5)

return &SpecTest{
return &UponTimeoutTest{
Name: "round 5",
Pre: pre,
PostRoot: sc.Root(),
Expand Down
10 changes: 5 additions & 5 deletions qbft/spectest/tests/timeout/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
typescomparable "github.com/bloxapp/ssv-spec/types/testingutils/comparable"
)

type SpecTest struct {
type UponTimeoutTest struct {
Name string
Pre *qbft.Instance
PostRoot string
Expand All @@ -23,11 +23,11 @@ type SpecTest struct {
ExpectedError string
}

func (test *SpecTest) TestName() string {
return "qbft timeout " + test.Name
func (test *UponTimeoutTest) TestName() string {
return "qbft upon timeout " + test.Name
}

func (test *SpecTest) Run(t *testing.T) {
func (test *UponTimeoutTest) Run(t *testing.T) {
err := test.Pre.UponRoundTimeout()

if len(test.ExpectedError) != 0 {
Expand Down Expand Up @@ -66,6 +66,6 @@ func (test *SpecTest) Run(t *testing.T) {
}
}

func (test *SpecTest) GetPostState() (interface{}, error) {
func (test *UponTimeoutTest) GetPostState() (interface{}, error) {
return nil, nil
}
26 changes: 26 additions & 0 deletions qbft/spectest/tests/timeout/timeoutduration/multi_spectest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package timeoutduration

import (
"testing"
)

type MultiSpecTest struct {
Name string
Tests []*TimeoutDurationTest
}

func (test *MultiSpecTest) GetPostState() (interface{}, error) {
return nil, nil
}

func (test *MultiSpecTest) TestName() string {
return test.Name
}

func (test *MultiSpecTest) Run(t *testing.T) {
for _, test := range test.Tests {
t.Run(test.TestName(), func(t *testing.T) {
test.Run(t)
})
}
}
68 changes: 68 additions & 0 deletions qbft/spectest/tests/timeout/timeoutduration/round_13_duration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package timeoutduration

import (
"github.com/attestantio/go-eth2-client/spec/phase0"
"github.com/bloxapp/ssv-spec/qbft"
"github.com/bloxapp/ssv-spec/qbft/spectest/tests"
"github.com/bloxapp/ssv-spec/types"
)

// Round13Duration tests timeout duration for round 13 where the current time is the expected start of the round
func Round13Duration() tests.SpecTest {
testingNetwork := types.HoleskyNetwork
height := qbft.Height(40)
var round qbft.Round = 13
dutyStartTime := testingNetwork.EstimatedTimeAtSlot(phase0.Slot(height))

return &MultiSpecTest{
Name: "round 13 duration",
Tests: []*TimeoutDurationTest{
{
Name: "sync committee",
Role: types.BNRoleSyncCommittee,
Height: height,
Round: round,
Network: testingNetwork,
CurrentTime: dutyStartTime + 16 + 6*120,
ExpectedDuration: 120,
},
{
Name: "sync committee contribution",
Role: types.BNRoleSyncCommitteeContribution,
Height: height,
Round: round,
Network: testingNetwork,
CurrentTime: dutyStartTime + 20 + 6*120,
ExpectedDuration: 120,
},
{
Name: "attester",
Role: types.BNRoleAttester,
Height: height,
Round: round,
Network: testingNetwork,
CurrentTime: dutyStartTime + 16 + 6*120,
ExpectedDuration: 120,
},
{
Name: "aggregator",
Role: types.BNRoleAggregator,
Height: height,
Round: round,
Network: testingNetwork,
CurrentTime: dutyStartTime + 20 + 6*120,
ExpectedDuration: 120,
},
{
Name: "block proposer",
Role: types.BNRoleProposer,
Height: height,
Round: round,
Network: testingNetwork,
CurrentTime: dutyStartTime + 12 + 6*120,
ExpectedDuration: 120,
},
},
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package timeoutduration

import (
"github.com/attestantio/go-eth2-client/spec/phase0"
"github.com/bloxapp/ssv-spec/qbft"
"github.com/bloxapp/ssv-spec/qbft/spectest/tests"
"github.com/bloxapp/ssv-spec/types"
)

// Round13DurationOnRound12Time tests timeout duration for round 13 where the current time is the expected start of
// round 12
func Round13DurationOnRound12Time() tests.SpecTest {
testingNetwork := types.HoleskyNetwork
height := qbft.Height(40)
var round qbft.Round = 13
dutyStartTime := testingNetwork.EstimatedTimeAtSlot(phase0.Slot(height))

return &MultiSpecTest{
Name: "round 13 duration on round 12 time",
Tests: []*TimeoutDurationTest{
{
Name: "sync committee",
Role: types.BNRoleSyncCommittee,
Height: height,
Round: round,
Network: testingNetwork,
CurrentTime: dutyStartTime + 16 + 5*120,
ExpectedDuration: 240,
},
{
Name: "sync committee contribution",
Role: types.BNRoleSyncCommitteeContribution,
Height: height,
Round: round,
Network: testingNetwork,
CurrentTime: dutyStartTime + 20 + 5*120,
ExpectedDuration: 240,
},
{
Name: "attester",
Role: types.BNRoleAttester,
Height: height,
Round: round,
Network: testingNetwork,
CurrentTime: dutyStartTime + 16 + 5*120,
ExpectedDuration: 240,
},
{
Name: "aggregator",
Role: types.BNRoleAggregator,
Height: height,
Round: round,
Network: testingNetwork,
CurrentTime: dutyStartTime + 20 + 5*120,
ExpectedDuration: 240,
},
{
Name: "block proposer",
Role: types.BNRoleProposer,
Height: height,
Round: round,
Network: testingNetwork,
CurrentTime: dutyStartTime + 12 + 5*120,
ExpectedDuration: 120,
},
},
}

}
68 changes: 68 additions & 0 deletions qbft/spectest/tests/timeout/timeoutduration/round_1_duration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package timeoutduration

import (
"github.com/attestantio/go-eth2-client/spec/phase0"
"github.com/bloxapp/ssv-spec/qbft"
"github.com/bloxapp/ssv-spec/qbft/spectest/tests"

"github.com/bloxapp/ssv-spec/types"
)

// Round1Duration tests timeout duration for round 1
func Round1Duration() tests.SpecTest {
var testingNetwork = types.HoleskyNetwork
height := qbft.FirstHeight
dutyStartTime := testingNetwork.EstimatedTimeAtSlot(phase0.Slot(height))

return &MultiSpecTest{
Name: "round 1",
Tests: []*TimeoutDurationTest{
{
Name: "sync committee",
Role: types.BNRoleSyncCommittee,
Height: 0,
Round: qbft.FirstRound,
Network: testingNetwork,
CurrentTime: dutyStartTime,
ExpectedDuration: 6,
},
{
Name: "sync committee contribution",
Role: types.BNRoleSyncCommitteeContribution,
Height: 0,
Round: qbft.FirstRound,
Network: testingNetwork,
CurrentTime: dutyStartTime,
ExpectedDuration: 10,
},
{
Name: "attester",
Role: types.BNRoleAttester,
Height: 0,
Round: qbft.FirstRound,
Network: testingNetwork,
CurrentTime: dutyStartTime,
ExpectedDuration: 6,
},
{
Name: "aggregator",
Role: types.BNRoleAggregator,
Height: 0,
Round: qbft.FirstRound,
Network: testingNetwork,
CurrentTime: dutyStartTime,
ExpectedDuration: 10,
},
{
Name: "block proposer",
Role: types.BNRoleProposer,
Height: 0,
Round: qbft.FirstRound,
Network: testingNetwork,
CurrentTime: dutyStartTime,
ExpectedDuration: 2,
},
},
}

}
Loading