github.com/cosmos/cosmos-sdk@v0.50.10/server/config/toml.go (about) 1 package config 2 3 import ( 4 "bytes" 5 "fmt" 6 "os" 7 "text/template" 8 9 "github.com/spf13/viper" 10 ) 11 12 const DefaultConfigTemplate = `# This is a TOML config file. 13 # For more information, see https://github.com/toml-lang/toml 14 15 ############################################################################### 16 ### Base Configuration ### 17 ############################################################################### 18 19 # The minimum gas prices a validator is willing to accept for processing a 20 # transaction. A transaction's fees must meet the minimum of any denomination 21 # specified in this config (e.g. 0.25token1,0.0001token2). 22 minimum-gas-prices = "{{ .BaseConfig.MinGasPrices }}" 23 24 # The maximum gas a query coming over rest/grpc may consume. 25 # If this is set to zero, the query can consume an unbounded amount of gas. 26 query-gas-limit = "{{ .BaseConfig.QueryGasLimit }}" 27 28 # default: the last 362880 states are kept, pruning at 10 block intervals 29 # nothing: all historic states will be saved, nothing will be deleted (i.e. archiving node) 30 # everything: 2 latest states will be kept; pruning at 10 block intervals. 31 # custom: allow pruning options to be manually specified through 'pruning-keep-recent', and 'pruning-interval' 32 pruning = "{{ .BaseConfig.Pruning }}" 33 34 # These are applied if and only if the pruning strategy is custom. 35 pruning-keep-recent = "{{ .BaseConfig.PruningKeepRecent }}" 36 pruning-interval = "{{ .BaseConfig.PruningInterval }}" 37 38 # HaltHeight contains a non-zero block height at which a node will gracefully 39 # halt and shutdown that can be used to assist upgrades and testing. 40 # 41 # Note: Commitment of state will be attempted on the corresponding block. 42 halt-height = {{ .BaseConfig.HaltHeight }} 43 44 # HaltTime contains a non-zero minimum block time (in Unix seconds) at which 45 # a node will gracefully halt and shutdown that can be used to assist upgrades 46 # and testing. 47 # 48 # Note: Commitment of state will be attempted on the corresponding block. 49 halt-time = {{ .BaseConfig.HaltTime }} 50 51 # MinRetainBlocks defines the minimum block height offset from the current 52 # block being committed, such that all blocks past this offset are pruned 53 # from CometBFT. It is used as part of the process of determining the 54 # ResponseCommit.RetainHeight value during ABCI Commit. A value of 0 indicates 55 # that no blocks should be pruned. 56 # 57 # This configuration value is only responsible for pruning CometBFT blocks. 58 # It has no bearing on application state pruning which is determined by the 59 # "pruning-*" configurations. 60 # 61 # Note: CometBFT block pruning is dependant on this parameter in conjunction 62 # with the unbonding (safety threshold) period, state pruning and state sync 63 # snapshot parameters to determine the correct minimum value of 64 # ResponseCommit.RetainHeight. 65 min-retain-blocks = {{ .BaseConfig.MinRetainBlocks }} 66 67 # InterBlockCache enables inter-block caching. 68 inter-block-cache = {{ .BaseConfig.InterBlockCache }} 69 70 # IndexEvents defines the set of events in the form {eventType}.{attributeKey}, 71 # which informs CometBFT what to index. If empty, all events will be indexed. 72 # 73 # Example: 74 # ["message.sender", "message.recipient"] 75 index-events = [{{ range .BaseConfig.IndexEvents }}{{ printf "%q, " . }}{{end}}] 76 77 # IavlCacheSize set the size of the iavl tree cache (in number of nodes). 78 iavl-cache-size = {{ .BaseConfig.IAVLCacheSize }} 79 80 # IAVLDisableFastNode enables or disables the fast node feature of IAVL. 81 # Default is false. 82 iavl-disable-fastnode = {{ .BaseConfig.IAVLDisableFastNode }} 83 84 # AppDBBackend defines the database backend type to use for the application and snapshots DBs. 85 # An empty string indicates that a fallback will be used. 86 # The fallback is the db_backend value set in CometBFT's config.toml. 87 app-db-backend = "{{ .BaseConfig.AppDBBackend }}" 88 89 ############################################################################### 90 ### Telemetry Configuration ### 91 ############################################################################### 92 93 [telemetry] 94 95 # Prefixed with keys to separate services. 96 service-name = "{{ .Telemetry.ServiceName }}" 97 98 # Enabled enables the application telemetry functionality. When enabled, 99 # an in-memory sink is also enabled by default. Operators may also enabled 100 # other sinks such as Prometheus. 101 enabled = {{ .Telemetry.Enabled }} 102 103 # Enable prefixing gauge values with hostname. 104 enable-hostname = {{ .Telemetry.EnableHostname }} 105 106 # Enable adding hostname to labels. 107 enable-hostname-label = {{ .Telemetry.EnableHostnameLabel }} 108 109 # Enable adding service to labels. 110 enable-service-label = {{ .Telemetry.EnableServiceLabel }} 111 112 # PrometheusRetentionTime, when positive, enables a Prometheus metrics sink. 113 prometheus-retention-time = {{ .Telemetry.PrometheusRetentionTime }} 114 115 # GlobalLabels defines a global set of name/value label tuples applied to all 116 # metrics emitted using the wrapper functions defined in telemetry package. 117 # 118 # Example: 119 # [["chain_id", "cosmoshub-1"]] 120 global-labels = [{{ range $k, $v := .Telemetry.GlobalLabels }} 121 ["{{index $v 0 }}", "{{ index $v 1}}"],{{ end }} 122 ] 123 124 # MetricsSink defines the type of metrics sink to use. 125 metrics-sink = "{{ .Telemetry.MetricsSink }}" 126 127 # StatsdAddr defines the address of a statsd server to send metrics to. 128 # Only utilized if MetricsSink is set to "statsd" or "dogstatsd". 129 statsd-addr = "{{ .Telemetry.StatsdAddr }}" 130 131 # DatadogHostname defines the hostname to use when emitting metrics to 132 # Datadog. Only utilized if MetricsSink is set to "dogstatsd". 133 datadog-hostname = "{{ .Telemetry.DatadogHostname }}" 134 135 ############################################################################### 136 ### API Configuration ### 137 ############################################################################### 138 139 [api] 140 141 # Enable defines if the API server should be enabled. 142 enable = {{ .API.Enable }} 143 144 # Swagger defines if swagger documentation should automatically be registered. 145 swagger = {{ .API.Swagger }} 146 147 # Address defines the API server to listen on. 148 address = "{{ .API.Address }}" 149 150 # MaxOpenConnections defines the number of maximum open connections. 151 max-open-connections = {{ .API.MaxOpenConnections }} 152 153 # RPCReadTimeout defines the CometBFT RPC read timeout (in seconds). 154 rpc-read-timeout = {{ .API.RPCReadTimeout }} 155 156 # RPCWriteTimeout defines the CometBFT RPC write timeout (in seconds). 157 rpc-write-timeout = {{ .API.RPCWriteTimeout }} 158 159 # RPCMaxBodyBytes defines the CometBFT maximum request body (in bytes). 160 rpc-max-body-bytes = {{ .API.RPCMaxBodyBytes }} 161 162 # EnableUnsafeCORS defines if CORS should be enabled (unsafe - use it at your own risk). 163 enabled-unsafe-cors = {{ .API.EnableUnsafeCORS }} 164 165 ############################################################################### 166 ### gRPC Configuration ### 167 ############################################################################### 168 169 [grpc] 170 171 # Enable defines if the gRPC server should be enabled. 172 enable = {{ .GRPC.Enable }} 173 174 # Address defines the gRPC server address to bind to. 175 address = "{{ .GRPC.Address }}" 176 177 # MaxRecvMsgSize defines the max message size in bytes the server can receive. 178 # The default value is 10MB. 179 max-recv-msg-size = "{{ .GRPC.MaxRecvMsgSize }}" 180 181 # MaxSendMsgSize defines the max message size in bytes the server can send. 182 # The default value is math.MaxInt32. 183 max-send-msg-size = "{{ .GRPC.MaxSendMsgSize }}" 184 185 ############################################################################### 186 ### gRPC Web Configuration ### 187 ############################################################################### 188 189 [grpc-web] 190 191 # GRPCWebEnable defines if the gRPC-web should be enabled. 192 # NOTE: gRPC must also be enabled, otherwise, this configuration is a no-op. 193 # NOTE: gRPC-Web uses the same address as the API server. 194 enable = {{ .GRPCWeb.Enable }} 195 196 ############################################################################### 197 ### State Sync Configuration ### 198 ############################################################################### 199 200 # State sync snapshots allow other nodes to rapidly join the network without replaying historical 201 # blocks, instead downloading and applying a snapshot of the application state at a given height. 202 [state-sync] 203 204 # snapshot-interval specifies the block interval at which local state sync snapshots are 205 # taken (0 to disable). 206 snapshot-interval = {{ .StateSync.SnapshotInterval }} 207 208 # snapshot-keep-recent specifies the number of recent snapshots to keep and serve (0 to keep all). 209 snapshot-keep-recent = {{ .StateSync.SnapshotKeepRecent }} 210 211 ############################################################################### 212 ### State Streaming ### 213 ############################################################################### 214 215 # Streaming allows nodes to stream state to external systems. 216 [streaming] 217 218 # streaming.abci specifies the configuration for the ABCI Listener streaming service. 219 [streaming.abci] 220 221 # List of kv store keys to stream out via gRPC. 222 # The store key names MUST match the module's StoreKey name. 223 # 224 # Example: 225 # ["acc", "bank", "gov", "staking", "mint"[,...]] 226 # ["*"] to expose all keys. 227 keys = [{{ range .Streaming.ABCI.Keys }}{{ printf "%q, " . }}{{end}}] 228 229 # The plugin name used for streaming via gRPC. 230 # Streaming is only enabled if this is set. 231 # Supported plugins: abci 232 plugin = "{{ .Streaming.ABCI.Plugin }}" 233 234 # stop-node-on-err specifies whether to stop the node on message delivery error. 235 stop-node-on-err = {{ .Streaming.ABCI.StopNodeOnErr }} 236 237 ############################################################################### 238 ### Mempool ### 239 ############################################################################### 240 241 [mempool] 242 # Setting max-txs to 0 will allow for a unbounded amount of transactions in the mempool. 243 # Setting max_txs to negative 1 (-1) will disable transactions from being inserted into the mempool (no-op mempool). 244 # Setting max_txs to a positive number (> 0) will limit the number of transactions in the mempool, by the specified amount. 245 # 246 # Note, this configuration only applies to SDK built-in app-side mempool 247 # implementations. 248 max-txs = {{ .Mempool.MaxTxs }} 249 ` 250 251 var configTemplate *template.Template 252 253 func init() { 254 var err error 255 256 tmpl := template.New("appConfigFileTemplate") 257 258 if configTemplate, err = tmpl.Parse(DefaultConfigTemplate); err != nil { 259 panic(err) 260 } 261 } 262 263 // ParseConfig retrieves the default environment configuration for the 264 // application. 265 func ParseConfig(v *viper.Viper) (*Config, error) { 266 conf := DefaultConfig() 267 err := v.Unmarshal(conf) 268 269 return conf, err 270 } 271 272 // SetConfigTemplate sets the custom app config template for 273 // the application 274 func SetConfigTemplate(customTemplate string) { 275 var err error 276 277 tmpl := template.New("appConfigFileTemplate") 278 279 if configTemplate, err = tmpl.Parse(customTemplate); err != nil { 280 panic(err) 281 } 282 } 283 284 // WriteConfigFile renders config using the template and writes it to 285 // configFilePath. 286 func WriteConfigFile(configFilePath string, config interface{}) { 287 var buffer bytes.Buffer 288 289 if err := configTemplate.Execute(&buffer, config); err != nil { 290 panic(err) 291 } 292 293 mustWriteFile(configFilePath, buffer.Bytes(), 0o644) 294 } 295 296 func mustWriteFile(filePath string, contents []byte, mode os.FileMode) { 297 if err := os.WriteFile(filePath, contents, mode); err != nil { 298 panic(fmt.Errorf("failed to write file: %w", err)) 299 } 300 }