Skip to content

Commit

Permalink
fix: remove unused conver runner role
Browse files Browse the repository at this point in the history
  • Loading branch information
anatolie-ssv committed Oct 21, 2024
1 parent 3de919b commit f7c12ad
Show file tree
Hide file tree
Showing 18 changed files with 92 additions and 181 deletions.
8 changes: 3 additions & 5 deletions cli/operator/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ import (
"github.com/ilyakaznacheev/cleanenv"
"github.com/pkg/errors"
"github.com/spf13/cobra"
genesisspectypes "github.com/ssvlabs/ssv-spec-pre-cc/types"
spectypes "github.com/ssvlabs/ssv-spec/types"
"go.uber.org/zap"

genesisspectypes "github.com/ssvlabs/ssv-spec-pre-cc/types"
convert "github.com/ssvlabs/ssv-spec/types"
spectypes "github.com/ssvlabs/ssv-spec/types"
"github.com/ssvlabs/ssv/api/handlers"
apiserver "github.com/ssvlabs/ssv/api/server"
"github.com/ssvlabs/ssv/beacon/goclient"
Expand All @@ -33,7 +34,6 @@ import (
"github.com/ssvlabs/ssv/eth/localevents"
exporterapi "github.com/ssvlabs/ssv/exporter/api"
"github.com/ssvlabs/ssv/exporter/api/decided"
"github.com/ssvlabs/ssv/exporter/convert"
genesisibftstorage "github.com/ssvlabs/ssv/ibft/genesisstorage"
ibftstorage "github.com/ssvlabs/ssv/ibft/storage"
ssv_identity "github.com/ssvlabs/ssv/identity"
Expand Down Expand Up @@ -295,9 +295,7 @@ var StartNodeCmd = &cobra.Command{

storageRoles := []convert.RunnerRole{
convert.RoleCommittee,
convert.RoleAttester,
convert.RoleProposer,
convert.RoleSyncCommittee,
convert.RoleAggregator,
convert.RoleSyncCommitteeContribution,
convert.RoleValidatorRegistration,
Expand Down
17 changes: 8 additions & 9 deletions exporter/api/query_handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (
"github.com/attestantio/go-eth2-client/spec/phase0"
"github.com/herumi/bls-eth-go-binary/bls"
"github.com/pkg/errors"
specqbft "github.com/ssvlabs/ssv-spec/qbft"
spectypes "github.com/ssvlabs/ssv-spec/types"
"github.com/stretchr/testify/require"
"go.uber.org/zap"

specqbft "github.com/ssvlabs/ssv-spec/qbft"
spectypes "github.com/ssvlabs/ssv-spec/types"
"github.com/ssvlabs/ssv/exporter/convert"
qbftstorage "github.com/ssvlabs/ssv/ibft/storage"
"github.com/ssvlabs/ssv/logging"
Expand Down Expand Up @@ -87,12 +87,11 @@ func TestHandleDecidedQuery(t *testing.T) {
db, l, done := newDBAndLoggerForTest(logger)
defer done()

roles := []convert.RunnerRole{
convert.RoleAttester,
convert.RoleCommittee,
convert.RoleProposer,
convert.RoleAggregator,
convert.RoleSyncCommitteeContribution,
roles := []spectypes.RunnerRole{
spectypes.RoleCommittee,
spectypes.RoleProposer,
spectypes.RoleAggregator,
spectypes.RoleSyncCommitteeContribution,
// skipping spectypes.BNRoleSyncCommitteeContribution to test non-existing storage
}
_, ibftStorage := newStorageForTest(db, l, roles...)
Expand Down Expand Up @@ -203,7 +202,7 @@ func newDBAndLoggerForTest(logger *zap.Logger) (basedb.Database, *zap.Logger, fu
}
}

func newStorageForTest(db basedb.Database, logger *zap.Logger, roles ...convert.RunnerRole) (storage.Storage, *qbftstorage.QBFTStores) {
func newStorageForTest(db basedb.Database, logger *zap.Logger, roles ...spectypes.RunnerRole) (storage.Storage, *qbftstorage.QBFTStores) {
sExporter, err := storage.NewNodeStorage(logger, db)
if err != nil {
panic(err)
Expand Down
6 changes: 3 additions & 3 deletions exporter/convert/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (msg MessageID) GetDutyExecutorID() []byte {
return msg[dutyExecutorIDStartPos : dutyExecutorIDStartPos+dutyExecutorIDSize]
}

func (msg MessageID) GetRoleType() RunnerRole {
func (msg MessageID) GetRoleType() spectypes.RunnerRole {
roleByts := msg[roleTypeStartPos : roleTypeStartPos+roleTypeSize]
roleValue := binary.LittleEndian.Uint32(roleByts)

Expand All @@ -37,10 +37,10 @@ func (msg MessageID) GetRoleType() RunnerRole {
return spectypes.RoleUnknown
}

return RunnerRole(roleValue)
return spectypes.RunnerRole(roleValue)
}

func NewMsgID(domain spectypes.DomainType, dutyExecutorID []byte, role RunnerRole) MessageID {
func NewMsgID(domain spectypes.DomainType, dutyExecutorID []byte, role spectypes.RunnerRole) MessageID {
// Sanitize role. If bad role, return an empty MessageID
roleValue := int32(role)
if roleValue < 0 {
Expand Down
61 changes: 0 additions & 61 deletions exporter/convert/roles.go

This file was deleted.

19 changes: 9 additions & 10 deletions ibft/storage/stores.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
package storage

import (
"github.com/ssvlabs/ssv/utils/hashmap"

"github.com/ssvlabs/ssv/exporter/convert"
spectypes "github.com/ssvlabs/ssv-spec/types"
qbftstorage "github.com/ssvlabs/ssv/protocol/v2/qbft/storage"
"github.com/ssvlabs/ssv/storage/basedb"
"github.com/ssvlabs/ssv/utils/hashmap"
)

// QBFTStores wraps sync map with cast functions to qbft store
type QBFTStores struct {
m *hashmap.Map[convert.RunnerRole, qbftstorage.QBFTStore]
m *hashmap.Map[spectypes.RunnerRole, qbftstorage.QBFTStore]
}

func NewStores() *QBFTStores {
return &QBFTStores{
m: hashmap.New[convert.RunnerRole, qbftstorage.QBFTStore](),
m: hashmap.New[spectypes.RunnerRole, qbftstorage.QBFTStore](),
}
}

func NewStoresFromRoles(db basedb.Database, roles ...convert.RunnerRole) *QBFTStores {
func NewStoresFromRoles(db basedb.Database, roles ...spectypes.RunnerRole) *QBFTStores {
stores := NewStores()
for _, role := range roles {
stores.Add(role, New(db, role.String()))
Expand All @@ -28,7 +27,7 @@ func NewStoresFromRoles(db basedb.Database, roles ...convert.RunnerRole) *QBFTSt
}

// Get store from sync map by role type
func (qs *QBFTStores) Get(role convert.RunnerRole) qbftstorage.QBFTStore {
func (qs *QBFTStores) Get(role spectypes.RunnerRole) qbftstorage.QBFTStore {
s, ok := qs.m.Get(role)
if !ok {
return nil
Expand All @@ -37,14 +36,14 @@ func (qs *QBFTStores) Get(role convert.RunnerRole) qbftstorage.QBFTStore {
}

// Add store to sync map by role as a key
func (qs *QBFTStores) Add(role convert.RunnerRole, store qbftstorage.QBFTStore) {
func (qs *QBFTStores) Add(role spectypes.RunnerRole, store qbftstorage.QBFTStore) {
qs.m.Set(role, store)
}

// Each iterates over all stores and calls the given function
func (qs *QBFTStores) Each(f func(role convert.RunnerRole, store qbftstorage.QBFTStore) error) error {
func (qs *QBFTStores) Each(f func(role spectypes.RunnerRole, store qbftstorage.QBFTStore) error) error {
var err error
qs.m.Range(func(role convert.RunnerRole, store qbftstorage.QBFTStore) bool {
qs.m.Range(func(role spectypes.RunnerRole, store qbftstorage.QBFTStore) bool {
err = f(role, store)
return err == nil
})
Expand Down
23 changes: 12 additions & 11 deletions ibft/storage/stores_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package storage
import (
"testing"

"github.com/stretchr/testify/require"

specqbft "github.com/ssvlabs/ssv-spec/qbft"
"github.com/ssvlabs/ssv/exporter/convert"
spectypes "github.com/ssvlabs/ssv-spec/types"
"github.com/ssvlabs/ssv/logging"
qbftstorage "github.com/ssvlabs/ssv/protocol/v2/qbft/storage"
"github.com/ssvlabs/ssv/storage/basedb"
"github.com/ssvlabs/ssv/storage/kv"
"github.com/stretchr/testify/require"
)

func TestQBFTStores(t *testing.T) {
Expand All @@ -19,29 +20,29 @@ func TestQBFTStores(t *testing.T) {

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

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

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

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

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

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

instance, err := qbftMap.Get(convert.RoleCommittee).GetInstance(id, 1)
instance, err := qbftMap.Get(spectypes.RoleCommittee).GetInstance(id, 1)
require.NoError(t, err)
require.NotNil(t, instance)
require.Equal(t, specqbft.Height(1), instance.State.Height)
Expand Down
22 changes: 10 additions & 12 deletions integration/qbft/tests/scenario_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import (

spec "github.com/attestantio/go-eth2-client/spec/phase0"
"github.com/ethereum/go-ethereum/common"
spectypes "github.com/ssvlabs/ssv-spec/types"
"github.com/ssvlabs/ssv-spec/types/testingutils"
spectestingutils "github.com/ssvlabs/ssv-spec/types/testingutils"
"github.com/stretchr/testify/require"
"go.uber.org/zap"

spectypes "github.com/ssvlabs/ssv-spec/types"
"github.com/ssvlabs/ssv-spec/types/testingutils"
spectestingutils "github.com/ssvlabs/ssv-spec/types/testingutils"
"github.com/ssvlabs/ssv/exporter/convert"
qbftstorage "github.com/ssvlabs/ssv/ibft/storage"
"github.com/ssvlabs/ssv/logging"
Expand Down Expand Up @@ -174,15 +174,13 @@ func newStores(logger *zap.Logger) *qbftstorage.QBFTStores {

storageMap := qbftstorage.NewStores()

roles := []convert.RunnerRole{
convert.RoleAttester,
convert.RoleAggregator,
convert.RoleProposer,
convert.RoleSyncCommitteeContribution,
convert.RoleSyncCommittee,
convert.RoleValidatorRegistration,
convert.RoleVoluntaryExit,
convert.RoleCommittee,
roles := []spectypes.RunnerRole{
spectypes.RoleAggregator,
spectypes.RoleProposer,
spectypes.RoleSyncCommitteeContribution,
spectypes.RoleValidatorRegistration,
spectypes.RoleVoluntaryExit,
spectypes.RoleCommittee,
}
for _, role := range roles {
storageMap.Add(role, qbftstorage.New(db, role.String()))
Expand Down
8 changes: 3 additions & 5 deletions logging/fields/fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,17 @@ import (
"strings"
"time"

"github.com/ssvlabs/ssv/exporter/convert"

"github.com/attestantio/go-eth2-client/spec"
"github.com/attestantio/go-eth2-client/spec/phase0"
"github.com/dgraph-io/ristretto"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/p2p/enode"
"github.com/libp2p/go-libp2p/core/peer"
specqbft "github.com/ssvlabs/ssv-spec/qbft"
spectypes "github.com/ssvlabs/ssv-spec/types"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"

specqbft "github.com/ssvlabs/ssv-spec/qbft"
spectypes "github.com/ssvlabs/ssv-spec/types"
"github.com/ssvlabs/ssv/eth/contract"
"github.com/ssvlabs/ssv/logging/fields/stringer"
"github.com/ssvlabs/ssv/network/records"
Expand Down Expand Up @@ -233,7 +231,7 @@ func BeaconRole(val spectypes.BeaconRole) zap.Field {
func Role(val spectypes.RunnerRole) zap.Field {
return zap.Stringer(FieldRole, val)
}
func ExporterRole(val convert.RunnerRole) zap.Field {
func ExporterRole(val spectypes.RunnerRole) zap.Field {
return zap.Stringer(FieldRole, val)
}

Expand Down
8 changes: 4 additions & 4 deletions operator/validator/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/jellydator/ttlcache/v3"
"github.com/pkg/errors"
"go.uber.org/zap"

genesisspecqbft "github.com/ssvlabs/ssv-spec-pre-cc/qbft"
genesisspecssv "github.com/ssvlabs/ssv-spec-pre-cc/ssv"
genesisspectypes "github.com/ssvlabs/ssv-spec-pre-cc/types"
specqbft "github.com/ssvlabs/ssv-spec/qbft"
spectypes "github.com/ssvlabs/ssv-spec/types"
"go.uber.org/zap"

"github.com/ssvlabs/ssv/exporter/convert"
"github.com/ssvlabs/ssv/ibft/genesisstorage"
"github.com/ssvlabs/ssv/ibft/storage"
Expand Down Expand Up @@ -1239,7 +1239,7 @@ func SetupCommitteeRunners(
leader := qbft.RoundRobinProposer(state, round)
return leader
},
Storage: options.Storage.Get(convert.RunnerRole(role)),
Storage: options.Storage.Get(role),
Network: options.Network,
Timer: roundtimer.New(ctx, options.NetworkConfig.Beacon, role, nil),
CutOffRound: roundtimer.CutOffRound,
Expand Down Expand Up @@ -1303,7 +1303,7 @@ func SetupRunners(
//logger.Debug("leader", zap.Int("operator_id", int(leader)))
return leader
},
Storage: options.Storage.Get(convert.RunnerRole(role)),
Storage: options.Storage.Get(role),
Network: options.Network,
Timer: roundtimer.New(ctx, options.NetworkConfig.Beacon, role, nil),
CutOffRound: roundtimer.CutOffRound,
Expand Down
Loading

0 comments on commit f7c12ad

Please sign in to comment.