Skip to content

Commit

Permalink
alan: cleanup after fork
Browse files Browse the repository at this point in the history
  • Loading branch information
nkryuchkov committed Oct 26, 2024
1 parent 0bc6433 commit bd2bd43
Show file tree
Hide file tree
Showing 191 changed files with 699 additions and 23,940 deletions.
41 changes: 0 additions & 41 deletions beacon/goclient/genesisgoclient/adapter.go

This file was deleted.

74 changes: 9 additions & 65 deletions cli/operator/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@ 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"

"github.com/ssvlabs/ssv/api/handlers"
apiserver "github.com/ssvlabs/ssv/api/server"
"github.com/ssvlabs/ssv/beacon/goclient"
"github.com/ssvlabs/ssv/beacon/goclient/genesisgoclient"
global_config "github.com/ssvlabs/ssv/cli/config"
"github.com/ssvlabs/ssv/ekm"
"github.com/ssvlabs/ssv/eth/eventhandler"
Expand All @@ -35,14 +33,12 @@ import (
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"
"github.com/ssvlabs/ssv/logging"
"github.com/ssvlabs/ssv/logging/fields"
"github.com/ssvlabs/ssv/message/signatureverifier"
"github.com/ssvlabs/ssv/message/validation"
genesisvalidation "github.com/ssvlabs/ssv/message/validation/genesis"
"github.com/ssvlabs/ssv/migrations"
"github.com/ssvlabs/ssv/monitoring/metrics"
"github.com/ssvlabs/ssv/monitoring/metricsreporter"
Expand All @@ -59,7 +55,6 @@ import (
operatorstorage "github.com/ssvlabs/ssv/operator/storage"
"github.com/ssvlabs/ssv/operator/validator"
"github.com/ssvlabs/ssv/operator/validators"
genesisssvtypes "github.com/ssvlabs/ssv/protocol/genesis/types"
beaconprotocol "github.com/ssvlabs/ssv/protocol/v2/blockchain/beacon"
"github.com/ssvlabs/ssv/protocol/v2/types"
registrystorage "github.com/ssvlabs/ssv/registry/storage"
Expand Down Expand Up @@ -169,7 +164,7 @@ var StartNodeCmd = &cobra.Command{

usingLocalEvents := len(cfg.LocalEventsPath) != 0

if err := validateConfig(nodeStorage, networkConfig.AlanForkNetworkName(), usingLocalEvents); err != nil {
if err := validateConfig(nodeStorage, networkConfig.NetworkName(), usingLocalEvents); err != nil {
logger.Fatal("failed to validate config", zap.Error(err))
}

Expand Down Expand Up @@ -228,9 +223,7 @@ var StartNodeCmd = &cobra.Command{

validatorStore := nodeStorage.ValidatorStore()

var messageValidator validation.MessageValidator

alanMsgValidator := validation.New(
messageValidator := validation.New(
networkConfig,
validatorStore,
dutyStore,
Expand All @@ -239,27 +232,11 @@ var StartNodeCmd = &cobra.Command{
validation.WithMetrics(metricsReporter),
)

if networkConfig.PastAlanFork() {
messageValidator = alanMsgValidator
} else {
messageValidator = &validation.ForkingMessageValidation{
NetworkConfig: networkConfig,
Alan: alanMsgValidator,
Genesis: genesisvalidation.New(
networkConfig,
genesisvalidation.WithNodeStorage(nodeStorage),
genesisvalidation.WithLogger(logger),
genesisvalidation.WithMetrics(metricsReporter),
genesisvalidation.WithDutyStore(dutyStore),
),
}
}

cfg.P2pNetworkConfig.Metrics = metricsReporter
cfg.P2pNetworkConfig.MessageValidator = messageValidator
cfg.SSVOptions.ValidatorOptions.MessageValidator = messageValidator

p2pNetwork, genesisP2pNetwork := setupP2P(logger, db, metricsReporter)
p2pNetwork := setupP2P(logger, db, metricsReporter)

cfg.SSVOptions.Context = cmd.Context()
cfg.SSVOptions.DB = db
Expand All @@ -273,7 +250,6 @@ var StartNodeCmd = &cobra.Command{
cfg.SSVOptions.ValidatorOptions.DB = db
cfg.SSVOptions.ValidatorOptions.Network = p2pNetwork
cfg.SSVOptions.ValidatorOptions.Beacon = consensusClient
cfg.SSVOptions.ValidatorOptions.GenesisBeacon = genesisgoclient.NewAdapter(consensusClient)
cfg.SSVOptions.ValidatorOptions.BeaconSigner = keyManager
cfg.SSVOptions.ValidatorOptions.ValidatorsMap = validatorsMap
cfg.SSVOptions.ValidatorOptions.NetworkConfig = networkConfig
Expand All @@ -283,8 +259,6 @@ var StartNodeCmd = &cobra.Command{
cfg.SSVOptions.ValidatorOptions.RecipientsStorage = nodeStorage
cfg.SSVOptions.ValidatorOptions.GasLimit = cfg.ConsensusClient.GasLimit

cfg.SSVOptions.ValidatorOptions.GenesisControllerOptions.KeyManager = &ekm.GenesisKeyManagerAdapter{KeyManager: keyManager}

if cfg.WsAPIPort != 0 {
ws := exporterapi.NewWsServer(cmd.Context(), nil, http.NewServeMux(), cfg.WithPing)
cfg.SSVOptions.WS = ws
Expand All @@ -311,32 +285,13 @@ var StartNodeCmd = &cobra.Command{
storageMap.Add(storageRole, ibftstorage.New(cfg.SSVOptions.ValidatorOptions.DB, storageRole.String()))
}

genesisStorageRoles := []genesisspectypes.BeaconRole{
genesisspectypes.BNRoleAttester,
genesisspectypes.BNRoleAggregator,
genesisspectypes.BNRoleProposer,
genesisspectypes.BNRoleSyncCommittee,
genesisspectypes.BNRoleSyncCommitteeContribution,
genesisspectypes.BNRoleValidatorRegistration,
genesisspectypes.BNRoleVoluntaryExit,
}

genesisStorageMap := genesisibftstorage.NewStores()

for _, storageRole := range genesisStorageRoles {
genesisStorageMap.Add(storageRole, genesisibftstorage.New(cfg.SSVOptions.ValidatorOptions.DB, "genesis_"+storageRole.String()))
}

cfg.SSVOptions.ValidatorOptions.StorageMap = storageMap
cfg.SSVOptions.ValidatorOptions.Metrics = metricsReporter
cfg.SSVOptions.ValidatorOptions.Graffiti = []byte(cfg.Graffiti)
cfg.SSVOptions.ValidatorOptions.ValidatorStore = nodeStorage.ValidatorStore()
cfg.SSVOptions.ValidatorOptions.OperatorSigner = types.NewSsvOperatorSigner(operatorPrivKey, operatorDataStore.GetOperatorID)
cfg.SSVOptions.Metrics = metricsReporter

cfg.SSVOptions.ValidatorOptions.GenesisControllerOptions.StorageMap = genesisStorageMap
cfg.SSVOptions.ValidatorOptions.GenesisControllerOptions.Network = &genesisP2pNetwork

validatorCtrl := validator.NewController(logger, cfg.SSVOptions.ValidatorOptions)
cfg.SSVOptions.ValidatorController = validatorCtrl
cfg.SSVOptions.ValidatorStore = validatorStore
Expand Down Expand Up @@ -610,33 +565,22 @@ func setupSSVNetwork(logger *zap.Logger) (networkconfig.NetworkConfig, error) {
return networkconfig.NetworkConfig{}, errors.New("custom domain type must be 4 bytes")
}

// Assign domain type as-is for Genesis.
networkConfig.GenesisDomainType = spectypes.DomainType(byts)

// Assign domain type incremented by 1 for Alan.
alanDomainType := binary.BigEndian.Uint32(byts) + 1
binary.BigEndian.PutUint32(networkConfig.AlanDomainType[:], alanDomainType)
domainType := binary.BigEndian.Uint32(byts)
binary.BigEndian.PutUint32(networkConfig.DomainType[:], domainType)

logger.Info("running with custom domain type",
zap.Stringer("genesis", format.DomainType(networkConfig.GenesisDomainType)),
zap.Stringer("alan", format.DomainType(networkConfig.AlanDomainType)),
fields.Domain(networkConfig.DomainType),
)
}

genesisssvtypes.SetDefaultDomain(genesisspectypes.DomainType(networkConfig.GenesisDomainType))

nodeType := "light"
if cfg.SSVOptions.ValidatorOptions.FullNode {
nodeType = "full"
}

if !networkConfig.PastAlanFork() {
logger = logger.With(zap.Stringer("alan_domain", format.DomainType(networkConfig.AlanDomainType)))
}

logger.Info("setting ssv network",
fields.Network(networkConfig.Name),
fields.Domain(networkConfig.DomainType()),
fields.Domain(networkConfig.DomainType),
zap.String("nodeType", nodeType),
zap.Any("beaconNetwork", networkConfig.Beacon.GetNetwork().BeaconNetwork),
zap.Uint64("genesisEpoch", uint64(networkConfig.GenesisEpoch)),
Expand All @@ -646,7 +590,7 @@ func setupSSVNetwork(logger *zap.Logger) (networkconfig.NetworkConfig, error) {
return networkConfig, nil
}

func setupP2P(logger *zap.Logger, db basedb.Database, mr metricsreporter.MetricsReporter) (network.P2PNetwork, p2pv1.GenesisP2P) {
func setupP2P(logger *zap.Logger, db basedb.Database, mr metricsreporter.MetricsReporter) network.P2PNetwork {
istore := ssv_identity.NewIdentityStore(db)
netPrivKey, err := istore.SetupNetworkKey(logger, cfg.NetworkPrivateKey)
if err != nil {
Expand All @@ -658,7 +602,7 @@ func setupP2P(logger *zap.Logger, db basedb.Database, mr metricsreporter.Metrics
if err != nil {
logger.Fatal("failed to setup p2p network", zap.Error(err))
}
return n, p2pv1.GenesisP2P{Network: n}
return n
}

func setupConsensusClient(
Expand Down
2 changes: 1 addition & 1 deletion cli/operator/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func Test_verifyConfig(t *testing.T) {
nodeStorage, err := operatorstorage.NewNodeStorage(logger, db)
require.NoError(t, err)

testNetworkName := networkconfig.TestNetwork.AlanForkNetworkName()
testNetworkName := networkconfig.TestNetwork.NetworkName()

t.Run("no config in DB", func(t *testing.T) {
c := &operatorstorage.ConfigLock{
Expand Down
27 changes: 1 addition & 26 deletions ekm/eth_key_manager_signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ type KeyManager interface {
AddShare(shareKey *bls.SecretKey) error
// RemoveShare removes a share key
RemoveShare(pubKey string) error

// SignRoot TODO: (Alan) genesis support - should be removed after alan fork
SignRoot(data spectypes.Root, sigType spectypes.SignatureType, pk []byte) (spectypes.Signature, error)
}

// NewETHKeyManagerSigner returns a new instance of ethKeyManagerSigner
Expand Down Expand Up @@ -105,7 +102,7 @@ func NewETHKeyManagerSigner(logger *zap.Logger, db basedb.Database, network netw
walletLock: &sync.RWMutex{},
signer: beaconSigner,
storage: signerStore,
domain: network.DomainType(),
domain: network.DomainType,
slashingProtector: slashingProtector,
}, nil
}
Expand Down Expand Up @@ -256,28 +253,6 @@ func (km *ethKeyManagerSigner) IsBeaconBlockSlashable(pk []byte, slot phase0.Slo
return nil
}

func (km *ethKeyManagerSigner) SignRoot(data spectypes.Root, sigType spectypes.SignatureType, pk []byte) (spectypes.Signature, error) {
km.walletLock.RLock()
defer km.walletLock.RUnlock()

account, err := km.wallet.AccountByPublicKey(hex.EncodeToString(pk))
if err != nil {
return nil, errors.Wrap(err, "could not get signing account")
}

root, err := spectypes.ComputeSigningRoot(data, spectypes.ComputeSignatureDomain(km.domain, sigType))
if err != nil {
return nil, errors.Wrap(err, "could not compute signing root")
}

sig, err := account.ValidationKeySign(root[:])
if err != nil {
return nil, errors.Wrap(err, "could not sign message")
}

return sig, nil
}

func (km *ethKeyManagerSigner) AddShare(shareKey *bls.SecretKey) error {
km.walletLock.Lock()
defer km.walletLock.Unlock()
Expand Down
77 changes: 0 additions & 77 deletions ekm/genesis_adapter.go

This file was deleted.

Loading

0 comments on commit bd2bd43

Please sign in to comment.