config.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. "github.com/ethereum/go-ethereum/common"
  24. "github.com/ethereum/go-ethereum/common/hexutil"
  25. "github.com/ethereum/go-ethereum/core"
  26. "github.com/ethereum/go-ethereum/eth/downloader"
  27. "github.com/ethereum/go-ethereum/eth/gasprice"
  28. "github.com/ethereum/go-ethereum/params"
  29. )
  30. // DefaultConfig contains default settings for use on the Ethereum main net.
  31. var DefaultConfig = Config{
  32. SyncMode: downloader.FastSync,
  33. EthashCachesInMem: 2,
  34. EthashCachesOnDisk: 3,
  35. EthashDatasetsInMem: 1,
  36. EthashDatasetsOnDisk: 2,
  37. NetworkId: 1,
  38. LightPeers: 20,
  39. DatabaseCache: 128,
  40. GasPrice: big.NewInt(20 * params.Shannon),
  41. GPO: gasprice.Config{
  42. Blocks: 10,
  43. Percentile: 50,
  44. },
  45. }
  46. func init() {
  47. home := os.Getenv("HOME")
  48. if home == "" {
  49. if user, err := user.Current(); err == nil {
  50. home = user.HomeDir
  51. }
  52. }
  53. if runtime.GOOS == "windows" {
  54. DefaultConfig.EthashDatasetDir = filepath.Join(home, "AppData", "Ethash")
  55. } else {
  56. DefaultConfig.EthashDatasetDir = filepath.Join(home, ".ethash")
  57. }
  58. }
  59. //go:generate gencodec -type Config -field-override configMarshaling -formats toml -out gen_config.go
  60. type Config struct {
  61. // The genesis block, which is inserted if the database is empty.
  62. // If nil, the Ethereum main net block is used.
  63. Genesis *core.Genesis `toml:",omitempty"`
  64. // Protocol options
  65. NetworkId int // Network ID to use for selecting peers to connect to
  66. SyncMode downloader.SyncMode
  67. // Light client options
  68. LightServ int `toml:",omitempty"` // Maximum percentage of time allowed for serving LES requests
  69. LightPeers int `toml:",omitempty"` // Maximum number of LES client peers
  70. MaxPeers int `toml:"-"` // Maximum number of global peers
  71. // Database options
  72. SkipBcVersionCheck bool `toml:"-"`
  73. DatabaseHandles int `toml:"-"`
  74. DatabaseCache int
  75. // Mining-related options
  76. Etherbase common.Address `toml:",omitempty"`
  77. MinerThreads int `toml:",omitempty"`
  78. ExtraData []byte `toml:",omitempty"`
  79. GasPrice *big.Int
  80. // Ethash options
  81. EthashCacheDir string
  82. EthashCachesInMem int
  83. EthashCachesOnDisk int
  84. EthashDatasetDir string
  85. EthashDatasetsInMem int
  86. EthashDatasetsOnDisk int
  87. // Gas Price Oracle options
  88. GPO gasprice.Config
  89. // Enables tracking of SHA3 preimages in the VM
  90. EnablePreimageRecording bool
  91. // Miscellaneous options
  92. DocRoot string `toml:"-"`
  93. PowFake bool `toml:"-"`
  94. PowTest bool `toml:"-"`
  95. PowShared bool `toml:"-"`
  96. }
  97. type configMarshaling struct {
  98. ExtraData hexutil.Bytes
  99. }