diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d4ce0b3ebf..01364a3220a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ Changelog for NeoFS Node - Support of verified domains for the storage nodes (#2280) - `neofs-lens storage status` CLI command (#2550) - Human-readable output of objects' creation timestamp to `neofs-cli container list-objects` (#2653) +- Ability to preset P2PNotary and NeoFSAlphabet roles to validators at the FS chain's genesis (#2643) ### Fixed - `neofs-cli netmap netinfo` documentation (#2555) diff --git a/config/example/ir.yaml b/config/example/ir.yaml index 82884e99801..337e461c432 100644 --- a/config/example/ir.yaml +++ b/config/example/ir.yaml @@ -83,6 +83,9 @@ morph: ping: # Optional settings of pinging mechanism interval: 30s # Optional time period between pings. Defaults to 30s. Must not be negative timeout: 90s # Optional time period to wait for pong. Defaults to 1m. Must not be negative + set_roles_in_genesis: true # Optional flag for designating P2PNotary and NeoFSAlphabet roles to all + # genesis block validators. The validators depend on 'committee' and, if set, 'validators_history'. + # Must be 'true' or 'false'. fschain_autodeploy: true # Optional flag to run auto-deployment procedure of the FS chain. By default, # the chain is expected to be deployed/updated in the background (e.g. via NeoFS ADM tool). diff --git a/pkg/innerring/config.go b/pkg/innerring/config.go index 4f212a4add0..2926b6f8314 100644 --- a/pkg/innerring/config.go +++ b/pkg/innerring/config.go @@ -218,6 +218,11 @@ func parseBlockchainConfig(v *viper.Viper, _logger *zap.Logger) (c blockchain.Co } } + c.SetRolesInGenesis, err = parseConfigBool(v, rootSection+".set_roles_in_genesis", "flag to set roles for the committee in the genesis block") + if err != nil && !errors.Is(err, errMissingConfig) { + return c, err + } + c.Logger = _logger return c, nil diff --git a/pkg/innerring/config_test.go b/pkg/innerring/config_test.go index 0d79cab9d62..1638058ec0d 100644 --- a/pkg/innerring/config_test.go +++ b/pkg/innerring/config_test.go @@ -67,6 +67,7 @@ const validBlockchainConfigOptions = ` ping: interval: 44s timeout: 55s + set_roles_in_genesis: true ` func _newConfigFromYAML(tb testing.TB, yaml1, yaml2 string) *viper.Viper { @@ -199,6 +200,7 @@ func TestParseBlockchainConfig(t *testing.T) { 4: 1, 12: 4, }, + SetRolesInGenesis: true, }, c) }) @@ -280,6 +282,11 @@ func TestParseBlockchainConfig(t *testing.T) { {kvF("p2p.peers.max", math.MaxInt32+1)}, {kvF("p2p.peers.attempts", -1)}, {kvF("p2p.peers.attempts", math.MaxInt32+1)}, + {kvF("set_roles_in_genesis", "not a boolean")}, + {kvF("set_roles_in_genesis", 1)}, + {kvF("set_roles_in_genesis", "True")}, + {kvF("set_roles_in_genesis", "False")}, + {kvF("set_roles_in_genesis", "not a boolean")}, } { var reportMsg []string diff --git a/pkg/innerring/internal/blockchain/blockchain.go b/pkg/innerring/internal/blockchain/blockchain.go index 24087f8af78..1165b8a6fe1 100644 --- a/pkg/innerring/internal/blockchain/blockchain.go +++ b/pkg/innerring/internal/blockchain/blockchain.go @@ -12,6 +12,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/config/netmode" "github.com/nspcc-dev/neo-go/pkg/consensus" "github.com/nspcc-dev/neo-go/pkg/core" + "github.com/nspcc-dev/neo-go/pkg/core/native/noderoles" "github.com/nspcc-dev/neo-go/pkg/core/storage" "github.com/nspcc-dev/neo-go/pkg/core/storage/dbconfig" "github.com/nspcc-dev/neo-go/pkg/core/transaction" @@ -239,6 +240,13 @@ type Config struct { // must not exceed Committee length. Value for zero key (genesis height) is // required. ValidatorsHistory map[uint32]uint32 + + // Whether to designate [noderoles.P2PNotary] and [noderoles.NeoFSAlphabet] + // roles to the Committee (keep an eye on ValidatorsHistory) for genesis block + // in the RoleManagement contract. + // + // Optional: by default, roles are unset. + SetRolesInGenesis bool } // New returns new Blockchain configured by the specified Config. New panics if @@ -350,6 +358,16 @@ func New(cfg Config) (res *Blockchain, err error) { cfgBaseProto.ValidatorsCount = uint32(len(standByCommittee)) } + if cfg.SetRolesInGenesis { + // note that ValidatorsHistory or ValidatorsCount field must be set above + genesisValidatorsCount := cfgBaseProto.GetNumOfCNs(0) + cfgBaseProto.Genesis.Roles = map[noderoles.Role]keys.PublicKeys{ + // Notary service is always enabled, see below + noderoles.P2PNotary: cfg.Committee[:genesisValidatorsCount], + noderoles.NeoFSAlphabet: cfg.Committee[:genesisValidatorsCount], + } + } + cfgBaseApp := &cfgBase.ApplicationConfiguration cfgBaseApp.Relay = true cfgBaseApp.Consensus.Enabled = true