Skip to content

Commit

Permalink
ir: Support P2PNotary and NeoFSAlphabet roles preset in the Sidechain
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
cthulhu-rider committed Dec 4, 2023
1 parent e7f78ae commit 5bb5eb2
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions config/example/ir.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'.

network_settings: # NeoFS network settings managed in the Netmap contract
epoch_duration: 240 # Time interval (approximate) between two adjacent NeoFS epochs measured in Sidechain blocks.
Expand Down
5 changes: 5 additions & 0 deletions pkg/innerring/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,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
Expand Down
7 changes: 7 additions & 0 deletions pkg/innerring/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const validBlockchainConfigOptions = `
ping:
interval: 44s
timeout: 55s
set_roles_in_genesis: true
`

func _newConfigFromYAML(tb testing.TB, yaml1, yaml2 string) *viper.Viper {
Expand Down Expand Up @@ -200,6 +201,7 @@ func TestParseBlockchainConfig(t *testing.T) {
4: 1,
12: 4,
},
SetRolesInGenesis: true,
}, c)
})

Expand Down Expand Up @@ -281,6 +283,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

Expand Down
17 changes: 17 additions & 0 deletions pkg/innerring/internal/blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -350,6 +358,15 @@ func New(cfg Config) (res *Blockchain, err error) {
cfgBaseProto.ValidatorsCount = uint32(len(standByCommittee))
}

if cfg.SetRolesInGenesis {
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
Expand Down

0 comments on commit 5bb5eb2

Please sign in to comment.