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 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
29 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
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.Round8Duration,
timeoutduration.Round9Duration,
timeoutduration.Round14Duration,
timeoutduration.Round1DurationFutureCurrentTime,
timeoutduration.Round3DurationOnDutyStartTime,
timeoutduration.Round5DurationOnRound3Time,
timeoutduration.Round9DurationOnDutyStartTime,
timeoutduration.Round14DurationOnRound13Time,

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.

13 changes: 11 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,18 @@ func TestJson(t *testing.T) {

tests[testName] = typedTest
typedTest.Run(t)
case reflect.TypeOf(&timeout.SpecTest{}).String():
case reflect.TypeOf(timeoutduration.TimeoutDurationTest{}).String():
byts, err := json.Marshal(test)
require.NoError(t, err)
typedTest := &timeout.SpecTest{}
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
24 changes: 24 additions & 0 deletions qbft/spectest/tests/multi_spectest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package tests

import "testing"

type MultiSpecTest struct {
Name string
Tests []SpecTest
}

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)
})
}
}
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
}
68 changes: 68 additions & 0 deletions qbft/spectest/tests/timeout/timeoutduration/round_14_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"
)

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

return &tests.MultiSpecTest{
Name: "round 14 duration",
Tests: []tests.SpecTest{
&TimeoutDurationTest{
Name: "sync committee",
Role: types.BNRoleSyncCommittee,
Height: height,
Round: round,
Network: testingNetwork,
CurrentTime: dutyStartTime + 20 + 5*120,
ExpectedDuration: 120,
},
&TimeoutDurationTest{
Name: "sync committee contribution",
Role: types.BNRoleSyncCommitteeContribution,
Height: height,
Round: round,
Network: testingNetwork,
CurrentTime: dutyStartTime + 24 + 5*120,
ExpectedDuration: 120,
},
&TimeoutDurationTest{
Name: "attester",
Role: types.BNRoleAttester,
Height: height,
Round: round,
Network: testingNetwork,
CurrentTime: dutyStartTime + 20 + 5*120,
ExpectedDuration: 120,
},
&TimeoutDurationTest{
Name: "aggregator",
Role: types.BNRoleAggregator,
Height: height,
Round: round,
Network: testingNetwork,
CurrentTime: dutyStartTime + 24 + 5*120,
ExpectedDuration: 120,
},
&TimeoutDurationTest{
Name: "block proposer",
Role: types.BNRoleProposer,
Height: height,
Round: round,
Network: testingNetwork,
CurrentTime: dutyStartTime + 20 + 5*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"
)

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

return &tests.MultiSpecTest{
Name: "round 14 duration on round 13 time",
Tests: []tests.SpecTest{
&TimeoutDurationTest{
Name: "sync committee",
Role: types.BNRoleSyncCommittee,
Height: height,
Round: round,
Network: testingNetwork,
CurrentTime: dutyStartTime + 20 + 4*120,
ExpectedDuration: 240,
},
&TimeoutDurationTest{
Name: "sync committee contribution",
Role: types.BNRoleSyncCommitteeContribution,
Height: height,
Round: round,
Network: testingNetwork,
CurrentTime: dutyStartTime + 24 + 4*120,
ExpectedDuration: 240,
},
&TimeoutDurationTest{
Name: "attester",
Role: types.BNRoleAttester,
Height: height,
Round: round,
Network: testingNetwork,
CurrentTime: dutyStartTime + 20 + 4*120,
ExpectedDuration: 240,
},
&TimeoutDurationTest{
Name: "aggregator",
Role: types.BNRoleAggregator,
Height: height,
Round: round,
Network: testingNetwork,
CurrentTime: dutyStartTime + 24 + 4*120,
ExpectedDuration: 240,
},
&TimeoutDurationTest{
Name: "block proposer",
Role: types.BNRoleProposer,
Height: height,
Round: round,
Network: testingNetwork,
CurrentTime: dutyStartTime + 20 + 4*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 &tests.MultiSpecTest{
Name: "round 1",
Tests: []tests.SpecTest{
&TimeoutDurationTest{
Name: "sync committee",
Role: types.BNRoleSyncCommittee,
Height: 0,
Round: qbft.FirstRound,
Network: testingNetwork,
CurrentTime: dutyStartTime,
ExpectedDuration: 6,
},
&TimeoutDurationTest{
Name: "sync committee contribution",
Role: types.BNRoleSyncCommitteeContribution,
Height: 0,
Round: qbft.FirstRound,
Network: testingNetwork,
CurrentTime: dutyStartTime,
ExpectedDuration: 10,
},
&TimeoutDurationTest{
Name: "attester",
Role: types.BNRoleAttester,
Height: 0,
Round: qbft.FirstRound,
Network: testingNetwork,
CurrentTime: dutyStartTime,
ExpectedDuration: 6,
},
&TimeoutDurationTest{
Name: "aggregator",
Role: types.BNRoleAggregator,
Height: 0,
Round: qbft.FirstRound,
Network: testingNetwork,
CurrentTime: dutyStartTime,
ExpectedDuration: 10,
},
&TimeoutDurationTest{
Name: "block proposer",
Role: types.BNRoleProposer,
Height: 0,
Round: qbft.FirstRound,
Network: testingNetwork,
CurrentTime: dutyStartTime,
ExpectedDuration: 2,
},
},
}

}
Loading
Loading