github.com/fff-chain/go-fff@v0.0.0-20220726032732-1c84420b8a99/eth/ethconfig/config.go (about) 1 // Copyright 2017 The go-ethereum Authors 2 // This file is part of the go-ethereum library. 3 // 4 // The go-ethereum library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The go-ethereum library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 16 17 // Package ethconfig contains the configuration of the ETH and LES protocols. 18 package ethconfig 19 20 import ( 21 "github.com/fff-chain/go-fff/global_config" 22 "math/big" 23 "os/user" 24 "path/filepath" 25 "runtime" 26 "time" 27 28 "github.com/fff-chain/go-fff/common" 29 "github.com/fff-chain/go-fff/consensus" 30 "github.com/fff-chain/go-fff/consensus/clique" 31 "github.com/fff-chain/go-fff/consensus/ethash" 32 "github.com/fff-chain/go-fff/consensus/parlia" 33 "github.com/fff-chain/go-fff/core" 34 "github.com/fff-chain/go-fff/eth/downloader" 35 "github.com/fff-chain/go-fff/eth/gasprice" 36 "github.com/fff-chain/go-fff/ethdb" 37 "github.com/fff-chain/go-fff/internal/ethapi" 38 "github.com/fff-chain/go-fff/log" 39 "github.com/fff-chain/go-fff/miner" 40 "github.com/fff-chain/go-fff/node" 41 "github.com/fff-chain/go-fff/params" 42 ) 43 44 // FullNodeGPO contains default gasprice oracle settings for full node. 45 var FullNodeGPO = gasprice.Config{ 46 Blocks: 20, 47 Percentile: 60, 48 MaxPrice: gasprice.DefaultMaxPrice, 49 OracleThreshold: 1000, 50 } 51 52 // LightClientGPO contains default gasprice oracle settings for light client. 53 var LightClientGPO = gasprice.Config{ 54 Blocks: 2, 55 Percentile: 60, 56 MaxPrice: gasprice.DefaultMaxPrice, 57 } 58 59 // Defaults contains default settings for use on the Ethereum main net. 60 var Defaults = Config{ 61 SyncMode: downloader.FastSync, 62 Ethash: ethash.Config{ 63 CacheDir: "ethash", 64 CachesInMem: 2, 65 CachesOnDisk: 3, 66 CachesLockMmap: false, 67 DatasetsInMem: 1, 68 DatasetsOnDisk: 2, 69 DatasetsLockMmap: false, 70 }, 71 NetworkId: 1, 72 TxLookupLimit: 2350000, 73 LightPeers: 100, 74 UltraLightFraction: 75, 75 DatabaseCache: 512, 76 TrieCleanCache: 154, 77 TrieCleanCacheJournal: "triecache", 78 TrieCleanCacheRejournal: 60 * time.Minute, 79 TrieDirtyCache: 256, 80 TrieTimeout: 60 * time.Minute, 81 TriesInMemory: 128, 82 SnapshotCache: 102, 83 DiffBlock: uint64(86400), 84 Miner: miner.Config{ 85 GasFloor: 8000000, 86 GasCeil: 8000000, 87 GasPrice: big.NewInt(params.GWei), 88 Recommit: 3 * time.Second, 89 DelayLeftOver: 50 * time.Millisecond, 90 }, 91 TxPool: core.DefaultTxPoolConfig, 92 RPCGasCap: 25000000, 93 GPO: FullNodeGPO, 94 RPCTxFeeCap: 1, // 1 ether 95 } 96 97 func init() { 98 home := global_config.DefaultHomePath 99 if home == "" { 100 if user, err := user.Current(); err == nil { 101 home = user.HomeDir 102 } 103 } 104 if runtime.GOOS == "darwin" { 105 Defaults.Ethash.DatasetDir = filepath.Join(home, "Library", "Ethash") 106 } else if runtime.GOOS == "windows" { 107 localappdata := home 108 if localappdata != "" { 109 Defaults.Ethash.DatasetDir = filepath.Join(localappdata, "Ethash") 110 } else { 111 Defaults.Ethash.DatasetDir = filepath.Join(home, "AppData", "Local", "Ethash") 112 } 113 } else { 114 Defaults.Ethash.DatasetDir = filepath.Join(home, ".ethash") 115 } 116 } 117 118 //go:generate gencodec -type Config -formats toml -out gen_config.go 119 120 // Config contains configuration options for of the ETH and LES protocols. 121 type Config struct { 122 // The genesis block, which is inserted if the database is empty. 123 // If nil, the Ethereum main net block is used. 124 Genesis *core.Genesis `toml:",omitempty"` 125 126 // Protocol options 127 NetworkId uint64 // Network ID to use for selecting peers to connect to 128 SyncMode downloader.SyncMode 129 DisablePeerTxBroadcast bool 130 131 // This can be set to list of enrtree:// URLs which will be queried for 132 // for nodes to connect to. 133 EthDiscoveryURLs []string 134 SnapDiscoveryURLs []string 135 136 NoPruning bool // Whether to disable pruning and flush everything to disk 137 DirectBroadcast bool 138 DisableSnapProtocol bool //Whether disable snap protocol 139 DiffSync bool // Whether support diff sync 140 PipeCommit bool 141 RangeLimit bool 142 143 TxLookupLimit uint64 `toml:",omitempty"` // The maximum number of blocks from head whose tx indices are reserved. 144 145 // Whitelist of required block number -> hash values to accept 146 Whitelist map[uint64]common.Hash `toml:"-"` 147 148 // Light client options 149 LightServ int `toml:",omitempty"` // Maximum percentage of time allowed for serving LES requests 150 LightIngress int `toml:",omitempty"` // Incoming bandwidth limit for light servers 151 LightEgress int `toml:",omitempty"` // Outgoing bandwidth limit for light servers 152 LightPeers int `toml:",omitempty"` // Maximum number of LES client peers 153 LightNoPrune bool `toml:",omitempty"` // Whether to disable light chain pruning 154 LightNoSyncServe bool `toml:",omitempty"` // Whether to serve light clients before syncing 155 SyncFromCheckpoint bool `toml:",omitempty"` // Whether to sync the header chain from the configured checkpoint 156 157 // Ultra Light client options 158 UltraLightServers []string `toml:",omitempty"` // List of trusted ultra light servers 159 UltraLightFraction int `toml:",omitempty"` // Percentage of trusted servers to accept an announcement 160 UltraLightOnlyAnnounce bool `toml:",omitempty"` // Whether to only announce headers, or also serve them 161 162 // Database options 163 SkipBcVersionCheck bool `toml:"-"` 164 DatabaseHandles int `toml:"-"` 165 DatabaseCache int 166 DatabaseFreezer string 167 DatabaseDiff string 168 PersistDiff bool 169 DiffBlock uint64 170 171 TrieCleanCache int 172 TrieCleanCacheJournal string `toml:",omitempty"` // Disk journal directory for trie cache to survive node restarts 173 TrieCleanCacheRejournal time.Duration `toml:",omitempty"` // Time interval to regenerate the journal for clean cache 174 TrieDirtyCache int 175 TrieTimeout time.Duration 176 SnapshotCache int 177 TriesInMemory uint64 178 Preimages bool 179 180 // Mining options 181 Miner miner.Config 182 183 // Ethash options 184 Ethash ethash.Config `toml:",omitempty"` 185 186 // Transaction pool options 187 TxPool core.TxPoolConfig 188 189 // Gas Price Oracle options 190 GPO gasprice.Config 191 192 // Enables tracking of SHA3 preimages in the VM 193 EnablePreimageRecording bool 194 195 // Miscellaneous options 196 DocRoot string `toml:"-"` 197 198 // Type of the EWASM interpreter ("" for default) 199 EWASMInterpreter string 200 201 // Type of the EVM interpreter ("" for default) 202 EVMInterpreter string 203 204 // RPCGasCap is the global gas cap for eth-call variants. 205 RPCGasCap uint64 206 207 // RPCTxFeeCap is the global transaction fee(price * gaslimit) cap for 208 // send-transction variants. The unit is ether. 209 RPCTxFeeCap float64 210 211 // Checkpoint is a hardcoded checkpoint which can be nil. 212 Checkpoint *params.TrustedCheckpoint `toml:",omitempty"` 213 214 // CheckpointOracle is the configuration for checkpoint oracle. 215 CheckpointOracle *params.CheckpointOracleConfig `toml:",omitempty"` 216 217 // Berlin block override (TODO: remove after the fork) 218 OverrideBerlin *big.Int `toml:",omitempty"` 219 } 220 221 // CreateConsensusEngine creates a consensus engine for the given chain configuration. 222 func CreateConsensusEngine(stack *node.Node, chainConfig *params.ChainConfig, config *ethash.Config, notify []string, noverify bool, db ethdb.Database, ee *ethapi.PublicBlockChainAPI, genesisHash common.Hash) consensus.Engine { 223 // If proof-of-authority is requested, set it up 224 if chainConfig.Clique != nil { 225 return clique.New(chainConfig.Clique, db) 226 } 227 if chainConfig.Parlia != nil { 228 return parlia.New(chainConfig, db, ee, genesisHash) 229 } 230 // Otherwise assume proof-of-work 231 switch config.PowMode { 232 case ethash.ModeFake: 233 log.Warn("Ethash used in fake mode") 234 case ethash.ModeTest: 235 log.Warn("Ethash used in test mode") 236 case ethash.ModeShared: 237 log.Warn("Ethash used in shared mode") 238 } 239 engine := ethash.New(ethash.Config{ 240 PowMode: config.PowMode, 241 CacheDir: stack.ResolvePath(config.CacheDir), 242 CachesInMem: config.CachesInMem, 243 CachesOnDisk: config.CachesOnDisk, 244 CachesLockMmap: config.CachesLockMmap, 245 DatasetDir: config.DatasetDir, 246 DatasetsInMem: config.DatasetsInMem, 247 DatasetsOnDisk: config.DatasetsOnDisk, 248 DatasetsLockMmap: config.DatasetsLockMmap, 249 NotifyFull: config.NotifyFull, 250 }, notify, noverify) 251 engine.SetThreads(-1) // Disable CPU mining 252 return engine 253 }