config.go 3.2 KB

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