Skip to content

Commit

Permalink
Merge branch 'stage' into alan/pre-fork-spec-alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
MatheusFranco99 committed Aug 8, 2024
2 parents 3400b0c + 72d2677 commit b1b8c4e
Show file tree
Hide file tree
Showing 13 changed files with 423 additions and 208 deletions.
35 changes: 16 additions & 19 deletions integration/qbft/tests/regular_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

func TestRegular4CommitteeScenario(t *testing.T) {
t.Skip("tests in this package are stuck")
t.Skip("to be fixed")

regular := &Scenario{
Committee: 4,
Expand All @@ -29,15 +29,14 @@ func TestRegular4CommitteeScenario(t *testing.T) {
},
}

regular.Run(t, spectypes.BNRoleAttester)
regular.Run(t, spectypes.BNRoleAggregator)
regular.Run(t, spectypes.BNRoleProposer)
regular.Run(t, spectypes.BNRoleSyncCommittee)
regular.Run(t, spectypes.BNRoleSyncCommitteeContribution)
//regular.Run(t, spectypes.RoleCommittee) // fails because committee runner needs to be created
regular.Run(t, spectypes.RoleAggregator)
regular.Run(t, spectypes.RoleProposer)
regular.Run(t, spectypes.RoleSyncCommitteeContribution)
}

func TestRegular7CommitteeScenario(t *testing.T) {
t.Skip("tests in this package are stuck")
t.Skip("to be fixed")

regular := &Scenario{
Committee: 7,
Expand All @@ -61,15 +60,14 @@ func TestRegular7CommitteeScenario(t *testing.T) {
},
}

regular.Run(t, spectypes.BNRoleAttester)
regular.Run(t, spectypes.BNRoleAggregator)
regular.Run(t, spectypes.BNRoleProposer)
regular.Run(t, spectypes.BNRoleSyncCommittee)
regular.Run(t, spectypes.BNRoleSyncCommitteeContribution)
regular.Run(t, spectypes.RoleCommittee)
regular.Run(t, spectypes.RoleAggregator)
regular.Run(t, spectypes.RoleProposer)
regular.Run(t, spectypes.RoleSyncCommitteeContribution)
}

func TestRegular10CommitteeScenario(t *testing.T) {
t.Skip("tests in this package are stuck")
t.Skip("to be fixed")

regular := &Scenario{
Committee: 10,
Expand Down Expand Up @@ -99,11 +97,10 @@ func TestRegular10CommitteeScenario(t *testing.T) {
},
}

regular.Run(t, spectypes.BNRoleAttester)
regular.Run(t, spectypes.BNRoleAggregator)
regular.Run(t, spectypes.BNRoleProposer)
regular.Run(t, spectypes.BNRoleSyncCommittee)
regular.Run(t, spectypes.BNRoleSyncCommitteeContribution)
regular.Run(t, spectypes.RoleCommittee)
regular.Run(t, spectypes.RoleAggregator)
regular.Run(t, spectypes.RoleProposer)
regular.Run(t, spectypes.RoleSyncCommitteeContribution)
}

func regularValidator() func(t *testing.T, committee int, actual *protocolstorage.StoredInstance) {
Expand All @@ -112,6 +109,6 @@ func regularValidator() func(t *testing.T, committee int, actual *protocolstorag
require.Equal(t, int(qbft.FirstRound), int(actual.State.Round), "round not matching")

require.NotNil(t, actual.DecidedMessage, "no decided message")
require.Greater(t, len(actual.DecidedMessage.Signatures), quorum(committee)-1, "no commit qourum")
require.Greater(t, len(actual.DecidedMessage.Signatures), quorum(committee)-1, "no commit quorum")
}
}
5 changes: 2 additions & 3 deletions integration/qbft/tests/round_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

func TestRoundChange4CommitteeScenario(t *testing.T) {
t.Skip("tests in this package are stuck")
t.Skip("to be fixed")

t.SkipNow() // TODO: test is flakey

Expand All @@ -32,10 +32,9 @@ func TestRoundChange4CommitteeScenario(t *testing.T) {
},
}

roundChange.Run(t, spectypes.BNRoleAttester)
roundChange.Run(t, spectypes.RoleCommittee)
//roundChange.Run(t, spectypes.BNRoleAggregator) todo implement aggregator role support
//roundChange.Run(t, spectypes.BNRoleProposer) todo implement proposer role support
roundChange.Run(t, spectypes.BNRoleSyncCommittee)
//roundChange.Run(t, spectypes.BNRoleSyncCommitteeContribution) todo implement sync committee contribution role support
}

Expand Down
36 changes: 25 additions & 11 deletions integration/qbft/tests/scenario_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ type Scenario struct {
validators map[spectypes.OperatorID]*protocolvalidator.Validator
}

func (s *Scenario) Run(t *testing.T, role spectypes.BeaconRole) {
t.Skip("tests in this package are stuck")

func (s *Scenario) Run(t *testing.T, role spectypes.RunnerRole) {
t.Run(role.String(), func(t *testing.T) {
//preparing resources
ctx, cancel := context.WithCancel(context.Background())
Expand All @@ -73,18 +71,31 @@ func (s *Scenario) Run(t *testing.T, role spectypes.BeaconRole) {
duty := createDuty(getKeySet(s.Committee).ValidatorPK.Serialize(), dutyProp.Slot, dutyProp.ValidatorIndex, role)
var pk spec.BLSPubKey
copy(pk[:], getKeySet(s.Committee).ValidatorPK.Serialize())
ssvMsg, err := validator.CreateDutyExecuteMsg(duty.(*spectypes.ValidatorDuty), pk[:], networkconfig.TestNetwork.DomainType())
require.NoError(t, err)

var ssvMsg *spectypes.SSVMessage
switch d := duty.(type) {
case *spectypes.ValidatorDuty:
msg, err := validator.CreateDutyExecuteMsg(d, pk[:], networkconfig.TestNetwork.DomainType())
require.NoError(t, err)

ssvMsg = msg
case *spectypes.CommitteeDuty:
msg, err := validator.CreateCommitteeDutyExecuteMsg(d, spectypes.CommitteeID(pk[16:]), networkconfig.TestNetwork.DomainType())
require.NoError(t, err)

ssvMsg = msg
}

dec, err := queue.DecodeSSVMessage(ssvMsg)
require.NoError(t, err)

s.validators[id].Queues[spectypes.MapDutyToRunnerRole(role)].Q.Push(dec)
s.validators[id].Queues[role].Q.Push(dec)
}(id, dutyProp)
}

//validating state of validator after invoking duties
for id, validationFunc := range s.ValidationFunctions {
identifier := spectypes.NewMsgID(networkconfig.TestNetwork.DomainType(), getKeySet(s.Committee).ValidatorPK.Serialize(), spectypes.MapDutyToRunnerRole(role))
identifier := spectypes.NewMsgID(networkconfig.TestNetwork.DomainType(), getKeySet(s.Committee).ValidatorPK.Serialize(), role)
//getting stored state of validator
var storedInstance *protocolstorage.StoredInstance
for {
Expand Down Expand Up @@ -164,12 +175,14 @@ func newStores(logger *zap.Logger) *qbftstorage.QBFTStores {
storageMap := qbftstorage.NewStores()

roles := []convert.RunnerRole{
convert.RoleCommittee,
convert.RoleProposer,
convert.RoleAttester,
convert.RoleAggregator,
convert.RoleProposer,
convert.RoleSyncCommitteeContribution,
convert.RoleSyncCommittee,
convert.RoleValidatorRegistration,
convert.RoleVoluntaryExit,
convert.RoleCommittee,
}
for _, role := range roles {
storageMap.Add(role, qbftstorage.New(db, role.String()))
Expand Down Expand Up @@ -202,8 +215,9 @@ func createValidator(t *testing.T, pCtx context.Context, id spectypes.OperatorID
Liquidated: false,
},
},
Beacon: NewTestingBeaconNodeWrapped(),
Signer: km,
Beacon: NewTestingBeaconNodeWrapped(),
Signer: km,
Operator: spectestingutils.TestingCommitteeMember(keySet),
}

options.DutyRunners = validator.SetupRunners(ctx, logger, options)
Expand Down
89 changes: 54 additions & 35 deletions integration/qbft/tests/setup_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
package tests

import (
"context"
"testing"

eth2apiv1 "github.com/attestantio/go-eth2-client/api/v1"
spectypes "github.com/ssvlabs/ssv-spec/types"
spectestingutils "github.com/ssvlabs/ssv-spec/types/testingutils"
"github.com/stretchr/testify/require"
"go.uber.org/zap"

"github.com/ssvlabs/ssv/logging"
"github.com/ssvlabs/ssv/network"
p2pv1 "github.com/ssvlabs/ssv/network/p2p"
beaconprotocol "github.com/ssvlabs/ssv/protocol/v2/blockchain/beacon"
ssvtypes "github.com/ssvlabs/ssv/protocol/v2/types"
)

const (
Expand All @@ -27,39 +35,50 @@ func GetSharedData(t *testing.T) SharedData { //singleton B-)
}

func TestMain(m *testing.M) {
_, _ = maxSupportedCommittee, maxSupportedQuorum
m.Run() // TODO: fix tests in the package and remove this block

//ctx := context.Background()
//if err := logging.SetGlobalLogger("debug", "capital", "console", nil); err != nil {
// panic(err)
//}
//
//logger := zap.L().Named("integration-tests")
//
//ln, err := p2pv1.CreateAndStartLocalNet(ctx, logger, p2pv1.LocalNetOptions{
// Nodes: maxSupportedCommittee,
// MinConnected: maxSupportedQuorum,
// UseDiscv5: false,
//})
//if err != nil {
// logger.Fatal("error creating and start local net", zap.Error(err))
// return
//}
//
//nodes := map[spectypes.OperatorID]network.P2PNetwork{}
//for i := 0; i < len(ln.Nodes); i++ {
// nodes[spectypes.OperatorID(i+1)] = ln.Nodes[i]
//}
//
//sharedData = &SharedData{
// Nodes: nodes,
//}
//
//m.Run()
//
////teardown
//for i := 0; i < len(ln.Nodes); i++ {
// _ = ln.Nodes[i].Close()
//}
ctx := context.Background()
if err := logging.SetGlobalLogger("debug", "capital", "console", nil); err != nil {
panic(err)
}

logger := zap.L().Named("integration-tests")

shares := []*ssvtypes.SSVShare{
{
Share: *spectestingutils.TestingShare(spectestingutils.Testing4SharesSet(), spectestingutils.TestingValidatorIndex),
Metadata: ssvtypes.Metadata{
BeaconMetadata: &beaconprotocol.ValidatorMetadata{
Status: eth2apiv1.ValidatorStateActiveOngoing,
Index: spectestingutils.TestingShare(spectestingutils.Testing4SharesSet(), spectestingutils.TestingValidatorIndex).ValidatorIndex,
},
Liquidated: false,
},
},
}

ln, err := p2pv1.CreateAndStartLocalNet(ctx, logger, p2pv1.LocalNetOptions{
Nodes: maxSupportedCommittee,
MinConnected: maxSupportedQuorum,
UseDiscv5: false,
Shares: shares,
})
if err != nil {
logger.Fatal("error creating and start local net", zap.Error(err))
return
}

nodes := map[spectypes.OperatorID]network.P2PNetwork{}
for i := 0; i < len(ln.Nodes); i++ {
nodes[spectypes.OperatorID(i+1)] = ln.Nodes[i]
}

sharedData = &SharedData{
Nodes: nodes,
}

m.Run()

//teardown
for i := 0; i < len(ln.Nodes); i++ {
_ = ln.Nodes[i].Close()
}
}
18 changes: 10 additions & 8 deletions integration/qbft/tests/test_duty.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,30 @@ type DutyProperties struct {
Delay time.Duration
}

func createDuty(pk []byte, slot phase0.Slot, idx phase0.ValidatorIndex, role spectypes.BeaconRole) spectypes.Duty {
func createDuty(pk []byte, slot phase0.Slot, idx phase0.ValidatorIndex, role spectypes.RunnerRole) spectypes.Duty {
var pkBytes [48]byte
copy(pkBytes[:], pk)

var testingDuty spectypes.ValidatorDuty
var beaconRole spectypes.BeaconRole
switch role {
case spectypes.BNRoleAttester:
case spectypes.RoleCommittee:
return spectestingutils.TestingCommitteeAttesterDuty(slot, []int{int(idx)})
case spectypes.BNRoleAggregator:
case spectypes.RoleAggregator:
testingDuty = spectestingutils.TestingAggregatorDuty
case spectypes.BNRoleProposer:
beaconRole = spectypes.BNRoleAggregator
case spectypes.RoleProposer:
testingDuty = *spectestingutils.TestingProposerDutyV(spec.DataVersionCapella)
case spectypes.BNRoleSyncCommittee:
return spectestingutils.TestingCommitteeSyncCommitteeDuty(slot, []int{int(idx)})
case spectypes.BNRoleSyncCommitteeContribution:
beaconRole = spectypes.BNRoleProposer
case spectypes.RoleSyncCommitteeContribution:
testingDuty = spectestingutils.TestingSyncCommitteeContributionDuty
beaconRole = spectypes.BNRoleSyncCommitteeContribution
default:
panic("unknown role")
}

return &spectypes.ValidatorDuty{
Type: role,
Type: beaconRole,
PubKey: pkBytes,
Slot: slot,
ValidatorIndex: idx,
Expand Down
3 changes: 1 addition & 2 deletions network/p2p/p2p_pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"math/rand"
"time"

genesisqueue "github.com/ssvlabs/ssv/protocol/genesis/ssv/genesisqueue"

pubsub "github.com/libp2p/go-libp2p-pubsub"
"github.com/pkg/errors"
spectypes "github.com/ssvlabs/ssv-spec/types"
Expand All @@ -19,6 +17,7 @@ import (
"github.com/ssvlabs/ssv/network/commons"
"github.com/ssvlabs/ssv/network/records"
genesismessage "github.com/ssvlabs/ssv/protocol/genesis/message"
"github.com/ssvlabs/ssv/protocol/genesis/ssv/genesisqueue"
"github.com/ssvlabs/ssv/protocol/v2/message"
p2pprotocol "github.com/ssvlabs/ssv/protocol/v2/p2p"
"github.com/ssvlabs/ssv/protocol/v2/ssv/queue"
Expand Down
Loading

0 comments on commit b1b8c4e

Please sign in to comment.