code.vegaprotocol.io/vega@v0.79.0/core/blockchain/config.go (about) 1 // Copyright (C) 2023 Gobalsky Labs Limited 2 // 3 // This program is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU Affero General Public License as 5 // published by the Free Software Foundation, either version 3 of the 6 // License, or (at your option) any later version. 7 // 8 // This program is distributed in the hope that it will be useful, 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 // GNU Affero General Public License for more details. 12 // 13 // You should have received a copy of the GNU Affero General Public License 14 // along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16 package blockchain 17 18 import ( 19 "time" 20 21 "code.vegaprotocol.io/vega/libs/config/encoding" 22 "code.vegaprotocol.io/vega/logging" 23 ) 24 25 const ( 26 ProviderNullChain = "nullchain" 27 ProviderTendermint = "tendermint" 28 ) 29 30 // Config represent the configuration of the blockchain package. 31 type Config struct { 32 Level encoding.LogLevel `long:"log-level"` 33 LogTimeDebug bool `long:"log-time-debug"` 34 LogOrderSubmitDebug bool `long:"log-order-submit-debug"` 35 LogOrderAmendDebug bool `long:"log-order-amend-debug"` 36 LogOrderCancelDebug bool `long:"log-order-cancel-debug"` 37 ChainProvider string `long:"chain-provider"` 38 39 Tendermint TendermintConfig `group:"Tendermint" namespace:"tendermint"` 40 Null NullChainConfig `group:"NullChain" namespace:"nullchain"` 41 } 42 43 // NewDefaultConfig creates an instance of the package specific configuration, given a 44 // pointer to a logger instance to be used for logging within the package. 45 func NewDefaultConfig() Config { 46 return Config{ 47 Level: encoding.LogLevel{Level: logging.InfoLevel}, 48 LogOrderSubmitDebug: true, 49 LogTimeDebug: true, 50 ChainProvider: ProviderTendermint, 51 Tendermint: NewDefaultTendermintConfig(), 52 Null: NewDefaultNullChainConfig(), 53 } 54 } 55 56 type TendermintConfig struct { 57 Level encoding.LogLevel `description:" " long:"log-level"` 58 RPCAddr string `description:"address of the tendermint rpc" long:"rpc-addr"` 59 } 60 61 // NewDefaultTendermintConfig creates an instance of the package specific configuration, given a 62 // pointer to a logger instance to be used for logging within the package. 63 func NewDefaultTendermintConfig() TendermintConfig { 64 return TendermintConfig{ 65 Level: encoding.LogLevel{Level: logging.InfoLevel}, 66 } 67 } 68 69 type ReplayConfig struct { 70 Record bool `description:"whether to record block data to a file to allow replaying" long:"record"` 71 Replay bool `description:"whether to replay any blockdata found in replay-file" long:"replay"` 72 ReplayFile string `description:"path to file of which to write/read replay data" long:"replay-file"` 73 } 74 75 type NullChainConfig struct { 76 Level encoding.LogLevel `long:"log-level"` 77 BlockDuration encoding.Duration `description:"(default 1s)" long:"block-duration"` 78 TransactionsPerBlock uint64 `description:"(default 10)" long:"transactions-per-block"` 79 GenesisFile string `description:"path to a tendermint genesis file" long:"genesis-file"` 80 IP string `description:"time-forwarding IP (default localhost)" long:"ip"` 81 Port int `description:"time-forwarding port (default 3009)" long:"port"` 82 SpamProtection bool `description:"enable spam protection for null-chain (default false)" long:"spam-protection"` 83 Replay ReplayConfig 84 } 85 86 // NewDefaultNullChainConfig creates an instance of the package specific configuration, given a 87 // pointer to a logger instance to be used for logging within the package. 88 func NewDefaultNullChainConfig() NullChainConfig { 89 return NullChainConfig{ 90 Level: encoding.LogLevel{Level: logging.InfoLevel}, 91 BlockDuration: encoding.Duration{Duration: time.Second}, 92 TransactionsPerBlock: 10, 93 IP: "localhost", 94 Port: 3101, 95 SpamProtection: false, 96 Replay: ReplayConfig{}, 97 } 98 }