github.com/aergoio/aergo@v1.3.1/config/types.go (about) 1 package config 2 3 // Config should be read-only in outer world, but golang doesn't have any simple solution for that. 4 // A Developer MUST NOT modify config value in caller code. 5 const ( 6 defaultAergoHomePath = ".aergo" 7 defaultAergoConfigFileName = "config.toml" 8 9 EnvironmentPrefix = "AG" 10 11 //defaultLogFileName = "aergo.log" 12 ) 13 14 // Config defines configurations of each services 15 type Config struct { 16 BaseConfig `mapstructure:",squash"` 17 RPC *RPCConfig `mapstructure:"rpc"` 18 P2P *P2PConfig `mapstructure:"p2p"` 19 Polaris *PolarisConfig `mapstructure:"polaris"` 20 Blockchain *BlockchainConfig `mapstructure:"blockchain"` 21 Mempool *MempoolConfig `mapstructure:"mempool"` 22 Consensus *ConsensusConfig `mapstructure:"consensus"` 23 Monitor *MonitorConfig `mapstructure:"monitor"` 24 Account *AccountConfig `mapstructure:"account"` 25 Auth *AuthConfig `mapstructure:"auth"` 26 SQL *SQLConfig `mapstructure:"sql"` 27 } 28 29 // BaseConfig defines base configurations for aergo server 30 type BaseConfig struct { 31 DataDir string `mapstructure:"datadir" description:"Directory to store datafiles"` 32 DbType string `mapstructure:"dbtype" description:"db implementation to store data"` 33 EnableProfile bool `mapstructure:"enableprofile" description:"enable profiling"` 34 ProfilePort int `mapstructure:"profileport" description:"profiling port (default:6060)"` 35 EnableTestmode bool `mapstructure:"enabletestmode" description:"enable unsafe test mode"` 36 UseTestnet bool `mapstructure:"usetestnet" description:"need description"` 37 Personal bool `mapstructure:"personal" description:"enable personal account service"` 38 AuthDir string `mapstructure:"authdir" description:"Directory to store files for auth"` 39 } 40 41 // RPCConfig defines configurations for rpc service 42 type RPCConfig struct { 43 // RPC and REST 44 NetServiceAddr string `mapstructure:"netserviceaddr" description:"RPC service address"` 45 NetServicePort int `mapstructure:"netserviceport" description:"RPC service port"` 46 NetServiceTrace bool `mapstructure:"netservicetrace" description:"Trace RPC service"` 47 // RPC API with TLS 48 NSEnableTLS bool `mapstructure:"nstls" description:"Enable TLS on RPC or REST API"` 49 NSCert string `mapstructure:"nscert" description:"Server Certificate file for RPC or REST API"` 50 NSKey string `mapstructure:"nskey" description:"Private Key file for RPC or REST API"` 51 NSCACert string `mapstructure:"nscacert" description:"CA Certificate file for RPC or REST API"` 52 NSAllowCORS bool `mapstructure:"nsallowcors" description:"Allow CORS to RPC or REST API"` 53 } 54 55 // P2PConfig defines configurations for p2p service 56 type P2PConfig struct { 57 // N2N (peer-to-peer) network 58 NetProtocolAddr string `mapstructure:"netprotocoladdr" description:"N2N listen address to which other peer can connect. This address is advertized to other peers."` 59 NetProtocolPort int `mapstructure:"netprotocolport" description:"N2N listen port to which other peer can connect. This port is advertized to other peers."` 60 NPBindAddr string `mapstructure:"npbindaddr" description:"N2N bind address. If it was set, it only accept connection to this addresse only"` 61 NPBindPort int `mapstructure:"npbindport" description:"N2N bind port. It not set, bind port is same as netprotocolport. Set if server is configured with NAT and port is differ."` 62 NPEnableTLS bool `mapstructure:"nptls" description:"Enable TLS on N2N network"` 63 NPCert string `mapstructure:"npcert" description:"Certificate file for N2N network"` 64 NPKey string `mapstructure:"npkey" description:"Private Key file for N2N network"` 65 NPAddPeers []string `mapstructure:"npaddpeers" description'':"Add peers to connect to at startup"` 66 NPHiddenPeers []string `mapstructure:"nphiddenpeers" description:"List of peerids which will not show to other peers"` 67 NPDiscoverPeers bool `mapstructure:"npdiscoverpeers" description:"Whether to discover from polaris or other nodes and connects"` 68 NPMaxPeers int `mapstructure:"npmaxpeers" description:"Maximum number of remote peers to keep"` 69 NPPeerPool int `mapstructure:"nppeerpool" description:"Max peer pool size"` 70 71 NPExposeSelf bool `mapstructure:"npexposeself" description:"Whether to request expose self to polaris and other connected node"` 72 NPUsePolaris bool `mapstructure:"npusepolaris" description:"Whether to connect and get node list from polaris"` 73 NPAddPolarises []string `mapstructure:"npaddpolarises" description:"Add addresses of polarises if default polaris is not sufficient"` 74 75 LogFullPeerID bool `mapstructure:"logfullpeerid" description:"Whether to use full legnth peerID or short form"` 76 // NPPrivateChain and NPMainNet are not set from configfile, it must be got from genesis block. TODO this properties should not be in config 77 } 78 79 // AuthConfig defines configuration for auditing 80 type AuthConfig struct { 81 EnableLocalConf bool `mapstructure:"enablelocalconf" description:"apply local white/blacklist file or not"` 82 } 83 84 // PolarisConfig defines configuration for polaris server and client (i.e. polarisConnect) 85 type PolarisConfig struct { 86 AllowPrivate bool `mapstructure:"allowprivate" description:"allow peer to have private address. for private network and test"` 87 GenesisFile string `mapstructure:"genesisfile" description:"json file containing informations of genesisblock to which polaris refer "` 88 EnableBlacklist bool `mapstructure:"enableblacklist" description:"allow peer to have private address. for private network and test"` 89 } 90 91 // BlockchainConfig defines configurations for blockchain service 92 type BlockchainConfig struct { 93 MaxBlockSize uint32 `mapstructure:"maxblocksize" description:"maximum block size in bytes"` 94 CoinbaseAccount string `mapstructure:"coinbaseaccount" description:"wallet address for coinbase"` 95 MaxAnchorCount int `mapstructure:"maxanchorcount" description:"maximun anchor count for sync"` 96 VerifierCount int `mapstructure:"verifiercount" description:"maximun transaction verifier count"` 97 ForceResetHeight uint64 `mapstructure:"forceresetheight" description:"best height to reset chain manually"` 98 ZeroFee bool `mapstructure:"zerofee" description:"enable zero-fee mode(works only on private network)"` 99 VerifyOnly bool `mapstructure:"verifyonly" description:"In verify only mode, server verifies block chain of disk. server never modifies block chain'"` 100 StateTrace uint64 `mapstructure:"statetrace" description:"dump trace of setting state"` 101 } 102 103 // MempoolConfig defines configurations for mempool service 104 type MempoolConfig struct { 105 ShowMetrics bool `mapstructure:"showmetrics" description:"show mempool metric periodically"` 106 EnableFadeout bool `mapstructure:"enablefadeout" description:"Enable transaction fadeout over timeout period"` 107 FadeoutPeriod int `mapstructure:"fadeoutperiod" description:"time period for evict transactions(in hour)"` 108 VerifierNumber int `mapstructure:"verifiers" description:"number of concurrent verifier"` 109 DumpFilePath string `mapstructure:"dumpfilepath" description:"file path for recording mempool at process termintation"` 110 } 111 112 // ConsensusConfig defines configurations for consensus service 113 type ConsensusConfig struct { 114 EnableBp bool `mapstructure:"enablebp" description:"enable block production"` 115 BlockInterval int64 `mapstructure:"blockinterval" description:"block production interval (sec)"` 116 Raft *RaftConfig `mapstructure:"raft"` 117 } 118 119 type RaftConfig struct { 120 Name string `mapstructure:"name" description:"raft node name. this value must be unique in cluster"` 121 SkipEmpty bool `mapstructure:"skipempty" description:"skip producing block if there is no tx in block"` 122 HeartbeatTick uint `mapstructure:"heartbeattick" description:"heartbeat tick of raft server (millisec)"` 123 ElectionTickCount int `mapstructure:"electiontickcount" description:"number of ticks to wait to be a candidate when no heartbeat message comes from leader"` 124 BlockFactoryTickMs int64 `mapstructure:"blockfactorytickms" description:"interval to check if block factory should run new task(millisec)"` 125 BlockIntervalMs int64 `mapstructure:"blockintervalms" description:"block interval for raft (millisec). It overrides BlockInterval of consensus"` 126 NewCluster bool `mapstructure:"newcluster" description:"create a new raft cluster if it doesn't already exist"` 127 UseBackup bool `mapstructure:"usebackup" description:"use backup datafiles when creating a new cluster or joining to a existing cluster"` 128 SnapFrequency uint64 `mapstructure:"snapfrequency" description:"frequency which raft make snapshot with log"` 129 SlowNodeGap uint `mapstructure:"slownodegap" description:"frequency which raft make snapshot with log"` 130 RecoverBP *RaftBPConfig `mapstructure:"recoverbp" description:"bp info for creating a new cluster from backup"` 131 StopDupCommit bool `mapstructure:"stopdupcommit" description:"stop server when commit of duplicate height block occurs. use this only for debugging'"` 132 } 133 134 type RaftBPConfig struct { 135 Name string `mapstructure:"name" description:"raft node name"` 136 Address string `mapstructure:"address" description:"raft address"` 137 PeerID string `mapstructure:"peerid" description:"peerid of this bp"` 138 } 139 140 type MonitorConfig struct { 141 ServerProtocol string `mapstructure:"protocol" description:"Protocol is one of next: http, https or kafka"` 142 ServerEndpoint string `mapstructure:"endpoint" description:"Endpoint to send"` 143 } 144 145 // Account defines configurations for account service 146 type AccountConfig struct { 147 UnlockTimeout uint `mapstructure:"unlocktimeout" description:"lock automatically after timeout (sec)"` 148 } 149 150 type SQLConfig struct { 151 MaxDbSize uint32 `mapstructure:"maxdbsize" description:"maximum database size of a contract (MB)"` 152 } 153 154 /* 155 How to write this template 156 ======================================= 157 158 string_type = "{{.STRUCT.FILED}}" 159 bool/number_type = {{.STRUCT.FILED}} 160 string_array_type = [{{range .STRUCT.FILED}} 161 "{{.}}", {{end}} 162 ] 163 bool/number_array_type = [{{range .STRUCT.FILED}} 164 {{.}}, {{end}} 165 ] 166 map = does not support 167 */ 168 const tomlConfigFileTemplate = `# aergo TOML Configuration File (https://github.com/toml-lang/toml) 169 # base configurations 170 datadir = "{{.BaseConfig.DataDir}}" 171 dbtype = "{{.BaseConfig.DbType}}" 172 enableprofile = {{.BaseConfig.EnableProfile}} 173 profileport = {{.BaseConfig.ProfilePort}} 174 personal = {{.BaseConfig.Personal}} 175 authdir = "{{.BaseConfig.AuthDir}}" 176 177 [rpc] 178 netserviceaddr = "{{.RPC.NetServiceAddr}}" 179 netserviceport = {{.RPC.NetServicePort}} 180 netservicetrace = {{.RPC.NetServiceTrace}} 181 nstls = {{.RPC.NSEnableTLS}} 182 nscert = "{{.RPC.NSCert}}" 183 nskey = "{{.RPC.NSKey}}" 184 nscacert = "{{.RPC.NSCACert}}" 185 nsallowcors = {{.RPC.NSAllowCORS}} 186 187 [p2p] 188 # Set address and port to which the inbound peers connect, and don't set loopback address or private network unless used in local network 189 netprotocoladdr = "{{.P2P.NetProtocolAddr}}" 190 netprotocolport = {{.P2P.NetProtocolPort}} 191 npbindaddr = "{{.P2P.NPBindAddr}}" 192 npbindport = {{.P2P.NPBindPort}} 193 # TLS and certificate is not applied in alpha release. 194 nptls = {{.P2P.NPEnableTLS}} 195 npcert = "{{.P2P.NPCert}}" 196 # Set file path of key file 197 npkey = "{{.P2P.NPKey}}" 198 npaddpeers = [{{range .P2P.NPAddPeers}} 199 "{{.}}", {{end}} 200 ] 201 npdiscoverpeers = true 202 npmaxpeers = "{{.P2P.NPMaxPeers}}" 203 nppeerpool = "{{.P2P.NPPeerPool}}" 204 npexposeself = true 205 npusepolaris= {{.P2P.NPUsePolaris}} 206 npaddpolarises = [{{range .P2P.NPAddPolarises}} 207 "{{.}}", {{end}} 208 ] 209 210 [polaris] 211 allowprivate = {{.Polaris.AllowPrivate}} 212 genesisfile = "{{.Polaris.GenesisFile}}" 213 enableblacklist = "{{.Polaris.EnableBlacklist}}" 214 215 [blockchain] 216 # blockchain configurations 217 maxblocksize = {{.Blockchain.MaxBlockSize}} 218 coinbaseaccount = "{{.Blockchain.CoinbaseAccount}}" 219 maxanchorcount = "{{.Blockchain.MaxAnchorCount}}" 220 verifiercount = "{{.Blockchain.VerifierCount}}" 221 forceresetheight = "{{.Blockchain.ForceResetHeight}}" 222 223 [mempool] 224 showmetrics = {{.Mempool.ShowMetrics}} 225 enablefadeout = {{.Mempool.EnableFadeout}} 226 fadeoutperiod = {{.Mempool.FadeoutPeriod}} 227 verifiers = {{.Mempool.VerifierNumber}} 228 dumpfilepath = "{{.Mempool.DumpFilePath}}" 229 230 [consensus] 231 enablebp = {{.Consensus.EnableBp}} 232 blockinterval = {{.Consensus.BlockInterval}} 233 234 [monitor] 235 protocol = "{{.Monitor.ServerProtocol}}" 236 endpoint = "{{.Monitor.ServerEndpoint}}" 237 238 [account] 239 unlocktimeout = "{{.Account.UnlockTimeout}}" 240 241 [auth] 242 enablelocalconf = "{{.Auth.EnableLocalConf}}" 243 `