aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/utils
diff options
context:
space:
mode:
authorRyan Schneider <ryanleeschneider@gmail.com>2018-11-03 04:26:45 +0800
committerPéter Szilágyi <peterke@gmail.com>2018-12-10 20:30:06 +0800
commit48b70ecff1152f9eec091ff03b803d997a573b19 (patch)
tree9841b5efdbbd571c662d3d84afa679cdf6ade5aa /cmd/utils
parentc1e3fe6b140c6ac7f9d7c792480a10208a4ac7ec (diff)
downloadgo-tangerine-48b70ecff1152f9eec091ff03b803d997a573b19.tar
go-tangerine-48b70ecff1152f9eec091ff03b803d997a573b19.tar.gz
go-tangerine-48b70ecff1152f9eec091ff03b803d997a573b19.tar.bz2
go-tangerine-48b70ecff1152f9eec091ff03b803d997a573b19.tar.lz
go-tangerine-48b70ecff1152f9eec091ff03b803d997a573b19.tar.xz
go-tangerine-48b70ecff1152f9eec091ff03b803d997a573b19.tar.zst
go-tangerine-48b70ecff1152f9eec091ff03b803d997a573b19.zip
cmd, eth: Add support for `--whitelist <blocknum>=<hash>,...` flag
* Rejects peers that respond with a different hash for any of the passed in block numbers. * Meant for emergency situations when the network forks unexpectedly.
Diffstat (limited to 'cmd/utils')
-rw-r--r--cmd/utils/flags.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go
index 6a285fcb3..4727e7cdf 100644
--- a/cmd/utils/flags.go
+++ b/cmd/utils/flags.go
@@ -182,6 +182,10 @@ var (
Name: "lightkdf",
Usage: "Reduce key-derivation RAM & CPU usage at some expense of KDF strength",
}
+ WhitelistFlag = cli.StringFlag{
+ Name: "whitelist",
+ Usage: "Comma separated block number-to-hash mappings to enforce (<number>=<hash>)",
+ }
// Dashboard settings
DashboardEnabledFlag = cli.BoolFlag{
Name: metrics.DashboardEnabledFlag,
@@ -1072,6 +1076,34 @@ func setEthash(ctx *cli.Context, cfg *eth.Config) {
}
}
+func setWhitelist(ctx *cli.Context, cfg *eth.Config) {
+ if ctx.GlobalIsSet(WhitelistFlag.Name) {
+ entries := strings.Split(ctx.String(WhitelistFlag.Name), ",")
+ whitelist := make(map[uint64]common.Hash)
+ for _, entry := range entries {
+ split := strings.SplitN(entry, "=", 2)
+ if len(split) != 2 {
+ Fatalf("invalid whitelist entry: %s", entry)
+ }
+
+ bn, err := strconv.ParseUint(split[0], 0, 64)
+ if err != nil {
+ Fatalf("Invalid whitelist block number %s: %v", split[0], err)
+ }
+
+ hash := common.Hash{}
+ err = hash.UnmarshalText([]byte(split[1]))
+ if err != nil {
+ Fatalf("Invalid whitelist hash %s: %v", split[1], err)
+ }
+
+ whitelist[bn] = hash
+ }
+
+ cfg.Whitelist = whitelist
+ }
+}
+
// checkExclusive verifies that only a single instance of the provided flags was
// set by the user. Each flag might optionally be followed by a string type to
// specialize it further.
@@ -1137,6 +1169,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
setGPO(ctx, &cfg.GPO)
setTxPool(ctx, &cfg.TxPool)
setEthash(ctx, cfg)
+ setWhitelist(ctx, cfg)
if ctx.GlobalIsSet(SyncModeFlag.Name) {
cfg.SyncMode = *GlobalTextMarshaler(ctx, SyncModeFlag.Name).(*downloader.SyncMode)