Skip to content

Commit

Permalink
feat/Use parsed committee as validator list (#2363)
Browse files Browse the repository at this point in the history
Closes #2311.
  • Loading branch information
roman-khimov authored Jun 5, 2023
2 parents 68d997e + a9d88ba commit 18c8c88
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Changelog for NeoFS Node

### Changed
- NeoFS CLI generates random private key automatically if wallet is omitted (#2123)
- `morph.validators` config can be omitted for IR in local consensus mode but must be non-empty otherwise (#2311)

### Fixed
- Inability to restore RPC connection after the second disconnect (#2325)
Expand Down Expand Up @@ -45,6 +46,8 @@ Changelog for NeoFS Node
$ neofs-cli util keyer <hex_key> # outputs WIF
$ neo-go wallet import -w <wallet_file> --wif <wif_key>
or just generate/use new keys.
- In local consensus mode `morph.validators` in IR's config can be omitted now, `morph.consensus.committee` will be used instead.
For detached consensus, it is a required config parameter now.

## [0.36.1] - 2023-04-26

Expand Down
2 changes: 1 addition & 1 deletion config/example/ir.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ morph:
endpoints: # List of websocket RPC endpoints in sidechain
- wss://sidechain1.fs.neo.org:30333/ws
- wss://sidechain2.fs.neo.org:30333/ws
validators: # List of hex-encoded 33-byte public keys of sidechain validators to vote for at application startup
validators: # List of hex-encoded 33-byte public keys of sidechain validators to vote for at application startup; can be omitted if equals `consensus.committee`
- 0283120f4c8c1fc1d792af5063d2def9da5fddc90bc1384de7fcfdda33c3860170
consensus: # Local consensus launch mode activated only when 'endpoint.client' is unset.
magic: 15405 # Network magic. Must be unsigned integer in range [1:4294967295]
Expand Down
24 changes: 17 additions & 7 deletions pkg/innerring/innerring.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,12 @@ func New(ctx context.Context, log *logger.Logger, cfg *viper.Viper, errChan chan
walletPath := cfg.GetString(walletPathKey)
walletPass := cfg.GetString("wallet.password")

// parse default validators
server.predefinedValidators, err = parsePredefinedValidators(cfg)
if err != nil {
return nil, fmt.Errorf("can't parse predefined validators list: %w", err)
}

// create morph client
if isLocalConsensusMode(cfg) {
// go on a local blockchain
Expand All @@ -366,6 +372,10 @@ func New(ctx context.Context, log *logger.Logger, cfg *viper.Viper, errChan chan
return nil, fmt.Errorf("invalid blockchain configuration: %w", err)
}

if len(server.predefinedValidators) == 0 {
server.predefinedValidators = cfgBlockchain.Committee
}

cfgBlockchain.Wallet.Path = walletPath
cfgBlockchain.Wallet.Password = walletPass
cfgBlockchain.ErrorListener = errChan
Expand Down Expand Up @@ -411,6 +421,10 @@ func New(ctx context.Context, log *logger.Logger, cfg *viper.Viper, errChan chan
return nil, fmt.Errorf("init internal morph client: %w", err)
}
} else {
if len(server.predefinedValidators) == 0 {
return nil, fmt.Errorf("empty '%s' list in config", validatorsConfigKey)
}

// fallback to the pure RPC architecture
acc, err := utilConfig.LoadAccount(
walletPath,
Expand Down Expand Up @@ -511,12 +525,6 @@ func New(ctx context.Context, log *logger.Logger, cfg *viper.Viper, errChan chan
}
}

// parse default validators
server.predefinedValidators, err = parsePredefinedValidators(cfg)
if err != nil {
return nil, fmt.Errorf("ir: can't parse predefined validators list: %w", err)
}

server.pubKey = server.key.PublicKey().Bytes()

auditPool, err := ants.NewPool(cfg.GetInt("audit.task.exec_pool_size"))
Expand Down Expand Up @@ -1042,8 +1050,10 @@ func createClient(ctx context.Context, p *chainParams, errChan chan<- error) (*c
)
}

const validatorsConfigKey = "morph.validators"

func parsePredefinedValidators(cfg *viper.Viper) (keys.PublicKeys, error) {
publicKeyStrings := cfg.GetStringSlice("morph.validators")
publicKeyStrings := cfg.GetStringSlice(validatorsConfigKey)

return ParsePublicKeysFromStrings(publicKeyStrings)
}
Expand Down

0 comments on commit 18c8c88

Please sign in to comment.