github.com/Finschia/finschia-sdk@v0.48.1/server/config/toml.go (about) 1 package config 2 3 import ( 4 "bytes" 5 "text/template" 6 7 ostos "github.com/Finschia/ostracon/libs/os" 8 "github.com/spf13/viper" 9 ) 10 11 const DefaultConfigTemplate = `# This is a TOML config file. 12 # For more information, see https://github.com/toml-lang/toml 13 14 ############################################################################### 15 ### Base Configuration ### 16 ############################################################################### 17 18 # The minimum gas prices a validator is willing to accept for processing a 19 # transaction. A transaction's fees must meet the minimum of any denomination 20 # specified in this config (e.g. 0.25token1;0.0001token2). 21 minimum-gas-prices = "{{ .BaseConfig.MinGasPrices }}" 22 23 # default: the last 100 states are kept in addition to every 500th state; pruning at 10 block intervals 24 # nothing: all historic states will be saved, nothing will be deleted (i.e. archiving node) 25 # everything: all saved states will be deleted, storing only the current and previous state; pruning at 10 block intervals 26 # custom: allow pruning options to be manually specified through 'pruning-keep-recent', 'pruning-keep-every', and 'pruning-interval' 27 pruning = "{{ .BaseConfig.Pruning }}" 28 29 # These are applied if and only if the pruning strategy is custom. 30 pruning-keep-recent = "{{ .BaseConfig.PruningKeepRecent }}" 31 pruning-keep-every = "{{ .BaseConfig.PruningKeepEvery }}" 32 pruning-interval = "{{ .BaseConfig.PruningInterval }}" 33 34 # HaltHeight contains a non-zero block height at which a node will gracefully 35 # halt and shutdown that can be used to assist upgrades and testing. 36 # 37 # Note: Commitment of state will be attempted on the corresponding block. 38 halt-height = {{ .BaseConfig.HaltHeight }} 39 40 # HaltTime contains a non-zero minimum block time (in Unix seconds) at which 41 # a node will gracefully halt and shutdown that can be used to assist upgrades 42 # and testing. 43 # 44 # Note: Commitment of state will be attempted on the corresponding block. 45 halt-time = {{ .BaseConfig.HaltTime }} 46 47 # MinRetainBlocks defines the minimum block height offset from the current 48 # block being committed, such that all blocks past this offset are pruned 49 # from Tendermint. It is used as part of the process of determining the 50 # ResponseCommit.RetainHeight value during ABCI Commit. A value of 0 indicates 51 # that no blocks should be pruned. 52 # 53 # This configuration value is only responsible for pruning Tendermint blocks. 54 # It has no bearing on application state pruning which is determined by the 55 # "pruning-*" configurations. 56 # 57 # Note: Tendermint block pruning is dependant on this parameter in conunction 58 # with the unbonding (safety threshold) period, state pruning and state sync 59 # snapshot parameters to determine the correct minimum value of 60 # ResponseCommit.RetainHeight. 61 min-retain-blocks = {{ .BaseConfig.MinRetainBlocks }} 62 63 # InterBlockCache enables inter-block caching. 64 inter-block-cache = {{ .BaseConfig.InterBlockCache }} 65 66 # InterBlockCacheSize is the maximum bytes size of the inter-block cache. 67 inter-block-cache-size = {{ .BaseConfig.InterBlockCacheSize }} 68 69 # IAVLCacheSize is the maximum units size of iavl node cache (1 unit is 128 bytes) 70 # This iavl cache size is just one store cache size, and the store exists for each modules. 71 # So be careful that all iavl cache size are difference from this iavl cache size value. 72 iavl-cache-size = {{ .BaseConfig.IAVLCacheSize }} 73 74 # IAVLDisableFastNode enables or disables the fast node feature of IAVL. 75 # Default is true. 76 iavl-disable-fastnode = {{ .BaseConfig.IAVLDisableFastNode }} 77 78 # IndexEvents defines the set of events in the form {eventType}.{attributeKey}, 79 # which informs Tendermint what to index. If empty, all events will be indexed. 80 # 81 # Example: 82 # ["message.sender", "message.recipient"] 83 index-events = {{ .BaseConfig.IndexEvents }} 84 85 # When true, Prometheus metrics are served under /metrics on prometheus_listen_addr in config.toml. 86 # It works when tendermint's prometheus option (config.toml) is set to true. 87 prometheus = {{ .BaseConfig.Prometheus }} 88 89 # ChanCheckTxSize is the size of RequestCheckTxAsync of BaseApp. 90 # ChanCheckTxSize should be equals to or greater than the mempool size set in config.toml of Ostracon. 91 chan-check-tx-size = {{ .BaseConfig.ChanCheckTxSize }} 92 93 ############################################################################### 94 ### Telemetry Configuration ### 95 ############################################################################### 96 97 [telemetry] 98 99 # Prefixed with keys to separate services. 100 service-name = "{{ .Telemetry.ServiceName }}" 101 102 # Enabled enables the application telemetry functionality. When enabled, 103 # an in-memory sink is also enabled by default. Operators may also enabled 104 # other sinks such as Prometheus. 105 enabled = {{ .Telemetry.Enabled }} 106 107 # Enable prefixing gauge values with hostname. 108 enable-hostname = {{ .Telemetry.EnableHostname }} 109 110 # Enable adding hostname to labels. 111 enable-hostname-label = {{ .Telemetry.EnableHostnameLabel }} 112 113 # Enable adding service to labels. 114 enable-service-label = {{ .Telemetry.EnableServiceLabel }} 115 116 # PrometheusRetentionTime, when positive, enables a Prometheus metrics sink. 117 prometheus-retention-time = {{ .Telemetry.PrometheusRetentionTime }} 118 119 # GlobalLabels defines a global set of name/value label tuples applied to all 120 # metrics emitted using the wrapper functions defined in telemetry package. 121 # 122 # Example: 123 # [["chain_id", "cosmoshub-1"]] 124 global-labels = [{{ range $k, $v := .Telemetry.GlobalLabels }} 125 ["{{index $v 0 }}", "{{ index $v 1}}"],{{ end }} 126 ] 127 128 ############################################################################### 129 ### API Configuration ### 130 ############################################################################### 131 132 [api] 133 134 # Enable defines if the API server should be enabled. 135 enable = {{ .API.Enable }} 136 137 # Swagger defines if swagger documentation should automatically be registered. 138 swagger = {{ .API.Swagger }} 139 140 # Address defines the API server to listen on. 141 address = "{{ .API.Address }}" 142 143 # MaxOpenConnections defines the number of maximum open connections. 144 max-open-connections = {{ .API.MaxOpenConnections }} 145 146 # RPCReadTimeout defines the Ostracon RPC read timeout (in seconds). 147 rpc-read-timeout = {{ .API.RPCReadTimeout }} 148 149 # RPCWriteTimeout defines the Ostracon RPC write timeout (in seconds). 150 rpc-write-timeout = {{ .API.RPCWriteTimeout }} 151 152 # RPCIdleTimeout defines the Ostracon RPC idle timeout (in seconds). 153 rpc-idle-timeout = {{ .API.RPCIdleTimeout }} 154 155 # RPCMaxBodyBytes defines the Ostracon maximum response body (in bytes). 156 rpc-max-body-bytes = {{ .API.RPCMaxBodyBytes }} 157 158 # EnableUnsafeCORS defines if CORS should be enabled (unsafe - use it at your own risk). 159 enabled-unsafe-cors = {{ .API.EnableUnsafeCORS }} 160 161 ############################################################################### 162 ### Rosetta Configuration ### 163 ############################################################################### 164 165 [rosetta] 166 167 # Enable defines if the Rosetta API server should be enabled. 168 enable = {{ .Rosetta.Enable }} 169 170 # Address defines the Rosetta API server to listen on. 171 address = "{{ .Rosetta.Address }}" 172 173 # Network defines the name of the blockchain that will be returned by Rosetta. 174 blockchain = "{{ .Rosetta.Blockchain }}" 175 176 # Network defines the name of the network that will be returned by Rosetta. 177 network = "{{ .Rosetta.Network }}" 178 179 # Retries defines the number of retries when connecting to the node before failing. 180 retries = {{ .Rosetta.Retries }} 181 182 # Offline defines if Rosetta server should run in offline mode. 183 offline = {{ .Rosetta.Offline }} 184 185 ############################################################################### 186 ### gRPC Configuration ### 187 ############################################################################### 188 189 [grpc] 190 191 # Enable defines if the gRPC server should be enabled. 192 enable = {{ .GRPC.Enable }} 193 194 # Address defines the gRPC server address to bind to. 195 address = "{{ .GRPC.Address }}" 196 197 # MaxRecvMsgSize defines the max message size in bytes the server can receive. 198 # The default value is 10MB. 199 max-recv-msg-size = "{{ .GRPC.MaxRecvMsgSize }}" 200 201 # MaxSendMsgSize defines the max message size in bytes the server can send. 202 # The default value is math.MaxInt32. 203 max-send-msg-size = "{{ .GRPC.MaxSendMsgSize }}" 204 205 ############################################################################### 206 ### gRPC Web Configuration ### 207 ############################################################################### 208 209 [grpc-web] 210 211 # GRPCWebEnable defines if the gRPC-web should be enabled. 212 # NOTE: gRPC must also be enabled, otherwise, this configuration is a no-op. 213 enable = {{ .GRPCWeb.Enable }} 214 215 # Address defines the gRPC-web server address to bind to. 216 address = "{{ .GRPCWeb.Address }}" 217 218 # EnableUnsafeCORS defines if CORS should be enabled (unsafe - use it at your own risk). 219 enable-unsafe-cors = {{ .GRPCWeb.EnableUnsafeCORS }} 220 221 ############################################################################### 222 ### State Sync Configuration ### 223 ############################################################################### 224 225 # State sync snapshots allow other nodes to rapidly join the network without replaying historical 226 # blocks, instead downloading and applying a snapshot of the application state at a given height. 227 [state-sync] 228 229 # snapshot-interval specifies the block interval at which local state sync snapshots are 230 # taken (0 to disable). Must be a multiple of pruning-keep-every. 231 snapshot-interval = {{ .StateSync.SnapshotInterval }} 232 233 # snapshot-keep-recent specifies the number of recent snapshots to keep and serve (0 to keep all). 234 snapshot-keep-recent = {{ .StateSync.SnapshotKeepRecent }} 235 ` 236 237 var configTemplate *template.Template 238 239 func init() { 240 var err error 241 242 tmpl := template.New("appConfigFileTemplate") 243 244 if configTemplate, err = tmpl.Parse(DefaultConfigTemplate); err != nil { 245 panic(err) 246 } 247 } 248 249 // ParseConfig retrieves the default environment configuration for the 250 // application. 251 func ParseConfig(v *viper.Viper) (*Config, error) { 252 conf := DefaultConfig() 253 err := v.Unmarshal(conf) 254 255 return conf, err 256 } 257 258 // SetConfigTemplate sets the custom app config template for 259 // the application 260 func SetConfigTemplate(customTemplate string) { 261 var err error 262 263 tmpl := template.New("appConfigFileTemplate") 264 265 if configTemplate, err = tmpl.Parse(customTemplate); err != nil { 266 panic(err) 267 } 268 } 269 270 // WriteConfigFile renders config using the template and writes it to 271 // configFilePath. 272 func WriteConfigFile(configFilePath string, config interface{}) { 273 var buffer bytes.Buffer 274 275 if err := configTemplate.Execute(&buffer, config); err != nil { 276 panic(err) 277 } 278 279 ostos.MustWriteFile(configFilePath, buffer.Bytes(), 0644) 280 }