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

(Alan/no-fork) Make spec tests work again #1480

Merged
merged 11 commits into from
Jul 18, 2024
20 changes: 10 additions & 10 deletions ibft/storage/stores_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"

specqbft "github.com/ssvlabs/ssv-spec/qbft"
spectypes "github.com/ssvlabs/ssv-spec/types"
"github.com/ssvlabs/ssv/exporter/convert"
"github.com/ssvlabs/ssv/logging"
qbftstorage "github.com/ssvlabs/ssv/protocol/v2/qbft/storage"
"github.com/ssvlabs/ssv/storage/basedb"
Expand All @@ -19,28 +19,28 @@ func TestQBFTStores(t *testing.T) {

store, err := newTestIbftStorage(logger, "")
require.NoError(t, err)
qbftMap.Add(spectypes.RoleCommittee, store)
qbftMap.Add(spectypes.RoleCommittee, store)
qbftMap.Add(convert.RoleCommittee, store)
qbftMap.Add(convert.RoleCommittee, store)

require.NotNil(t, qbftMap.Get(spectypes.RoleCommittee))
require.NotNil(t, qbftMap.Get(spectypes.RoleCommittee))
require.NotNil(t, qbftMap.Get(convert.RoleCommittee))
require.NotNil(t, qbftMap.Get(convert.RoleCommittee))

db, err := kv.NewInMemory(logger.Named(logging.NameBadgerDBLog), basedb.Options{
Reporting: true,
})
require.NoError(t, err)
qbftMap = NewStoresFromRoles(db, spectypes.RoleCommittee, spectypes.RoleProposer)
qbftMap = NewStoresFromRoles(db, convert.RoleCommittee, convert.RoleProposer)

require.NotNil(t, qbftMap.Get(spectypes.RoleCommittee))
require.NotNil(t, qbftMap.Get(spectypes.RoleCommittee))
require.NotNil(t, qbftMap.Get(convert.RoleCommittee))
require.NotNil(t, qbftMap.Get(convert.RoleCommittee))

id := []byte{1, 2, 3}

qbftMap.Each(func(role spectypes.RunnerRole, store qbftstorage.QBFTStore) error {
qbftMap.Each(func(role convert.RunnerRole, store qbftstorage.QBFTStore) error {
return store.SaveInstance(&qbftstorage.StoredInstance{State: &specqbft.State{Height: 1, ID: id}})
})

instance, err := qbftMap.Get(spectypes.RoleCommittee).GetInstance(id, 1)
instance, err := qbftMap.Get(convert.RoleCommittee).GetInstance(id, 1)
require.NoError(t, err)
require.NotNil(t, instance)
require.Equal(t, specqbft.Height(1), instance.State.Height)
Expand Down
3 changes: 2 additions & 1 deletion protocol/v2/qbft/spectest/msg_processing_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"testing"
"time"

"github.com/ssvlabs/ssv/exporter/convert"
"github.com/stretchr/testify/require"

specqbft "github.com/ssvlabs/ssv-spec/qbft"
Expand All @@ -31,7 +32,7 @@ func RunMsgProcessing(t *testing.T, test *spectests.MsgProcessingSpecTest) {
msgId := specqbft.ControllerIdToMessageID(test.Pre.State.ID)
logger := logging.TestLogger(t)
pre := instance.NewInstance(
qbfttesting.TestingConfig(logger, spectestingutils.KeySetForCommitteeMember(test.Pre.State.CommitteeMember), msgId.GetRoleType()),
qbfttesting.TestingConfig(logger, spectestingutils.KeySetForCommitteeMember(test.Pre.State.CommitteeMember), convert.RunnerRole(msgId.GetRoleType())),
y0sher marked this conversation as resolved.
Show resolved Hide resolved
test.Pre.State.CommitteeMember,
test.Pre.State.ID,
test.Pre.State.Height,
Expand Down
3 changes: 2 additions & 1 deletion protocol/v2/qbft/spectest/qbft_mapping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/ssvlabs/ssv-spec/qbft/spectest/tests/timeout"
spectypes "github.com/ssvlabs/ssv-spec/types"
"github.com/ssvlabs/ssv-spec/types/testingutils"
"github.com/ssvlabs/ssv/exporter/convert"
"github.com/stretchr/testify/require"

"github.com/ssvlabs/ssv/logging"
Expand Down Expand Up @@ -100,7 +101,7 @@ func TestQBFTMapping(t *testing.T) {
preByts, _ := typedTest.Pre.Encode()
logger := logging.TestLogger(t)
pre := instance.NewInstance(
testing2.TestingConfig(logger, testingutils.KeySetForCommitteeMember(typedTest.Pre.State.CommitteeMember), spectypes.RoleCommittee),
testing2.TestingConfig(logger, testingutils.KeySetForCommitteeMember(typedTest.Pre.State.CommitteeMember), convert.RunnerRole(spectypes.RoleCommittee)),
typedTest.Pre.State.CommitteeMember,
typedTest.Pre.State.ID,
typedTest.Pre.State.Height,
Expand Down
8 changes: 5 additions & 3 deletions protocol/v2/qbft/testing/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package testing

import (
"context"
"github.com/ssvlabs/ssv/exporter/convert"
"sync"

"github.com/ssvlabs/ssv/exporter/convert"
qbftstorage "github.com/ssvlabs/ssv/ibft/storage"
"github.com/ssvlabs/ssv/storage/basedb"
"github.com/ssvlabs/ssv/storage/kv"
Expand All @@ -28,12 +28,14 @@ func getDB(logger *zap.Logger) basedb.Database {
}

var allRoles = []convert.RunnerRole{
convert.RoleCommittee,
convert.RoleProposer,
convert.RoleAttester,
convert.RoleAggregator,
convert.RoleProposer,
convert.RoleSyncCommitteeContribution,
convert.RoleSyncCommittee,
convert.RoleValidatorRegistration,
convert.RoleVoluntaryExit,
convert.RoleCommittee,
}

func TestingStores(logger *zap.Logger) *qbftstorage.QBFTStores {
Expand Down
1 change: 1 addition & 0 deletions protocol/v2/qbft/testing/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package testing

import (
"bytes"

"github.com/pkg/errors"
"github.com/ssvlabs/ssv/exporter/convert"
"github.com/ssvlabs/ssv/protocol/v2/qbft/roundtimer"
Expand Down
12 changes: 11 additions & 1 deletion protocol/v2/ssv/runner/runner_state_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package runner
import (
"encoding/hex"

"github.com/attestantio/go-eth2-client/spec/phase0"
spectypes "github.com/ssvlabs/ssv-spec/types"
)

Expand All @@ -16,7 +17,16 @@ func getPreConsensusSigners(state *State, root [32]byte) []spectypes.OperatorID
}

func getPostConsensusSigners(state *State, root [32]byte) []spectypes.OperatorID {
sigs := state.PostConsensusContainer.Signatures[state.StartingDuty.(*spectypes.BeaconDuty).ValidatorIndex][hex.EncodeToString(root[:])]
var valIdx phase0.ValidatorIndex
switch state.StartingDuty.(type) {
case *spectypes.BeaconDuty:
valIdx = state.StartingDuty.(*spectypes.BeaconDuty).ValidatorIndex
case *spectypes.CommitteeDuty:
valIdx = state.StartingDuty.(*spectypes.CommitteeDuty).BeaconDuties[0].ValidatorIndex
y0sher marked this conversation as resolved.
Show resolved Hide resolved
default:
return nil
}
sigs := state.PostConsensusContainer.Signatures[valIdx][hex.EncodeToString(root[:])]
var signers []spectypes.OperatorID
for op := range sigs {
signers = append(signers, op)
Expand Down
5 changes: 3 additions & 2 deletions protocol/v2/ssv/testing/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"

"github.com/attestantio/go-eth2-client/spec/phase0"
"github.com/ssvlabs/ssv/exporter/convert"
"github.com/ssvlabs/ssv/integration/qbft/tests"
"github.com/ssvlabs/ssv/networkconfig"
"github.com/ssvlabs/ssv/operator/validator"
Expand Down Expand Up @@ -84,7 +85,7 @@ var baseRunner = func(
operator := spectestingutils.TestingCommitteeMember(keySet)
opSigner := spectestingutils.NewTestingOperatorSigner(keySet, 1)

config := testing.TestingConfig(logger, keySet, identifier.GetRoleType())
config := testing.TestingConfig(logger, keySet, convert.RunnerRole(identifier.GetRoleType()))
config.ValueCheckF = valCheck
config.ProposerF = func(state *specqbft.State, round specqbft.Round) spectypes.OperatorID {
return 1
Expand Down Expand Up @@ -288,7 +289,7 @@ var baseRunnerWithShareMap = func(
committeeMember := spectestingutils.TestingCommitteeMember(keySetInstance)
opSigner := spectestingutils.NewTestingOperatorSigner(keySetInstance, committeeMember.OperatorID)

config := testing.TestingConfig(logger, keySetInstance, identifier.GetRoleType())
config := testing.TestingConfig(logger, keySetInstance, convert.RunnerRole(identifier.GetRoleType()))
config.ValueCheckF = valCheck
config.ProposerF = func(state *specqbft.State, round specqbft.Round) spectypes.OperatorID {
return 1
Expand Down
53 changes: 28 additions & 25 deletions protocol/v2/ssv/validator/committee.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,32 +98,35 @@ func (c *Committee) StartDuty(logger *zap.Logger, duty *spectypes.CommitteeDuty)
return errors.New(fmt.Sprintf("CommitteeRunner for slot %d already exists", duty.Slot))
}

validatorShares := make(map[phase0.ValidatorIndex]*spectypes.Share, len(duty.BeaconDuties))
toRemove := make([]int, 0)
// Remove beacon duties that don't have a share
for i, bd := range duty.BeaconDuties {
share, ok := c.Shares[bd.ValidatorIndex]
if !ok {
toRemove = append(toRemove, i)
continue
}
validatorShares[bd.ValidatorIndex] = share
}
// Remove beacon duties that don't have a share
if len(toRemove) > 0 {
newDuties, err := removeIndices(duty.BeaconDuties, toRemove)
if err != nil {
logger.Warn("could not remove beacon duties", zap.Error(err), zap.Ints("indices", toRemove))
} else {
duty.BeaconDuties = newDuties
}
//validatorShares := make(map[phase0.ValidatorIndex]*spectypes.Share, len(duty.BeaconDuties))
//toRemove := make([]int, 0)
//// Remove beacon duties that don't have a share
//for i, bd := range duty.BeaconDuties {
// share, ok := c.Shares[bd.ValidatorIndex]
// if !ok {
// toRemove = append(toRemove, i)
// continue
// }
// validatorShares[bd.ValidatorIndex] = share
//}
//// Remove beacon duties that don't have a share
//if len(toRemove) > 0 {
// newDuties, err := removeIndices(duty.BeaconDuties, toRemove)
// if err != nil {
// logger.Warn("could not remove beacon duties", zap.Error(err), zap.Ints("indices", toRemove))
// } else {
// duty.BeaconDuties = newDuties
// }
//}
//
//if len(duty.BeaconDuties) == 0 {
// return errors.New("CommitteeDuty has no valid beacon duties")
//}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we want to filter the shares and execute the committeeRunner only with the relevant shares and duties (these that have a duty in this slot)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GalRogozinski, shouldn't we do changes in spec tests then?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AKorpusenko what test is failing because of that?

Copy link
Contributor

@y0sher y0sher Jul 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will work once ssvlabs/ssv-spec#467 is merged and code is aligned. please add a todo to revert it once its aligned and done.

var sharesCopy = make(map[phase0.ValidatorIndex]*spectypes.Share, len(c.Shares))
for k, v := range c.Shares {
sharesCopy[k] = v
}

if len(duty.BeaconDuties) == 0 {
return errors.New("CommitteeDuty has no valid beacon duties")
}

r := c.CreateRunnerFn(duty.Slot, validatorShares)
r := c.CreateRunnerFn(duty.Slot, sharesCopy)
// Set timeout function.
r.GetBaseRunner().TimeoutF = c.onTimeout
c.Runners[duty.Slot] = r
Expand Down
Loading