github.com/SmartMeshFoundation/Spectrum@v0.0.0-20220621030607-452a266fee1e/eth/config.go (about)

     1  // Copyright 2017 The Spectrum Authors
     2  // This file is part of the Spectrum library.
     3  //
     4  // The Spectrum 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 Spectrum 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 Spectrum 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  
    26  	"github.com/SmartMeshFoundation/Spectrum/common"
    27  	"github.com/SmartMeshFoundation/Spectrum/common/hexutil"
    28  	"github.com/SmartMeshFoundation/Spectrum/consensus/ethash"
    29  	"github.com/SmartMeshFoundation/Spectrum/core"
    30  	"github.com/SmartMeshFoundation/Spectrum/eth/downloader"
    31  	"github.com/SmartMeshFoundation/Spectrum/eth/gasprice"
    32  	"github.com/SmartMeshFoundation/Spectrum/params"
    33  )
    34  
    35  // DefaultConfig contains default settings for use on the Ethereum main net.
    36  var DefaultConfig = Config{
    37  	SyncMode: downloader.FastSync,
    38  	Ethash: ethash.Config{
    39  		CacheDir:       "ethash",
    40  		CachesInMem:    2,
    41  		CachesOnDisk:   3,
    42  		DatasetsInMem:  1,
    43  		DatasetsOnDisk: 2,
    44  	},
    45  	NetworkId:     1,
    46  	LightPeers:    20,
    47  	DatabaseCache: 128,
    48  	GasPrice:      big.NewInt(18 * params.Shannon),
    49  
    50  	TxPool: core.DefaultTxPoolConfig,
    51  	GPO: gasprice.Config{
    52  		Blocks:     10,
    53  		Percentile: 50,
    54  	},
    55  }
    56  
    57  func init() {
    58  	home := os.Getenv("HOME")
    59  	if home == "" {
    60  		if user, err := user.Current(); err == nil {
    61  			home = user.HomeDir
    62  		}
    63  	}
    64  	if runtime.GOOS == "windows" {
    65  		DefaultConfig.Ethash.DatasetDir = filepath.Join(home, "AppData", "Ethash")
    66  	} else {
    67  		DefaultConfig.Ethash.DatasetDir = filepath.Join(home, ".ethash")
    68  	}
    69  }
    70  
    71  //go:generate gencodec -type Config -field-override configMarshaling -formats toml -out gen_config.go
    72  
    73  type Config struct {
    74  	// The genesis block, which is inserted if the database is empty.
    75  	// If nil, the Ethereum main net block is used.
    76  	Genesis *core.Genesis `toml:",omitempty"`
    77  
    78  	// Protocol options
    79  	NetworkId uint64 // Network ID to use for selecting peers to connect to
    80  	SyncMode  downloader.SyncMode
    81  
    82  	// Light client options
    83  	LightServ  int `toml:",omitempty"` // Maximum percentage of time allowed for serving LES requests
    84  	LightPeers int `toml:",omitempty"` // Maximum number of LES client peers
    85  
    86  	// Database options
    87  	SkipBcVersionCheck bool `toml:"-"`
    88  	DatabaseHandles    int  `toml:"-"`
    89  	DatabaseCache      int
    90  
    91  	// Mining-related options
    92  	Etherbase    common.Address `toml:",omitempty"`
    93  	MinerThreads int            `toml:",omitempty"`
    94  	ExtraData    []byte         `toml:",omitempty"`
    95  	GasPrice     *big.Int
    96  
    97  	// Ethash options
    98  	Ethash ethash.Config
    99  
   100  	// Transaction pool options
   101  	TxPool core.TxPoolConfig
   102  
   103  	// Gas Price Oracle options
   104  	GPO gasprice.Config
   105  
   106  	// Enables tracking of SHA3 preimages in the VM
   107  	EnablePreimageRecording bool
   108  
   109  	// Miscellaneous options
   110  	DocRoot string `toml:"-"`
   111  }
   112  
   113  type configMarshaling struct {
   114  	ExtraData hexutil.Bytes
   115  }