Skip to content

Commit

Permalink
Alan/switch domain at runtime (#1454)
Browse files Browse the repository at this point in the history
* add DomainType() calculating fork

* update network consumers to use DomainType()

* add ENR update function at fork

* add fork listener to scheduler

* add fork handler test

* some refactors and fixes

* TODO

* use dynamic domain type in runners

* add next domain type support in discovery

* fix merge leftovers

* (handshakes) update self NodeInfo domain type before handing over to peers

* change Alan domain type for holesky-stage

---------

Co-authored-by: moshe-blox <[email protected]>
Co-authored-by: y0sher <[email protected]>
  • Loading branch information
3 people authored Jul 17, 2024
1 parent d664144 commit aad4fff
Show file tree
Hide file tree
Showing 64 changed files with 499 additions and 726 deletions.
4 changes: 2 additions & 2 deletions cli/operator/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (
"github.com/ilyakaznacheev/cleanenv"
"github.com/pkg/errors"
"github.com/spf13/cobra"
spectypes "github.com/ssvlabs/ssv-spec/types"
"go.uber.org/zap"

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 Down Expand Up @@ -567,7 +567,7 @@ func setupSSVNetwork(logger *zap.Logger) (networkconfig.NetworkConfig, error) {

logger.Info("setting ssv network",
fields.Network(networkConfig.Name),
fields.Domain(networkConfig.Domain),
fields.Domain(networkConfig.DomainType()),
zap.String("nodeType", nodeType),
zap.Any("beaconNetwork", networkConfig.Beacon.GetNetwork().BeaconNetwork),
zap.Uint64("genesisEpoch", uint64(networkConfig.GenesisEpoch)),
Expand Down
2 changes: 1 addition & 1 deletion config/config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ db:
ssv:
# The SSV network to join to
# Mainnet = Network: mainnet (default)
# Testnet = Network: jato-v2
# Testnet = Network: holesky
Network: mainnet

eth2:
Expand Down
2 changes: 1 addition & 1 deletion docs/bootnode.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ bootnode:
PrivateKey: [Your Private Key]
ExternalIP: [Your External IP]
DbPath: ./data/bootnode
Network: jato-v2
Network: mainnet
```
_Note: This is an example. Replace the placeholders as explained below._
Expand Down
5 changes: 3 additions & 2 deletions ekm/eth_key_manager_signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ import (
ssz "github.com/ferranbt/fastssz"
"github.com/herumi/bls-eth-go-binary/bls"
"github.com/pkg/errors"
"go.uber.org/zap"

spectypes "github.com/ssvlabs/ssv-spec/types"
"github.com/ssvlabs/ssv/networkconfig"
"github.com/ssvlabs/ssv/storage/basedb"
"go.uber.org/zap"
)

const (
Expand Down Expand Up @@ -100,7 +101,7 @@ func NewETHKeyManagerSigner(logger *zap.Logger, db basedb.Database, network netw
walletLock: &sync.RWMutex{},
signer: beaconSigner,
storage: signerStore,
domain: network.Domain,
domain: network.DomainType(),
slashingProtector: slashingProtector,
}, nil
}
Expand Down
16 changes: 8 additions & 8 deletions ekm/signer_key_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,17 @@ import (
"github.com/holiman/uint256"
"github.com/pkg/errors"
"github.com/prysmaticlabs/go-bitfield"
genesisspecqbft "github.com/ssvlabs/ssv-spec-pre-cc/qbft"
genesisspectypes "github.com/ssvlabs/ssv-spec-pre-cc/types"
spectypes "github.com/ssvlabs/ssv-spec/types"
"github.com/stretchr/testify/require"
"go.uber.org/zap"

genesisspecqbft "github.com/ssvlabs/ssv-spec-pre-cc/qbft"
genesisspectypes "github.com/ssvlabs/ssv-spec-pre-cc/types"
spectypes "github.com/ssvlabs/ssv-spec/types"
"github.com/ssvlabs/ssv/logging"
"github.com/ssvlabs/ssv/networkconfig"
"github.com/ssvlabs/ssv/operator/keys"
"github.com/ssvlabs/ssv/storage/basedb"
"github.com/ssvlabs/ssv/utils"

"github.com/ssvlabs/ssv/utils/threshold"
)

Expand All @@ -49,8 +48,9 @@ func testKeyManager(t *testing.T, network *networkconfig.NetworkConfig) KeyManag

if network == nil {
network = &networkconfig.NetworkConfig{
Beacon: utils.SetupMockBeaconNetwork(t, nil),
Domain: networkconfig.TestNetwork.Domain,
Beacon: utils.SetupMockBeaconNetwork(t, nil),
GenesisDomainType: networkconfig.TestNetwork.DomainType(),
AlanDomainType: networkconfig.TestNetwork.DomainType(),
}
}

Expand Down Expand Up @@ -715,7 +715,7 @@ func TestSignRoot(t *testing.T) {

err = signed.Signature.VerifyByOperators(
signed,
genesisspectypes.DomainType(networkconfig.TestNetwork.Domain),
genesisspectypes.DomainType(networkconfig.TestNetwork.DomainType()),
genesisspectypes.QBFTSignatureType,
[]*genesisspectypes.Operator{{OperatorID: spectypes.OperatorID(1), PubKey: pk.Serialize()}},
)
Expand Down Expand Up @@ -747,7 +747,7 @@ func TestSignRoot(t *testing.T) {

err = signed.Signature.VerifyByOperators(
signed,
genesisspectypes.DomainType(networkconfig.TestNetwork.Domain),
genesisspectypes.DomainType(networkconfig.TestNetwork.DomainType()),
genesisspectypes.QBFTSignatureType,
[]*genesisspectypes.Operator{{OperatorID: spectypes.OperatorID(1), PubKey: pk.Serialize()}},
)
Expand Down
9 changes: 4 additions & 5 deletions eth/eventhandler/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@ import (
"errors"
"fmt"

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

"github.com/attestantio/go-eth2-client/spec/phase0"
ethcommon "github.com/ethereum/go-ethereum/common"
"github.com/herumi/bls-eth-go-binary/bls"
spectypes "github.com/ssvlabs/ssv-spec/types"
"go.uber.org/zap"

spectypes "github.com/ssvlabs/ssv-spec/types"
"github.com/ssvlabs/ssv/ekm"
"github.com/ssvlabs/ssv/eth/contract"
"github.com/ssvlabs/ssv/exporter/convert"
"github.com/ssvlabs/ssv/logging/fields"
"github.com/ssvlabs/ssv/operator/duties"
qbftstorage "github.com/ssvlabs/ssv/protocol/v2/qbft/storage"
Expand Down Expand Up @@ -335,7 +334,7 @@ func (eh *EventHandler) validatorAddedEventToShare(
})
}

validatorShare.DomainType = eh.networkConfig.Domain
validatorShare.DomainType = eh.networkConfig.DomainType()
validatorShare.Committee = shareMembers
validatorShare.Graffiti = []byte("ssv.network")

Expand Down Expand Up @@ -375,7 +374,7 @@ func (eh *EventHandler) handleValidatorRemoved(txn basedb.Txn, event *contract.C
}

removeDecidedMessages := func(role convert.RunnerRole, store qbftstorage.QBFTStore) error {
messageID := convert.NewMsgID(eh.networkConfig.Domain, share.ValidatorPubKey[:], role)
messageID := convert.NewMsgID(eh.networkConfig.DomainType(), share.ValidatorPubKey[:], role)
return store.CleanAllInstances(logger, messageID[:])
}
err := eh.storageMap.Each(removeDecidedMessages)
Expand Down
12 changes: 6 additions & 6 deletions exporter/api/query_handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func TestHandleDecidedQuery(t *testing.T) {
networkConfig, err := networkconfig.GetNetworkConfigByName(networkconfig.HoleskyStage.Name)
require.NoError(t, err)
decided250Seq, err := protocoltesting.CreateMultipleStoredInstances(rsaKeys, specqbft.Height(0), specqbft.Height(250), func(height specqbft.Height) ([]spectypes.OperatorID, *specqbft.Message) {
id := convert.NewMsgID(networkConfig.Domain, pk.Serialize(), role)
id := convert.NewMsgID(networkConfig.DomainType(), pk.Serialize(), role)
return oids, &specqbft.Message{
MsgType: specqbft.CommitMsgType,
Height: height,
Expand All @@ -131,7 +131,7 @@ func TestHandleDecidedQuery(t *testing.T) {

t.Run("valid range", func(t *testing.T) {
nm := newParticipantsAPIMsg(pk.SerializeToHexStr(), spectypes.BNRoleAttester, 0, 250)
HandleParticipantsQuery(l, ibftStorage, nm, networkConfig.Domain)
HandleParticipantsQuery(l, ibftStorage, nm, networkConfig.DomainType())
require.NotNil(t, nm.Msg.Data)
msgs, ok := nm.Msg.Data.([]*ParticipantsAPI)

Expand All @@ -141,7 +141,7 @@ func TestHandleDecidedQuery(t *testing.T) {

t.Run("invalid range", func(t *testing.T) {
nm := newParticipantsAPIMsg(pk.SerializeToHexStr(), spectypes.BNRoleAttester, 400, 404)
HandleParticipantsQuery(l, ibftStorage, nm, networkConfig.Domain)
HandleParticipantsQuery(l, ibftStorage, nm, networkConfig.DomainType())
require.NotNil(t, nm.Msg.Data)
data, ok := nm.Msg.Data.([]string)
require.True(t, ok)
Expand All @@ -150,7 +150,7 @@ func TestHandleDecidedQuery(t *testing.T) {

t.Run("non-existing validator", func(t *testing.T) {
nm := newParticipantsAPIMsg("xxx", spectypes.BNRoleAttester, 400, 404)
HandleParticipantsQuery(l, ibftStorage, nm, networkConfig.Domain)
HandleParticipantsQuery(l, ibftStorage, nm, networkConfig.DomainType())
require.NotNil(t, nm.Msg.Data)
errs, ok := nm.Msg.Data.([]string)
require.True(t, ok)
Expand All @@ -159,7 +159,7 @@ func TestHandleDecidedQuery(t *testing.T) {

t.Run("non-existing role", func(t *testing.T) {
nm := newParticipantsAPIMsg(pk.SerializeToHexStr(), math.MaxUint64, 0, 250)
HandleParticipantsQuery(l, ibftStorage, nm, networkConfig.Domain)
HandleParticipantsQuery(l, ibftStorage, nm, networkConfig.DomainType())
require.NotNil(t, nm.Msg.Data)
errs, ok := nm.Msg.Data.([]string)
require.True(t, ok)
Expand All @@ -168,7 +168,7 @@ func TestHandleDecidedQuery(t *testing.T) {

t.Run("non-existing storage", func(t *testing.T) {
nm := newParticipantsAPIMsg(pk.SerializeToHexStr(), spectypes.BNRoleSyncCommitteeContribution, 0, 250)
HandleParticipantsQuery(l, ibftStorage, nm, networkConfig.Domain)
HandleParticipantsQuery(l, ibftStorage, nm, networkConfig.DomainType())
require.NotNil(t, nm.Msg.Data)
errs, ok := nm.Msg.Data.([]string)
require.True(t, ok)
Expand Down
8 changes: 4 additions & 4 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"
qbftstorage "github.com/ssvlabs/ssv/ibft/storage"
"github.com/ssvlabs/ssv/logging"
"github.com/ssvlabs/ssv/logging/fields"
Expand Down Expand Up @@ -70,7 +70,7 @@ 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.BeaconDuty), pk[:], networkconfig.TestNetwork.Domain)
ssvMsg, err := validator.CreateDutyExecuteMsg(duty.(*spectypes.BeaconDuty), pk[:], networkconfig.TestNetwork.DomainType())
require.NoError(t, err)
dec, err := queue.DecodeSSVMessage(ssvMsg)
require.NoError(t, err)
Expand Down
14 changes: 7 additions & 7 deletions message/validation/genesis/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ import (
pubsub "github.com/libp2p/go-libp2p-pubsub"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/pkg/errors"
specqbft "github.com/ssvlabs/ssv-spec-pre-cc/qbft"
spectypes "github.com/ssvlabs/ssv-spec-pre-cc/types"
alanspecqbft "github.com/ssvlabs/ssv-spec/qbft"
alanspectypes "github.com/ssvlabs/ssv-spec/types"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"golang.org/x/exp/slices"

specqbft "github.com/ssvlabs/ssv-spec-pre-cc/qbft"
spectypes "github.com/ssvlabs/ssv-spec-pre-cc/types"
alanspecqbft "github.com/ssvlabs/ssv-spec/qbft"
alanspectypes "github.com/ssvlabs/ssv-spec/types"
"github.com/ssvlabs/ssv/logging/fields"
"github.com/ssvlabs/ssv/monitoring/metricsreporter"
"github.com/ssvlabs/ssv/network/commons"
Expand Down Expand Up @@ -387,11 +387,11 @@ func (mv *messageValidator) validateSSVMessage(msg *queue.DecodedSSVMessage, rec
err.want = maxMessageSize
return nil, descriptor, err
}

if !bytes.Equal(ssvMessage.MsgID.GetDomain(), mv.netCfg.Domain[:]) {
domain := mv.netCfg.DomainType()
if !bytes.Equal(ssvMessage.MsgID.GetDomain(), domain[:]) {
err := ErrWrongDomain
err.got = hex.EncodeToString(ssvMessage.MsgID.GetDomain())
err.want = hex.EncodeToString(mv.netCfg.Domain[:])
err.want = hex.EncodeToString(domain[:])
return nil, descriptor, err
}

Expand Down
Loading

0 comments on commit aad4fff

Please sign in to comment.