diff --git a/src/init.cpp b/src/init.cpp index 3cfd301fbab..7fdbf75dc66 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -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.