Skip to content

Commit f691d66

Browse files
authored
cmd/utils: fix disabling discovery through config file (#33279)
No matter what value of P2P.DiscoveryV4 or DiscoveryV5 is set in config file, it will be overwritten by the CLI flag, even if the flag is not set. This fixes it to apply the flag only if set.
1 parent f432281 commit f691d66

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

cmd/utils/flags.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -864,14 +864,14 @@ var (
864864
Aliases: []string{"discv4"},
865865
Usage: "Enables the V4 discovery mechanism",
866866
Category: flags.NetworkingCategory,
867-
Value: true,
867+
Value: node.DefaultConfig.P2P.DiscoveryV4,
868868
}
869869
DiscoveryV5Flag = &cli.BoolFlag{
870870
Name: "discovery.v5",
871871
Aliases: []string{"discv5"},
872872
Usage: "Enables the V5 discovery mechanism",
873873
Category: flags.NetworkingCategory,
874-
Value: true,
874+
Value: node.DefaultConfig.P2P.DiscoveryV5,
875875
}
876876
NetrestrictFlag = &cli.StringFlag{
877877
Name: "netrestrict",
@@ -1373,8 +1373,12 @@ func SetP2PConfig(ctx *cli.Context, cfg *p2p.Config) {
13731373

13741374
flags.CheckExclusive(ctx, DiscoveryV4Flag, NoDiscoverFlag)
13751375
flags.CheckExclusive(ctx, DiscoveryV5Flag, NoDiscoverFlag)
1376-
cfg.DiscoveryV4 = ctx.Bool(DiscoveryV4Flag.Name)
1377-
cfg.DiscoveryV5 = ctx.Bool(DiscoveryV5Flag.Name)
1376+
if ctx.IsSet(DiscoveryV4Flag.Name) {
1377+
cfg.DiscoveryV4 = ctx.Bool(DiscoveryV4Flag.Name)
1378+
}
1379+
if ctx.IsSet(DiscoveryV5Flag.Name) {
1380+
cfg.DiscoveryV5 = ctx.Bool(DiscoveryV5Flag.Name)
1381+
}
13781382

13791383
if netrestrict := ctx.String(NetrestrictFlag.Name); netrestrict != "" {
13801384
list, err := netutil.ParseNetlist(netrestrict)

node/defaults.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,11 @@ var DefaultConfig = Config{
6969
BatchResponseMaxSize: 25 * 1000 * 1000,
7070
GraphQLVirtualHosts: []string{"localhost"},
7171
P2P: p2p.Config{
72-
ListenAddr: ":30303",
73-
MaxPeers: 50,
74-
NAT: nat.Any(),
72+
ListenAddr: ":30303",
73+
MaxPeers: 50,
74+
NAT: nat.Any(),
75+
DiscoveryV4: true,
76+
DiscoveryV5: true,
7577
},
7678
DBEngine: "", // Use whatever exists, will default to Pebble if non-existent and supported
7779
}

0 commit comments

Comments
 (0)