config.go 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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. // Package ethconfig contains the configuration of the ETH and LES protocols.
  17. package ethconfig
  18. import (
  19. "math/big"
  20. "os"
  21. "os/user"
  22. "path/filepath"
  23. "runtime"
  24. "time"
  25. "github.com/ethereum/go-ethereum/common"
  26. "github.com/ethereum/go-ethereum/consensus"
  27. "github.com/ethereum/go-ethereum/consensus/clique"
  28. "github.com/ethereum/go-ethereum/consensus/ethash"
  29. "github.com/ethereum/go-ethereum/consensus/parlia"
  30. "github.com/ethereum/go-ethereum/core"
  31. "github.com/ethereum/go-ethereum/eth/downloader"
  32. "github.com/ethereum/go-ethereum/eth/gasprice"
  33. "github.com/ethereum/go-ethereum/ethdb"
  34. "github.com/ethereum/go-ethereum/internal/ethapi"
  35. "github.com/ethereum/go-ethereum/log"
  36. "github.com/ethereum/go-ethereum/miner"
  37. "github.com/ethereum/go-ethereum/node"
  38. "github.com/ethereum/go-ethereum/params"
  39. )
  40. // FullNodeGPO contains default gasprice oracle settings for full node.
  41. var FullNodeGPO = gasprice.Config{
  42. Blocks: 20,
  43. Percentile: 60,
  44. MaxPrice: gasprice.DefaultMaxPrice,
  45. OracleThreshold: 1000,
  46. }
  47. // LightClientGPO contains default gasprice oracle settings for light client.
  48. var LightClientGPO = gasprice.Config{
  49. Blocks: 2,
  50. Percentile: 60,
  51. MaxPrice: gasprice.DefaultMaxPrice,
  52. }
  53. // Defaults contains default settings for use on the Ethereum main net.
  54. var Defaults = Config{
  55. SyncMode: downloader.FastSync,
  56. Ethash: ethash.Config{
  57. CacheDir: "ethash",
  58. CachesInMem: 2,
  59. CachesOnDisk: 3,
  60. CachesLockMmap: false,
  61. DatasetsInMem: 1,
  62. DatasetsOnDisk: 2,
  63. DatasetsLockMmap: false,
  64. },
  65. NetworkId: 1,
  66. TxLookupLimit: 2350000,
  67. LightPeers: 100,
  68. UltraLightFraction: 75,
  69. DatabaseCache: 512,
  70. TrieCleanCache: 154,
  71. TrieCleanCacheJournal: "triecache",
  72. TrieCleanCacheRejournal: 60 * time.Minute,
  73. TrieDirtyCache: 256,
  74. TrieTimeout: 60 * time.Minute,
  75. TriesInMemory: 128,
  76. SnapshotCache: 102,
  77. Miner: miner.Config{
  78. GasFloor: 8000000,
  79. GasCeil: 8000000,
  80. GasPrice: big.NewInt(params.GWei),
  81. Recommit: 3 * time.Second,
  82. DelayLeftOver: 50 * time.Millisecond,
  83. },
  84. TxPool: core.DefaultTxPoolConfig,
  85. RPCGasCap: 25000000,
  86. GPO: FullNodeGPO,
  87. RPCTxFeeCap: 1, // 1 ether
  88. }
  89. func init() {
  90. home := os.Getenv("HOME")
  91. if home == "" {
  92. if user, err := user.Current(); err == nil {
  93. home = user.HomeDir
  94. }
  95. }
  96. if runtime.GOOS == "darwin" {
  97. Defaults.Ethash.DatasetDir = filepath.Join(home, "Library", "Ethash")
  98. } else if runtime.GOOS == "windows" {
  99. localappdata := os.Getenv("LOCALAPPDATA")
  100. if localappdata != "" {
  101. Defaults.Ethash.DatasetDir = filepath.Join(localappdata, "Ethash")
  102. } else {
  103. Defaults.Ethash.DatasetDir = filepath.Join(home, "AppData", "Local", "Ethash")
  104. }
  105. } else {
  106. Defaults.Ethash.DatasetDir = filepath.Join(home, ".ethash")
  107. }
  108. }
  109. //go:generate gencodec -type Config -formats toml -out gen_config.go
  110. // Config contains configuration options for of the ETH and LES protocols.
  111. type Config struct {
  112. // The genesis block, which is inserted if the database is empty.
  113. // If nil, the Ethereum main net block is used.
  114. Genesis *core.Genesis `toml:",omitempty"`
  115. // Protocol options
  116. NetworkId uint64 // Network ID to use for selecting peers to connect to
  117. SyncMode downloader.SyncMode
  118. // This can be set to list of enrtree:// URLs which will be queried for
  119. // for nodes to connect to.
  120. EthDiscoveryURLs []string
  121. SnapDiscoveryURLs []string
  122. NoPruning bool // Whether to disable pruning and flush everything to disk
  123. DirectBroadcast bool
  124. RangeLimit bool
  125. TxLookupLimit uint64 `toml:",omitempty"` // The maximum number of blocks from head whose tx indices are reserved.
  126. // Whitelist of required block number -> hash values to accept
  127. Whitelist map[uint64]common.Hash `toml:"-"`
  128. // Light client options
  129. LightServ int `toml:",omitempty"` // Maximum percentage of time allowed for serving LES requests
  130. LightIngress int `toml:",omitempty"` // Incoming bandwidth limit for light servers
  131. LightEgress int `toml:",omitempty"` // Outgoing bandwidth limit for light servers
  132. LightPeers int `toml:",omitempty"` // Maximum number of LES client peers
  133. LightNoPrune bool `toml:",omitempty"` // Whether to disable light chain pruning
  134. LightNoSyncServe bool `toml:",omitempty"` // Whether to serve light clients before syncing
  135. SyncFromCheckpoint bool `toml:",omitempty"` // Whether to sync the header chain from the configured checkpoint
  136. // Ultra Light client options
  137. UltraLightServers []string `toml:",omitempty"` // List of trusted ultra light servers
  138. UltraLightFraction int `toml:",omitempty"` // Percentage of trusted servers to accept an announcement
  139. UltraLightOnlyAnnounce bool `toml:",omitempty"` // Whether to only announce headers, or also serve them
  140. // Database options
  141. SkipBcVersionCheck bool `toml:"-"`
  142. DatabaseHandles int `toml:"-"`
  143. DatabaseCache int
  144. DatabaseFreezer string
  145. TrieCleanCache int
  146. TrieCleanCacheJournal string `toml:",omitempty"` // Disk journal directory for trie cache to survive node restarts
  147. TrieCleanCacheRejournal time.Duration `toml:",omitempty"` // Time interval to regenerate the journal for clean cache
  148. TrieDirtyCache int
  149. TrieTimeout time.Duration
  150. SnapshotCache int
  151. TriesInMemory uint64
  152. Preimages bool
  153. // Mining options
  154. Miner miner.Config
  155. // Ethash options
  156. Ethash ethash.Config `toml:",omitempty"`
  157. // Transaction pool options
  158. TxPool core.TxPoolConfig
  159. // Gas Price Oracle options
  160. GPO gasprice.Config
  161. // Enables tracking of SHA3 preimages in the VM
  162. EnablePreimageRecording bool
  163. // Miscellaneous options
  164. DocRoot string `toml:"-"`
  165. // Type of the EWASM interpreter ("" for default)
  166. EWASMInterpreter string
  167. // Type of the EVM interpreter ("" for default)
  168. EVMInterpreter string
  169. // RPCGasCap is the global gas cap for eth-call variants.
  170. RPCGasCap uint64
  171. // RPCTxFeeCap is the global transaction fee(price * gaslimit) cap for
  172. // send-transction variants. The unit is ether.
  173. RPCTxFeeCap float64
  174. // Checkpoint is a hardcoded checkpoint which can be nil.
  175. Checkpoint *params.TrustedCheckpoint `toml:",omitempty"`
  176. // CheckpointOracle is the configuration for checkpoint oracle.
  177. CheckpointOracle *params.CheckpointOracleConfig `toml:",omitempty"`
  178. // Berlin block override (TODO: remove after the fork)
  179. OverrideBerlin *big.Int `toml:",omitempty"`
  180. }
  181. // CreateConsensusEngine creates a consensus engine for the given chain configuration.
  182. 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 {
  183. // If proof-of-authority is requested, set it up
  184. if chainConfig.Clique != nil {
  185. return clique.New(chainConfig.Clique, db)
  186. }
  187. if chainConfig.Parlia != nil {
  188. return parlia.New(chainConfig, db, ee, genesisHash)
  189. }
  190. // Otherwise assume proof-of-work
  191. switch config.PowMode {
  192. case ethash.ModeFake:
  193. log.Warn("Ethash used in fake mode")
  194. case ethash.ModeTest:
  195. log.Warn("Ethash used in test mode")
  196. case ethash.ModeShared:
  197. log.Warn("Ethash used in shared mode")
  198. }
  199. engine := ethash.New(ethash.Config{
  200. PowMode: config.PowMode,
  201. CacheDir: stack.ResolvePath(config.CacheDir),
  202. CachesInMem: config.CachesInMem,
  203. CachesOnDisk: config.CachesOnDisk,
  204. CachesLockMmap: config.CachesLockMmap,
  205. DatasetDir: config.DatasetDir,
  206. DatasetsInMem: config.DatasetsInMem,
  207. DatasetsOnDisk: config.DatasetsOnDisk,
  208. DatasetsLockMmap: config.DatasetsLockMmap,
  209. NotifyFull: config.NotifyFull,
  210. }, notify, noverify)
  211. engine.SetThreads(-1) // Disable CPU mining
  212. return engine
  213. }