zcashd/src/deprecation.cpp

125 lines
4.9 KiB
C++
Raw Normal View History

// Copyright (c) 2017 The Zcash developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or https://www.opensource.org/licenses/mit-license.php .
#include "deprecation.h"
#include "alert.h"
#include "clientversion.h"
#include "init.h"
#include "ui_interface.h"
#include "util.h"
2018-03-07 08:33:55 -08:00
#include "chainparams.h"
Allow deprecated wallet features to be preemptively disabled. This adds an `-allowdeprecated` CLI parameter whose value is a flag indicating a deprecated feature that should be explicitly enabled. Multiple instances of this argument may be provided. In the case that this parameter is not provided, all currently deprecated RPC methods that are not slated for removal in the next release remain available. A user may disable all deprecated features entirely by providing the string "none" as the argument to this parameter, or enable all deprecated features, including those slated for removal, by providing the string "all" as the argument to this parameter. In the case that "all" or "none" is specified, multiple invocations of `-allowdeprecated` are not permitted. To explicitly enable only a specific set of deprecated features, use `-allowdeprecated=<flag1> -allowdeprecated=<flagN> ...` when starting zcashd. The following flags are recognized: - "all" - enables all deprecated features. - "none" - disables all deprecated features. - "legacy_privacy" - enables the use of the deprecated "legacy" privacy policy for z_sendmany. This causes the default behavior to conform to the `FullPrivacy` directive in all cases instead of just for transactions involving unified addresses. - "getnewaddress" - enables the `getnewaddress` RPC method. - "z_getnewaddress" - enables the `z_getnewaddress` RPC method. - "zcrawreceive" - enables the `zcrawreceive` RPC method. - "zcrawjoinsplit" - enables the `zcrawjoinsplit` RPC method. - "zcrawkeygen" - enables the `zcrawkeygen` RPC method. - "addrtype" - when this option is set, the deprecated `type` attribute is returned in addition to `pool` or `address_type` (which contain the same information) in the results of RPC methods that return address metadata.
2022-04-21 15:47:56 -07:00
// Flags that enable deprecated functionality.
#ifdef ENABLE_WALLET
bool fEnableGetNewAddress = true;
bool fEnableZGetNewAddress = true;
bool fEnableLegacyPrivacyStrategy = true;
bool fEnableZCRawReceive = true;
bool fEnableZCRawJoinSplit = true;
bool fEnableZCRawKeygen = true;
bool fEnableAddrTypeField = true;
#endif
static const std::string CLIENT_VERSION_STR = FormatVersion(CLIENT_VERSION);
void EnforceNodeDeprecation(int nHeight, bool forceLogging, bool fThread) {
2018-03-07 08:33:55 -08:00
// Do not enforce deprecation in regtest or on testnet
std::string networkID = Params().NetworkIDString();
if (networkID != "main") return;
int blocksToDeprecation = DEPRECATION_HEIGHT - nHeight;
if (blocksToDeprecation <= 0) {
// In order to ensure we only log once per process when deprecation is
// disabled (to avoid log spam), we only need to log in two cases:
// - The deprecating block just arrived
// - This can be triggered more than once if a block chain reorg
// occurs, but that's an irregular event that won't cause spam.
// - The node is starting
if (blocksToDeprecation == 0 || forceLogging) {
auto msg = strprintf(_("This version has been deprecated as of block height %d."),
DEPRECATION_HEIGHT) + " " +
_("You should upgrade to the latest version of Zcash.");
LogPrintf("*** %s\n", msg);
CAlert::Notify(msg, fThread);
uiInterface.ThreadSafeMessageBox(msg, "", CClientUIInterface::MSG_ERROR);
}
StartShutdown();
} else if (blocksToDeprecation == DEPRECATION_WARN_LIMIT ||
(blocksToDeprecation < DEPRECATION_WARN_LIMIT && forceLogging)) {
std::string msg = strprintf(_("This version will be deprecated at block height %d, and will automatically shut down."),
DEPRECATION_HEIGHT) + " " +
_("You should upgrade to the latest version of Zcash.");
LogPrintf("*** %s\n", msg);
CAlert::Notify(msg, fThread);
uiInterface.ThreadSafeMessageBox(msg, "", CClientUIInterface::MSG_WARNING);
}
}
Allow deprecated wallet features to be preemptively disabled. This adds an `-allowdeprecated` CLI parameter whose value is a flag indicating a deprecated feature that should be explicitly enabled. Multiple instances of this argument may be provided. In the case that this parameter is not provided, all currently deprecated RPC methods that are not slated for removal in the next release remain available. A user may disable all deprecated features entirely by providing the string "none" as the argument to this parameter, or enable all deprecated features, including those slated for removal, by providing the string "all" as the argument to this parameter. In the case that "all" or "none" is specified, multiple invocations of `-allowdeprecated` are not permitted. To explicitly enable only a specific set of deprecated features, use `-allowdeprecated=<flag1> -allowdeprecated=<flagN> ...` when starting zcashd. The following flags are recognized: - "all" - enables all deprecated features. - "none" - disables all deprecated features. - "legacy_privacy" - enables the use of the deprecated "legacy" privacy policy for z_sendmany. This causes the default behavior to conform to the `FullPrivacy` directive in all cases instead of just for transactions involving unified addresses. - "getnewaddress" - enables the `getnewaddress` RPC method. - "z_getnewaddress" - enables the `z_getnewaddress` RPC method. - "zcrawreceive" - enables the `zcrawreceive` RPC method. - "zcrawjoinsplit" - enables the `zcrawjoinsplit` RPC method. - "zcrawkeygen" - enables the `zcrawkeygen` RPC method. - "addrtype" - when this option is set, the deprecated `type` attribute is returned in addition to `pool` or `address_type` (which contain the same information) in the results of RPC methods that return address metadata.
2022-04-21 15:47:56 -07:00
std::optional<std::string> SetAllowedDeprecatedFeaturesFromCLIArgs() {
auto args = GetMultiArg("-allowdeprecated");
std::set<std::string> allowdeprecated(args.begin(), args.end());
if (allowdeprecated.empty()) {
allowdeprecated = DEFAULT_ALLOW_DEPRECATED;
}
if (allowdeprecated.count("all") > 0) {
if (allowdeprecated.size() > 1)
return "When using -allowdeprecated=all no other values may be provided for -allowdeprecated.";
allowdeprecated = {};
allowdeprecated.insert(DEFAULT_ALLOW_DEPRECATED.begin(), DEFAULT_ALLOW_DEPRECATED.end());
allowdeprecated.insert(DEFAULT_DENY_DEPRECATED.begin(), DEFAULT_DENY_DEPRECATED.end());
}
if (allowdeprecated.count("none") > 0) {
if (allowdeprecated.size() > 1)
return "When using -allowdeprecated=none no other values may be provided for -allowdeprecated.";
allowdeprecated = {};
}
std::set<std::string> unrecognized;
for (const auto& flag : allowdeprecated) {
if (DEFAULT_ALLOW_DEPRECATED.count(flag) == 0 && DEFAULT_DENY_DEPRECATED.count(flag) == 0)
unrecognized.insert(flag);
}
if (unrecognized.size() > 0) {
std::string unrecMsg;
for (const auto& value : unrecognized) {
if (unrecMsg.size() > 0) unrecMsg += ", ";
unrecMsg += "\"" + value + "\"";
}
return strprintf(
"Unrecognized argument(s) to -allowdeprecated: %s;\n"
"Please select from the following values: %s",
unrecMsg, GetAllowableDeprecatedFeatures());
}
#ifdef ENABLE_WALLET
fEnableLegacyPrivacyStrategy = allowdeprecated.count("legacy_privacy") > 0;
fEnableGetNewAddress = allowdeprecated.count("getnewaddress") > 0;
fEnableZGetNewAddress = allowdeprecated.count("z_getnewaddress") > 0;
fEnableZCRawReceive = allowdeprecated.count("zcrawreceive") > 0;
fEnableZCRawJoinSplit = allowdeprecated.count("zcrawjoinsplit") > 0;
fEnableZCRawKeygen = allowdeprecated.count("zcrawkeygen") > 0;
fEnableAddrTypeField = allowdeprecated.count("addrtype") > 0;
#endif
return std::nullopt;
}
std::string GetAllowableDeprecatedFeatures() {
std::string result = "\"all\", \"none\"";
for (const auto& value : DEFAULT_ALLOW_DEPRECATED) {
result += ", \"" + value + "\"";
}
for (const auto& value : DEFAULT_DENY_DEPRECATED) {
result += ", \"" + value + "\"";
}
return result;
}