From f691d661c4ade255894cb570f55e8c30b888290c Mon Sep 17 00:00:00 2001 From: cui Date: Fri, 28 Nov 2025 17:52:21 +0800 Subject: [PATCH] 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. --- cmd/utils/flags.go | 12 ++++++++---- node/defaults.go | 8 +++++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 072a1d607b..9f69581754 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -864,14 +864,14 @@ var ( Aliases: []string{"discv4"}, Usage: "Enables the V4 discovery mechanism", Category: flags.NetworkingCategory, - Value: true, + Value: node.DefaultConfig.P2P.DiscoveryV4, } DiscoveryV5Flag = &cli.BoolFlag{ Name: "discovery.v5", Aliases: []string{"discv5"}, Usage: "Enables the V5 discovery mechanism", Category: flags.NetworkingCategory, - Value: true, + Value: node.DefaultConfig.P2P.DiscoveryV5, } NetrestrictFlag = &cli.StringFlag{ Name: "netrestrict", @@ -1373,8 +1373,12 @@ func SetP2PConfig(ctx *cli.Context, cfg *p2p.Config) { flags.CheckExclusive(ctx, DiscoveryV4Flag, NoDiscoverFlag) flags.CheckExclusive(ctx, DiscoveryV5Flag, NoDiscoverFlag) - cfg.DiscoveryV4 = ctx.Bool(DiscoveryV4Flag.Name) - cfg.DiscoveryV5 = ctx.Bool(DiscoveryV5Flag.Name) + if ctx.IsSet(DiscoveryV4Flag.Name) { + cfg.DiscoveryV4 = ctx.Bool(DiscoveryV4Flag.Name) + } + if ctx.IsSet(DiscoveryV5Flag.Name) { + cfg.DiscoveryV5 = ctx.Bool(DiscoveryV5Flag.Name) + } if netrestrict := ctx.String(NetrestrictFlag.Name); netrestrict != "" { list, err := netutil.ParseNetlist(netrestrict) diff --git a/node/defaults.go b/node/defaults.go index 6c643e2b54..403a7f88a3 100644 --- a/node/defaults.go +++ b/node/defaults.go @@ -69,9 +69,11 @@ var DefaultConfig = Config{ BatchResponseMaxSize: 25 * 1000 * 1000, GraphQLVirtualHosts: []string{"localhost"}, P2P: p2p.Config{ - ListenAddr: ":30303", - MaxPeers: 50, - NAT: nat.Any(), + ListenAddr: ":30303", + MaxPeers: 50, + NAT: nat.Any(), + DiscoveryV4: true, + DiscoveryV5: true, }, DBEngine: "", // Use whatever exists, will default to Pebble if non-existent and supported }