les: implement ultralight client (#16904)
For more information about this light client mode, read https://hackmd.io/s/HJy7jjZpm
This commit is contained in:
@ -19,6 +19,7 @@ package utils
|
||||
|
||||
import (
|
||||
"crypto/ecdsa"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"math/big"
|
||||
@ -161,6 +162,23 @@ var (
|
||||
Usage: "Document Root for HTTPClient file scheme",
|
||||
Value: DirectoryString{homeDir()},
|
||||
}
|
||||
ULCModeConfigFlag = cli.StringFlag{
|
||||
Name: "ulc.config",
|
||||
Usage: "Config file to use for ultra light client mode",
|
||||
}
|
||||
OnlyAnnounceModeFlag = cli.BoolFlag{
|
||||
Name: "ulc.onlyannounce",
|
||||
Usage: "ULC server sends announcements only",
|
||||
}
|
||||
ULCMinTrustedFractionFlag = cli.IntFlag{
|
||||
Name: "ulc.fraction",
|
||||
Usage: "Minimum % of trusted ULC servers required to announce a new head",
|
||||
}
|
||||
ULCTrustedNodesFlag = cli.StringFlag{
|
||||
Name: "ulc.trusted",
|
||||
Usage: "List of trusted ULC servers",
|
||||
}
|
||||
|
||||
defaultSyncMode = eth.DefaultConfig.SyncMode
|
||||
SyncModeFlag = TextMarshalerFlag{
|
||||
Name: "syncmode",
|
||||
@ -871,6 +889,40 @@ func setIPC(ctx *cli.Context, cfg *node.Config) {
|
||||
}
|
||||
}
|
||||
|
||||
// SetULC setup ULC config from file if given.
|
||||
func SetULC(ctx *cli.Context, cfg *eth.Config) {
|
||||
// ULC config isn't loaded from global config and ULC config and ULC trusted nodes are not defined.
|
||||
if cfg.ULC == nil && !(ctx.GlobalIsSet(ULCModeConfigFlag.Name) || ctx.GlobalIsSet(ULCTrustedNodesFlag.Name)) {
|
||||
return
|
||||
}
|
||||
cfg.ULC = ð.ULCConfig{}
|
||||
|
||||
path := ctx.GlobalString(ULCModeConfigFlag.Name)
|
||||
if path != "" {
|
||||
cfgData, err := ioutil.ReadFile(path)
|
||||
if err != nil {
|
||||
Fatalf("Failed to unmarshal ULC configuration: %v", err)
|
||||
}
|
||||
|
||||
err = json.Unmarshal(cfgData, &cfg.ULC)
|
||||
if err != nil {
|
||||
Fatalf("Failed to unmarshal ULC configuration: %s", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
if trustedNodes := ctx.GlobalString(ULCTrustedNodesFlag.Name); trustedNodes != "" {
|
||||
cfg.ULC.TrustedServers = strings.Split(trustedNodes, ",")
|
||||
}
|
||||
|
||||
if trustedFraction := ctx.GlobalInt(ULCMinTrustedFractionFlag.Name); trustedFraction > 0 {
|
||||
cfg.ULC.MinTrustedFraction = trustedFraction
|
||||
}
|
||||
if cfg.ULC.MinTrustedFraction <= 0 && cfg.ULC.MinTrustedFraction > 100 {
|
||||
log.Error("MinTrustedFraction is invalid", "MinTrustedFraction", cfg.ULC.MinTrustedFraction, "Changed to default", eth.DefaultULCMinTrustedFraction)
|
||||
cfg.ULC.MinTrustedFraction = eth.DefaultULCMinTrustedFraction
|
||||
}
|
||||
}
|
||||
|
||||
// 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 {
|
||||
@ -1222,6 +1274,9 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
|
||||
if ctx.GlobalIsSet(LightPeersFlag.Name) {
|
||||
cfg.LightPeers = ctx.GlobalInt(LightPeersFlag.Name)
|
||||
}
|
||||
if ctx.GlobalIsSet(OnlyAnnounceModeFlag.Name) {
|
||||
cfg.OnlyAnnounce = ctx.GlobalBool(OnlyAnnounceModeFlag.Name)
|
||||
}
|
||||
if ctx.GlobalIsSet(NetworkIdFlag.Name) {
|
||||
cfg.NetworkId = ctx.GlobalUint64(NetworkIdFlag.Name)
|
||||
}
|
||||
|
Reference in New Issue
Block a user