forked from TrueCloudLab/frostfs-node
[#170] Vote for validators on inner ring startup
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
2240cde826
commit
0b65c64e98
2 changed files with 42 additions and 2 deletions
|
@ -50,6 +50,7 @@ func defaultConfiguration(cfg *viper.Viper) {
|
||||||
cfg.SetDefault("morph.endpoint.client", "")
|
cfg.SetDefault("morph.endpoint.client", "")
|
||||||
cfg.SetDefault("morph.endpoint.notification", "")
|
cfg.SetDefault("morph.endpoint.notification", "")
|
||||||
cfg.SetDefault("morph.dial_timeout", "10s")
|
cfg.SetDefault("morph.dial_timeout", "10s")
|
||||||
|
cfg.SetDefault("morph.validators", []string{})
|
||||||
|
|
||||||
cfg.SetDefault("mainnet.endpoint.client", "")
|
cfg.SetDefault("mainnet.endpoint.client", "")
|
||||||
cfg.SetDefault("mainnet.endpoint.notification", "")
|
cfg.SetDefault("mainnet.endpoint.notification", "")
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
crypto "github.com/nspcc-dev/neofs-crypto"
|
crypto "github.com/nspcc-dev/neofs-crypto"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/innerring/invoke"
|
"github.com/nspcc-dev/neofs-node/pkg/innerring/invoke"
|
||||||
|
@ -44,6 +45,7 @@ type (
|
||||||
// internal variables
|
// internal variables
|
||||||
key *ecdsa.PrivateKey
|
key *ecdsa.PrivateKey
|
||||||
contracts *contracts
|
contracts *contracts
|
||||||
|
predefinedValidators []keys.PublicKey
|
||||||
}
|
}
|
||||||
|
|
||||||
contracts struct {
|
contracts struct {
|
||||||
|
@ -82,6 +84,14 @@ func (s *Server) Start(ctx context.Context, intError chan<- error) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// vote for sidechain validator if it is prepared in config
|
||||||
|
err = s.voteForSidechainValidator(s.predefinedValidators)
|
||||||
|
if err != nil {
|
||||||
|
// we don't stop inner ring execution on this error
|
||||||
|
s.log.Warn("can't vote for prepared validators",
|
||||||
|
zap.String("error", err.Error()))
|
||||||
|
}
|
||||||
|
|
||||||
s.localTimers.Start(ctx) // local timers start ticking
|
s.localTimers.Start(ctx) // local timers start ticking
|
||||||
|
|
||||||
morphErr := make(chan error)
|
morphErr := make(chan error)
|
||||||
|
@ -128,6 +138,12 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// parse default validators
|
||||||
|
server.predefinedValidators, err = parsePredefinedValidators(cfg)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "ir: can't parse predefined validators list")
|
||||||
|
}
|
||||||
|
|
||||||
// create local timer instance
|
// create local timer instance
|
||||||
server.localTimers = timers.New(&timers.Params{
|
server.localTimers = timers.New(&timers.Params{
|
||||||
Log: log,
|
Log: log,
|
||||||
|
@ -355,6 +371,29 @@ func parseContracts(cfg *viper.Viper) (*contracts, error) {
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parsePredefinedValidators(cfg *viper.Viper) ([]keys.PublicKey, error) {
|
||||||
|
publicKeyStrings := cfg.GetStringSlice("morph.validators")
|
||||||
|
|
||||||
|
return ParsePublicKeysFromStrings(publicKeyStrings)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ParsePublicKeysFromStrings returns slice of neo public keys from slice
|
||||||
|
// of hex encoded strings.
|
||||||
|
func ParsePublicKeysFromStrings(pubKeys []string) ([]keys.PublicKey, error) {
|
||||||
|
publicKeys := make([]keys.PublicKey, 0, len(pubKeys))
|
||||||
|
|
||||||
|
for i := range pubKeys {
|
||||||
|
key, err := keys.NewPublicKeyFromString(pubKeys[i])
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "can't decode public key")
|
||||||
|
}
|
||||||
|
|
||||||
|
publicKeys = append(publicKeys, *key)
|
||||||
|
}
|
||||||
|
|
||||||
|
return publicKeys, nil
|
||||||
|
}
|
||||||
|
|
||||||
func parseAlphabetContracts(cfg *viper.Viper) (res [7]util.Uint160, err error) {
|
func parseAlphabetContracts(cfg *viper.Viper) (res [7]util.Uint160, err error) {
|
||||||
// list of glagolic script letters that represent alphabet contracts
|
// list of glagolic script letters that represent alphabet contracts
|
||||||
glagolic := []string{"az", "buky", "vedi", "glagoli", "dobro", "jest", "zhivete"}
|
glagolic := []string{"az", "buky", "vedi", "glagoli", "dobro", "jest", "zhivete"}
|
||||||
|
|
Loading…
Reference in a new issue