From f2e880465e6d46b1cb847df3b66423e6fa6febf1 Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Thu, 23 Mar 2023 16:33:54 +0300 Subject: [PATCH] [#165] ir: Refactor config default init Resolve funlen linter for defaultConfiguration function Signed-off-by: Dmitrii Stepanov --- cmd/frostfs-ir/defaults.go | 191 ++++++++++++++++++++++++------------- 1 file changed, 123 insertions(+), 68 deletions(-) diff --git a/cmd/frostfs-ir/defaults.go b/cmd/frostfs-ir/defaults.go index 9157d282..bd374fcb 100644 --- a/cmd/frostfs-ir/defaults.go +++ b/cmd/frostfs-ir/defaults.go @@ -41,33 +41,122 @@ func newConfig(path, directory string) (*viper.Viper, error) { return v, err } -// nolint: funlen func defaultConfiguration(cfg *viper.Viper) { cfg.SetDefault("logger.level", "info") - cfg.SetDefault("pprof.address", "localhost:6060") - cfg.SetDefault("pprof.shutdown_timeout", "30s") + setPprofDefaults(cfg) - cfg.SetDefault("prometheus.address", "localhost:9090") - cfg.SetDefault("prometheus.shutdown_timeout", "30s") + setPrometheusDefaults(cfg) cfg.SetDefault("without_mainnet", false) cfg.SetDefault("node.persistent_state.path", ".frostfs-ir-state") - cfg.SetDefault("morph.endpoint.client", []string{}) - cfg.SetDefault("morph.dial_timeout", 15*time.Second) - cfg.SetDefault("morph.validators", []string{}) - cfg.SetDefault("morph.switch_interval", 2*time.Minute) + setMorphDefaults(cfg) - cfg.SetDefault("mainnet.endpoint.client", []string{}) - cfg.SetDefault("mainnet.dial_timeout", 15*time.Second) - cfg.SetDefault("mainnet.switch_interval", 2*time.Minute) + setMainNetDefaults(cfg) - cfg.SetDefault("wallet.path", "") // inner ring node NEP-6 wallet - cfg.SetDefault("wallet.address", "") // account address - cfg.SetDefault("wallet.password", "") // password + setWalletDefaults(cfg) + setContractsDefaults(cfg) + + setTimersDefaults(cfg) + + setWorkersDefaults(cfg) + + setNetmapCleanerDefaults(cfg) + + setEmitDefaults(cfg) + + setAuditDefaults(cfg) + + setSettlementDefaults(cfg) + + cfg.SetDefault("indexer.cache_timeout", 15*time.Second) + + cfg.SetDefault("locode.db.path", "") + + setFeeDefaults(cfg) + + setControlDefaults(cfg) + + cfg.SetDefault("governance.disable", false) +} + +func setControlDefaults(cfg *viper.Viper) { + cfg.SetDefault("control.authorized_keys", []string{}) + cfg.SetDefault("control.grpc.endpoint", "") +} + +func setFeeDefaults(cfg *viper.Viper) { + // extra fee values for working mode without notary contract + cfg.SetDefault("fee.main_chain", 5000_0000) // 0.5 Fixed8 + cfg.SetDefault("fee.side_chain", 2_0000_0000) // 2.0 Fixed8 + cfg.SetDefault("fee.named_container_register", 25_0000_0000) // 25.0 Fixed8 +} + +func setSettlementDefaults(cfg *viper.Viper) { + cfg.SetDefault("settlement.basic_income_rate", 0) + cfg.SetDefault("settlement.audit_fee", 0) +} + +func setAuditDefaults(cfg *viper.Viper) { + cfg.SetDefault("audit.task.exec_pool_size", 10) + cfg.SetDefault("audit.task.queue_capacity", 100) + cfg.SetDefault("audit.timeout.get", "5s") + cfg.SetDefault("audit.timeout.head", "5s") + cfg.SetDefault("audit.timeout.rangehash", "5s") + cfg.SetDefault("audit.timeout.search", "10s") + cfg.SetDefault("audit.pdp.max_sleep_interval", "5s") + cfg.SetDefault("audit.pdp.pairs_pool_size", "10") + cfg.SetDefault("audit.por.pool_size", "10") +} + +func setEmitDefaults(cfg *viper.Viper) { + cfg.SetDefault("emit.storage.amount", 0) + cfg.SetDefault("emit.mint.cache_size", 1000) + cfg.SetDefault("emit.mint.threshold", 1) + cfg.SetDefault("emit.mint.value", 20000000) // 0.2 Fixed8 + cfg.SetDefault("emit.gas.balance_threshold", 0) + cfg.SetDefault("emit.extra_wallets", nil) +} + +func setPprofDefaults(cfg *viper.Viper) { + cfg.SetDefault("pprof.address", "localhost:6060") + cfg.SetDefault("pprof.shutdown_timeout", "30s") +} + +func setPrometheusDefaults(cfg *viper.Viper) { + cfg.SetDefault("prometheus.address", "localhost:9090") + cfg.SetDefault("prometheus.shutdown_timeout", "30s") +} + +func setNetmapCleanerDefaults(cfg *viper.Viper) { + cfg.SetDefault("netmap_cleaner.enabled", true) + cfg.SetDefault("netmap_cleaner.threshold", 3) +} + +func setWorkersDefaults(cfg *viper.Viper) { + cfg.SetDefault("workers.netmap", "10") + cfg.SetDefault("workers.balance", "10") + cfg.SetDefault("workers.frostfs", "10") + cfg.SetDefault("workers.container", "10") + cfg.SetDefault("workers.alphabet", "10") + cfg.SetDefault("workers.reputation", "10") + cfg.SetDefault("workers.subnet", "10") +} + +func setTimersDefaults(cfg *viper.Viper) { + cfg.SetDefault("timers.emit", "0") + cfg.SetDefault("timers.stop_estimation.mul", 1) + cfg.SetDefault("timers.stop_estimation.div", 4) + cfg.SetDefault("timers.collect_basic_income.mul", 1) + cfg.SetDefault("timers.collect_basic_income.div", 2) + cfg.SetDefault("timers.distribute_basic_income.mul", 3) + cfg.SetDefault("timers.distribute_basic_income.div", 4) +} + +func setContractsDefaults(cfg *viper.Viper) { cfg.SetDefault("contracts.netmap", "") cfg.SetDefault("contracts.frostfs", "") cfg.SetDefault("contracts.balance", "") @@ -78,57 +167,23 @@ func defaultConfiguration(cfg *viper.Viper) { cfg.SetDefault("contracts.reputation", "") cfg.SetDefault("contracts.subnet", "") cfg.SetDefault("contracts.proxy", "") - - cfg.SetDefault("timers.emit", "0") - cfg.SetDefault("timers.stop_estimation.mul", 1) - cfg.SetDefault("timers.stop_estimation.div", 4) - cfg.SetDefault("timers.collect_basic_income.mul", 1) - cfg.SetDefault("timers.collect_basic_income.div", 2) - cfg.SetDefault("timers.distribute_basic_income.mul", 3) - cfg.SetDefault("timers.distribute_basic_income.div", 4) - - cfg.SetDefault("workers.netmap", "10") - cfg.SetDefault("workers.balance", "10") - cfg.SetDefault("workers.frostfs", "10") - cfg.SetDefault("workers.container", "10") - cfg.SetDefault("workers.alphabet", "10") - cfg.SetDefault("workers.reputation", "10") - cfg.SetDefault("workers.subnet", "10") - - cfg.SetDefault("netmap_cleaner.enabled", true) - cfg.SetDefault("netmap_cleaner.threshold", 3) - - cfg.SetDefault("emit.storage.amount", 0) - cfg.SetDefault("emit.mint.cache_size", 1000) - cfg.SetDefault("emit.mint.threshold", 1) - cfg.SetDefault("emit.mint.value", 20000000) // 0.2 Fixed8 - cfg.SetDefault("emit.gas.balance_threshold", 0) - cfg.SetDefault("emit.extra_wallets", nil) - - cfg.SetDefault("audit.task.exec_pool_size", 10) - cfg.SetDefault("audit.task.queue_capacity", 100) - cfg.SetDefault("audit.timeout.get", "5s") - cfg.SetDefault("audit.timeout.head", "5s") - cfg.SetDefault("audit.timeout.rangehash", "5s") - cfg.SetDefault("audit.timeout.search", "10s") - cfg.SetDefault("audit.pdp.max_sleep_interval", "5s") - cfg.SetDefault("audit.pdp.pairs_pool_size", "10") - cfg.SetDefault("audit.por.pool_size", "10") - - cfg.SetDefault("settlement.basic_income_rate", 0) - cfg.SetDefault("settlement.audit_fee", 0) - - cfg.SetDefault("indexer.cache_timeout", 15*time.Second) - - cfg.SetDefault("locode.db.path", "") - - // extra fee values for working mode without notary contract - cfg.SetDefault("fee.main_chain", 5000_0000) // 0.5 Fixed8 - cfg.SetDefault("fee.side_chain", 2_0000_0000) // 2.0 Fixed8 - cfg.SetDefault("fee.named_container_register", 25_0000_0000) // 25.0 Fixed8 - - cfg.SetDefault("control.authorized_keys", []string{}) - cfg.SetDefault("control.grpc.endpoint", "") - - cfg.SetDefault("governance.disable", false) +} + +func setWalletDefaults(cfg *viper.Viper) { + cfg.SetDefault("wallet.path", "") // inner ring node NEP-6 wallet + cfg.SetDefault("wallet.address", "") // account address + cfg.SetDefault("wallet.password", "") // password +} + +func setMainNetDefaults(cfg *viper.Viper) { + cfg.SetDefault("mainnet.endpoint.client", []string{}) + cfg.SetDefault("mainnet.dial_timeout", 15*time.Second) + cfg.SetDefault("mainnet.switch_interval", 2*time.Minute) +} + +func setMorphDefaults(cfg *viper.Viper) { + cfg.SetDefault("morph.endpoint.client", []string{}) + cfg.SetDefault("morph.dial_timeout", 15*time.Second) + cfg.SetDefault("morph.validators", []string{}) + cfg.SetDefault("morph.switch_interval", 2*time.Minute) }