Auto merge of #4402 - oxarbitrage:issue4326, r=str4d

Add -lightwalletd experimental option

Similar to `-insightexplorer` but loading less indexes.

After testing and code review this should be able to close https://github.com/zcash/zcash/issues/4326
This commit is contained in:
Homu 2020-04-10 03:42:54 +00:00
commit 3033b8a0ec
12 changed files with 159 additions and 55 deletions

View File

@ -3,14 +3,14 @@
# Distributed under the MIT software license, see the accompanying # Distributed under the MIT software license, see the accompanying
# file COPYING or https://www.opensource.org/licenses/mit-license.php . # file COPYING or https://www.opensource.org/licenses/mit-license.php .
# #
# Test addressindex generation and fetching for insightexplorer # Test addressindex generation and fetching for insightexplorer or lightwalletd
# #
# RPCs tested here: # RPCs tested here:
# #
# getaddresstxids # getaddresstxids
# getaddressbalance # getaddressbalance
# getaddressdeltas # getaddressdeltas
# getaddressutxos # getaddressutxos - available only for insightexplorer
# getaddressmempool # getaddressmempool
@ -22,7 +22,7 @@ from test_framework.util import (
start_nodes, start_nodes,
stop_nodes, stop_nodes,
connect_nodes, connect_nodes,
wait_bitcoinds, wait_bitcoinds
) )
from test_framework.script import ( from test_framework.script import (
@ -46,14 +46,18 @@ class AddressIndexTest(BitcoinTestFramework):
def setup_chain(self): def setup_chain(self):
print("Initializing test directory "+self.options.tmpdir) print("Initializing test directory "+self.options.tmpdir)
initialize_chain_clean(self.options.tmpdir, 3) initialize_chain_clean(self.options.tmpdir, 4)
def setup_network(self): def setup_network(self):
# -insightexplorer causes addressindex to be enabled (fAddressIndex = true) # -insightexplorer causes addressindex to be enabled (fAddressIndex = true)
args = ('-debug', '-txindex', '-experimentalfeatures', '-insightexplorer') args_insight = ('-debug', '-txindex', '-experimentalfeatures', '-insightexplorer')
self.nodes = start_nodes(3, self.options.tmpdir, [args] * 3) # -lightwallet also causes addressindex to be enabled
args_lightwallet = ('-debug', '-txindex', '-experimentalfeatures', '-lightwalletd')
self.nodes = start_nodes(4, self.options.tmpdir, [args_insight] * 3 + [args_lightwallet])
connect_nodes(self.nodes[0], 1) connect_nodes(self.nodes[0], 1)
connect_nodes(self.nodes[0], 2) connect_nodes(self.nodes[0], 2)
connect_nodes(self.nodes[0], 3) # node3 is only for testing lightwalletd
self.is_network_split = False self.is_network_split = False
self.sync_all() self.sync_all()
@ -120,6 +124,9 @@ class AddressIndexTest(BitcoinTestFramework):
assert_equal(len(self.nodes[1].getaddresstxids(addr_p2pkh)), 105) assert_equal(len(self.nodes[1].getaddresstxids(addr_p2pkh)), 105)
assert_equal(len(self.nodes[1].getaddresstxids(addr_p2sh)), 105) assert_equal(len(self.nodes[1].getaddresstxids(addr_p2sh)), 105)
# test getaddresstxids for lightwalletd
assert_equal(len(self.nodes[3].getaddresstxids(addr_p2pkh)), 105)
assert_equal(len(self.nodes[3].getaddresstxids(addr_p2sh)), 105)
# only the oldest 5 transactions are in the unspent list, # only the oldest 5 transactions are in the unspent list,
# dup addresses are ignored # dup addresses are ignored
@ -181,6 +188,9 @@ class AddressIndexTest(BitcoinTestFramework):
# check that duplicate addresses are processed correctly # check that duplicate addresses are processed correctly
mempool = self.nodes[0].getaddressmempool({'addresses': [addr2, addr1, addr2]}) mempool = self.nodes[0].getaddressmempool({'addresses': [addr2, addr1, addr2]})
assert_equal(len(mempool), 3) assert_equal(len(mempool), 3)
# test getaddressmempool for lightwalletd node
mempool = self.nodes[3].getaddressmempool({'addresses': [addr2, addr1, addr2]})
assert_equal(len(mempool), 3)
# addr2 (first arg) # addr2 (first arg)
assert_equal(mempool[0]['address'], addr2) assert_equal(mempool[0]['address'], addr2)
@ -253,8 +263,12 @@ class AddressIndexTest(BitcoinTestFramework):
tx = self.nodes[0].getrawtransaction(txid, 1) tx = self.nodes[0].getrawtransaction(txid, 1)
change_vout = list(filter(lambda v: v['valueZat'] != 3 * COIN, tx['vout'])) change_vout = list(filter(lambda v: v['valueZat'] != 3 * COIN, tx['vout']))
change = change_vout[0]['scriptPubKey']['addresses'][0] change = change_vout[0]['scriptPubKey']['addresses'][0]
bal = self.nodes[2].getaddressbalance(change)
# test getaddressbalance
for node in (2, 3):
bal = self.nodes[node].getaddressbalance(change)
assert(bal['received'] > 0) assert(bal['received'] > 0)
# the inequality is due to randomness in the tx fee # the inequality is due to randomness in the tx fee
assert(bal['received'] < (4 - 3) * COIN) assert(bal['received'] < (4 - 3) * COIN)
assert_equal(bal['received'], bal['balance']) assert_equal(bal['received'], bal['balance'])
@ -283,7 +297,9 @@ class AddressIndexTest(BitcoinTestFramework):
# set(txids_all) removes its (expected) duplicates # set(txids_all) removes its (expected) duplicates
assert_equal(set(multitxids), set(txids_all)) assert_equal(set(multitxids), set(txids_all))
deltas = self.nodes[1].getaddressdeltas({'addresses': [addr1]}) # test getaddressdeltas
for node in (1, 3):
deltas = self.nodes[node].getaddressdeltas({'addresses': [addr1]})
assert_equal(len(deltas), len(expected_deltas)) assert_equal(len(deltas), len(expected_deltas))
for i in range(len(deltas)): for i in range(len(deltas)):
assert_equal(deltas[i]['address'], addr1) assert_equal(deltas[i]['address'], addr1)

View File

@ -10,6 +10,7 @@ bool fExperimentalDeveloperEncryptWallet = false;
bool fExperimentalDeveloperSetPoolSizeZero = false; bool fExperimentalDeveloperSetPoolSizeZero = false;
bool fExperimentalPaymentDisclosure = false; bool fExperimentalPaymentDisclosure = false;
bool fExperimentalInsightExplorer = false; bool fExperimentalInsightExplorer = false;
bool fExperimentalLightWalletd = false;
boost::optional<std::string> InitExperimentalMode() boost::optional<std::string> InitExperimentalMode()
{ {
@ -18,6 +19,7 @@ boost::optional<std::string> InitExperimentalMode()
fExperimentalDeveloperSetPoolSizeZero = GetBoolArg("-developersetpoolsizezero", false); fExperimentalDeveloperSetPoolSizeZero = GetBoolArg("-developersetpoolsizezero", false);
fExperimentalPaymentDisclosure = GetBoolArg("-paymentdisclosure", false); fExperimentalPaymentDisclosure = GetBoolArg("-paymentdisclosure", false);
fExperimentalInsightExplorer = GetBoolArg("-insightexplorer", false); fExperimentalInsightExplorer = GetBoolArg("-insightexplorer", false);
fExperimentalLightWalletd = GetBoolArg("-lightwalletd", false);
// Fail if user has set experimental options without the global flag // Fail if user has set experimental options without the global flag
if (!fExperimentalMode) { if (!fExperimentalMode) {
@ -29,6 +31,8 @@ boost::optional<std::string> InitExperimentalMode()
return _("Payment disclosure requires -experimentalfeatures."); return _("Payment disclosure requires -experimentalfeatures.");
} else if (fExperimentalInsightExplorer) { } else if (fExperimentalInsightExplorer) {
return _("Insight explorer requires -experimentalfeatures."); return _("Insight explorer requires -experimentalfeatures.");
} else if (fExperimentalLightWalletd) {
return _("Light Walletd requires -experimentalfeatures.");
} }
} }
return boost::none; return boost::none;
@ -45,6 +49,8 @@ std::vector<std::string> GetExperimentalFeatures()
experimentalfeatures.push_back("paymentdisclosure"); experimentalfeatures.push_back("paymentdisclosure");
if (fExperimentalInsightExplorer) if (fExperimentalInsightExplorer)
experimentalfeatures.push_back("insightexplorer"); experimentalfeatures.push_back("insightexplorer");
if (fExperimentalLightWalletd)
experimentalfeatures.push_back("lightwalletd");
return experimentalfeatures; return experimentalfeatures;
} }

View File

@ -10,6 +10,7 @@ extern bool fExperimentalDeveloperEncryptWallet;
extern bool fExperimentalDeveloperSetPoolSizeZero; extern bool fExperimentalDeveloperSetPoolSizeZero;
extern bool fExperimentalPaymentDisclosure; extern bool fExperimentalPaymentDisclosure;
extern bool fExperimentalInsightExplorer; extern bool fExperimentalInsightExplorer;
extern bool fExperimentalLightWalletd;
boost::optional<std::string> InitExperimentalMode(); boost::optional<std::string> InitExperimentalMode();
std::vector<std::string> GetExperimentalFeatures(); std::vector<std::string> GetExperimentalFeatures();

View File

@ -26,3 +26,44 @@ TEST(rpc, CheckBlockToJSONReturnsMinifiedSolution) {
UniValue obj = blockToJSON(block, &index); UniValue obj = blockToJSON(block, &index);
EXPECT_EQ("009f44ff7505d789b964d6817734b8ce1377d456255994370d06e59ac99bd5791b6ad174a66fd71c70e60cfc7fd88243ffe06f80b1ad181625f210779c745524629448e25348a5fce4f346a1735e60fdf53e144c0157dbc47c700a21a236f1efb7ee75f65b8d9d9e29026cfd09048233175202b211b9a49de4ab46f1cac71b6ea57a686377bd612378746e70c61a659c9cd683269e9c2a5cbc1d19f1149345302bbd0a1e62bf4bab01e9caeea789a1519441a61b146de35a4cc75dbdf01029127e311ad5073e7e96397f47226a7df9df66b2086b70756db013bbaeb068260157014b2602fc7dc71336e1439c887d2742d9730b4e79b08ec7839c3e2a037ae1565d04e05e351bb3531e5ef42cf7b71ca1482a9205245dd41f4db0f71644f8bdb88e845558537c03834c06ac83f336651e54e2edfc12e15ea9b7ea2c074e6155654d44c4d3bd90d9511050e9ad87d170db01448e5be6f45419cd86008978db5e3ceab79890234f992648d69bf1053855387db646ccdee5575c65f81dd0f670b016d9f9a84707d91f77b862f697b8bb08365ba71fbe6bfa47af39155a75ebdcb1e5d69f59c40c9e3a64988c1ec26f7f5159eef5c244d504a9e46125948ecc389c2ec3028ac4ff39ffd66e7743970819272b21e0c2df75b308bc62896873952147e57ed79446db4cdb5a563e76ec4c25899d41128afb9a5f8fc8063621efb7a58b9dd666d30c73e318cdcf3393bfec200e160f500e645f7baac263db99fa4a7c1cb4fea219fc512193102034d379f244c21a81821301b8d47c90247713a3e902c762d7bafa6cdb744eeb6d3b50dd175599d02b6e9f5bbda59366e04862aa765135968426e7ac0116de7351940dc57c0ae451d63f667e39891bc81e09e6c76f6f8a7582f7447c6f5945f717b0e52a7e3dd0c6db4061362123cc53fd8ede4abed4865201dc4d8eb4e5d48baa565183b69a5304a44c0600bb24dcaeee9d95ceebd27c1b0a33e0b46f23797d7d7907300b2bb7d62ef2fc5aa139250c73930c621bb5f41fc235534ee8014dfaddd5245aeb01198420ba7b5c076545329c94d54fa725a8e807579f5f0cc9d98170598023268f5930893620190275e6b3c6f5181e36310a9a475208316911d78f917d724c5946c553b7ec042c563c540114b6b78bd4c6e808ee391a4a9d93e127032983c5b3708037b14aa604cfb034e7c8b0ffdd6936446fe80216178506a87402653a373926eeff66e704daf992a0a9a5c3ad80566c0339be9e5b8e35b3b3226b2f7767e20d992ea6c3d6e322eca37b0c7f7e60060802f5abcc1975841365cadbdc3867063addfc803766ae525375ecddee61f9df9ffcd20343c83ab82b0e91de039c59cb435c8d3159cc338b4901f40c9b5c27043bcf2bd5fa9b685b65c9ba5a1e11a51dd3f773051560341f9ec81d05bf259e2d4b7161f896fbb6812cfc924a32120b7367d5e40439e267adda6a1315bb0d6200ce6a503174c8d2a638ea6fd6b1f486d68db11bdca63c4f4a725d1ab6231ea875484e70b27d293c05803386924f283d4c12bb953474d92b7dd43d2d97193bd96281ebb63fa075d2f9ecd310c70ee1d97b5330bd8fb5791c5943ecf084e5f2c83915acac57519c46b166136068d6f9ec0dd598616e32c591128ce13705a283ca39d5b211409600e07b3713113374d9700207a45394eac5b3b7afc9b1b2bad7d89fd3f35f6b2413ce615ee7869b3569009403b96fdacdb32ef0a7e5229e2b666d51e95bdfb009b892e88bde70621a9b6509f068781392df4bdbc5723bb15071993f0d9a11575af5ff6ef85eaea39bc86805b35d8beee91b779354147f2d85304b8b49d053e7444fdd3deb9d16de331f2552af5b3be7766bb8f3f6a78c62148efb231f2268", find_value(obj, "solution").get_str()); EXPECT_EQ("009f44ff7505d789b964d6817734b8ce1377d456255994370d06e59ac99bd5791b6ad174a66fd71c70e60cfc7fd88243ffe06f80b1ad181625f210779c745524629448e25348a5fce4f346a1735e60fdf53e144c0157dbc47c700a21a236f1efb7ee75f65b8d9d9e29026cfd09048233175202b211b9a49de4ab46f1cac71b6ea57a686377bd612378746e70c61a659c9cd683269e9c2a5cbc1d19f1149345302bbd0a1e62bf4bab01e9caeea789a1519441a61b146de35a4cc75dbdf01029127e311ad5073e7e96397f47226a7df9df66b2086b70756db013bbaeb068260157014b2602fc7dc71336e1439c887d2742d9730b4e79b08ec7839c3e2a037ae1565d04e05e351bb3531e5ef42cf7b71ca1482a9205245dd41f4db0f71644f8bdb88e845558537c03834c06ac83f336651e54e2edfc12e15ea9b7ea2c074e6155654d44c4d3bd90d9511050e9ad87d170db01448e5be6f45419cd86008978db5e3ceab79890234f992648d69bf1053855387db646ccdee5575c65f81dd0f670b016d9f9a84707d91f77b862f697b8bb08365ba71fbe6bfa47af39155a75ebdcb1e5d69f59c40c9e3a64988c1ec26f7f5159eef5c244d504a9e46125948ecc389c2ec3028ac4ff39ffd66e7743970819272b21e0c2df75b308bc62896873952147e57ed79446db4cdb5a563e76ec4c25899d41128afb9a5f8fc8063621efb7a58b9dd666d30c73e318cdcf3393bfec200e160f500e645f7baac263db99fa4a7c1cb4fea219fc512193102034d379f244c21a81821301b8d47c90247713a3e902c762d7bafa6cdb744eeb6d3b50dd175599d02b6e9f5bbda59366e04862aa765135968426e7ac0116de7351940dc57c0ae451d63f667e39891bc81e09e6c76f6f8a7582f7447c6f5945f717b0e52a7e3dd0c6db4061362123cc53fd8ede4abed4865201dc4d8eb4e5d48baa565183b69a5304a44c0600bb24dcaeee9d95ceebd27c1b0a33e0b46f23797d7d7907300b2bb7d62ef2fc5aa139250c73930c621bb5f41fc235534ee8014dfaddd5245aeb01198420ba7b5c076545329c94d54fa725a8e807579f5f0cc9d98170598023268f5930893620190275e6b3c6f5181e36310a9a475208316911d78f917d724c5946c553b7ec042c563c540114b6b78bd4c6e808ee391a4a9d93e127032983c5b3708037b14aa604cfb034e7c8b0ffdd6936446fe80216178506a87402653a373926eeff66e704daf992a0a9a5c3ad80566c0339be9e5b8e35b3b3226b2f7767e20d992ea6c3d6e322eca37b0c7f7e60060802f5abcc1975841365cadbdc3867063addfc803766ae525375ecddee61f9df9ffcd20343c83ab82b0e91de039c59cb435c8d3159cc338b4901f40c9b5c27043bcf2bd5fa9b685b65c9ba5a1e11a51dd3f773051560341f9ec81d05bf259e2d4b7161f896fbb6812cfc924a32120b7367d5e40439e267adda6a1315bb0d6200ce6a503174c8d2a638ea6fd6b1f486d68db11bdca63c4f4a725d1ab6231ea875484e70b27d293c05803386924f283d4c12bb953474d92b7dd43d2d97193bd96281ebb63fa075d2f9ecd310c70ee1d97b5330bd8fb5791c5943ecf084e5f2c83915acac57519c46b166136068d6f9ec0dd598616e32c591128ce13705a283ca39d5b211409600e07b3713113374d9700207a45394eac5b3b7afc9b1b2bad7d89fd3f35f6b2413ce615ee7869b3569009403b96fdacdb32ef0a7e5229e2b666d51e95bdfb009b892e88bde70621a9b6509f068781392df4bdbc5723bb15071993f0d9a11575af5ff6ef85eaea39bc86805b35d8beee91b779354147f2d85304b8b49d053e7444fdd3deb9d16de331f2552af5b3be7766bb8f3f6a78c62148efb231f2268", find_value(obj, "solution").get_str());
} }
TEST(rpc, CheckExperimentalDisabledHelpMsg) {
EXPECT_EQ(experimentalDisabledHelpMsg("somerpc", {"somevalue"}),
"\nWARNING: somerpc is disabled.\n"
"To enable it, restart zcashd with the following command line options:\n"
"-experimentalfeatures and -somevalue\n\n"
"Alternatively add these two lines to the zcash.conf file:\n\n"
"experimentalfeatures=1\n"
"somevalue=1\n");
EXPECT_EQ(experimentalDisabledHelpMsg("somerpc", {"somevalue", "someothervalue"}),
"\nWARNING: somerpc is disabled.\n"
"To enable it, restart zcashd with the following command line options:\n"
"-experimentalfeatures and -somevalue"
" or:\n-experimentalfeatures and -someothervalue"
"\n\n"
"Alternatively add these two lines to the zcash.conf file:\n\n"
"experimentalfeatures=1\n"
"somevalue=1\n"
"\nor:\n\n"
"experimentalfeatures=1\n"
"someothervalue=1\n");
EXPECT_EQ(experimentalDisabledHelpMsg("somerpc", {"somevalue", "someothervalue", "athirdvalue"}),
"\nWARNING: somerpc is disabled.\n"
"To enable it, restart zcashd with the following command line options:\n"
"-experimentalfeatures and -somevalue"
" or:\n-experimentalfeatures and -someothervalue"
" or:\n-experimentalfeatures and -athirdvalue"
"\n\n"
"Alternatively add these two lines to the zcash.conf file:\n\n"
"experimentalfeatures=1\n"
"somevalue=1\n"
"\nor:\n\n"
"experimentalfeatures=1\n"
"someothervalue=1\n"
"\nor:\n\n"
"experimentalfeatures=1\n"
"athirdvalue=1\n");
}

View File

@ -1421,6 +1421,14 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
break; break;
} }
// Check for changed -lightwalletd state
bool fLightWalletdPreviouslySet = false;
pblocktree->ReadFlag("lightwalletd", fLightWalletdPreviouslySet);
if (fExperimentalLightWalletd != fLightWalletdPreviouslySet) {
strLoadError = _("You need to rebuild the database using -reindex to change -lightwalletd");
break;
}
// Check for changed -prune state. What we are concerned about is a user who has pruned blocks // Check for changed -prune state. What we are concerned about is a user who has pruned blocks
// in the past, but is now trying to run unpruned. // in the past, but is now trying to run unpruned.
if (fHavePruned && !fPruneMode) { if (fHavePruned && !fPruneMode) {

View File

@ -70,7 +70,7 @@ int nScriptCheckThreads = 0;
bool fImporting = false; bool fImporting = false;
std::atomic_bool fReindex(false); std::atomic_bool fReindex(false);
bool fTxIndex = false; bool fTxIndex = false;
bool fAddressIndex = false; // insightexplorer bool fAddressIndex = false; // insightexplorer || lightwalletd
bool fSpentIndex = false; // insightexplorer bool fSpentIndex = false; // insightexplorer
bool fTimestampIndex = false; // insightexplorer bool fTimestampIndex = false; // insightexplorer
bool fHavePruned = false; bool fHavePruned = false;
@ -4498,14 +4498,22 @@ bool static LoadBlockIndexDB()
pblocktree->ReadFlag("txindex", fTxIndex); pblocktree->ReadFlag("txindex", fTxIndex);
LogPrintf("%s: transaction index %s\n", __func__, fTxIndex ? "enabled" : "disabled"); LogPrintf("%s: transaction index %s\n", __func__, fTxIndex ? "enabled" : "disabled");
// insightexplorer // insightexplorer and lightwalletd
// Check whether block explorer features are enabled // Check whether block explorer features are enabled
bool fInsightExplorer = false; bool fInsightExplorer = false;
bool fLightWalletd = false;
pblocktree->ReadFlag("insightexplorer", fInsightExplorer); pblocktree->ReadFlag("insightexplorer", fInsightExplorer);
pblocktree->ReadFlag("lightwalletd", fLightWalletd);
LogPrintf("%s: insight explorer %s\n", __func__, fInsightExplorer ? "enabled" : "disabled"); LogPrintf("%s: insight explorer %s\n", __func__, fInsightExplorer ? "enabled" : "disabled");
fAddressIndex = fInsightExplorer; LogPrintf("%s: light wallet daemon %s\n", __func__, fLightWalletd ? "enabled" : "disabled");
fSpentIndex = fInsightExplorer; if (fInsightExplorer) {
fTimestampIndex = fInsightExplorer; fAddressIndex = true;
fSpentIndex = true;
fTimestampIndex = true;
}
else if (fLightWalletd) {
fAddressIndex = true;
}
// Fill in-memory data // Fill in-memory data
BOOST_FOREACH(const PAIRTYPE(uint256, CBlockIndex*)& item, mapBlockIndex) BOOST_FOREACH(const PAIRTYPE(uint256, CBlockIndex*)& item, mapBlockIndex)
@ -4845,11 +4853,17 @@ bool InitBlockIndex(const CChainParams& chainparams)
fTxIndex = GetBoolArg("-txindex", DEFAULT_TXINDEX); fTxIndex = GetBoolArg("-txindex", DEFAULT_TXINDEX);
pblocktree->WriteFlag("txindex", fTxIndex); pblocktree->WriteFlag("txindex", fTxIndex);
// Use the provided setting for -insightexplorer in the new database // Use the provided setting for -insightexplorer or -lightwalletd in the new database
pblocktree->WriteFlag("insightexplorer", fExperimentalInsightExplorer); pblocktree->WriteFlag("insightexplorer", fExperimentalInsightExplorer);
fAddressIndex = fExperimentalInsightExplorer; pblocktree->WriteFlag("lightwalletd", fExperimentalLightWalletd);
fSpentIndex = fExperimentalInsightExplorer; if (fExperimentalInsightExplorer) {
fTimestampIndex = fExperimentalInsightExplorer; fAddressIndex = true;
fSpentIndex = true;
fTimestampIndex = true;
}
else if (fExperimentalLightWalletd) {
fAddressIndex = true;
}
LogPrintf("Initializing databases...\n"); LogPrintf("Initializing databases...\n");

View File

@ -408,8 +408,8 @@ UniValue getrawmempool(const UniValue& params, bool fHelp)
UniValue getblockdeltas(const UniValue& params, bool fHelp) UniValue getblockdeltas(const UniValue& params, bool fHelp)
{ {
std::string disabledMsg = ""; std::string disabledMsg = "";
if (!fExperimentalInsightExplorer) { if (!(fExperimentalInsightExplorer || fExperimentalLightWalletd)) {
disabledMsg = experimentalDisabledHelpMsg("getblockdeltas", "insightexplorer"); disabledMsg = experimentalDisabledHelpMsg("getblockdeltas", {"insightexplorer", "lightwalletd"});
} }
if (fHelp || params.size() != 1) if (fHelp || params.size() != 1)
throw runtime_error( throw runtime_error(
@ -462,7 +462,7 @@ UniValue getblockdeltas(const UniValue& params, bool fHelp)
+ HelpExampleRpc("getblockdeltas", "\"00227e566682aebd6a7a5b772c96d7a999cadaebeaf1ce96f4191a3aad58b00b\"") + HelpExampleRpc("getblockdeltas", "\"00227e566682aebd6a7a5b772c96d7a999cadaebeaf1ce96f4191a3aad58b00b\"")
); );
if (!fExperimentalInsightExplorer) { if (!(fExperimentalInsightExplorer || fExperimentalLightWalletd)) {
throw JSONRPCError(RPC_MISC_ERROR, "Error: getblockdeltas is disabled. " throw JSONRPCError(RPC_MISC_ERROR, "Error: getblockdeltas is disabled. "
"Run './zcash-cli help getblockdeltas' for instructions on how to enable this feature."); "Run './zcash-cli help getblockdeltas' for instructions on how to enable this feature.");
} }
@ -491,8 +491,8 @@ UniValue getblockdeltas(const UniValue& params, bool fHelp)
UniValue getblockhashes(const UniValue& params, bool fHelp) UniValue getblockhashes(const UniValue& params, bool fHelp)
{ {
std::string disabledMsg = ""; std::string disabledMsg = "";
if (!fExperimentalInsightExplorer) { if (!(fExperimentalInsightExplorer || fExperimentalLightWalletd)) {
disabledMsg = experimentalDisabledHelpMsg("getblockhashes", "insightexplorer"); disabledMsg = experimentalDisabledHelpMsg("getblockhashes", {"insightexplorer", "lightwalletd"});
} }
if (fHelp || params.size() < 2) if (fHelp || params.size() < 2)
throw runtime_error( throw runtime_error(
@ -525,7 +525,7 @@ UniValue getblockhashes(const UniValue& params, bool fHelp)
+ HelpExampleCli("getblockhashes", "1558141697 1558141576 '{\"noOrphans\":false, \"logicalTimes\":true}'") + HelpExampleCli("getblockhashes", "1558141697 1558141576 '{\"noOrphans\":false, \"logicalTimes\":true}'")
); );
if (!fExperimentalInsightExplorer) { if (!(fExperimentalInsightExplorer || fExperimentalLightWalletd)) {
throw JSONRPCError(RPC_MISC_ERROR, "Error: getblockhashes is disabled. " throw JSONRPCError(RPC_MISC_ERROR, "Error: getblockhashes is disabled. "
"Run './zcash-cli help getblockhashes' for instructions on how to enable this feature."); "Run './zcash-cli help getblockhashes' for instructions on how to enable this feature.");
} }

View File

@ -576,8 +576,8 @@ static bool getAddressesFromParams(
UniValue getaddressmempool(const UniValue& params, bool fHelp) UniValue getaddressmempool(const UniValue& params, bool fHelp)
{ {
std::string disabledMsg = ""; std::string disabledMsg = "";
if (!fExperimentalInsightExplorer) { if (!(fExperimentalInsightExplorer || fExperimentalLightWalletd)) {
disabledMsg = experimentalDisabledHelpMsg("getaddressmempool", "insightexplorer"); disabledMsg = experimentalDisabledHelpMsg("getaddressmempool", {"insightexplorer", "lightwalletd"});
} }
if (fHelp || params.size() != 1) if (fHelp || params.size() != 1)
throw runtime_error( throw runtime_error(
@ -611,7 +611,7 @@ UniValue getaddressmempool(const UniValue& params, bool fHelp)
+ HelpExampleRpc("getaddressmempool", "{\"addresses\": [\"tmYXBYJj1K7vhejSec5osXK2QsGa5MTisUQ\"]}") + HelpExampleRpc("getaddressmempool", "{\"addresses\": [\"tmYXBYJj1K7vhejSec5osXK2QsGa5MTisUQ\"]}")
); );
if (!fExperimentalInsightExplorer) { if (!(fExperimentalInsightExplorer || fExperimentalLightWalletd)) {
throw JSONRPCError(RPC_MISC_ERROR, "Error: getaddressmempool is disabled. " throw JSONRPCError(RPC_MISC_ERROR, "Error: getaddressmempool is disabled. "
"Run './zcash-cli help getaddressmempool' for instructions on how to enable this feature."); "Run './zcash-cli help getaddressmempool' for instructions on how to enable this feature.");
} }
@ -656,7 +656,7 @@ UniValue getaddressutxos(const UniValue& params, bool fHelp)
{ {
std::string disabledMsg = ""; std::string disabledMsg = "";
if (!fExperimentalInsightExplorer) { if (!fExperimentalInsightExplorer) {
disabledMsg = experimentalDisabledHelpMsg("getaddressutxos", "insightexplorer"); disabledMsg = experimentalDisabledHelpMsg("getaddressutxos", {"insightexplorer"});
} }
if (fHelp || params.size() != 1) if (fHelp || params.size() != 1)
throw runtime_error( throw runtime_error(
@ -812,8 +812,8 @@ static void getAddressesInHeightRange(
UniValue getaddressdeltas(const UniValue& params, bool fHelp) UniValue getaddressdeltas(const UniValue& params, bool fHelp)
{ {
std::string disabledMsg = ""; std::string disabledMsg = "";
if (!fExperimentalInsightExplorer) { if (!(fExperimentalInsightExplorer || fExperimentalLightWalletd)) {
disabledMsg = experimentalDisabledHelpMsg("getaddressdeltas", "insightexplorer"); disabledMsg = experimentalDisabledHelpMsg("getaddressdeltas", {"insightexplorer", "lightwalletd"});
} }
if (fHelp || params.size() != 1) if (fHelp || params.size() != 1)
throw runtime_error( throw runtime_error(
@ -873,7 +873,7 @@ UniValue getaddressdeltas(const UniValue& params, bool fHelp)
+ HelpExampleRpc("getaddressdeltas", "{\"addresses\": [\"tmYXBYJj1K7vhejSec5osXK2QsGa5MTisUQ\"], \"start\": 1000, \"end\": 2000, \"chainInfo\": true}") + HelpExampleRpc("getaddressdeltas", "{\"addresses\": [\"tmYXBYJj1K7vhejSec5osXK2QsGa5MTisUQ\"], \"start\": 1000, \"end\": 2000, \"chainInfo\": true}")
); );
if (!fExperimentalInsightExplorer) { if (!(fExperimentalInsightExplorer || fExperimentalLightWalletd)) {
throw JSONRPCError(RPC_MISC_ERROR, "Error: getaddressdeltas is disabled. " throw JSONRPCError(RPC_MISC_ERROR, "Error: getaddressdeltas is disabled. "
"Run './zcash-cli help getaddressdeltas' for instructions on how to enable this feature."); "Run './zcash-cli help getaddressdeltas' for instructions on how to enable this feature.");
} }
@ -941,8 +941,8 @@ UniValue getaddressdeltas(const UniValue& params, bool fHelp)
UniValue getaddressbalance(const UniValue& params, bool fHelp) UniValue getaddressbalance(const UniValue& params, bool fHelp)
{ {
std::string disabledMsg = ""; std::string disabledMsg = "";
if (!fExperimentalInsightExplorer) { if (!(fExperimentalInsightExplorer || fExperimentalLightWalletd)) {
disabledMsg = experimentalDisabledHelpMsg("getaddressbalance", "insightexplorer"); disabledMsg = experimentalDisabledHelpMsg("getaddressbalance", {"insightexplorer", "lightwalletd"});
} }
if (fHelp || params.size() != 1) if (fHelp || params.size() != 1)
throw runtime_error( throw runtime_error(
@ -969,7 +969,7 @@ UniValue getaddressbalance(const UniValue& params, bool fHelp)
+ HelpExampleRpc("getaddressbalance", "{\"addresses\": [\"tmYXBYJj1K7vhejSec5osXK2QsGa5MTisUQ\"]}") + HelpExampleRpc("getaddressbalance", "{\"addresses\": [\"tmYXBYJj1K7vhejSec5osXK2QsGa5MTisUQ\"]}")
); );
if (!fExperimentalInsightExplorer) { if (!(fExperimentalInsightExplorer || fExperimentalLightWalletd)) {
throw JSONRPCError(RPC_MISC_ERROR, "Error: getaddressbalance is disabled. " throw JSONRPCError(RPC_MISC_ERROR, "Error: getaddressbalance is disabled. "
"Run './zcash-cli help getaddressbalance' for instructions on how to enable this feature."); "Run './zcash-cli help getaddressbalance' for instructions on how to enable this feature.");
} }
@ -998,8 +998,8 @@ UniValue getaddressbalance(const UniValue& params, bool fHelp)
UniValue getaddresstxids(const UniValue& params, bool fHelp) UniValue getaddresstxids(const UniValue& params, bool fHelp)
{ {
std::string disabledMsg = ""; std::string disabledMsg = "";
if (!fExperimentalInsightExplorer) { if (!(fExperimentalInsightExplorer || fExperimentalLightWalletd)) {
disabledMsg = experimentalDisabledHelpMsg("getaddresstxids", "insightexplorer"); disabledMsg = experimentalDisabledHelpMsg("getaddresstxids", {"insightexplorer", "lightwalletd"});
} }
if (fHelp || params.size() != 1) if (fHelp || params.size() != 1)
throw runtime_error( throw runtime_error(
@ -1029,7 +1029,7 @@ UniValue getaddresstxids(const UniValue& params, bool fHelp)
+ HelpExampleRpc("getaddresstxids", "{\"addresses\": [\"tmYXBYJj1K7vhejSec5osXK2QsGa5MTisUQ\"], \"start\": 1000, \"end\": 2000}") + HelpExampleRpc("getaddresstxids", "{\"addresses\": [\"tmYXBYJj1K7vhejSec5osXK2QsGa5MTisUQ\"], \"start\": 1000, \"end\": 2000}")
); );
if (!fExperimentalInsightExplorer) { if (!(fExperimentalInsightExplorer || fExperimentalLightWalletd)) {
throw JSONRPCError(RPC_MISC_ERROR, "Error: getaddresstxids is disabled. " throw JSONRPCError(RPC_MISC_ERROR, "Error: getaddresstxids is disabled. "
"Run './zcash-cli help getaddresstxids' for instructions on how to enable this feature."); "Run './zcash-cli help getaddresstxids' for instructions on how to enable this feature.");
} }
@ -1064,7 +1064,7 @@ UniValue getspentinfo(const UniValue& params, bool fHelp)
{ {
std::string disabledMsg = ""; std::string disabledMsg = "";
if (!fExperimentalInsightExplorer) { if (!fExperimentalInsightExplorer) {
disabledMsg = experimentalDisabledHelpMsg("getspentinfo", "insightexplorer"); disabledMsg = experimentalDisabledHelpMsg("getspentinfo", {"insightexplorer"});
} }
if (fHelp || params.size() != 1 || !params[0].isObject()) if (fHelp || params.size() != 1 || !params[0].isObject())
throw runtime_error( throw runtime_error(

View File

@ -467,14 +467,32 @@ std::string HelpExampleRpc(const std::string& methodname, const std::string& arg
"\"method\": \"" + methodname + "\", \"params\": [" + args + "] }' -H 'content-type: text/plain;' http://127.0.0.1:8232/\n"; "\"method\": \"" + methodname + "\", \"params\": [" + args + "] }' -H 'content-type: text/plain;' http://127.0.0.1:8232/\n";
} }
string experimentalDisabledHelpMsg(const string& rpc, const string& enableArg) std::string experimentalDisabledHelpMsg(const std::string& rpc, const std::vector<string>& enableArgs)
{ {
return "\nWARNING: " + rpc + " is disabled.\n" std::string cmd, config = "";
"To enable it, restart zcashd with the -experimentalfeatures and\n" const auto size = enableArgs.size();
"-" + enableArg + " commandline options, or add these two lines\n" assert(size > 0);
"to the zcash.conf file:\n\n"
"experimentalfeatures=1\n" for (size_t i = 0; i < size; ++i)
+ enableArg + "=1\n"; {
if (size == 1 || i == 0)
{
cmd += "-experimentalfeatures and -" + enableArgs.at(i);
config += "experimentalfeatures=1\n";
config += enableArgs.at(i) + "=1\n";
}
else {
cmd += " or:\n-experimentalfeatures and -" + enableArgs.at(i);
config += "\nor:\n\n";
config += "experimentalfeatures=1\n";
config += enableArgs.at(i) + "=1\n";
}
}
return "\nWARNING: " + rpc + " is disabled.\n" +
"To enable it, restart zcashd with the following command line options:\n"
+ cmd + "\n\n" +
"Alternatively add these two lines to the zcash.conf file:\n\n"
+ config;
} }
void RPCRegisterTimerInterface(RPCTimerInterface *iface) void RPCRegisterTimerInterface(RPCTimerInterface *iface)

View File

@ -183,6 +183,6 @@ void InterruptRPC();
void StopRPC(); void StopRPC();
std::string JSONRPCExecBatch(const UniValue& vReq); std::string JSONRPCExecBatch(const UniValue& vReq);
extern std::string experimentalDisabledHelpMsg(const std::string& rpc, const std::string& enableArg); extern std::string experimentalDisabledHelpMsg(const std::string& rpc, const std::vector<std::string>& enableArgs);
#endif // BITCOIN_RPCSERVER_H #endif // BITCOIN_RPCSERVER_H

View File

@ -43,7 +43,7 @@ UniValue z_getpaymentdisclosure(const UniValue& params, bool fHelp)
string disabledMsg = ""; string disabledMsg = "";
if (!fExperimentalPaymentDisclosure) { if (!fExperimentalPaymentDisclosure) {
disabledMsg = experimentalDisabledHelpMsg("z_getpaymentdisclosure", "paymentdisclosure"); disabledMsg = experimentalDisabledHelpMsg("z_getpaymentdisclosure", {"paymentdisclosure"});
} }
if (fHelp || params.size() < 3 || params.size() > 4 ) if (fHelp || params.size() < 3 || params.size() > 4 )
@ -148,7 +148,7 @@ UniValue z_validatepaymentdisclosure(const UniValue& params, bool fHelp)
string disabledMsg = ""; string disabledMsg = "";
if (!fExperimentalPaymentDisclosure) { if (!fExperimentalPaymentDisclosure) {
disabledMsg = experimentalDisabledHelpMsg("z_validatepaymentdisclosure", "paymentdisclosure"); disabledMsg = experimentalDisabledHelpMsg("z_validatepaymentdisclosure", {"paymentdisclosure"});
} }
if (fHelp || params.size() != 1) if (fHelp || params.size() != 1)

View File

@ -2041,7 +2041,7 @@ UniValue encryptwallet(const UniValue& params, bool fHelp)
std::string disabledMsg = ""; std::string disabledMsg = "";
if (!fExperimentalDeveloperEncryptWallet) { if (!fExperimentalDeveloperEncryptWallet) {
disabledMsg = experimentalDisabledHelpMsg("encryptwallet", "developerencryptwallet"); disabledMsg = experimentalDisabledHelpMsg("encryptwallet", {"developerencryptwallet"});
} }
if (!pwalletMain->IsCrypted() && (fHelp || params.size() != 1)) if (!pwalletMain->IsCrypted() && (fHelp || params.size() != 1))