Skip to content

Commit 482e1f7

Browse files
committed
ir: Support P2PNotary and NeoFSAlphabet roles preset in the Sidechain
The roles are required to be set for the validators in almost all NeoFS environments. Previously, this required dedicated transaction signed by the committee majority. Starting from release v0.103.0, Neo Go support protocol extension that allows to designate various roles to the various accounts on blockchain genesis (zero height). With this feature, Inner Ring running in local consensus may be at the configuration level. Add `set_roles_in_genesis` value to `morph.consensus` section providing option to Inner Ring to start blockchain with P2PNotary and NeoFSAlphabet roles designated to the genesis block's validators. Closes #2643. Signed-off-by: Leonard Lyubich <leonard@morphbits.io>
1 parent b17cda1 commit 482e1f7

File tree

5 files changed

+34
-0
lines changed

5 files changed

+34
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Changelog for NeoFS Node
88
- Support of verified domains for the storage nodes (#2280)
99
- `neofs-lens storage status` CLI command (#2550)
1010
- Human-readable output of objects' creation timestamp to `neofs-cli container list-objects` (#2653)
11+
- Ability to preset P2PNotary and NeoFSAlphabet roles to validators at the FS chain's genesis (#2643)
1112

1213
### Fixed
1314
- `neofs-cli netmap netinfo` documentation (#2555)

config/example/ir.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ morph:
8383
ping: # Optional settings of pinging mechanism
8484
interval: 30s # Optional time period between pings. Defaults to 30s. Must not be negative
8585
timeout: 90s # Optional time period to wait for pong. Defaults to 1m. Must not be negative
86+
set_roles_in_genesis: true # Optional flag for designating P2PNotary and NeoFSAlphabet roles to all
87+
# genesis block validators. The validators depend on 'committee' and, if set, 'validators_history'.
88+
# Must be 'true' or 'false'.
8689

8790
fschain_autodeploy: true # Optional flag to run auto-deployment procedure of the FS chain. By default,
8891
# the chain is expected to be deployed/updated in the background (e.g. via NeoFS ADM tool).

pkg/innerring/config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,11 @@ func parseBlockchainConfig(v *viper.Viper, _logger *zap.Logger) (c blockchain.Co
218218
}
219219
}
220220

221+
c.SetRolesInGenesis, err = parseConfigBool(v, rootSection+".set_roles_in_genesis", "flag to set roles for the committee in the genesis block")
222+
if err != nil && !errors.Is(err, errMissingConfig) {
223+
return c, err
224+
}
225+
221226
c.Logger = _logger
222227

223228
return c, nil

pkg/innerring/config_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ const validBlockchainConfigOptions = `
6767
ping:
6868
interval: 44s
6969
timeout: 55s
70+
set_roles_in_genesis: true
7071
`
7172

7273
func _newConfigFromYAML(tb testing.TB, yaml1, yaml2 string) *viper.Viper {
@@ -199,6 +200,7 @@ func TestParseBlockchainConfig(t *testing.T) {
199200
4: 1,
200201
12: 4,
201202
},
203+
SetRolesInGenesis: true,
202204
}, c)
203205
})
204206

@@ -280,6 +282,11 @@ func TestParseBlockchainConfig(t *testing.T) {
280282
{kvF("p2p.peers.max", math.MaxInt32+1)},
281283
{kvF("p2p.peers.attempts", -1)},
282284
{kvF("p2p.peers.attempts", math.MaxInt32+1)},
285+
{kvF("set_roles_in_genesis", "not a boolean")},
286+
{kvF("set_roles_in_genesis", 1)},
287+
{kvF("set_roles_in_genesis", "True")},
288+
{kvF("set_roles_in_genesis", "False")},
289+
{kvF("set_roles_in_genesis", "not a boolean")},
283290
} {
284291
var reportMsg []string
285292

pkg/innerring/internal/blockchain/blockchain.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
1313
"github.com/nspcc-dev/neo-go/pkg/consensus"
1414
"github.com/nspcc-dev/neo-go/pkg/core"
15+
"github.com/nspcc-dev/neo-go/pkg/core/native/noderoles"
1516
"github.com/nspcc-dev/neo-go/pkg/core/storage"
1617
"github.com/nspcc-dev/neo-go/pkg/core/storage/dbconfig"
1718
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
@@ -239,6 +240,13 @@ type Config struct {
239240
// must not exceed Committee length. Value for zero key (genesis height) is
240241
// required.
241242
ValidatorsHistory map[uint32]uint32
243+
244+
// Whether to designate [noderoles.P2PNotary] and [noderoles.NeoFSAlphabet]
245+
// roles to the Committee (keep an eye on ValidatorsHistory) for genesis block
246+
// in the RoleManagement contract.
247+
//
248+
// Optional: by default, roles are unset.
249+
SetRolesInGenesis bool
242250
}
243251

244252
// New returns new Blockchain configured by the specified Config. New panics if
@@ -350,6 +358,16 @@ func New(cfg Config) (res *Blockchain, err error) {
350358
cfgBaseProto.ValidatorsCount = uint32(len(standByCommittee))
351359
}
352360

361+
if cfg.SetRolesInGenesis {
362+
// note that ValidatorsHistory or ValidatorsCount field must be set above
363+
genesisValidatorsCount := cfgBaseProto.GetNumOfCNs(0)
364+
cfgBaseProto.Genesis.Roles = map[noderoles.Role]keys.PublicKeys{
365+
// Notary service is always enabled, see below
366+
noderoles.P2PNotary: cfg.Committee[:genesisValidatorsCount],
367+
noderoles.NeoFSAlphabet: cfg.Committee[:genesisValidatorsCount],
368+
}
369+
}
370+
353371
cfgBaseApp := &cfgBase.ApplicationConfiguration
354372
cfgBaseApp.Relay = true
355373
cfgBaseApp.Consensus.Enabled = true

0 commit comments

Comments
 (0)