github.1485827954.workers.dev/ethereum/go-ethereum@v1.14.3/eth/ethconfig/config.go (about)

     1  // Copyright 2021 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  
    17  // Package ethconfig contains the configuration of the ETH and LES protocols.
    18  package ethconfig
    19  
    20  import (
    21  	"errors"
    22  	"time"
    23  
    24  	"github.com/ethereum/go-ethereum/common"
    25  	"github.com/ethereum/go-ethereum/consensus"
    26  	"github.com/ethereum/go-ethereum/consensus/beacon"
    27  	"github.com/ethereum/go-ethereum/consensus/clique"
    28  	"github.com/ethereum/go-ethereum/consensus/ethash"
    29  	"github.com/ethereum/go-ethereum/core"
    30  	"github.com/ethereum/go-ethereum/core/txpool/blobpool"
    31  	"github.com/ethereum/go-ethereum/core/txpool/legacypool"
    32  	"github.com/ethereum/go-ethereum/eth/downloader"
    33  	"github.com/ethereum/go-ethereum/eth/gasprice"
    34  	"github.com/ethereum/go-ethereum/ethdb"
    35  	"github.com/ethereum/go-ethereum/miner"
    36  	"github.com/ethereum/go-ethereum/params"
    37  )
    38  
    39  // FullNodeGPO contains default gasprice oracle settings for full node.
    40  var FullNodeGPO = gasprice.Config{
    41  	Blocks:           20,
    42  	Percentile:       60,
    43  	MaxHeaderHistory: 1024,
    44  	MaxBlockHistory:  1024,
    45  	MaxPrice:         gasprice.DefaultMaxPrice,
    46  	IgnorePrice:      gasprice.DefaultIgnorePrice,
    47  }
    48  
    49  // Defaults contains default settings for use on the Ethereum main net.
    50  var Defaults = Config{
    51  	SyncMode:           downloader.SnapSync,
    52  	NetworkId:          0, // enable auto configuration of networkID == chainID
    53  	TxLookupLimit:      2350000,
    54  	TransactionHistory: 2350000,
    55  	StateHistory:       params.FullImmutabilityThreshold,
    56  	LightPeers:         100,
    57  	DatabaseCache:      512,
    58  	TrieCleanCache:     154,
    59  	TrieDirtyCache:     256,
    60  	TrieTimeout:        60 * time.Minute,
    61  	SnapshotCache:      102,
    62  	FilterLogCacheSize: 32,
    63  	Miner:              miner.DefaultConfig,
    64  	TxPool:             legacypool.DefaultConfig,
    65  	BlobPool:           blobpool.DefaultConfig,
    66  	RPCGasCap:          50000000,
    67  	RPCEVMTimeout:      5 * time.Second,
    68  	GPO:                FullNodeGPO,
    69  	RPCTxFeeCap:        1, // 1 ether
    70  }
    71  
    72  //go:generate go run github.com/fjl/gencodec -type Config -formats toml -out gen_config.go
    73  
    74  // Config contains configuration options for ETH and LES protocols.
    75  type Config struct {
    76  	// The genesis block, which is inserted if the database is empty.
    77  	// If nil, the Ethereum main net block is used.
    78  	Genesis *core.Genesis `toml:",omitempty"`
    79  
    80  	// Network ID separates blockchains on the peer-to-peer networking level. When left
    81  	// zero, the chain ID is used as network ID.
    82  	NetworkId uint64
    83  	SyncMode  downloader.SyncMode
    84  
    85  	// This can be set to list of enrtree:// URLs which will be queried for
    86  	// nodes to connect to.
    87  	EthDiscoveryURLs  []string
    88  	SnapDiscoveryURLs []string
    89  
    90  	NoPruning  bool // Whether to disable pruning and flush everything to disk
    91  	NoPrefetch bool // Whether to disable prefetching and only load state on demand
    92  
    93  	// Deprecated, use 'TransactionHistory' instead.
    94  	TxLookupLimit      uint64 `toml:",omitempty"` // The maximum number of blocks from head whose tx indices are reserved.
    95  	TransactionHistory uint64 `toml:",omitempty"` // The maximum number of blocks from head whose tx indices are reserved.
    96  	StateHistory       uint64 `toml:",omitempty"` // The maximum number of blocks from head whose state histories are reserved.
    97  
    98  	// State scheme represents the scheme used to store ethereum states and trie
    99  	// nodes on top. It can be 'hash', 'path', or none which means use the scheme
   100  	// consistent with persistent state.
   101  	StateScheme string `toml:",omitempty"`
   102  
   103  	// RequiredBlocks is a set of block number -> hash mappings which must be in the
   104  	// canonical chain of all remote peers. Setting the option makes geth verify the
   105  	// presence of these blocks for every new peer connection.
   106  	RequiredBlocks map[uint64]common.Hash `toml:"-"`
   107  
   108  	// Light client options
   109  	LightServ        int  `toml:",omitempty"` // Maximum percentage of time allowed for serving LES requests
   110  	LightIngress     int  `toml:",omitempty"` // Incoming bandwidth limit for light servers
   111  	LightEgress      int  `toml:",omitempty"` // Outgoing bandwidth limit for light servers
   112  	LightPeers       int  `toml:",omitempty"` // Maximum number of LES client peers
   113  	LightNoPrune     bool `toml:",omitempty"` // Whether to disable light chain pruning
   114  	LightNoSyncServe bool `toml:",omitempty"` // Whether to serve light clients before syncing
   115  
   116  	// Database options
   117  	SkipBcVersionCheck bool `toml:"-"`
   118  	DatabaseHandles    int  `toml:"-"`
   119  	DatabaseCache      int
   120  	DatabaseFreezer    string
   121  
   122  	TrieCleanCache int
   123  	TrieDirtyCache int
   124  	TrieTimeout    time.Duration
   125  	SnapshotCache  int
   126  	Preimages      bool
   127  
   128  	// This is the number of blocks for which logs will be cached in the filter system.
   129  	FilterLogCacheSize int
   130  
   131  	// Mining options
   132  	Miner miner.Config
   133  
   134  	// Transaction pool options
   135  	TxPool   legacypool.Config
   136  	BlobPool blobpool.Config
   137  
   138  	// Gas Price Oracle options
   139  	GPO gasprice.Config
   140  
   141  	// Enables tracking of SHA3 preimages in the VM
   142  	EnablePreimageRecording bool
   143  
   144  	// Enables VM tracing
   145  	VMTrace           string
   146  	VMTraceJsonConfig string
   147  
   148  	// Miscellaneous options
   149  	DocRoot string `toml:"-"`
   150  
   151  	// RPCGasCap is the global gas cap for eth-call variants.
   152  	RPCGasCap uint64
   153  
   154  	// RPCEVMTimeout is the global timeout for eth-call.
   155  	RPCEVMTimeout time.Duration
   156  
   157  	// RPCTxFeeCap is the global transaction fee(price * gaslimit) cap for
   158  	// send-transaction variants. The unit is ether.
   159  	RPCTxFeeCap float64
   160  
   161  	// OverrideCancun (TODO: remove after the fork)
   162  	OverrideCancun *uint64 `toml:",omitempty"`
   163  
   164  	// OverrideVerkle (TODO: remove after the fork)
   165  	OverrideVerkle *uint64 `toml:",omitempty"`
   166  }
   167  
   168  // CreateConsensusEngine creates a consensus engine for the given chain config.
   169  // Clique is allowed for now to live standalone, but ethash is forbidden and can
   170  // only exist on already merged networks.
   171  func CreateConsensusEngine(config *params.ChainConfig, db ethdb.Database) (consensus.Engine, error) {
   172  	// Geth v1.14.0 dropped support for non-merged networks in any consensus
   173  	// mode. If such a network is requested, reject startup.
   174  	if !config.TerminalTotalDifficultyPassed {
   175  		return nil, errors.New("only PoS networks are supported, please transition old ones with Geth v1.13.x")
   176  	}
   177  	// Wrap previously supported consensus engines into their post-merge counterpart
   178  	if config.Clique != nil {
   179  		return beacon.New(clique.New(config.Clique, db)), nil
   180  	}
   181  	return beacon.New(ethash.NewFaker()), nil
   182  }