config.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. // DefaultConfig contains default settings for use on the Ethereum main net.
  33. var DefaultConfig = Config{
  34. SyncMode: downloader.FastSync,
  35. Ethash: ethash.Config{
  36. CacheDir: "ethash",
  37. CachesInMem: 2,
  38. CachesOnDisk: 3,
  39. DatasetsInMem: 1,
  40. DatasetsOnDisk: 2,
  41. },
  42. NetworkId: 1,
  43. LightPeers: 100,
  44. UltraLightFraction: 75,
  45. DatabaseCache: 512,
  46. TrieCleanCache: 256,
  47. TrieDirtyCache: 256,
  48. TrieTimeout: 60 * time.Minute,
  49. Miner: miner.Config{
  50. GasFloor: 8000000,
  51. GasCeil: 8000000,
  52. GasPrice: big.NewInt(params.GWei),
  53. Recommit: 3 * time.Second,
  54. },
  55. TxPool: core.DefaultTxPoolConfig,
  56. GPO: gasprice.Config{
  57. Blocks: 20,
  58. Percentile: 60,
  59. },
  60. }
  61. func init() {
  62. home := os.Getenv("HOME")
  63. if home == "" {
  64. if user, err := user.Current(); err == nil {
  65. home = user.HomeDir
  66. }
  67. }
  68. if runtime.GOOS == "darwin" {
  69. DefaultConfig.Ethash.DatasetDir = filepath.Join(home, "Library", "Ethash")
  70. } else if runtime.GOOS == "windows" {
  71. localappdata := os.Getenv("LOCALAPPDATA")
  72. if localappdata != "" {
  73. DefaultConfig.Ethash.DatasetDir = filepath.Join(localappdata, "Ethash")
  74. } else {
  75. DefaultConfig.Ethash.DatasetDir = filepath.Join(home, "AppData", "Local", "Ethash")
  76. }
  77. } else {
  78. DefaultConfig.Ethash.DatasetDir = filepath.Join(home, ".ethash")
  79. }
  80. }
  81. //go:generate gencodec -type Config -formats toml -out gen_config.go
  82. type Config struct {
  83. // The genesis block, which is inserted if the database is empty.
  84. // If nil, the Ethereum main net block is used.
  85. Genesis *core.Genesis `toml:",omitempty"`
  86. // Protocol options
  87. NetworkId uint64 // Network ID to use for selecting peers to connect to
  88. SyncMode downloader.SyncMode
  89. NoPruning bool // Whether to disable pruning and flush everything to disk
  90. NoPrefetch bool // Whether to disable prefetching and only load state on demand
  91. // Whitelist of required block number -> hash values to accept
  92. Whitelist map[uint64]common.Hash `toml:"-"`
  93. // Light client options
  94. LightServ int `toml:",omitempty"` // Maximum percentage of time allowed for serving LES requests
  95. LightBandwidthIn int `toml:",omitempty"` // Incoming bandwidth limit for light servers
  96. LightBandwidthOut int `toml:",omitempty"` // Outgoing bandwidth limit for light servers
  97. LightPeers int `toml:",omitempty"` // Maximum number of LES client peers
  98. // Ultra Light client options
  99. UltraLightServers []string `toml:",omitempty"` // List of trusted ultra light servers
  100. UltraLightFraction int `toml:",omitempty"` // Percentage of trusted servers to accept an announcement
  101. UltraLightOnlyAnnounce bool `toml:",omitempty"` // Whether to only announce headers, or also serve them
  102. // Database options
  103. SkipBcVersionCheck bool `toml:"-"`
  104. DatabaseHandles int `toml:"-"`
  105. DatabaseCache int
  106. DatabaseFreezer string
  107. TrieCleanCache int
  108. TrieDirtyCache int
  109. TrieTimeout time.Duration
  110. // Mining options
  111. Miner miner.Config
  112. // Ethash options
  113. Ethash ethash.Config
  114. // Transaction pool options
  115. TxPool core.TxPoolConfig
  116. // Gas Price Oracle options
  117. GPO gasprice.Config
  118. // Enables tracking of SHA3 preimages in the VM
  119. EnablePreimageRecording bool
  120. // Miscellaneous options
  121. DocRoot string `toml:"-"`
  122. // Type of the EWASM interpreter ("" for default)
  123. EWASMInterpreter string
  124. // Type of the EVM interpreter ("" for default)
  125. EVMInterpreter string
  126. // RPCGasCap is the global gas cap for eth-call variants.
  127. RPCGasCap *big.Int `toml:",omitempty"`
  128. // Checkpoint is a hardcoded checkpoint which can be nil.
  129. Checkpoint *params.TrustedCheckpoint
  130. // CheckpointOracle is the configuration for checkpoint oracle.
  131. CheckpointOracle *params.CheckpointOracleConfig
  132. }