@@ -8,14 +8,11 @@ import (
88
99 "github.com/cosmos/cosmos-sdk/telemetry"
1010
11- serverconfig "github.com/cosmos/cosmos-sdk/server/config"
12- storetypes "github.com/cosmos/cosmos-sdk/store/types"
11+ "github.com/cosmos/cosmos-sdk/server/config"
1312 sdk "github.com/cosmos/cosmos-sdk/types"
1413)
1514
1615const (
17- defaultMinGasPrices = ""
18-
1916 // DefaultGRPCAddress is the default address the gRPC server binds to.
2017 DefaultGRPCAddress = "0.0.0.0:9900"
2118
@@ -26,67 +23,6 @@ const (
2623 DefaultEVMWSAddress = "0.0.0.0:1318"
2724)
2825
29- // BaseConfig defines the server's basic configuration
30- type BaseConfig struct {
31- // The minimum gas prices a validator is willing to accept for processing a
32- // transaction. A transaction's fees must meet the minimum of any denomination
33- // specified in this config (e.g. 0.25token1;0.0001token2).
34- MinGasPrices string `mapstructure:"minimum-gas-prices"`
35-
36- Pruning string `mapstructure:"pruning"`
37- PruningKeepRecent string `mapstructure:"pruning-keep-recent"`
38- PruningKeepEvery string `mapstructure:"pruning-keep-every"`
39- PruningInterval string `mapstructure:"pruning-interval"`
40-
41- // HaltHeight contains a non-zero block height at which a node will gracefully
42- // halt and shutdown that can be used to assist upgrades and testing.
43- //
44- // Note: Commitment of state will be attempted on the corresponding block.
45- HaltHeight uint64 `mapstructure:"halt-height"`
46-
47- // HaltTime contains a non-zero minimum block time (in Unix seconds) at which
48- // a node will gracefully halt and shutdown that can be used to assist
49- // upgrades and testing.
50- //
51- // Note: Commitment of state will be attempted on the corresponding block.
52- HaltTime uint64 `mapstructure:"halt-time"`
53-
54- // MinRetainBlocks defines the minimum block height offset from the current
55- // block being committed, such that blocks past this offset may be pruned
56- // from Tendermint. It is used as part of the process of determining the
57- // ResponseCommit.RetainHeight value during ABCI Commit. A value of 0 indicates
58- // that no blocks should be pruned.
59- //
60- // This configuration value is only responsible for pruning Tendermint blocks.
61- // It has no bearing on application state pruning which is determined by the
62- // "pruning-*" configurations.
63- //
64- // Note: Tendermint block pruning is dependant on this parameter in conunction
65- // with the unbonding (safety threshold) period, state pruning and state sync
66- // snapshot parameters to determine the correct minimum value of
67- // ResponseCommit.RetainHeight.
68- MinRetainBlocks uint64 `mapstructure:"min-retain-blocks"`
69-
70- // InterBlockCache enables inter-block caching.
71- InterBlockCache bool `mapstructure:"inter-block-cache"`
72-
73- // IndexEvents defines the set of events in the form {eventType}.{attributeKey},
74- // which informs Tendermint what to index. If empty, all events will be indexed.
75- IndexEvents []string `mapstructure:"index-events"`
76- }
77-
78- // APIConfig defines the API listener configuration.
79- type APIConfig = serverconfig.APIConfig
80-
81- // GRPCConfig defines configuration for the gRPC server.
82- type GRPCConfig struct {
83- // Enable defines if the gRPC server should be enabled.
84- Enable bool `mapstructure:"enable"`
85-
86- // Address defines the API server to listen on
87- Address string `mapstructure:"address"`
88- }
89-
9026// EVMRPCConfig defines configuration for the EVM RPC server.
9127type EVMRPCConfig struct {
9228 // Enable defines if the EVM RPC server should be enabled.
@@ -97,27 +33,26 @@ type EVMRPCConfig struct {
9733 WsAddress string `mapstructure:"ws-address"`
9834}
9935
100- // StateSyncConfig defines the state sync snapshot configuration.
101- type StateSyncConfig struct {
102- // SnapshotInterval sets the interval at which state sync snapshots are taken.
103- // 0 disables snapshots. Must be a multiple of PruningKeepEvery.
104- SnapshotInterval uint64 `mapstructure:"snapshot-interval"`
105-
106- // SnapshotKeepRecent sets the number of recent state sync snapshots to keep.
107- // 0 keeps all snapshots.
108- SnapshotKeepRecent uint32 `mapstructure:"snapshot-keep-recent"`
109- }
110-
11136// Config defines the server's top level configuration
11237type Config struct {
113- BaseConfig `mapstructure:",squash"`
38+ config. BaseConfig `mapstructure:",squash"`
11439
11540 // Telemetry defines the application telemetry configuration
116- Telemetry telemetry.Config `mapstructure:"telemetry"`
117- API APIConfig `mapstructure:"api"`
118- GRPC GRPCConfig `mapstructure:"grpc"`
119- EVMRPC EVMRPCConfig `mapstructure:"evm-rpc"`
120- StateSync StateSyncConfig `mapstructure:"state-sync"`
41+ Telemetry telemetry.Config `mapstructure:"telemetry"`
42+ API config.APIConfig `mapstructure:"api"`
43+ GRPC config.GRPCConfig `mapstructure:"grpc"`
44+ EVMRPC EVMRPCConfig `mapstructure:"evm-rpc"`
45+ StateSync config.StateSyncConfig `mapstructure:"state-sync"`
46+ }
47+
48+ func (c * Config ) ToSDKConfig () * config.Config {
49+ return & config.Config {
50+ BaseConfig : c .BaseConfig ,
51+ Telemetry : c .Telemetry ,
52+ API : c .API ,
53+ GRPC : c .GRPC ,
54+ StateSync : c .StateSync ,
55+ }
12156}
12257
12358// SetMinGasPrices sets the validator's minimum gas prices.
@@ -149,95 +84,36 @@ func (c *Config) GetMinGasPrices() sdk.DecCoins {
14984
15085// DefaultConfig returns server's default configuration.
15186func DefaultConfig () * Config {
152-
87+ cfg := config . DefaultConfig ()
15388 return & Config {
154- BaseConfig : BaseConfig {
155- MinGasPrices : defaultMinGasPrices ,
156- InterBlockCache : true ,
157- Pruning : storetypes .PruningOptionNothing ,
158- PruningKeepRecent : "0" ,
159- PruningKeepEvery : "0" ,
160- PruningInterval : "0" ,
161- MinRetainBlocks : 0 ,
162- IndexEvents : make ([]string , 0 ),
163- },
164- Telemetry : telemetry.Config {
165- Enabled : false ,
166- GlobalLabels : [][]string {},
167- },
168- API : APIConfig {
169- Enable : true ,
170- Swagger : true ,
171- Address : "tcp://0.0.0.0:10337" ,
172- MaxOpenConnections : 1000 ,
173- RPCReadTimeout : 10 ,
174- RPCMaxBodyBytes : 1000000 ,
175- },
176- GRPC : GRPCConfig {
177- Enable : true ,
178- Address : DefaultGRPCAddress ,
179- },
89+ BaseConfig : cfg .BaseConfig ,
90+ Telemetry : cfg .Telemetry ,
91+ API : cfg .API ,
92+ GRPC : cfg .GRPC ,
18093 EVMRPC : EVMRPCConfig {
18194 Enable : true ,
18295 RPCAddress : DefaultEVMAddress ,
18396 WsAddress : DefaultEVMWSAddress ,
18497 },
185- StateSync : StateSyncConfig {
186- SnapshotInterval : 0 ,
187- SnapshotKeepRecent : 2 ,
188- },
98+ StateSync : cfg .StateSync ,
18999 }
190100}
191101
192102// GetConfig returns a fully parsed Config object.
193103func GetConfig (v * viper.Viper ) Config {
194- globalLabelsRaw := v . Get ( "telemetry.global-labels" ).([] interface {})
195- globalLabels := make ([][] string , 0 , len ( globalLabelsRaw ) )
104+
105+ cfg := config . GetConfig ( v )
196106
197107 return Config {
198- BaseConfig : BaseConfig {
199- MinGasPrices : v .GetString ("minimum-gas-prices" ),
200- InterBlockCache : v .GetBool ("inter-block-cache" ),
201- Pruning : v .GetString ("pruning" ),
202- PruningKeepRecent : v .GetString ("pruning-keep-recent" ),
203- PruningKeepEvery : v .GetString ("pruning-keep-every" ),
204- PruningInterval : v .GetString ("pruning-interval" ),
205- HaltHeight : v .GetUint64 ("halt-height" ),
206- HaltTime : v .GetUint64 ("halt-time" ),
207- IndexEvents : v .GetStringSlice ("index-events" ),
208- MinRetainBlocks : v .GetUint64 ("min-retain-blocks" ),
209- },
210- Telemetry : telemetry.Config {
211- ServiceName : v .GetString ("telemetry.service-name" ),
212- Enabled : v .GetBool ("telemetry.enabled" ),
213- EnableHostname : v .GetBool ("telemetry.enable-hostname" ),
214- EnableHostnameLabel : v .GetBool ("telemetry.enable-hostname-label" ),
215- EnableServiceLabel : v .GetBool ("telemetry.enable-service-label" ),
216- PrometheusRetentionTime : v .GetInt64 ("telemetry.prometheus-retention-time" ),
217- GlobalLabels : globalLabels ,
218- },
219- API : APIConfig {
220- Enable : v .GetBool ("api.enable" ),
221- Swagger : v .GetBool ("api.swagger" ),
222- Address : v .GetString ("api.address" ),
223- MaxOpenConnections : v .GetUint ("api.max-open-connections" ),
224- RPCReadTimeout : v .GetUint ("api.rpc-read-timeout" ),
225- RPCWriteTimeout : v .GetUint ("api.rpc-write-timeout" ),
226- RPCMaxBodyBytes : v .GetUint ("api.rpc-max-body-bytes" ),
227- EnableUnsafeCORS : v .GetBool ("api.enabled-unsafe-cors" ),
228- },
229- GRPC : GRPCConfig {
230- Enable : v .GetBool ("grpc.enable" ),
231- Address : v .GetString ("grpc.address" ),
232- },
108+ BaseConfig : cfg .BaseConfig ,
109+ Telemetry : cfg .Telemetry ,
110+ API : cfg .API ,
111+ GRPC : cfg .GRPC ,
233112 EVMRPC : EVMRPCConfig {
234113 Enable : v .GetBool ("evm-rpc.enable" ),
235114 RPCAddress : v .GetString ("evm-rpc.address" ),
236115 WsAddress : v .GetString ("evm-rpc.ws-address" ),
237116 },
238- StateSync : StateSyncConfig {
239- SnapshotInterval : v .GetUint64 ("state-sync.snapshot-interval" ),
240- SnapshotKeepRecent : v .GetUint32 ("state-sync.snapshot-keep-recent" ),
241- },
117+ StateSync : cfg .StateSync ,
242118 }
243119}
0 commit comments