cmd, eth: ulc options added

This commit is contained in:
Evgeny Danienko 2017-12-12 13:35:17 +03:00
parent 732f5468d3
commit fb55fd1265
No known key found for this signature in database
GPG key ID: BC8C34D8B45BECBF
6 changed files with 77 additions and 53 deletions

View file

@ -126,6 +126,7 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, gethConfig) {
} }
// Apply flags. // Apply flags.
utils.SetULC(ctx, &cfg.Eth, &cfg.Node.P2P)
utils.SetNodeConfig(ctx, &cfg.Node) utils.SetNodeConfig(ctx, &cfg.Node)
stack, err := node.New(&cfg.Node) stack, err := node.New(&cfg.Node)
if err != nil { if err != nil {

View file

@ -84,6 +84,7 @@ var (
utils.TxPoolLifetimeFlag, utils.TxPoolLifetimeFlag,
utils.FastSyncFlag, utils.FastSyncFlag,
utils.LightModeFlag, utils.LightModeFlag,
utils.ULCModeConfigFlag,
utils.SyncModeFlag, utils.SyncModeFlag,
utils.LightServFlag, utils.LightServFlag,
utils.LightPeersFlag, utils.LightPeersFlag,

View file

@ -56,6 +56,7 @@ import (
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
whisper "github.com/ethereum/go-ethereum/whisper/whisperv5" whisper "github.com/ethereum/go-ethereum/whisper/whisperv5"
"gopkg.in/urfave/cli.v1" "gopkg.in/urfave/cli.v1"
"encoding/json"
) )
var ( var (
@ -163,6 +164,10 @@ var (
Name: "light", Name: "light",
Usage: "Enable light client mode", Usage: "Enable light client mode",
} }
ULCModeConfigFlag = cli.StringFlag{
Name: "ulcconfig",
Usage: "Config file to use for ULC mode",
}
defaultSyncMode = eth.DefaultConfig.SyncMode defaultSyncMode = eth.DefaultConfig.SyncMode
SyncModeFlag = TextMarshalerFlag{ SyncModeFlag = TextMarshalerFlag{
Name: "syncmode", 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 // makeDatabaseHandles raises out the number of allowed file handles per process
// for Geth and returns half of the allowance to assign to the database. // for Geth and returns half of the allowance to assign to the database.
func makeDatabaseHandles() int { func makeDatabaseHandles() int {

View file

@ -42,6 +42,7 @@ var DefaultConfig = Config{
DatasetsInMem: 1, DatasetsInMem: 1,
DatasetsOnDisk: 2, DatasetsOnDisk: 2,
}, },
ULC: &ULCConfig{MinTrustedFraction: 75},
NetworkId: 1, NetworkId: 1,
LightPeers: 20, LightPeers: 20,
DatabaseCache: 128, DatabaseCache: 128,
@ -83,6 +84,9 @@ type Config struct {
LightServ int `toml:",omitempty"` // Maximum percentage of time allowed for serving LES requests LightServ int `toml:",omitempty"` // Maximum percentage of time allowed for serving LES requests
LightPeers int `toml:",omitempty"` // Maximum number of LES client peers LightPeers int `toml:",omitempty"` // Maximum number of LES client peers
// Ultra Light client options
ULC *ULCConfig `toml:",omitempty"`
// Database options // Database options
SkipBcVersionCheck bool `toml:"-"` SkipBcVersionCheck bool `toml:"-"`
DatabaseHandles int `toml:"-"` DatabaseHandles int `toml:"-"`

View file

@ -13,32 +13,28 @@ import (
"github.com/ethereum/go-ethereum/eth/gasprice" "github.com/ethereum/go-ethereum/eth/gasprice"
) )
var _ = (*configMarshaling)(nil)
func (c Config) MarshalTOML() (interface{}, error) { func (c Config) MarshalTOML() (interface{}, error) {
type Config struct { type Config struct {
Genesis *core.Genesis `toml:",omitempty"` Genesis *core.Genesis `toml:",omitempty"`
NetworkId uint64 NetworkId uint64
SyncMode downloader.SyncMode SyncMode downloader.SyncMode
LightServ int `toml:",omitempty"` LightServ int `toml:",omitempty"`
LightPeers int `toml:",omitempty"` LightPeers int `toml:",omitempty"`
MaxPeers int `toml:"-"` ULC *ULCConfig `toml:",omitempty"`
SkipBcVersionCheck bool `toml:"-"` SkipBcVersionCheck bool `toml:"-"`
DatabaseHandles int `toml:"-"` DatabaseHandles int `toml:"-"`
DatabaseCache int DatabaseCache int
Etherbase common.Address `toml:",omitempty"` Etherbase common.Address `toml:",omitempty"`
MinerThreads int `toml:",omitempty"` MinerThreads int `toml:",omitempty"`
ExtraData hexutil.Bytes `toml:",omitempty"` ExtraData hexutil.Bytes `toml:",omitempty"`
GasPrice *big.Int GasPrice *big.Int
EthashCacheDir string Ethash ethash.Config
EthashCachesInMem int
EthashCachesOnDisk int
EthashDatasetDir string
EthashDatasetsInMem int
EthashDatasetsOnDisk int
TxPool core.TxPoolConfig TxPool core.TxPoolConfig
GPO gasprice.Config GPO gasprice.Config
EnablePreimageRecording bool EnablePreimageRecording bool
DocRoot string `toml:"-"` DocRoot string `toml:"-"`
PowMode ethash.Mode `toml:"-"`
} }
var enc Config var enc Config
enc.Genesis = c.Genesis enc.Genesis = c.Genesis
@ -46,6 +42,7 @@ func (c Config) MarshalTOML() (interface{}, error) {
enc.SyncMode = c.SyncMode enc.SyncMode = c.SyncMode
enc.LightServ = c.LightServ enc.LightServ = c.LightServ
enc.LightPeers = c.LightPeers enc.LightPeers = c.LightPeers
enc.ULC = c.ULC
enc.SkipBcVersionCheck = c.SkipBcVersionCheck enc.SkipBcVersionCheck = c.SkipBcVersionCheck
enc.DatabaseHandles = c.DatabaseHandles enc.DatabaseHandles = c.DatabaseHandles
enc.DatabaseCache = c.DatabaseCache enc.DatabaseCache = c.DatabaseCache
@ -53,17 +50,11 @@ func (c Config) MarshalTOML() (interface{}, error) {
enc.MinerThreads = c.MinerThreads enc.MinerThreads = c.MinerThreads
enc.ExtraData = c.ExtraData enc.ExtraData = c.ExtraData
enc.GasPrice = c.GasPrice enc.GasPrice = c.GasPrice
enc.EthashCacheDir = c.Ethash.CacheDir enc.Ethash = c.Ethash
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.TxPool = c.TxPool enc.TxPool = c.TxPool
enc.GPO = c.GPO enc.GPO = c.GPO
enc.EnablePreimageRecording = c.EnablePreimageRecording enc.EnablePreimageRecording = c.EnablePreimageRecording
enc.DocRoot = c.DocRoot enc.DocRoot = c.DocRoot
enc.PowMode = c.Ethash.PowMode
return &enc, nil return &enc, nil
} }
@ -72,27 +63,21 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
Genesis *core.Genesis `toml:",omitempty"` Genesis *core.Genesis `toml:",omitempty"`
NetworkId *uint64 NetworkId *uint64
SyncMode *downloader.SyncMode SyncMode *downloader.SyncMode
LightServ *int `toml:",omitempty"` LightServ *int `toml:",omitempty"`
LightPeers *int `toml:",omitempty"` LightPeers *int `toml:",omitempty"`
MaxPeers *int `toml:"-"` ULC *ULCConfig `toml:",omitempty"`
SkipBcVersionCheck *bool `toml:"-"` SkipBcVersionCheck *bool `toml:"-"`
DatabaseHandles *int `toml:"-"` DatabaseHandles *int `toml:"-"`
DatabaseCache *int DatabaseCache *int
Etherbase *common.Address `toml:",omitempty"` Etherbase *common.Address `toml:",omitempty"`
MinerThreads *int `toml:",omitempty"` MinerThreads *int `toml:",omitempty"`
ExtraData hexutil.Bytes `toml:",omitempty"` ExtraData hexutil.Bytes `toml:",omitempty"`
GasPrice *big.Int GasPrice *big.Int
EthashCacheDir *string Ethash *ethash.Config
EthashCachesInMem *int
EthashCachesOnDisk *int
EthashDatasetDir *string
EthashDatasetsInMem *int
EthashDatasetsOnDisk *int
TxPool *core.TxPoolConfig TxPool *core.TxPoolConfig
GPO *gasprice.Config GPO *gasprice.Config
EnablePreimageRecording *bool EnablePreimageRecording *bool
DocRoot *string `toml:"-"` DocRoot *string `toml:"-"`
PowMode *ethash.Mode `toml:"-"`
} }
var dec Config var dec Config
if err := unmarshal(&dec); err != nil { if err := unmarshal(&dec); err != nil {
@ -113,6 +98,9 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
if dec.LightPeers != nil { if dec.LightPeers != nil {
c.LightPeers = *dec.LightPeers c.LightPeers = *dec.LightPeers
} }
if dec.ULC != nil {
c.ULC = dec.ULC
}
if dec.SkipBcVersionCheck != nil { if dec.SkipBcVersionCheck != nil {
c.SkipBcVersionCheck = *dec.SkipBcVersionCheck c.SkipBcVersionCheck = *dec.SkipBcVersionCheck
} }
@ -134,23 +122,8 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
if dec.GasPrice != nil { if dec.GasPrice != nil {
c.GasPrice = dec.GasPrice c.GasPrice = dec.GasPrice
} }
if dec.EthashCacheDir != nil { if dec.Ethash != nil {
c.Ethash.CacheDir = *dec.EthashCacheDir c.Ethash = *dec.Ethash
}
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.TxPool != nil { if dec.TxPool != nil {
c.TxPool = *dec.TxPool c.TxPool = *dec.TxPool
@ -164,8 +137,5 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
if dec.DocRoot != nil { if dec.DocRoot != nil {
c.DocRoot = *dec.DocRoot c.DocRoot = *dec.DocRoot
} }
if dec.PowMode != nil {
c.Ethash.PowMode = *dec.PowMode
}
return nil return nil
} }

7
eth/ulc_config.go Normal file
View 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)
}