github.com/nitinawathare/ethereumassignment3@v0.0.0-20211021213010-f07344c2b868/go-ethereum/eth/config.go (about)

     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  
    17  package eth
    18  
    19  import (
    20  	"math/big"
    21  	"os"
    22  	"os/user"
    23  	"path/filepath"
    24  	"runtime"
    25  	"time"
    26  
    27  	"github.com/ethereum/go-ethereum/common"
    28  	"github.com/ethereum/go-ethereum/common/hexutil"
    29  	"github.com/ethereum/go-ethereum/consensus/ethash"
    30  	"github.com/ethereum/go-ethereum/core"
    31  	"github.com/ethereum/go-ethereum/eth/downloader"
    32  	"github.com/ethereum/go-ethereum/eth/gasprice"
    33  	"github.com/ethereum/go-ethereum/params"
    34  )
    35  
    36  // DefaultConfig contains default settings for use on the Ethereum main net.
    37  var DefaultConfig = Config{
    38  	SyncMode: downloader.FastSync,
    39  	Ethash: ethash.Config{
    40  		CacheDir:       "ethash",
    41  		CachesInMem:    2,
    42  		CachesOnDisk:   3,
    43  		DatasetsInMem:  1,
    44  		DatasetsOnDisk: 2,
    45  	},
    46  	InterArrival:   15,
    47  	HashPower:      1,
    48  	Behavior:       0,
    49  	NetworkId:      1,
    50  	LightPeers:     100,
    51  	DatabaseCache:  512,
    52  	TrieCleanCache: 256,
    53  	TrieDirtyCache: 256,
    54  	TrieTimeout:    60 * time.Minute,
    55  	MinerGasFloor:  400000000,
    56  	MinerGasCeil:   400000000,
    57  	MinerGasPrice:  big.NewInt(params.GWei),
    58  	MinerRecommit:  3 * time.Second,
    59  
    60  	TxPool: core.DefaultTxPoolConfig,
    61  	GPO: gasprice.Config{
    62  		Blocks:     20,
    63  		Percentile: 60,
    64  	},
    65  }
    66  
    67  func init() {
    68  	home := os.Getenv("HOME")
    69  	if home == "" {
    70  		if user, err := user.Current(); err == nil {
    71  			home = user.HomeDir
    72  		}
    73  	}
    74  	if runtime.GOOS == "darwin" {
    75  		DefaultConfig.Ethash.DatasetDir = filepath.Join(home, "Library", "Ethash")
    76  	} else if runtime.GOOS == "windows" {
    77  		localappdata := os.Getenv("LOCALAPPDATA")
    78  		if localappdata != "" {
    79  			DefaultConfig.Ethash.DatasetDir = filepath.Join(localappdata, "Ethash")
    80  		} else {
    81  			DefaultConfig.Ethash.DatasetDir = filepath.Join(home, "AppData", "Local", "Ethash")
    82  		}
    83  	} else {
    84  		DefaultConfig.Ethash.DatasetDir = filepath.Join(home, ".ethash")
    85  	}
    86  }
    87  
    88  //go:generate gencodec -type Config -field-override configMarshaling -formats toml -out gen_config.go
    89  
    90  type Config struct {
    91  	// The genesis block, which is inserted if the database is empty.
    92  	// If nil, the Ethereum main net block is used.
    93  	Genesis *core.Genesis `toml:",omitempty"`
    94  
    95  	// Protocol options
    96  	NetworkId    uint64 // Network ID to use for selecting peers to connect to
    97  	InterArrival float64
    98  	HashPower    float64
    99  	Behavior     uint64
   100  	SyncMode     downloader.SyncMode
   101  
   102  	NoPruning  bool // Whether to disable pruning and flush everything to disk
   103  	NoPrefetch bool // Whether to disable prefetching and only load state on demand
   104  
   105  	// Whitelist of required block number -> hash values to accept
   106  	Whitelist 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  	LightBandwidthIn  int  `toml:",omitempty"` // Incoming bandwidth limit for light servers
   111  	LightBandwidthOut int  `toml:",omitempty"` // Outgoing bandwidth limit for light servers
   112  	LightPeers        int  `toml:",omitempty"` // Maximum number of LES client peers
   113  	OnlyAnnounce      bool // Maximum number of LES client peers
   114  
   115  	// Ultra Light client options
   116  	ULC *ULCConfig `toml:",omitempty"`
   117  
   118  	// Database options
   119  	SkipBcVersionCheck bool `toml:"-"`
   120  	DatabaseHandles    int  `toml:"-"`
   121  	DatabaseCache      int
   122  
   123  	TrieCleanCache int
   124  	TrieDirtyCache int
   125  	TrieTimeout    time.Duration
   126  
   127  	// Mining-related options
   128  	Etherbase      common.Address `toml:",omitempty"`
   129  	MinerNotify    []string       `toml:",omitempty"`
   130  	MinerExtraData []byte         `toml:",omitempty"`
   131  	MinerGasFloor  uint64
   132  	MinerGasCeil   uint64
   133  	MinerGasPrice  *big.Int
   134  	MinerRecommit  time.Duration
   135  	MinerNoverify  bool
   136  
   137  	// Ethash options
   138  	Ethash ethash.Config
   139  
   140  	// Transaction pool options
   141  	TxPool core.TxPoolConfig
   142  
   143  	// Gas Price Oracle options
   144  	GPO gasprice.Config
   145  
   146  	// Enables tracking of SHA3 preimages in the VM
   147  	EnablePreimageRecording bool
   148  
   149  	// Miscellaneous options
   150  	DocRoot string `toml:"-"`
   151  
   152  	// Type of the EWASM interpreter ("" for default)
   153  	EWASMInterpreter string
   154  
   155  	// Type of the EVM interpreter ("" for default)
   156  	EVMInterpreter string
   157  
   158  	// Constantinople block override (TODO: remove after the fork)
   159  	ConstantinopleOverride *big.Int
   160  
   161  	// RPCGasCap is the global gas cap for eth-call variants.
   162  	RPCGasCap *big.Int `toml:",omitempty"`
   163  }
   164  
   165  type configMarshaling struct {
   166  	MinerExtraData hexutil.Bytes
   167  }