github.com/theQRL/go-zond@v0.1.1/zond/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/theQRL/go-zond/common"
    25  	"github.com/theQRL/go-zond/consensus"
    26  	"github.com/theQRL/go-zond/consensus/beacon"
    27  	"github.com/theQRL/go-zond/consensus/clique"
    28  	"github.com/theQRL/go-zond/consensus/ethash"
    29  	"github.com/theQRL/go-zond/core"
    30  	"github.com/theQRL/go-zond/core/rawdb"
    31  	"github.com/theQRL/go-zond/core/txpool/blobpool"
    32  	"github.com/theQRL/go-zond/core/txpool/legacypool"
    33  	"github.com/theQRL/go-zond/miner"
    34  	"github.com/theQRL/go-zond/params"
    35  	"github.com/theQRL/go-zond/zond/downloader"
    36  	"github.com/theQRL/go-zond/zond/gasprice"
    37  	"github.com/theQRL/go-zond/zonddb"
    38  )
    39  
    40  // FullNodeGPO contains default gasprice oracle settings for full node.
    41  var FullNodeGPO = gasprice.Config{
    42  	Blocks:           20,
    43  	Percentile:       60,
    44  	MaxHeaderHistory: 1024,
    45  	MaxBlockHistory:  1024,
    46  	MaxPrice:         gasprice.DefaultMaxPrice,
    47  	IgnorePrice:      gasprice.DefaultIgnorePrice,
    48  }
    49  
    50  // LightClientGPO contains default gasprice oracle settings for light client.
    51  var LightClientGPO = gasprice.Config{
    52  	Blocks:           2,
    53  	Percentile:       60,
    54  	MaxHeaderHistory: 300,
    55  	MaxBlockHistory:  5,
    56  	MaxPrice:         gasprice.DefaultMaxPrice,
    57  	IgnorePrice:      gasprice.DefaultIgnorePrice,
    58  }
    59  
    60  // Defaults contains default settings for use on the Ethereum main net.
    61  var Defaults = Config{
    62  	SyncMode:           downloader.SnapSync,
    63  	NetworkId:          1,
    64  	TxLookupLimit:      2350000,
    65  	TransactionHistory: 2350000,
    66  	StateHistory:       params.FullImmutabilityThreshold,
    67  	StateScheme:        rawdb.HashScheme,
    68  	LightPeers:         100,
    69  	DatabaseCache:      512,
    70  	TrieCleanCache:     154,
    71  	TrieDirtyCache:     256,
    72  	TrieTimeout:        60 * time.Minute,
    73  	SnapshotCache:      102,
    74  	FilterLogCacheSize: 32,
    75  	Miner:              miner.DefaultConfig,
    76  	TxPool:             legacypool.DefaultConfig,
    77  	BlobPool:           blobpool.DefaultConfig,
    78  	RPCGasCap:          50000000,
    79  	RPCEVMTimeout:      5 * time.Second,
    80  	GPO:                FullNodeGPO,
    81  	RPCTxFeeCap:        1, // 1 ether
    82  }
    83  
    84  //go:generate go run github.com/fjl/gencodec -type Config -formats toml -out gen_config.go
    85  
    86  // Config contains configuration options for of the ETH and LES protocols.
    87  type Config struct {
    88  	// The genesis block, which is inserted if the database is empty.
    89  	// If nil, the Ethereum main net block is used.
    90  	Genesis *core.Genesis `toml:",omitempty"`
    91  
    92  	// Protocol options
    93  	NetworkId uint64 // Network ID to use for selecting peers to connect to
    94  	SyncMode  downloader.SyncMode
    95  
    96  	// This can be set to list of enrtree:// URLs which will be queried for
    97  	// for nodes to connect to.
    98  	EthDiscoveryURLs  []string
    99  	SnapDiscoveryURLs []string
   100  
   101  	NoPruning  bool // Whether to disable pruning and flush everything to disk
   102  	NoPrefetch bool // Whether to disable prefetching and only load state on demand
   103  
   104  	// Deprecated, use 'TransactionHistory' instead.
   105  	TxLookupLimit      uint64 `toml:",omitempty"` // The maximum number of blocks from head whose tx indices are reserved.
   106  	TransactionHistory uint64 `toml:",omitempty"` // The maximum number of blocks from head whose tx indices are reserved.
   107  	StateHistory       uint64 `toml:",omitempty"` // The maximum number of blocks from head whose state histories are reserved.
   108  	StateScheme        string `toml:",omitempty"` // State scheme used to store ethereum state and merkle trie nodes on top
   109  
   110  	// RequiredBlocks is a set of block number -> hash mappings which must be in the
   111  	// canonical chain of all remote peers. Setting the option makes geth verify the
   112  	// presence of these blocks for every new peer connection.
   113  	RequiredBlocks map[uint64]common.Hash `toml:"-"`
   114  
   115  	// Light client options
   116  	LightServ        int  `toml:",omitempty"` // Maximum percentage of time allowed for serving LES requests
   117  	LightIngress     int  `toml:",omitempty"` // Incoming bandwidth limit for light servers
   118  	LightEgress      int  `toml:",omitempty"` // Outgoing bandwidth limit for light servers
   119  	LightPeers       int  `toml:",omitempty"` // Maximum number of LES client peers
   120  	LightNoPrune     bool `toml:",omitempty"` // Whether to disable light chain pruning
   121  	LightNoSyncServe bool `toml:",omitempty"` // Whether to serve light clients before syncing
   122  
   123  	// Database options
   124  	SkipBcVersionCheck bool `toml:"-"`
   125  	DatabaseHandles    int  `toml:"-"`
   126  	DatabaseCache      int
   127  	DatabaseFreezer    string
   128  
   129  	TrieCleanCache int
   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   legacypool.Config
   143  	BlobPool blobpool.Config
   144  
   145  	// Gas Price Oracle options
   146  	GPO gasprice.Config
   147  
   148  	// Enables tracking of SHA3 preimages in the VM
   149  	EnablePreimageRecording bool
   150  
   151  	// Miscellaneous options
   152  	DocRoot string `toml:"-"`
   153  
   154  	// RPCGasCap is the global gas cap for eth-call variants.
   155  	RPCGasCap uint64
   156  
   157  	// RPCEVMTimeout is the global timeout for eth-call.
   158  	RPCEVMTimeout time.Duration
   159  
   160  	// RPCTxFeeCap is the global transaction fee(price * gaslimit) cap for
   161  	// send-transaction variants. The unit is ether.
   162  	RPCTxFeeCap float64
   163  
   164  	// OverrideCancun (TODO: remove after the fork)
   165  	OverrideCancun *uint64 `toml:",omitempty"`
   166  
   167  	// OverrideVerkle (TODO: remove after the fork)
   168  	OverrideVerkle *uint64 `toml:",omitempty"`
   169  }
   170  
   171  // CreateConsensusEngine creates a consensus engine for the given chain config.
   172  // Clique is allowed for now to live standalone, but ethash is forbidden and can
   173  // only exist on already merged networks.
   174  func CreateConsensusEngine(config *params.ChainConfig, db zonddb.Database) (consensus.Engine, error) {
   175  	// If proof-of-authority is requested, set it up
   176  	if config.Clique != nil {
   177  		return beacon.New(clique.New(config.Clique, db)), nil
   178  	}
   179  	// If defaulting to proof-of-work, enforce an already merged network since
   180  	// we cannot run PoW algorithms and more, so we cannot even follow a chain
   181  	// not coordinated by a beacon node.
   182  	if !config.TerminalTotalDifficultyPassed {
   183  		return nil, errors.New("ethash is only supported as a historical component of already merged networks")
   184  	}
   185  	return beacon.New(ethash.NewFaker()), nil
   186  }