aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/utils
diff options
context:
space:
mode:
authorb00ris <b00ris@mail.ru>2019-01-24 19:18:26 +0800
committerFelix Lange <fjl@users.noreply.github.com>2019-01-24 19:18:26 +0800
commit769657060e888612e7d585c6b6eae16a64c4ad19 (patch)
tree12d6b3dad5209d35972d3569b5ff56ad55363b40 /cmd/utils
parentb8f9b3779fbdc62d5a935b57f1360608fa4600b4 (diff)
downloadgo-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/utils')
-rw-r--r--cmd/utils/flags.go55
1 files changed, 55 insertions, 0 deletions
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 = &eth.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)
}