Skip to content

Commit a595011

Browse files
committed
Merge bitcoin#17728: rpc: require second argument only for scantxoutset start action
7d26357 rpc: require second argument only for scantxoutset start action (Andrew Chow) Pull request description: It was reported on [IRC](http://www.erisian.com.au/bitcoin-core-dev/log-2019-12-11.html#l-377) that `scantxoutset`'s API was broken in 0.19.0: ``` <belcher> i think scantxoutset may have been broken in bitcoin core 0.19 ? regardless of what parameters i run it with (e.g. "scantxoutset abort", "scantxoutset status") it just returns the help doc, according to the release notes the only change was https://github.com/bitcoin/bitcoin/pull/16285/files but i dont see anything that wouldve broken it, it works fine in 0.18 <belcher> im on regtest, in case its important <harding> I can confirm `scantxoutset abort` returns the help doc on latest master. Waiting for 0.18.1 to start now to attempt to reproduce there. <harding> It looks like it's expecting a second parameter (even though that doesn't make sense with "abort"). <jonatack> Same for me as well <harding> Can also confirm that `scantxoutset abort` returns the expected result on 0.18.1. ``` As noted in the conversation, previously, the second argument of `scanobjects` is only required for the `start` action. `Stop` and `abort` actions did not and could work without them. It appears that this was broken by bitcoin#16240 which enforced the size of the arguments to match the listed required arguments. To fix this issue, this PR makes the `scanobjects` argument an optional argument. Then only in the `start` action do we check whether the `scanobjects` argument is there and throw an informative error about that. Also a test is added for this case. ACKs for top commit: laanwj: ACK 7d26357 promag: ACK 7d26357. Tree-SHA512: 828bdfe47f4fffa5d00a2cf88db6cea4a2714d9c49276841ca5cbdd1603b87bb6862147b86edcf36d7b40314ddb80b1a07fd399faf288572c55cc788c5cf9526
2 parents ddecb67 + 7d26357 commit a595011

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/rpc/blockchain.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -2055,7 +2055,7 @@ UniValue scantxoutset(const JSONRPCRequest& request)
20552055
" \"start\" for starting a scan\n"
20562056
" \"abort\" for aborting the current scan (returns true when abort was successful)\n"
20572057
" \"status\" for progress report (in %) of the current scan"},
2058-
{"scanobjects", RPCArg::Type::ARR, RPCArg::Optional::NO, "Array of scan objects\n"
2058+
{"scanobjects", RPCArg::Type::ARR, RPCArg::Optional::OMITTED, "Array of scan objects. Required for \"start\" action\n"
20592059
" Every scan object is either a string descriptor or an object:",
20602060
{
20612061
{"descriptor", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "An output descriptor"},
@@ -2115,6 +2115,11 @@ UniValue scantxoutset(const JSONRPCRequest& request)
21152115
if (!reserver.reserve()) {
21162116
throw JSONRPCError(RPC_INVALID_PARAMETER, "Scan already in progress, use action \"abort\" or \"status\"");
21172117
}
2118+
2119+
if (request.params.size() < 2) {
2120+
throw JSONRPCError(RPC_MISC_ERROR, "scanobjects argument is required for the start action");
2121+
}
2122+
21182123
std::set<CScript> needles;
21192124
std::map<CScript, std::string> descriptors;
21202125
CAmount total_in = 0;

test/functional/rpc_scantxoutset.py

+7
Original file line numberDiff line numberDiff line change
@@ -116,5 +116,12 @@ def run_test(self):
116116
assert_equal(descriptors(self.nodes[0].scantxoutset("start", [ "combo(tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK/1/1/0)"])), ["pkh([0c5f9a1e/1/1/0]03e1c5b6e650966971d7e71ef2674f80222752740fc1dfd63bbbd220d2da9bd0fb)#cxmct4w8"])
117117
assert_equal(descriptors(self.nodes[0].scantxoutset("start", [ {"desc": "combo(tpubD6NzVbkrYhZ4WaWSyoBvQwbpLkojyoTZPRsgXELWz3Popb3qkjcJyJUGLnL4qHHoQvao8ESaAstxYSnhyswJ76uZPStJRJCTKvosUCJZL5B/1/1/*)", "range": 1500}])), ['pkh([0c5f9a1e/1/1/0]03e1c5b6e650966971d7e71ef2674f80222752740fc1dfd63bbbd220d2da9bd0fb)#cxmct4w8', 'pkh([0c5f9a1e/1/1/1500]03832901c250025da2aebae2bfb38d5c703a57ab66ad477f9c578bfbcd78abca6f)#vchwd07g', 'pkh([0c5f9a1e/1/1/1]030d820fc9e8211c4169be8530efbc632775d8286167afd178caaf1089b77daba7)#z2t3ypsa'])
118118

119+
# Check that status and abort don't need second arg
120+
assert_equal(self.nodes[0].scantxoutset("status"), None)
121+
assert_equal(self.nodes[0].scantxoutset("abort"), False)
122+
123+
# Check that second arg is needed for start
124+
assert_raises_rpc_error(-1, "scanobjects argument is required for the start action", self.nodes[0].scantxoutset, "start")
125+
119126
if __name__ == '__main__':
120127
ScantxoutsetTest().main()

0 commit comments

Comments
 (0)