github.com/yinchengtsinghua/golang-Eos-dpos-Ethereum@v0.0.0-20190121132951-92cc4225ed8e/eth/config.go (about)

     1  
     2  //此源码被清华学神尹成大魔王专业翻译分析并修改
     3  //尹成QQ77025077
     4  //尹成微信18510341407
     5  //尹成所在QQ群721929980
     6  //尹成邮箱 yinc13@mails.tsinghua.edu.cn
     7  //尹成毕业于清华大学,微软区块链领域全球最有价值专家
     8  //https://mvp.microsoft.com/zh-cn/PublicProfile/4033620
     9  //版权所有2017 Go Ethereum作者
    10  //此文件是Go以太坊库的一部分。
    11  //
    12  //Go-Ethereum库是免费软件:您可以重新分发它和/或修改
    13  //根据GNU发布的较低通用公共许可证的条款
    14  //自由软件基金会,或者许可证的第3版,或者
    15  //(由您选择)任何更高版本。
    16  //
    17  //Go以太坊图书馆的发行目的是希望它会有用,
    18  //但没有任何保证;甚至没有
    19  //适销性或特定用途的适用性。见
    20  //GNU较低的通用公共许可证,了解更多详细信息。
    21  //
    22  //你应该收到一份GNU较低级别的公共许可证副本
    23  //以及Go以太坊图书馆。如果没有,请参见<http://www.gnu.org/licenses/>。
    24  
    25  package eth
    26  
    27  import (
    28  	"math/big"
    29  	"os"
    30  	"os/user"
    31  	"path/filepath"
    32  	"runtime"
    33  	"time"
    34  
    35  	"github.com/ethereum/go-ethereum/common"
    36  	"github.com/ethereum/go-ethereum/common/hexutil"
    37  	"github.com/ethereum/go-ethereum/consensus/ethash"
    38  	"github.com/ethereum/go-ethereum/core"
    39  	"github.com/ethereum/go-ethereum/eth/downloader"
    40  	"github.com/ethereum/go-ethereum/eth/gasprice"
    41  	"github.com/ethereum/go-ethereum/params"
    42  )
    43  
    44  //defaultconfig包含在以太坊主网上使用的默认设置。
    45  var DefaultConfig = Config{
    46  	SyncMode: downloader.FastSync,
    47  	Ethash: ethash.Config{
    48  		CacheDir:       "ethash",
    49  		CachesInMem:    2,
    50  		CachesOnDisk:   3,
    51  		DatasetsInMem:  1,
    52  		DatasetsOnDisk: 2,
    53  	},
    54  	NetworkId:     1,
    55  	LightPeers:    100,
    56  	DatabaseCache: 768,
    57  	TrieCache:     256,
    58  	TrieTimeout:   60 * time.Minute,
    59  	MinerGasPrice: big.NewInt(18 * params.Shannon),
    60  	MinerRecommit: 3 * time.Second,
    61  
    62  	TxPool: core.DefaultTxPoolConfig,
    63  	GPO: gasprice.Config{
    64  		Blocks:     20,
    65  		Percentile: 60,
    66  	},
    67  }
    68  
    69  func init() {
    70  	home := os.Getenv("HOME")
    71  	if home == "" {
    72  		if user, err := user.Current(); err == nil {
    73  			home = user.HomeDir
    74  		}
    75  	}
    76  	if runtime.GOOS == "windows" {
    77  		DefaultConfig.Ethash.DatasetDir = filepath.Join(home, "AppData", "Ethash")
    78  	} else {
    79  		DefaultConfig.Ethash.DatasetDir = filepath.Join(home, ".ethash")
    80  	}
    81  }
    82  
    83  //go:生成gencodec-type config-field override configmarshaling-formats toml-out gen_config.go
    84  
    85  type Config struct {
    86  //如果数据库为空,则插入Genesis块。
    87  //如果为零,则使用以太坊主网块。
    88  	Genesis *core.Genesis `toml:",omitempty"`
    89  
    90  //协议选项
    91  NetworkId uint64 //用于选择要连接的对等端的网络ID
    92  	SyncMode  downloader.SyncMode
    93  	NoPruning bool
    94  
    95  //轻客户端选项
    96  LightServ  int `toml:",omitempty"` //允许LES请求的最大时间百分比
    97  LightPeers int `toml:",omitempty"` //最大LES客户端对等数
    98  
    99  //数据库选项
   100  	SkipBcVersionCheck bool `toml:"-"`
   101  	DatabaseHandles    int  `toml:"-"`
   102  	DatabaseCache      int
   103  	TrieCache          int
   104  	TrieTimeout        time.Duration
   105  
   106  //Mining-related options
   107  //etherbase common.address`toml:“,omitempty”`
   108  	Validator    common.Address `toml:",omitempty"`
   109  	Coinbase     common.Address `toml:",omitempty"`
   110  	MinerThreads   int            `toml:",omitempty"`
   111  	MinerNotify    []string       `toml:",omitempty"`
   112  	MinerExtraData []byte         `toml:",omitempty"`
   113  	MinerGasPrice  *big.Int
   114  	MinerRecommit  time.Duration
   115  
   116  //乙烯利选项
   117  	Ethash ethash.Config
   118  
   119  //事务池选项
   120  	TxPool core.TxPoolConfig
   121  
   122  //天然气价格Oracle选项
   123  	GPO gasprice.Config
   124  
   125  //允许跟踪虚拟机中的sha3 preimages
   126  	EnablePreimageRecording bool
   127  
   128  //其他选项
   129  	DocRoot string `toml:"-"`
   130  	Dpos      bool   `toml:"-"`
   131  }
   132  
   133  type configMarshaling struct {
   134  	MinerExtraData hexutil.Bytes
   135  }