From 48149defab4f57ca0749842778f40b2b875a68f0 Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Thu, 3 Sep 2020 07:13:50 -0600 Subject: [PATCH] Prevent creation of shielded transactions in initial block download. Author: Alfredo Garcia Co-authored-by: Jack Grigg Co-authored-by: Duke Leto --- src/rpc/blockchain.cpp | 6 ++++-- src/wallet/rpcwallet.cpp | 13 +++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 307572341..24d725341 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -995,6 +995,7 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp) "{\n" " \"chain\": \"xxxx\", (string) current network name as defined in BIP70 (main, test, regtest)\n" " \"blocks\": xxxxxx, (numeric) the current number of blocks processed in the server\n" + " \"initial_block_download_complete\": xx, (boolean) true if the initial download of the blockchain is complete\n" " \"headers\": xxxxxx, (numeric) the current number of headers we have validated\n" " \"bestblockhash\": \"...\", (string) the hash of the currently best block\n" " \"difficulty\": xxxxxx, (numeric) the current difficulty\n" @@ -1039,6 +1040,7 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp) UniValue obj(UniValue::VOBJ); obj.pushKV("chain", Params().NetworkIDString()); obj.pushKV("blocks", (int)chainActive.Height()); + obj.pushKV("initial_block_download_complete", !IsInitialBlockDownload(Params())); obj.pushKV("headers", pindexBestHeader ? pindexBestHeader->nHeight : -1); obj.pushKV("bestblockhash", chainActive.Tip()->GetBlockHash().GetHex()); obj.pushKV("difficulty", (double)GetNetworkDifficulty()); @@ -1048,9 +1050,9 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp) obj.pushKV("size_on_disk", CalculateCurrentUsage()); if (IsInitialBlockDownload(Params())) - obj.push_back(Pair("estimatedheight", EstimateNetHeight(Params().GetConsensus(), (int)chainActive.Height(), chainActive.Tip()->GetMedianTimePast()))); + obj.pushKV("estimatedheight", EstimateNetHeight(Params().GetConsensus(), (int)chainActive.Height(), chainActive.Tip()->GetMedianTimePast())); else - obj.push_back(Pair("estimatedheight", (int)chainActive.Height())); + obj.pushKV("estimatedheight", (int)chainActive.Height()); SproutMerkleTree tree; pcoinsTip->GetSproutAnchorAt(pcoinsTip->GetBestAnchor(SPROUT), tree); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 5fc348175..29b9cbcd4 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -85,6 +85,13 @@ void EnsureWalletIsUnlocked() throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the wallet passphrase with walletpassphrase first."); } +void ThrowIfInitialBlockDownload() +{ + if (IsInitialBlockDownload(Params())) { + throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "Error: Sending transactions is not supported during initial block download."); + } +} + void WalletTxToJSON(const CWalletTx& wtx, UniValue& entry) { int confirms = wtx.GetDepthInMainChain(); @@ -4026,6 +4033,8 @@ UniValue z_sendmany(const UniValue& params, bool fHelp) LOCK2(cs_main, pwalletMain->cs_wallet); + ThrowIfInitialBlockDownload(); + // Check that the from address is valid. auto fromaddress = params[0].get_str(); bool fromTaddr = false; @@ -4463,6 +4472,8 @@ UniValue z_shieldcoinbase(const UniValue& params, bool fHelp) LOCK2(cs_main, pwalletMain->cs_wallet); + ThrowIfInitialBlockDownload(); + // Validate the from address auto fromaddress = params[0].get_str(); bool isFromWildcard = fromaddress == "*"; @@ -4699,6 +4710,8 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp) LOCK2(cs_main, pwalletMain->cs_wallet); + ThrowIfInitialBlockDownload(); + bool useAnyUTXO = false; bool useAnySprout = false; bool useAnySapling = false;