[#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 <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-07-09 14:33:11 +03:00 committed by Alex Vanin
parent af412f7874
commit 9da777ac8c
2 changed files with 60 additions and 55 deletions

View file

@ -3,6 +3,9 @@ Changelog for NeoFS Node
## [Unreleased] ## [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 ## [0.22.2] - 2021-07-07
Updated broken version of NeoFS API Go. Updated broken version of NeoFS API Go.

View file

@ -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())) fmt.Println(hex.EncodeToString(server.key.PublicKey().Bytes()))
withoutMainNet := cfg.GetBool("without_mainnet")
// get all script hashes of contracts // get all script hashes of contracts
server.contracts, err = parseContracts(cfg) server.contracts, err = parseContracts(cfg, withoutMainNet)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -342,8 +344,6 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
return nil, err return nil, err
} }
withoutMainNet := cfg.GetBool("without_mainnet")
if withoutMainNet { if withoutMainNet {
// This works as long as event Listener starts listening loop once, // This works as long as event Listener starts listening loop once,
// otherwise Server.Start will run two similar routines. // 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 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 var alphaSync event.Handler
if withoutMainNet { 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") log.Debug("alphabet keys sync is disabled")
} }
} else { } 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 alphaSync = governanceProcessor.HandleAlphabetSync
err = bindMainnetProcessor(governanceProcessor, server) err = bindMainnetProcessor(governanceProcessor, server)
if err != nil { if err != nil {
@ -625,30 +625,32 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
return nil, err return nil, err
} }
// create mainnnet neofs processor if !withoutMainNet {
neofsProcessor, err := neofs.New(&neofs.Params{ // create mainnnet neofs processor
Log: log, neofsProcessor, err := neofs.New(&neofs.Params{
PoolSize: cfg.GetInt("workers.neofs"), Log: log,
NeoFSContract: server.contracts.neofs, PoolSize: cfg.GetInt("workers.neofs"),
NeoFSIDClient: neofsIDClient, NeoFSContract: server.contracts.neofs,
BalanceClient: server.balanceClient, NeoFSIDClient: neofsIDClient,
NetmapClient: server.netmapClient, BalanceClient: server.balanceClient,
MorphClient: server.morphClient, NetmapClient: server.netmapClient,
EpochState: server, MorphClient: server.morphClient,
AlphabetState: server, EpochState: server,
Converter: &server.precision, AlphabetState: server,
MintEmitCacheSize: cfg.GetInt("emit.mint.cache_size"), Converter: &server.precision,
MintEmitThreshold: cfg.GetUint64("emit.mint.threshold"), MintEmitCacheSize: cfg.GetInt("emit.mint.cache_size"),
MintEmitValue: fixedn.Fixed8(cfg.GetInt64("emit.mint.value")), MintEmitThreshold: cfg.GetUint64("emit.mint.threshold"),
GasBalanceThreshold: cfg.GetInt64("emit.gas.balance_threshold"), MintEmitValue: fixedn.Fixed8(cfg.GetInt64("emit.mint.value")),
}) GasBalanceThreshold: cfg.GetInt64("emit.gas.balance_threshold"),
if err != nil { })
return nil, err if err != nil {
} return nil, err
}
err = bindMainnetProcessor(neofsProcessor, server) err = bindMainnetProcessor(neofsProcessor, server)
if err != nil { if err != nil {
return nil, err return nil, err
}
} }
// create alphabet processor // 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 ( var (
result = new(contracts) result = new(contracts)
err error 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") netmapContractStr := cfg.GetString("contracts.netmap")
neofsContractStr := cfg.GetString("contracts.neofs")
balanceContractStr := cfg.GetString("contracts.balance") balanceContractStr := cfg.GetString("contracts.balance")
containerContractStr := cfg.GetString("contracts.container") containerContractStr := cfg.GetString("contracts.container")
auditContractStr := cfg.GetString("contracts.audit") auditContractStr := cfg.GetString("contracts.audit")
proxyContractStr := cfg.GetString("contracts.proxy") proxyContractStr := cfg.GetString("contracts.proxy")
processingContractStr := cfg.GetString("contracts.processing")
reputationContractStr := cfg.GetString("contracts.reputation") reputationContractStr := cfg.GetString("contracts.reputation")
neofsIDContractStr := cfg.GetString("contracts.neofsid") 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) 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) result.balance, err = util.Uint160DecodeStringLE(balanceContractStr)
if err != nil { if err != nil {
return nil, fmt.Errorf("ir: can't read balance script-hash: %w", err) 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) 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) result.reputation, err = util.Uint160DecodeStringLE(reputationContractStr)
if err != nil { if err != nil {
return nil, fmt.Errorf("ir: can't read reputation script-hash: %w", err) return nil, fmt.Errorf("ir: can't read reputation script-hash: %w", err)