github.com/calmw/ethereum@v0.1.1/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/calmw/ethereum/common"
    25  	"github.com/calmw/ethereum/consensus"
    26  	"github.com/calmw/ethereum/consensus/beacon"
    27  	"github.com/calmw/ethereum/consensus/clique"
    28  	"github.com/calmw/ethereum/consensus/ethash"
    29  	"github.com/calmw/ethereum/core"
    30  	"github.com/calmw/ethereum/core/txpool"
    31  	"github.com/calmw/ethereum/eth/downloader"
    32  	"github.com/calmw/ethereum/eth/gasprice"
    33  	"github.com/calmw/ethereum/ethdb"
    34  	"github.com/calmw/ethereum/miner"
    35  	"github.com/calmw/ethereum/params"
    36  )
    37  
    38  // FullNodeGPO contains default gasprice oracle settings for full node.
    39  var FullNodeGPO = gasprice.Config{
    40  	Blocks:           20,
    41  	Percentile:       60,
    42  	MaxHeaderHistory: 1024,
    43  	MaxBlockHistory:  1024,
    44  	MaxPrice:         gasprice.DefaultMaxPrice,
    45  	IgnorePrice:      gasprice.DefaultIgnorePrice,
    46  }
    47  
    48  // LightClientGPO contains default gasprice oracle settings for light client.
    49  var LightClientGPO = gasprice.Config{
    50  	Blocks:           2,
    51  	Percentile:       60,
    52  	MaxHeaderHistory: 300,
    53  	MaxBlockHistory:  5,
    54  	MaxPrice:         gasprice.DefaultMaxPrice,
    55  	IgnorePrice:      gasprice.DefaultIgnorePrice,
    56  }
    57  
    58  // Defaults contains default settings for use on the Ethereum main net.
    59  var Defaults = Config{
    60  	SyncMode:                downloader.SnapSync,
    61  	NetworkId:               1,
    62  	TxLookupLimit:           2350000,
    63  	LightPeers:              100,
    64  	UltraLightFraction:      75,
    65  	DatabaseCache:           512,
    66  	TrieCleanCache:          154,
    67  	TrieCleanCacheJournal:   "triecache",
    68  	TrieCleanCacheRejournal: 60 * time.Minute,
    69  	TrieDirtyCache:          256,
    70  	TrieTimeout:             60 * time.Minute,
    71  	SnapshotCache:           102,
    72  	FilterLogCacheSize:      32,
    73  	Miner:                   miner.DefaultConfig,
    74  	TxPool:                  txpool.DefaultConfig,
    75  	RPCGasCap:               50000000,
    76  	RPCEVMTimeout:           5 * time.Second,
    77  	GPO:                     FullNodeGPO,
    78  	RPCTxFeeCap:             1, // 1 ether
    79  }
    80  
    81  //go:generate go run github.com/fjl/gencodec -type Config -formats toml -out gen_config.go
    82  
    83  // Config contains configuration options for of the ETH and LES protocols.
    84  type Config struct {
    85  	// The genesis block, which is inserted if the database is empty.
    86  	// If nil, the Ethereum main net block is used.
    87  	Genesis *core.Genesis `toml:",omitempty"`
    88  
    89  	// Protocol options
    90  	NetworkId uint64 // Network ID to use for selecting peers to connect to
    91  	SyncMode  downloader.SyncMode
    92  
    93  	// This can be set to list of enrtree:// URLs which will be queried for
    94  	// for nodes to connect to.
    95  	EthDiscoveryURLs  []string
    96  	SnapDiscoveryURLs []string
    97  
    98  	NoPruning  bool // Whether to disable pruning and flush everything to disk
    99  	NoPrefetch bool // Whether to disable prefetching and only load state on demand
   100  
   101  	TxLookupLimit uint64 `toml:",omitempty"` // The maximum number of blocks from head whose tx indices are reserved.
   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  	// Ultra Light client options
   117  	UltraLightServers      []string `toml:",omitempty"` // List of trusted ultra light servers
   118  	UltraLightFraction     int      `toml:",omitempty"` // Percentage of trusted servers to accept an announcement
   119  	UltraLightOnlyAnnounce bool     `toml:",omitempty"` // Whether to only announce headers, or also serve them
   120  
   121  	// Database options
   122  	SkipBcVersionCheck bool `toml:"-"`
   123  	DatabaseHandles    int  `toml:"-"`
   124  	DatabaseCache      int
   125  	DatabaseFreezer    string
   126  
   127  	TrieCleanCache          int
   128  	TrieCleanCacheJournal   string        `toml:",omitempty"` // Disk journal directory for trie cache to survive node restarts
   129  	TrieCleanCacheRejournal time.Duration `toml:",omitempty"` // Time interval to regenerate the journal for clean cache
   130  	TrieDirtyCache          int
   131  	TrieTimeout             time.Duration
   132  	SnapshotCache           int
   133  	Preimages               bool
   134  
   135  	// This is the number of blocks for which logs will be cached in the filter system.
   136  	FilterLogCacheSize int
   137  
   138  	// Mining options
   139  	Miner miner.Config
   140  
   141  	// Transaction pool options
   142  	TxPool txpool.Config
   143  
   144  	// Gas Price Oracle options
   145  	GPO gasprice.Config
   146  
   147  	// Enables tracking of SHA3 preimages in the VM
   148  	EnablePreimageRecording bool
   149  
   150  	// Miscellaneous options
   151  	DocRoot string `toml:"-"`
   152  
   153  	// RPCGasCap is the global gas cap for eth-call variants.
   154  	RPCGasCap uint64
   155  
   156  	// RPCEVMTimeout is the global timeout for eth-call.
   157  	RPCEVMTimeout time.Duration
   158  
   159  	// RPCTxFeeCap is the global transaction fee(price * gaslimit) cap for
   160  	// send-transaction variants. The unit is ether.
   161  	RPCTxFeeCap float64
   162  
   163  	// OverrideCancun (TODO: remove after the fork)
   164  	OverrideCancun *uint64 `toml:",omitempty"`
   165  }
   166  
   167  // CreateConsensusEngine creates a consensus engine for the given chain config.
   168  // Clique is allowed for now to live standalone, but ethash is forbidden and can
   169  // only exist on already merged networks.
   170  func CreateConsensusEngine(config *params.ChainConfig, db ethdb.Database) (consensus.Engine, error) {
   171  	// If proof-of-authority is requested, set it up
   172  	if config.Clique != nil {
   173  		return beacon.New(clique.New(config.Clique, db)), nil
   174  	}
   175  	// If defaulting to proof-of-work, enforce an already merged network since
   176  	// we cannot run PoW algorithms and more, so we cannot even follow a chain
   177  	// not coordinated by a beacon node.
   178  	if !config.TerminalTotalDifficultyPassed {
   179  		return nil, errors.New("ethash is only supported as a historical component of already merged networks")
   180  	}
   181  	return beacon.New(ethash.NewFaker()), nil
   182  }