0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-03-04 13:55:23 -05:00

init: Handle dropped UPnP support more gracefully

Closes bitcoin-core/gui#843.

In that issue it was brought up that users likely don't care what kind
of port forwarding is used, and the setting is opportunistic anyway, so
instead of showing an extensive warning, we can simply migrate from
UPNP to NAT-PMP+PCP. This prevents nodes dropping from the public
network.

- Change the logic for removed runtime setting `-upnp` to set `-natpmp`
  instead, and only log a message.

- Also replace any lingering `upnp` in `settings.json` with `natpmp`.
This commit is contained in:
laanwj 2025-02-20 16:51:14 +01:00
parent e606c577cb
commit 44041ae0ec

View file

@ -793,6 +793,32 @@ void InitParameterInteraction(ArgsManager& args)
LogInfo("parameter interaction: -onlynet excludes IPv4 and IPv6 -> setting -dnsseed=0\n");
}
}
// If settings.json contains a "upnp" option, migrate it to use "natpmp" instead
bool settings_changed{false}; // Whether settings.json file needs to be rewritten
args.LockSettings([&](common::Settings& settings) {
if (auto* upnp{common::FindKey(settings.rw_settings, "upnp")}) {
if (common::FindKey(settings.rw_settings, "natpmp") == nullptr) {
LogWarning(R"(Adding "natpmp": %s to settings.json to replace obsolete "upnp" setting)", upnp->write());
settings.rw_settings["natpmp"] = *upnp;
}
LogWarning(R"(Removing obsolete "upnp" setting from settings.json)");
settings.rw_settings.erase("upnp");
settings_changed = true;
}
});
if (settings_changed) args.WriteSettingsFile();
// We dropped UPnP support but kept the arg as hidden for now to display a friendlier error to user who has the
// option in their config, and migrate the setting to -natpmp.
if (const auto arg{args.GetBoolArg("-upnp")}) {
std::string message;
if (args.SoftSetBoolArg("-natpmp", *arg)) {
message = strprintf(" Substituting '-natpmp=%s'.", *arg);
}
LogWarning("Option '-upnp=%s' is given but UPnP support was dropped in version 29.0.%s",
*arg, message);
}
}
/**
@ -874,12 +900,6 @@ bool AppInitParameterInteraction(const ArgsManager& args)
// also see: InitParameterInteraction()
// We drop UPnP support but kept the arg as hidden for now to display a friendlier error to user who have the
// option in their config. TODO: remove (here and above) for version 30.0.
if (args.IsArgSet("-upnp")) {
InitWarning(_("Option '-upnp' is set but UPnP support was dropped in version 29.0. Consider using '-natpmp' instead."));
}
// Error if network-specific options (-addnode, -connect, etc) are
// specified in default section of config file, but not overridden
// on the command line or in this chain's section of the config file.