2023-01-23 10:31:54 -08:00
|
|
|
// Copyright (c) 2017-2023 The Zcash developers
|
2017-04-24 23:06:29 -07:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2019-07-18 07:16:09 -07:00
|
|
|
// file COPYING or https://www.opensource.org/licenses/mit-license.php .
|
2017-04-24 23:06:29 -07:00
|
|
|
|
|
|
|
#include "deprecation.h"
|
|
|
|
|
2018-01-22 16:29:08 -08:00
|
|
|
#include "alert.h"
|
2017-04-24 23:06:29 -07:00
|
|
|
#include "clientversion.h"
|
|
|
|
#include "init.h"
|
|
|
|
#include "ui_interface.h"
|
2018-10-22 15:51:11 -07:00
|
|
|
#include "util/system.h"
|
2017-04-24 23:06:29 -07:00
|
|
|
|
2022-04-21 15:47:56 -07:00
|
|
|
// Flags that enable deprecated functionality.
|
2022-12-03 15:27:19 -08:00
|
|
|
bool fEnableGbtOldHashes = true;
|
2023-02-10 16:00:22 -08:00
|
|
|
bool fEnableDeprecationInfoDeprecationHeight = true;
|
2023-03-13 08:46:05 -07:00
|
|
|
bool fEnableAddrTypeField = true;
|
2022-04-21 15:47:56 -07:00
|
|
|
#ifdef ENABLE_WALLET
|
|
|
|
bool fEnableGetNewAddress = true;
|
2022-05-10 13:22:12 -07:00
|
|
|
bool fEnableGetRawChangeAddress = true;
|
2022-04-21 15:47:56 -07:00
|
|
|
bool fEnableZGetNewAddress = true;
|
2022-05-05 06:43:08 -07:00
|
|
|
bool fEnableZGetBalance = true;
|
|
|
|
bool fEnableZGetTotalBalance = true;
|
2022-05-10 13:22:12 -07:00
|
|
|
bool fEnableZListAddresses = true;
|
2022-04-21 15:47:56 -07:00
|
|
|
bool fEnableLegacyPrivacyStrategy = true;
|
2022-05-11 10:27:31 -07:00
|
|
|
bool fEnableWalletTxVJoinSplit = true;
|
2022-04-21 15:47:56 -07:00
|
|
|
#endif
|
|
|
|
|
2017-04-24 23:06:29 -07:00
|
|
|
static const std::string CLIENT_VERSION_STR = FormatVersion(CLIENT_VERSION);
|
|
|
|
|
2023-03-09 08:31:37 -08:00
|
|
|
int64_t EstimatedNodeDeprecationTime(const CClock& clock, int nHeight) {
|
|
|
|
auto blocksToDeprecation = DEPRECATION_HEIGHT - nHeight;
|
|
|
|
|
|
|
|
return clock.GetTime() + (blocksToDeprecation * Consensus::POST_BLOSSOM_POW_TARGET_SPACING);
|
|
|
|
}
|
|
|
|
|
2023-03-09 09:30:04 -08:00
|
|
|
void EnforceNodeDeprecation(const CChainParams& params, int nHeight, bool forceLogging, bool fThread) {
|
2018-03-07 08:33:55 -08:00
|
|
|
// Do not enforce deprecation in regtest or on testnet
|
2023-03-09 09:30:04 -08:00
|
|
|
std::string networkID = params.NetworkIDString();
|
2018-03-07 08:33:55 -08:00
|
|
|
if (networkID != "main") return;
|
|
|
|
|
2017-04-24 23:06:29 -07:00
|
|
|
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);
|
2018-01-22 16:29:08 -08:00
|
|
|
CAlert::Notify(msg, fThread);
|
2017-04-24 23:06:29 -07:00
|
|
|
uiInterface.ThreadSafeMessageBox(msg, "", CClientUIInterface::MSG_ERROR);
|
|
|
|
}
|
2018-04-03 05:25:44 -07:00
|
|
|
StartShutdown();
|
2017-04-24 23:06:29 -07:00
|
|
|
} else if (blocksToDeprecation == DEPRECATION_WARN_LIMIT ||
|
|
|
|
(blocksToDeprecation < DEPRECATION_WARN_LIMIT && forceLogging)) {
|
2018-04-03 05:25:44 -07:00
|
|
|
std::string msg = strprintf(_("This version will be deprecated at block height %d, and will automatically shut down."),
|
2017-04-24 23:06:29 -07:00
|
|
|
DEPRECATION_HEIGHT) + " " +
|
|
|
|
_("You should upgrade to the latest version of Zcash.");
|
|
|
|
LogPrintf("*** %s\n", msg);
|
2018-01-22 16:29:08 -08:00
|
|
|
CAlert::Notify(msg, fThread);
|
2017-04-24 23:06:29 -07:00
|
|
|
uiInterface.ThreadSafeMessageBox(msg, "", CClientUIInterface::MSG_WARNING);
|
|
|
|
}
|
2018-01-22 16:29:08 -08:00
|
|
|
}
|
2022-04-21 15:47:56 -07:00
|
|
|
|
2023-02-10 14:13:36 -08:00
|
|
|
std::optional<std::string> LoadAllowedDeprecatedFeatures() {
|
2022-04-21 15:47:56 -07:00
|
|
|
auto args = GetMultiArg("-allowdeprecated");
|
|
|
|
std::set<std::string> allowdeprecated(args.begin(), args.end());
|
|
|
|
|
|
|
|
if (allowdeprecated.count("none") > 0) {
|
|
|
|
if (allowdeprecated.size() > 1)
|
|
|
|
return "When using -allowdeprecated=none no other values may be provided for -allowdeprecated.";
|
|
|
|
allowdeprecated = {};
|
2022-05-03 08:25:24 -07:00
|
|
|
} else {
|
|
|
|
allowdeprecated.insert(DEFAULT_ALLOW_DEPRECATED.begin(), DEFAULT_ALLOW_DEPRECATED.end());
|
2022-04-21 15:47:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
2022-12-03 15:27:19 -08:00
|
|
|
fEnableGbtOldHashes = allowdeprecated.count("gbt_oldhashes") > 0;
|
2023-02-10 16:00:22 -08:00
|
|
|
fEnableDeprecationInfoDeprecationHeight = allowdeprecated.count("deprecationinfo_deprecationheight") > 0;
|
2023-03-13 08:46:05 -07:00
|
|
|
fEnableAddrTypeField = allowdeprecated.count("addrtype") > 0;
|
2022-04-21 15:47:56 -07:00
|
|
|
#ifdef ENABLE_WALLET
|
|
|
|
fEnableLegacyPrivacyStrategy = allowdeprecated.count("legacy_privacy") > 0;
|
|
|
|
fEnableGetNewAddress = allowdeprecated.count("getnewaddress") > 0;
|
2022-05-10 13:22:12 -07:00
|
|
|
fEnableGetRawChangeAddress = allowdeprecated.count("getrawchangeaddress") > 0;
|
2022-04-21 15:47:56 -07:00
|
|
|
fEnableZGetNewAddress = allowdeprecated.count("z_getnewaddress") > 0;
|
2022-05-05 06:43:08 -07:00
|
|
|
fEnableZGetBalance = allowdeprecated.count("z_getbalance") > 0;
|
|
|
|
fEnableZGetTotalBalance = allowdeprecated.count("z_gettotalbalance") > 0;
|
2022-05-10 13:22:12 -07:00
|
|
|
fEnableZListAddresses = allowdeprecated.count("z_listaddresses") > 0;
|
2022-05-11 10:27:31 -07:00
|
|
|
fEnableWalletTxVJoinSplit = allowdeprecated.count("wallettxvjoinsplit") > 0;
|
2022-04-21 15:47:56 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return std::nullopt;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string GetAllowableDeprecatedFeatures() {
|
2022-05-03 08:25:24 -07:00
|
|
|
std::string result = "\"none\"";
|
2022-04-21 15:47:56 -07:00
|
|
|
for (const auto& value : DEFAULT_ALLOW_DEPRECATED) {
|
|
|
|
result += ", \"" + value + "\"";
|
|
|
|
}
|
|
|
|
for (const auto& value : DEFAULT_DENY_DEPRECATED) {
|
|
|
|
result += ", \"" + value + "\"";
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|