config.go 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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 eth
  17. import (
  18. "math/big"
  19. "os"
  20. "os/user"
  21. "path/filepath"
  22. "runtime"
  23. "time"
  24. "github.com/ethereum/go-ethereum/common"
  25. "github.com/ethereum/go-ethereum/consensus/ethash"
  26. "github.com/ethereum/go-ethereum/core"
  27. "github.com/ethereum/go-ethereum/eth/downloader"
  28. "github.com/ethereum/go-ethereum/eth/gasprice"
  29. "github.com/ethereum/go-ethereum/miner"
  30. "github.com/ethereum/go-ethereum/params"
  31. )
  32. // DefaultFullGPOConfig contains default gasprice oracle settings for full node.
  33. var DefaultFullGPOConfig = gasprice.Config{
  34. Blocks: 20,
  35. Percentile: 60,
  36. MaxPrice: gasprice.DefaultMaxPrice,
  37. }
  38. // DefaultLightGPOConfig contains default gasprice oracle settings for light client.
  39. var DefaultLightGPOConfig = gasprice.Config{
  40. Blocks: 2,
  41. Percentile: 60,
  42. MaxPrice: gasprice.DefaultMaxPrice,
  43. }
  44. // DefaultConfig contains default settings for use on the Ethereum main net.
  45. var DefaultConfig = Config{
  46. SyncMode: downloader.FastSync,
  47. Ethash: ethash.Config{
  48. CacheDir: "ethash",
  49. CachesInMem: 2,
  50. CachesOnDisk: 3,
  51. CachesLockMmap: false,
  52. DatasetsInMem: 1,
  53. DatasetsOnDisk: 2,
  54. DatasetsLockMmap: false,
  55. },
  56. NetworkId: 1,
  57. LightPeers: 100,
  58. UltraLightFraction: 75,
  59. DatabaseCache: 512,
  60. TrieCleanCache: 154,
  61. TrieCleanCacheJournal: "triecache",
  62. TrieCleanCacheRejournal: 60 * time.Minute,
  63. TrieDirtyCache: 256,
  64. TrieTimeout: 60 * time.Minute,
  65. SnapshotCache: 102,
  66. Miner: miner.Config{
  67. GasFloor: 8000000,
  68. GasCeil: 8000000,
  69. GasPrice: big.NewInt(params.GWei),
  70. Recommit: 3 * time.Second,
  71. },
  72. TxPool: core.DefaultTxPoolConfig,
  73. RPCGasCap: 25000000,
  74. GPO: DefaultFullGPOConfig,
  75. RPCTxFeeCap: 1, // 1 ether
  76. }
  77. func init() {
  78. home := os.Getenv("HOME")
  79. if home == "" {
  80. if user, err := user.Current(); err == nil {
  81. home = user.HomeDir
  82. }
  83. }
  84. if runtime.GOOS == "darwin" {
  85. DefaultConfig.Ethash.DatasetDir = filepath.Join(home, "Library", "Ethash")
  86. } else if runtime.GOOS == "windows" {
  87. localappdata := os.Getenv("LOCALAPPDATA")
  88. if localappdata != "" {
  89. DefaultConfig.Ethash.DatasetDir = filepath.Join(localappdata, "Ethash")
  90. } else {
  91. DefaultConfig.Ethash.DatasetDir = filepath.Join(home, "AppData", "Local", "Ethash")
  92. }
  93. } else {
  94. DefaultConfig.Ethash.DatasetDir = filepath.Join(home, ".ethash")
  95. }
  96. }
  97. //go:generate gencodec -type Config -formats toml -out gen_config.go
  98. type Config struct {
  99. // The genesis block, which is inserted if the database is empty.
  100. // If nil, the Ethereum main net block is used.
  101. Genesis *core.Genesis `toml:",omitempty"`
  102. // Protocol options
  103. NetworkId uint64 // Network ID to use for selecting peers to connect to
  104. SyncMode downloader.SyncMode
  105. // This can be set to list of enrtree:// URLs which will be queried for
  106. // for nodes to connect to.
  107. EthDiscoveryURLs []string
  108. SnapDiscoveryURLs []string
  109. NoPruning bool // Whether to disable pruning and flush everything to disk
  110. NoPrefetch bool // Whether to disable prefetching and only load state on demand
  111. TxLookupLimit uint64 `toml:",omitempty"` // The maximum number of blocks from head whose tx indices are reserved.
  112. // Whitelist of required block number -> hash values to accept
  113. Whitelist map[uint64]common.Hash `toml:"-"`
  114. // Light client options
  115. LightServ int `toml:",omitempty"` // Maximum percentage of time allowed for serving LES requests
  116. LightIngress int `toml:",omitempty"` // Incoming bandwidth limit for light servers
  117. LightEgress int `toml:",omitempty"` // Outgoing bandwidth limit for light servers
  118. LightPeers int `toml:",omitempty"` // Maximum number of LES client peers
  119. LightNoPrune bool `toml:",omitempty"` // Whether to disable light chain pruning
  120. SyncFromCheckpoint bool `toml:",omitempty"` // Whether to sync the header chain from the configured checkpoint
  121. // Ultra Light client options
  122. UltraLightServers []string `toml:",omitempty"` // List of trusted ultra light servers
  123. UltraLightFraction int `toml:",omitempty"` // Percentage of trusted servers to accept an announcement
  124. UltraLightOnlyAnnounce bool `toml:",omitempty"` // Whether to only announce headers, or also serve them
  125. // Database options
  126. SkipBcVersionCheck bool `toml:"-"`
  127. DatabaseHandles int `toml:"-"`
  128. DatabaseCache int
  129. DatabaseFreezer string
  130. TrieCleanCache int
  131. TrieCleanCacheJournal string `toml:",omitempty"` // Disk journal directory for trie cache to survive node restarts
  132. TrieCleanCacheRejournal time.Duration `toml:",omitempty"` // Time interval to regenerate the journal for clean cache
  133. TrieDirtyCache int
  134. TrieTimeout time.Duration
  135. SnapshotCache int
  136. Preimages bool
  137. // Mining options
  138. Miner miner.Config
  139. // Ethash options
  140. Ethash ethash.Config
  141. // Transaction pool options
  142. TxPool core.TxPoolConfig
  143. // Gas Price Oracle options
  144. GPO gasprice.Config
  145. // Enables tracking of SHA3 preimages in the VM
  146. EnablePreimageRecording bool
  147. // Miscellaneous options
  148. DocRoot string `toml:"-"`
  149. // Type of the EWASM interpreter ("" for default)
  150. EWASMInterpreter string
  151. // Type of the EVM interpreter ("" for default)
  152. EVMInterpreter string
  153. // RPCGasCap is the global gas cap for eth-call variants.
  154. RPCGasCap uint64 `toml:",omitempty"`
  155. // RPCTxFeeCap is the global transaction fee(price * gaslimit) cap for
  156. // send-transction variants. The unit is ether.
  157. RPCTxFeeCap float64 `toml:",omitempty"`
  158. // Checkpoint is a hardcoded checkpoint which can be nil.
  159. Checkpoint *params.TrustedCheckpoint `toml:",omitempty"`
  160. // CheckpointOracle is the configuration for checkpoint oracle.
  161. CheckpointOracle *params.CheckpointOracleConfig `toml:",omitempty"`
  162. }