diff options
author | b00ris <b00ris@mail.ru> | 2019-01-24 19:18:26 +0800 |
---|---|---|
committer | Felix Lange <fjl@users.noreply.github.com> | 2019-01-24 19:18:26 +0800 |
commit | 769657060e888612e7d585c6b6eae16a64c4ad19 (patch) | |
tree | 12d6b3dad5209d35972d3569b5ff56ad55363b40 /cmd | |
parent | b8f9b3779fbdc62d5a935b57f1360608fa4600b4 (diff) | |
download | go-tangerine-769657060e888612e7d585c6b6eae16a64c4ad19.tar go-tangerine-769657060e888612e7d585c6b6eae16a64c4ad19.tar.gz go-tangerine-769657060e888612e7d585c6b6eae16a64c4ad19.tar.bz2 go-tangerine-769657060e888612e7d585c6b6eae16a64c4ad19.tar.lz go-tangerine-769657060e888612e7d585c6b6eae16a64c4ad19.tar.xz go-tangerine-769657060e888612e7d585c6b6eae16a64c4ad19.tar.zst go-tangerine-769657060e888612e7d585c6b6eae16a64c4ad19.zip |
les: implement ultralight client (#16904)
For more information about this light client mode, read
https://hackmd.io/s/HJy7jjZpm
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/geth/config.go | 1 | ||||
-rw-r--r-- | cmd/geth/main.go | 4 | ||||
-rw-r--r-- | cmd/utils/flags.go | 55 |
3 files changed, 60 insertions, 0 deletions
diff --git a/cmd/geth/config.go b/cmd/geth/config.go index 62eeef701..f316380ce 100644 --- a/cmd/geth/config.go +++ b/cmd/geth/config.go @@ -125,6 +125,7 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, gethConfig) { } // Apply flags. + utils.SetULC(ctx, &cfg.Eth) utils.SetNodeConfig(ctx, &cfg.Node) stack, err := node.New(&cfg.Node) if err != nil { diff --git a/cmd/geth/main.go b/cmd/geth/main.go index fb5ec20eb..2be2bca95 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -82,6 +82,10 @@ var ( utils.TxPoolAccountQueueFlag, utils.TxPoolGlobalQueueFlag, utils.TxPoolLifetimeFlag, + utils.ULCModeConfigFlag, + utils.OnlyAnnounceModeFlag, + utils.ULCTrustedNodesFlag, + utils.ULCMinTrustedFractionFlag, utils.SyncModeFlag, utils.GCModeFlag, utils.LightServFlag, diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 33650685c..a80cdd6cd 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -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) } |