config.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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/common/hexutil"
  26. "github.com/ethereum/go-ethereum/consensus/ethash"
  27. "github.com/ethereum/go-ethereum/core"
  28. "github.com/ethereum/go-ethereum/eth/downloader"
  29. "github.com/ethereum/go-ethereum/eth/gasprice"
  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. DatabaseCache: 768,
  45. TrieCache: 256,
  46. TrieTimeout: 60 * time.Minute,
  47. GasPrice: big.NewInt(18 * params.Shannon),
  48. TxPool: core.DefaultTxPoolConfig,
  49. GPO: gasprice.Config{
  50. Blocks: 20,
  51. Percentile: 60,
  52. },
  53. }
  54. func init() {
  55. home := os.Getenv("HOME")
  56. if home == "" {
  57. if user, err := user.Current(); err == nil {
  58. home = user.HomeDir
  59. }
  60. }
  61. if runtime.GOOS == "windows" {
  62. DefaultConfig.Ethash.DatasetDir = filepath.Join(home, "AppData", "Ethash")
  63. } else {
  64. DefaultConfig.Ethash.DatasetDir = filepath.Join(home, ".ethash")
  65. }
  66. }
  67. //go:generate gencodec -type Config -field-override configMarshaling -formats toml -out gen_config.go
  68. type Config struct {
  69. // The genesis block, which is inserted if the database is empty.
  70. // If nil, the Ethereum main net block is used.
  71. Genesis *core.Genesis `toml:",omitempty"`
  72. // Protocol options
  73. NetworkId uint64 // Network ID to use for selecting peers to connect to
  74. SyncMode downloader.SyncMode
  75. NoPruning bool
  76. // Light client options
  77. LightServ int `toml:",omitempty"` // Maximum percentage of time allowed for serving LES requests
  78. LightPeers int `toml:",omitempty"` // Maximum number of LES client peers
  79. // Database options
  80. SkipBcVersionCheck bool `toml:"-"`
  81. DatabaseHandles int `toml:"-"`
  82. DatabaseCache int
  83. TrieCache int
  84. TrieTimeout time.Duration
  85. // Mining-related options
  86. Etherbase common.Address `toml:",omitempty"`
  87. MinerThreads int `toml:",omitempty"`
  88. ExtraData []byte `toml:",omitempty"`
  89. GasPrice *big.Int
  90. // Ethash options
  91. Ethash ethash.Config
  92. // Transaction pool options
  93. TxPool core.TxPoolConfig
  94. // Gas Price Oracle options
  95. GPO gasprice.Config
  96. // Enables tracking of SHA3 preimages in the VM
  97. EnablePreimageRecording bool
  98. // Miscellaneous options
  99. DocRoot string `toml:"-"`
  100. }
  101. type configMarshaling struct {
  102. ExtraData hexutil.Bytes
  103. }