config.go 4.39 KB
Newer Older
1
// Copyright 2017 The go-ethereum Authors
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.

package eth

import (
	"math/big"
	"os"
	"os/user"
	"path/filepath"
	"runtime"
25
	"time"
26 27

	"github.com/ethereum/go-ethereum/common"
28
	"github.com/ethereum/go-ethereum/consensus/ethash"
29 30 31
	"github.com/ethereum/go-ethereum/core"
	"github.com/ethereum/go-ethereum/eth/downloader"
	"github.com/ethereum/go-ethereum/eth/gasprice"
32
	"github.com/ethereum/go-ethereum/miner"
33 34 35 36 37
	"github.com/ethereum/go-ethereum/params"
)

// DefaultConfig contains default settings for use on the Ethereum main net.
var DefaultConfig = Config{
38 39 40 41 42 43 44 45
	SyncMode: downloader.FastSync,
	Ethash: ethash.Config{
		CacheDir:       "ethash",
		CachesInMem:    2,
		CachesOnDisk:   3,
		DatasetsInMem:  1,
		DatasetsOnDisk: 2,
	},
46 47 48 49 50 51
	NetworkId:      1,
	LightPeers:     100,
	DatabaseCache:  512,
	TrieCleanCache: 256,
	TrieDirtyCache: 256,
	TrieTimeout:    60 * time.Minute,
52 53 54 55 56 57
	Miner: miner.Config{
		GasFloor: 8000000,
		GasCeil:  8000000,
		GasPrice: big.NewInt(params.GWei),
		Recommit: 3 * time.Second,
	},
58
	TxPool: core.DefaultTxPoolConfig,
59
	GPO: gasprice.Config{
60 61
		Blocks:     20,
		Percentile: 60,
62 63 64 65 66 67 68 69 70 71
	},
}

func init() {
	home := os.Getenv("HOME")
	if home == "" {
		if user, err := user.Current(); err == nil {
			home = user.HomeDir
		}
	}
72 73 74 75 76 77 78 79 80
	if runtime.GOOS == "darwin" {
		DefaultConfig.Ethash.DatasetDir = filepath.Join(home, "Library", "Ethash")
	} else if runtime.GOOS == "windows" {
		localappdata := os.Getenv("LOCALAPPDATA")
		if localappdata != "" {
			DefaultConfig.Ethash.DatasetDir = filepath.Join(localappdata, "Ethash")
		} else {
			DefaultConfig.Ethash.DatasetDir = filepath.Join(home, "AppData", "Local", "Ethash")
		}
81
	} else {
82
		DefaultConfig.Ethash.DatasetDir = filepath.Join(home, ".ethash")
83 84 85
	}
}

86
//go:generate gencodec -type Config -formats toml -out gen_config.go
87 88 89 90 91 92 93

type Config struct {
	// The genesis block, which is inserted if the database is empty.
	// If nil, the Ethereum main net block is used.
	Genesis *core.Genesis `toml:",omitempty"`

	// Protocol options
94
	NetworkId uint64 // Network ID to use for selecting peers to connect to
95
	SyncMode  downloader.SyncMode
96 97 98

	NoPruning  bool // Whether to disable pruning and flush everything to disk
	NoPrefetch bool // Whether to disable prefetching and only load state on demand
99

100 101 102
	// Whitelist of required block number -> hash values to accept
	Whitelist map[uint64]common.Hash `toml:"-"`

103
	// Light client options
104 105 106 107 108
	LightServ         int  `toml:",omitempty"` // Maximum percentage of time allowed for serving LES requests
	LightBandwidthIn  int  `toml:",omitempty"` // Incoming bandwidth limit for light servers
	LightBandwidthOut int  `toml:",omitempty"` // Outgoing bandwidth limit for light servers
	LightPeers        int  `toml:",omitempty"` // Maximum number of LES client peers
	OnlyAnnounce      bool // Maximum number of LES client peers
109 110 111

	// Ultra Light client options
	ULC *ULCConfig `toml:",omitempty"`
112 113 114 115 116

	// Database options
	SkipBcVersionCheck bool `toml:"-"`
	DatabaseHandles    int  `toml:"-"`
	DatabaseCache      int
117 118 119 120

	TrieCleanCache int
	TrieDirtyCache int
	TrieTimeout    time.Duration
121

122 123
	// Mining options
	Miner miner.Config
124 125

	// Ethash options
126
	Ethash ethash.Config
127

128 129 130
	// Transaction pool options
	TxPool core.TxPoolConfig

131 132 133 134 135 136 137
	// Gas Price Oracle options
	GPO gasprice.Config

	// Enables tracking of SHA3 preimages in the VM
	EnablePreimageRecording bool

	// Miscellaneous options
138
	DocRoot string `toml:"-"`
139

140
	// Type of the EWASM interpreter ("" for default)
141
	EWASMInterpreter string
142

143 144
	// Type of the EVM interpreter ("" for default)
	EVMInterpreter string
145 146 147

	// Constantinople block override (TODO: remove after the fork)
	ConstantinopleOverride *big.Int
148 149 150

	// RPCGasCap is the global gas cap for eth-call variants.
	RPCGasCap *big.Int `toml:",omitempty"`
151
}