Skip to content

Commit

Permalink
alan: cleanup after fork (#1820)
Browse files Browse the repository at this point in the history
* alan: cleanup after fork

* fix linter

* cleanup spec tests jobs

* cleanup discovery leftovers

* remove genesis differ

* fix unknown validator test

* fix issues after merging stage

* fix message validation tests

* get rid of next domain type

* fix bug with validation initialization

* cleanup

* fix imports

* increase custom domain by 1

* get rid of github.com/ssvlabs/ssv-spec-pre-cc

* fix issues after merging

* approve spec diff

* fix linter

---------

Co-authored-by: moshe-blox <[email protected]>
  • Loading branch information
2 people authored and olegshmuelov committed Dec 8, 2024
1 parent ccfcb68 commit fc62941
Show file tree
Hide file tree
Showing 193 changed files with 386 additions and 23,712 deletions.
34 changes: 0 additions & 34 deletions .github/workflows/genesis-spec-alignment.yml

This file was deleted.

6 changes: 0 additions & 6 deletions .github/workflows/spec-test-raceless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,5 @@ jobs:
with:
go-version: "1.22.x"

- name: Run pre-fork spec tests
run: make pre-fork-spec-test-raceless

- name: Run post-fork spec tests
run: make post-fork-spec-test-raceless

- name: Run all spec tests
run: make all-spec-test-raceless
12 changes: 0 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,11 @@ spec-test:
@echo "Running spec tests"
@go test -tags blst_enabled -timeout 90m ${COV_CMD} -race -count=1 -p 1 -v `go list ./... | grep spectest`


.PHONY: all-spec-test-raceless
all-spec-test-raceless:
@echo "Running spec tests"
@go test -tags blst_enabled -timeout 90m ${COV_CMD} -p 1 -v ./protocol/...


.PHONY: pre-fork-spec-test-raceless
pre-fork-spec-test-raceless:
@echo "Running spec tests"
@go test -tags blst_enabled -timeout 90m ${COV_CMD} -p 1 -v ./protocol/genesis/...

.PHONY: post-fork-spec-test-raceless
post-fork-spec-test-raceless:
@echo "Running spec tests"
@go test -tags blst_enabled -timeout 90m ${COV_CMD} -p 1 -v ./protocol/v2/...

.PHONY: spec-test-raceless
spec-test-raceless:
@echo "Running spec tests without race flag"
Expand Down
41 changes: 0 additions & 41 deletions beacon/goclient/genesisgoclient/adapter.go

This file was deleted.

82 changes: 13 additions & 69 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 @@ -268,12 +245,10 @@ var StartNodeCmd = &cobra.Command{
cfg.SSVOptions.Network = networkConfig
cfg.SSVOptions.P2PNetwork = p2pNetwork
cfg.SSVOptions.ValidatorOptions.NetworkConfig = networkConfig
cfg.SSVOptions.ValidatorOptions.BeaconNetwork = networkConfig.Beacon.GetNetwork()
cfg.SSVOptions.ValidatorOptions.Context = cmd.Context()
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 +258,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 +284,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 @@ -410,7 +364,7 @@ var StartNodeCmd = &cobra.Command{
Shares: nodeStorage.Shares(),
},
&handlers.Exporter{
DomainType: networkConfig.AlanDomainType,
DomainType: networkConfig.DomainType,
QBFTStores: storageMap,
},
)
Expand Down Expand Up @@ -606,41 +560,31 @@ func setupSSVNetwork(logger *zap.Logger) (networkconfig.NetworkConfig, error) {
if !strings.HasPrefix(cfg.SSVOptions.CustomDomainType, "0x") {
return networkconfig.NetworkConfig{}, errors.New("custom domain type must be a hex string")
}
byts, err := hex.DecodeString(cfg.SSVOptions.CustomDomainType[2:])
domainBytes, err := hex.DecodeString(cfg.SSVOptions.CustomDomainType[2:])
if err != nil {
return networkconfig.NetworkConfig{}, errors.Wrap(err, "failed to decode custom domain type")
}
if len(byts) != 4 {
if len(domainBytes) != 4 {
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)
// https://github.com/ssvlabs/ssv/pull/1808 incremented the post-fork domain type by 1, so we have to maintain the compatibility.
postForkDomain := binary.BigEndian.Uint32(domainBytes) + 1
binary.BigEndian.PutUint32(networkConfig.DomainType[:], postForkDomain)

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 @@ -650,7 +594,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 @@ -662,7 +606,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
Loading

0 comments on commit fc62941

Please sign in to comment.