github.com/linapex/ethereum-dpos-chinese@v0.0.0-20190316121959-b78b3a4a1ece/eth/config.go (about)

     1  
     2  //<developer>
     3  //    <name>linapex 曹一峰</name>
     4  //    <email>linapex@163.com</email>
     5  //    <wx>superexc</wx>
     6  //    <qqgroup>128148617</qqgroup>
     7  //    <url>https://jsq.ink</url>
     8  //    <role>pku engineer</role>
     9  //    <date>2019-03-16 12:09:38</date>
    10  //</624342633354891264>
    11  
    12  
    13  package eth
    14  
    15  import (
    16  	"math/big"
    17  	"os"
    18  	"os/user"
    19  	"path/filepath"
    20  	"runtime"
    21  	"time"
    22  
    23  	"github.com/ethereum/go-ethereum/common"
    24  	"github.com/ethereum/go-ethereum/common/hexutil"
    25  	"github.com/ethereum/go-ethereum/consensus/ethash"
    26  	"github.com/ethereum/go-ethereum/core"
    27  	"github.com/ethereum/go-ethereum/eth/downloader"
    28  	"github.com/ethereum/go-ethereum/eth/gasprice"
    29  	"github.com/ethereum/go-ethereum/params"
    30  )
    31  
    32  //defaultconfig包含在以太坊主网上使用的默认设置。
    33  var DefaultConfig = Config{
    34  	SyncMode: downloader.FastSync,
    35  	Ethash: ethash.Config{
    36  		CacheDir:       "ethash",
    37  		CachesInMem:    2,
    38  		CachesOnDisk:   3,
    39  		DatasetsInMem:  1,
    40  		DatasetsOnDisk: 2,
    41  	},
    42  	NetworkId:     1,
    43  	LightPeers:    100,
    44  	DatabaseCache: 768,
    45  	TrieCache:     256,
    46  	TrieTimeout:   60 * time.Minute,
    47  	MinerGasPrice: big.NewInt(18 * params.Shannon),
    48  	MinerRecommit: 3 * time.Second,
    49  
    50  	TxPool: core.DefaultTxPoolConfig,
    51  	GPO: gasprice.Config{
    52  		Blocks:     20,
    53  		Percentile: 60,
    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:生成gencodec-type config-field override configmarshaling-formats toml-out gen_config.go
    72  
    73  type Config struct {
    74  //如果数据库为空,则插入Genesis块。
    75  //如果为零,则使用以太坊主网块。
    76  	Genesis *core.Genesis `toml:",omitempty"`
    77  
    78  //协议选项
    79  NetworkId uint64 //用于选择要连接的对等端的网络ID
    80  	SyncMode  downloader.SyncMode
    81  	NoPruning bool
    82  
    83  //轻客户端选项
    84  LightServ  int `toml:",omitempty"` //允许LES请求的最大时间百分比
    85  LightPeers int `toml:",omitempty"` //最大LES客户端对等数
    86  
    87  //数据库选项
    88  	SkipBcVersionCheck bool `toml:"-"`
    89  	DatabaseHandles    int  `toml:"-"`
    90  	DatabaseCache      int
    91  	TrieCache          int
    92  	TrieTimeout        time.Duration
    93  
    94  //Mining-related options
    95  //etherbase common.address`toml:“,omitempty”`
    96  	Validator    common.Address `toml:",omitempty"`
    97  	Coinbase     common.Address `toml:",omitempty"`
    98  	MinerThreads   int            `toml:",omitempty"`
    99  	MinerNotify    []string       `toml:",omitempty"`
   100  	MinerExtraData []byte         `toml:",omitempty"`
   101  	MinerGasPrice  *big.Int
   102  	MinerRecommit  time.Duration
   103  
   104  //乙烯利选项
   105  	Ethash ethash.Config
   106  
   107  //事务池选项
   108  	TxPool core.TxPoolConfig
   109  
   110  //天然气价格Oracle选项
   111  	GPO gasprice.Config
   112  
   113  //允许跟踪虚拟机中的sha3 preimages
   114  	EnablePreimageRecording bool
   115  
   116  //其他选项
   117  	DocRoot string `toml:"-"`
   118  	Dpos      bool   `toml:"-"`
   119  }
   120  
   121  type configMarshaling struct {
   122  	MinerExtraData hexutil.Bytes
   123  }
   124