From 9da777ac8ce5a7a5fbcb9e39b11f27e4dad7b8c4 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Fri, 9 Jul 2021 14:33:11 +0300 Subject: [PATCH] [#681] ir: Do not require MainNet attributes If `WITHOUT_MAINNET` environmental variable is `true`: - Do not read `NeoFS` and `processing` script-hashes from envs; - Do not init Governance processor; - Do not init NeoFS processor. Signed-off-by: Pavel Karpy --- CHANGELOG.md | 3 + pkg/innerring/innerring.go | 112 +++++++++++++++++++------------------ 2 files changed, 60 insertions(+), 55 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b96b45bc4..3b9512c6d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ Changelog for NeoFS Node ## [Unreleased] +### Fixed +- Do not require MainNet attributes in "Without MainNet" mode ([#663](https://github.com/nspcc-dev/neofs-node/issues/663)). + ## [0.22.2] - 2021-07-07 Updated broken version of NeoFS API Go. diff --git a/pkg/innerring/innerring.go b/pkg/innerring/innerring.go index 5a945a910..e6d328f9e 100644 --- a/pkg/innerring/innerring.go +++ b/pkg/innerring/innerring.go @@ -305,8 +305,10 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error fmt.Println(hex.EncodeToString(server.key.PublicKey().Bytes())) + withoutMainNet := cfg.GetBool("without_mainnet") + // get all script hashes of contracts - server.contracts, err = parseContracts(cfg) + server.contracts, err = parseContracts(cfg, withoutMainNet) if err != nil { return nil, err } @@ -342,8 +344,6 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error return nil, err } - withoutMainNet := cfg.GetBool("without_mainnet") - if withoutMainNet { // This works as long as event Listener starts listening loop once, // otherwise Server.Start will run two similar routines. @@ -525,22 +525,6 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error return nil, err } - // create governance processor - governanceProcessor, err := governance.New(&governance.Params{ - Log: log, - NeoFSClient: neofsClient, - NetmapClient: server.netmapClient, - AlphabetState: server, - EpochState: server, - Voter: server, - MorphClient: server.morphClient, - MainnetClient: server.mainnetClient, - NotaryDisabled: server.sideNotaryConfig.disabled, - }) - if err != nil { - return nil, err - } - var alphaSync event.Handler if withoutMainNet { @@ -548,6 +532,22 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error log.Debug("alphabet keys sync is disabled") } } else { + // create governance processor + governanceProcessor, err := governance.New(&governance.Params{ + Log: log, + NeoFSClient: neofsClient, + NetmapClient: server.netmapClient, + AlphabetState: server, + EpochState: server, + Voter: server, + MorphClient: server.morphClient, + MainnetClient: server.mainnetClient, + NotaryDisabled: server.sideNotaryConfig.disabled, + }) + if err != nil { + return nil, err + } + alphaSync = governanceProcessor.HandleAlphabetSync err = bindMainnetProcessor(governanceProcessor, server) if err != nil { @@ -625,30 +625,32 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error return nil, err } - // create mainnnet neofs processor - neofsProcessor, err := neofs.New(&neofs.Params{ - Log: log, - PoolSize: cfg.GetInt("workers.neofs"), - NeoFSContract: server.contracts.neofs, - NeoFSIDClient: neofsIDClient, - BalanceClient: server.balanceClient, - NetmapClient: server.netmapClient, - MorphClient: server.morphClient, - EpochState: server, - AlphabetState: server, - Converter: &server.precision, - MintEmitCacheSize: cfg.GetInt("emit.mint.cache_size"), - MintEmitThreshold: cfg.GetUint64("emit.mint.threshold"), - MintEmitValue: fixedn.Fixed8(cfg.GetInt64("emit.mint.value")), - GasBalanceThreshold: cfg.GetInt64("emit.gas.balance_threshold"), - }) - if err != nil { - return nil, err - } + if !withoutMainNet { + // create mainnnet neofs processor + neofsProcessor, err := neofs.New(&neofs.Params{ + Log: log, + PoolSize: cfg.GetInt("workers.neofs"), + NeoFSContract: server.contracts.neofs, + NeoFSIDClient: neofsIDClient, + BalanceClient: server.balanceClient, + NetmapClient: server.netmapClient, + MorphClient: server.morphClient, + EpochState: server, + AlphabetState: server, + Converter: &server.precision, + MintEmitCacheSize: cfg.GetInt("emit.mint.cache_size"), + MintEmitThreshold: cfg.GetUint64("emit.mint.threshold"), + MintEmitValue: fixedn.Fixed8(cfg.GetInt64("emit.mint.value")), + GasBalanceThreshold: cfg.GetInt64("emit.gas.balance_threshold"), + }) + if err != nil { + return nil, err + } - err = bindMainnetProcessor(neofsProcessor, server) - if err != nil { - return nil, err + err = bindMainnetProcessor(neofsProcessor, server) + if err != nil { + return nil, err + } } // create alphabet processor @@ -828,19 +830,29 @@ func createClient(ctx context.Context, p *chainParams, notaryOpts ...client.Nota ) } -func parseContracts(cfg *viper.Viper) (*contracts, error) { +func parseContracts(cfg *viper.Viper, withoutMainNet bool) (*contracts, error) { var ( result = new(contracts) err error ) + if !withoutMainNet { + result.neofs, err = util.Uint160DecodeStringLE(cfg.GetString("contracts.neofs")) + if err != nil { + return nil, fmt.Errorf("ir: can't read neofs script-hash: %w", err) + } + + result.processing, err = util.Uint160DecodeStringLE(cfg.GetString("contracts.processing")) + if err != nil { + return nil, fmt.Errorf("ir: can't read processing script-hash: %w", err) + } + } + netmapContractStr := cfg.GetString("contracts.netmap") - neofsContractStr := cfg.GetString("contracts.neofs") balanceContractStr := cfg.GetString("contracts.balance") containerContractStr := cfg.GetString("contracts.container") auditContractStr := cfg.GetString("contracts.audit") proxyContractStr := cfg.GetString("contracts.proxy") - processingContractStr := cfg.GetString("contracts.processing") reputationContractStr := cfg.GetString("contracts.reputation") neofsIDContractStr := cfg.GetString("contracts.neofsid") @@ -849,11 +861,6 @@ func parseContracts(cfg *viper.Viper) (*contracts, error) { return nil, fmt.Errorf("ir: can't read netmap script-hash: %w", err) } - result.neofs, err = util.Uint160DecodeStringLE(neofsContractStr) - if err != nil { - return nil, fmt.Errorf("ir: can't read neofs script-hash: %w", err) - } - result.balance, err = util.Uint160DecodeStringLE(balanceContractStr) if err != nil { return nil, fmt.Errorf("ir: can't read balance script-hash: %w", err) @@ -874,11 +881,6 @@ func parseContracts(cfg *viper.Viper) (*contracts, error) { return nil, fmt.Errorf("ir: can't read proxy script-hash: %w", err) } - result.processing, err = util.Uint160DecodeStringLE(processingContractStr) - if err != nil { - return nil, fmt.Errorf("ir: can't read processing script-hash: %w", err) - } - result.reputation, err = util.Uint160DecodeStringLE(reputationContractStr) if err != nil { return nil, fmt.Errorf("ir: can't read reputation script-hash: %w", err)