github.com/samgwo/go-ethereum@v1.8.2-0.20180302101319-49bcb5fbd55e/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  	NetworkId:     1,
    47  	LightPeers:    100,
    48  	DatabaseCache: 768,
    49  	TrieCache:     256,
    50  	TrieTimeout:   5 * time.Minute,
    51  	GasPrice:      big.NewInt(18 * params.Shannon),
    52  
    53  	TxPool: core.DefaultTxPoolConfig,
    54  	GPO: gasprice.Config{
    55  		Blocks:     20,
    56  		Percentile: 60,
    57  	},
    58  }
    59  
    60  func init() {
    61  	home := os.Getenv("HOME")
    62  	if home == "" {
    63  		if user, err := user.Current(); err == nil {
    64  			home = user.HomeDir
    65  		}
    66  	}
    67  	if runtime.GOOS == "windows" {
    68  		DefaultConfig.Ethash.DatasetDir = filepath.Join(home, "AppData", "Ethash")
    69  	} else {
    70  		DefaultConfig.Ethash.DatasetDir = filepath.Join(home, ".ethash")
    71  	}
    72  }
    73  
    74  //go:generate gencodec -type Config -field-override configMarshaling -formats toml -out gen_config.go
    75  
    76  type Config struct {
    77  	// The genesis block, which is inserted if the database is empty.
    78  	// If nil, the Ethereum main net block is used.
    79  	Genesis *core.Genesis `toml:",omitempty"`
    80  
    81  	// Protocol options
    82  	NetworkId uint64 // Network ID to use for selecting peers to connect to
    83  	SyncMode  downloader.SyncMode
    84  	NoPruning bool
    85  
    86  	// Light client options
    87  	LightServ  int `toml:",omitempty"` // Maximum percentage of time allowed for serving LES requests
    88  	LightPeers int `toml:",omitempty"` // Maximum number of LES client peers
    89  
    90  	// Database options
    91  	SkipBcVersionCheck bool `toml:"-"`
    92  	DatabaseHandles    int  `toml:"-"`
    93  	DatabaseCache      int
    94  	TrieCache          int
    95  	TrieTimeout        time.Duration
    96  
    97  	// Mining-related options
    98  	Etherbase    common.Address `toml:",omitempty"`
    99  	MinerThreads int            `toml:",omitempty"`
   100  	ExtraData    []byte         `toml:",omitempty"`
   101  	GasPrice     *big.Int
   102  
   103  	// Ethash options
   104  	Ethash ethash.Config
   105  
   106  	// Transaction pool options
   107  	TxPool core.TxPoolConfig
   108  
   109  	// Gas Price Oracle options
   110  	GPO gasprice.Config
   111  
   112  	// Enables tracking of SHA3 preimages in the VM
   113  	EnablePreimageRecording bool
   114  
   115  	// Miscellaneous options
   116  	DocRoot string `toml:"-"`
   117  }
   118  
   119  type configMarshaling struct {
   120  	ExtraData hexutil.Bytes
   121  }