mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 01:13:45 +00:00
cmd, eth: ulc options added
This commit is contained in:
parent
732f5468d3
commit
fb55fd1265
6 changed files with 77 additions and 53 deletions
|
|
@ -126,6 +126,7 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, gethConfig) {
|
|||
}
|
||||
|
||||
// Apply flags.
|
||||
utils.SetULC(ctx, &cfg.Eth, &cfg.Node.P2P)
|
||||
utils.SetNodeConfig(ctx, &cfg.Node)
|
||||
stack, err := node.New(&cfg.Node)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -84,6 +84,7 @@ var (
|
|||
utils.TxPoolLifetimeFlag,
|
||||
utils.FastSyncFlag,
|
||||
utils.LightModeFlag,
|
||||
utils.ULCModeConfigFlag,
|
||||
utils.SyncModeFlag,
|
||||
utils.LightServFlag,
|
||||
utils.LightPeersFlag,
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@ import (
|
|||
"github.com/ethereum/go-ethereum/params"
|
||||
whisper "github.com/ethereum/go-ethereum/whisper/whisperv5"
|
||||
"gopkg.in/urfave/cli.v1"
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -163,6 +164,10 @@ var (
|
|||
Name: "light",
|
||||
Usage: "Enable light client mode",
|
||||
}
|
||||
ULCModeConfigFlag = cli.StringFlag{
|
||||
Name: "ulcconfig",
|
||||
Usage: "Config file to use for ULC mode",
|
||||
}
|
||||
defaultSyncMode = eth.DefaultConfig.SyncMode
|
||||
SyncModeFlag = TextMarshalerFlag{
|
||||
Name: "syncmode",
|
||||
|
|
@ -718,6 +723,42 @@ func setIPC(ctx *cli.Context, cfg *node.Config) {
|
|||
}
|
||||
}
|
||||
|
||||
// SetULC setup ULC config from file if given.
|
||||
func SetULC(ctx *cli.Context, cfg *eth.Config, p2pCfg *p2p.Config) {
|
||||
path := ctx.GlobalString(ULCModeConfigFlag.Name)
|
||||
if path == "" {
|
||||
return
|
||||
}
|
||||
|
||||
cfgData, err := ioutil.ReadFile(path)
|
||||
if err != nil {
|
||||
Fatalf("Failed to read ULC config file: %v", err)
|
||||
}
|
||||
|
||||
err = json.Unmarshal(cfgData, &cfg.ULC)
|
||||
if err != nil {
|
||||
Fatalf(err.Error())
|
||||
}
|
||||
|
||||
if len(cfg.ULC.TrustedNodes) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
if cfg.ULC.MinTrustedFraction <= 0 || cfg.ULC.MinTrustedFraction > 100 {
|
||||
cfg.ULC.MinTrustedFraction = eth.DefaultConfig.ULC.MinTrustedFraction
|
||||
}
|
||||
|
||||
p2pCfg.TrustedNodes = make([]*discover.Node, 0, len(cfg.ULC.TrustedNodes))
|
||||
for _, url := range cfg.ULC.TrustedNodes {
|
||||
node, err := discover.ParseNode(url)
|
||||
if err != nil {
|
||||
log.Error("Trusted node URL invalid", "enode", url, "err", err)
|
||||
continue
|
||||
}
|
||||
p2pCfg.TrustedNodes = append(p2pCfg.TrustedNodes, node)
|
||||
}
|
||||
}
|
||||
|
||||
// makeDatabaseHandles raises out the number of allowed file handles per process
|
||||
// for Geth and returns half of the allowance to assign to the database.
|
||||
func makeDatabaseHandles() int {
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ var DefaultConfig = Config{
|
|||
DatasetsInMem: 1,
|
||||
DatasetsOnDisk: 2,
|
||||
},
|
||||
ULC: &ULCConfig{MinTrustedFraction: 75},
|
||||
NetworkId: 1,
|
||||
LightPeers: 20,
|
||||
DatabaseCache: 128,
|
||||
|
|
@ -83,6 +84,9 @@ type Config struct {
|
|||
LightServ int `toml:",omitempty"` // Maximum percentage of time allowed for serving LES requests
|
||||
LightPeers int `toml:",omitempty"` // Maximum number of LES client peers
|
||||
|
||||
// Ultra Light client options
|
||||
ULC *ULCConfig `toml:",omitempty"`
|
||||
|
||||
// Database options
|
||||
SkipBcVersionCheck bool `toml:"-"`
|
||||
DatabaseHandles int `toml:"-"`
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ import (
|
|||
"github.com/ethereum/go-ethereum/eth/gasprice"
|
||||
)
|
||||
|
||||
var _ = (*configMarshaling)(nil)
|
||||
|
||||
func (c Config) MarshalTOML() (interface{}, error) {
|
||||
type Config struct {
|
||||
Genesis *core.Genesis `toml:",omitempty"`
|
||||
|
|
@ -20,7 +22,7 @@ func (c Config) MarshalTOML() (interface{}, error) {
|
|||
SyncMode downloader.SyncMode
|
||||
LightServ int `toml:",omitempty"`
|
||||
LightPeers int `toml:",omitempty"`
|
||||
MaxPeers int `toml:"-"`
|
||||
ULC *ULCConfig `toml:",omitempty"`
|
||||
SkipBcVersionCheck bool `toml:"-"`
|
||||
DatabaseHandles int `toml:"-"`
|
||||
DatabaseCache int
|
||||
|
|
@ -28,17 +30,11 @@ func (c Config) MarshalTOML() (interface{}, error) {
|
|||
MinerThreads int `toml:",omitempty"`
|
||||
ExtraData hexutil.Bytes `toml:",omitempty"`
|
||||
GasPrice *big.Int
|
||||
EthashCacheDir string
|
||||
EthashCachesInMem int
|
||||
EthashCachesOnDisk int
|
||||
EthashDatasetDir string
|
||||
EthashDatasetsInMem int
|
||||
EthashDatasetsOnDisk int
|
||||
Ethash ethash.Config
|
||||
TxPool core.TxPoolConfig
|
||||
GPO gasprice.Config
|
||||
EnablePreimageRecording bool
|
||||
DocRoot string `toml:"-"`
|
||||
PowMode ethash.Mode `toml:"-"`
|
||||
}
|
||||
var enc Config
|
||||
enc.Genesis = c.Genesis
|
||||
|
|
@ -46,6 +42,7 @@ func (c Config) MarshalTOML() (interface{}, error) {
|
|||
enc.SyncMode = c.SyncMode
|
||||
enc.LightServ = c.LightServ
|
||||
enc.LightPeers = c.LightPeers
|
||||
enc.ULC = c.ULC
|
||||
enc.SkipBcVersionCheck = c.SkipBcVersionCheck
|
||||
enc.DatabaseHandles = c.DatabaseHandles
|
||||
enc.DatabaseCache = c.DatabaseCache
|
||||
|
|
@ -53,17 +50,11 @@ func (c Config) MarshalTOML() (interface{}, error) {
|
|||
enc.MinerThreads = c.MinerThreads
|
||||
enc.ExtraData = c.ExtraData
|
||||
enc.GasPrice = c.GasPrice
|
||||
enc.EthashCacheDir = c.Ethash.CacheDir
|
||||
enc.EthashCachesInMem = c.Ethash.CachesInMem
|
||||
enc.EthashCachesOnDisk = c.Ethash.CachesOnDisk
|
||||
enc.EthashDatasetDir = c.Ethash.DatasetDir
|
||||
enc.EthashDatasetsInMem = c.Ethash.DatasetsInMem
|
||||
enc.EthashDatasetsOnDisk = c.Ethash.DatasetsOnDisk
|
||||
enc.Ethash = c.Ethash
|
||||
enc.TxPool = c.TxPool
|
||||
enc.GPO = c.GPO
|
||||
enc.EnablePreimageRecording = c.EnablePreimageRecording
|
||||
enc.DocRoot = c.DocRoot
|
||||
enc.PowMode = c.Ethash.PowMode
|
||||
return &enc, nil
|
||||
}
|
||||
|
||||
|
|
@ -74,7 +65,7 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
|
|||
SyncMode *downloader.SyncMode
|
||||
LightServ *int `toml:",omitempty"`
|
||||
LightPeers *int `toml:",omitempty"`
|
||||
MaxPeers *int `toml:"-"`
|
||||
ULC *ULCConfig `toml:",omitempty"`
|
||||
SkipBcVersionCheck *bool `toml:"-"`
|
||||
DatabaseHandles *int `toml:"-"`
|
||||
DatabaseCache *int
|
||||
|
|
@ -82,17 +73,11 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
|
|||
MinerThreads *int `toml:",omitempty"`
|
||||
ExtraData hexutil.Bytes `toml:",omitempty"`
|
||||
GasPrice *big.Int
|
||||
EthashCacheDir *string
|
||||
EthashCachesInMem *int
|
||||
EthashCachesOnDisk *int
|
||||
EthashDatasetDir *string
|
||||
EthashDatasetsInMem *int
|
||||
EthashDatasetsOnDisk *int
|
||||
Ethash *ethash.Config
|
||||
TxPool *core.TxPoolConfig
|
||||
GPO *gasprice.Config
|
||||
EnablePreimageRecording *bool
|
||||
DocRoot *string `toml:"-"`
|
||||
PowMode *ethash.Mode `toml:"-"`
|
||||
}
|
||||
var dec Config
|
||||
if err := unmarshal(&dec); err != nil {
|
||||
|
|
@ -113,6 +98,9 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
|
|||
if dec.LightPeers != nil {
|
||||
c.LightPeers = *dec.LightPeers
|
||||
}
|
||||
if dec.ULC != nil {
|
||||
c.ULC = dec.ULC
|
||||
}
|
||||
if dec.SkipBcVersionCheck != nil {
|
||||
c.SkipBcVersionCheck = *dec.SkipBcVersionCheck
|
||||
}
|
||||
|
|
@ -134,23 +122,8 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
|
|||
if dec.GasPrice != nil {
|
||||
c.GasPrice = dec.GasPrice
|
||||
}
|
||||
if dec.EthashCacheDir != nil {
|
||||
c.Ethash.CacheDir = *dec.EthashCacheDir
|
||||
}
|
||||
if dec.EthashCachesInMem != nil {
|
||||
c.Ethash.CachesInMem = *dec.EthashCachesInMem
|
||||
}
|
||||
if dec.EthashCachesOnDisk != nil {
|
||||
c.Ethash.CachesOnDisk = *dec.EthashCachesOnDisk
|
||||
}
|
||||
if dec.EthashDatasetDir != nil {
|
||||
c.Ethash.DatasetDir = *dec.EthashDatasetDir
|
||||
}
|
||||
if dec.EthashDatasetsInMem != nil {
|
||||
c.Ethash.DatasetsInMem = *dec.EthashDatasetsInMem
|
||||
}
|
||||
if dec.EthashDatasetsOnDisk != nil {
|
||||
c.Ethash.DatasetsOnDisk = *dec.EthashDatasetsOnDisk
|
||||
if dec.Ethash != nil {
|
||||
c.Ethash = *dec.Ethash
|
||||
}
|
||||
if dec.TxPool != nil {
|
||||
c.TxPool = *dec.TxPool
|
||||
|
|
@ -164,8 +137,5 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
|
|||
if dec.DocRoot != nil {
|
||||
c.DocRoot = *dec.DocRoot
|
||||
}
|
||||
if dec.PowMode != nil {
|
||||
c.Ethash.PowMode = *dec.PowMode
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
7
eth/ulc_config.go
Normal file
7
eth/ulc_config.go
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
package eth
|
||||
|
||||
// Ultra Light client options
|
||||
type ULCConfig struct {
|
||||
TrustedNodes []string `toml:",omitempty"` // A list of trusted servers
|
||||
MinTrustedFraction int `toml:",omitempty"` // Minimum percentage of connected trusted servers to validate trusted (1-100)
|
||||
}
|
||||
Loading…
Reference in a new issue