Skip to content

Commit ac68fcc

Browse files
committed
rpc: disallow undefined verbosity in getorphantxs
1 parent 25dacae commit ac68fcc

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/rpc/mempool.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -891,21 +891,22 @@ static RPCHelpMan getorphantxs()
891891

892892
UniValue ret(UniValue::VARR);
893893

894-
if (verbosity <= 0) {
894+
if (verbosity == 0) {
895895
for (auto const& orphan : orphanage) {
896896
ret.push_back(orphan.tx->GetHash().ToString());
897897
}
898898
} else if (verbosity == 1) {
899899
for (auto const& orphan : orphanage) {
900900
ret.push_back(OrphanToJSON(orphan));
901901
}
902-
} else {
903-
// >= 2
902+
} else if (verbosity == 2) {
904903
for (auto const& orphan : orphanage) {
905904
UniValue o{OrphanToJSON(orphan)};
906905
o.pushKV("hex", EncodeHexTx(*orphan.tx));
907906
ret.push_back(o);
908907
}
908+
} else {
909+
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid verbosity value " + ToString(verbosity));
909910
}
910911

911912
return ret;

test/functional/rpc_getorphantxs.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
from test_framework.mempool_util import tx_in_orphanage
88
from test_framework.messages import msg_tx
99
from test_framework.p2p import P2PInterface
10-
from test_framework.util import assert_equal
10+
from test_framework.util import (
11+
assert_equal,
12+
assert_raises_rpc_error,
13+
)
1114
from test_framework.test_framework import BitcoinTestFramework
1215
from test_framework.wallet import MiniWallet
1316

@@ -37,13 +40,13 @@ def test_orphan_activity(self):
3740
self.log.info("Check that neither parent is in the mempool")
3841
assert_equal(node.getmempoolinfo()["size"], 0)
3942

40-
self.log.info("Check that both children are in the orphanage")
41-
4243
orphanage = node.getorphantxs(verbosity=0)
4344
self.log.info("Check the size of the orphanage")
4445
assert_equal(len(orphanage), 2)
45-
self.log.info("Check that negative verbosity is treated as 0")
46-
assert_equal(orphanage, node.getorphantxs(verbosity=-1))
46+
self.log.info("Check that undefined verbosity is disallowed")
47+
assert_raises_rpc_error(-8, "Invalid verbosity value -1", node.getorphantxs, verbosity=-1)
48+
assert_raises_rpc_error(-8, "Invalid verbosity value 3", node.getorphantxs, verbosity=3)
49+
self.log.info("Check that both children are in the orphanage")
4750
assert tx_in_orphanage(node, tx_child_1["tx"])
4851
assert tx_in_orphanage(node, tx_child_2["tx"])
4952

0 commit comments

Comments
 (0)