Skip to content

Commit 4300325

Browse files
committed
Merge bitcoin/bitcoin#29292: rpc: improve submitpackage documentation and other improvements
78e52f6 doc: rpc: fix submitpackage examples (stickies-v) 1a875d4 rpc: update min package size error message in submitpackage (stickies-v) f9ece25 doc: rpc: submitpackage takes sorted array (stickies-v) 17f7451 test: add bounds checking for submitpackage RPC (stickies-v) Pull request description: `submitpackage` requires the package to be topologically sorted with the child being the last element in the array, but this is not documented in the RPC method or the error messages. Also sneaking in some other minor improvements that I found while going through the code: - Informing the user that `package` needs to be an array of length between `1` and `MAX_PACKAGE_COUNT` is confusing when `IsChildWithPackage()` requires that the package size >= 2. Remove this check to avoid code duplication and sending a confusing error message. - fixups to the `submitpackage` examples ACKs for top commit: fjahr: re-ACK 78e52f6 instagibbs: ACK bitcoin/bitcoin@78e52f6 achow101: ACK 78e52f6 glozow: utACK 78e52f6 Tree-SHA512: a8845621bb1cbf784167fc7c82cb8ceb105868b65b26d3465f072d1c04ef3699e85a21a524ade805d423bcecbc34f7d5bff12f2c21cbd902ae1fb154193ebdc9
2 parents 8a45f57 + 78e52f6 commit 4300325

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/rpc/mempool.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -813,13 +813,14 @@ static RPCHelpMan submitpackage()
813813
{
814814
return RPCHelpMan{"submitpackage",
815815
"Submit a package of raw transactions (serialized, hex-encoded) to local node.\n"
816-
"The package must consist of a child with its parents, and none of the parents may depend on one another.\n"
817816
"The package will be validated according to consensus and mempool policy rules. If any transaction passes, it will be accepted to mempool.\n"
818817
"This RPC is experimental and the interface may be unstable. Refer to doc/policy/packages.md for documentation on package policies.\n"
819818
"Warning: successful submission does not mean the transactions will propagate throughout the network.\n"
820819
,
821820
{
822-
{"package", RPCArg::Type::ARR, RPCArg::Optional::NO, "An array of raw transactions.",
821+
{"package", RPCArg::Type::ARR, RPCArg::Optional::NO, "An array of raw transactions.\n"
822+
"The package must solely consist of a child and its parents. None of the parents may depend on each other.\n"
823+
"The package must be topologically sorted, with the child being the last element in the array.",
823824
{
824825
{"rawtx", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED, ""},
825826
},
@@ -860,15 +861,15 @@ static RPCHelpMan submitpackage()
860861
},
861862
},
862863
RPCExamples{
863-
HelpExampleCli("testmempoolaccept", "[rawtx1, rawtx2]") +
864-
HelpExampleCli("submitpackage", "[rawtx1, rawtx2]")
864+
HelpExampleRpc("submitpackage", R"(["rawtx1", "rawtx2"])") +
865+
HelpExampleCli("submitpackage", R"('["rawtx1", "rawtx2"]')")
865866
},
866867
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
867868
{
868869
const UniValue raw_transactions = request.params[0].get_array();
869-
if (raw_transactions.size() < 1 || raw_transactions.size() > MAX_PACKAGE_COUNT) {
870+
if (raw_transactions.size() < 2 || raw_transactions.size() > MAX_PACKAGE_COUNT) {
870871
throw JSONRPCError(RPC_INVALID_PARAMETER,
871-
"Array must contain between 1 and " + ToString(MAX_PACKAGE_COUNT) + " transactions.");
872+
"Array must contain between 2 and " + ToString(MAX_PACKAGE_COUNT) + " transactions.");
872873
}
873874

874875
// Fee check needs to be run with chainstate and package context

test/functional/rpc_packages.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
)
2727

2828

29+
MAX_PACKAGE_COUNT = 25
30+
31+
2932
class RPCPackagesTest(BitcoinTestFramework):
3033
def set_test_params(self):
3134
self.num_nodes = 1
@@ -344,6 +347,13 @@ def test_submitpackage(self):
344347
assert_raises_rpc_error(-25, "package topology disallowed", node.submitpackage, chain_hex)
345348
assert_equal(legacy_pool, node.getrawmempool())
346349

350+
assert_raises_rpc_error(-8, f"Array must contain between 2 and {MAX_PACKAGE_COUNT} transactions.", node.submitpackage, [])
351+
assert_raises_rpc_error(-8, f"Array must contain between 2 and {MAX_PACKAGE_COUNT} transactions.", node.submitpackage, [chain_hex[0]] * 1)
352+
assert_raises_rpc_error(
353+
-8, f"Array must contain between 2 and {MAX_PACKAGE_COUNT} transactions.",
354+
node.submitpackage, [chain_hex[0]] * (MAX_PACKAGE_COUNT + 1)
355+
)
356+
347357
# Create a transaction chain such as only the parent gets accepted (by making the child's
348358
# version non-standard). Make sure the parent does get broadcast.
349359
self.log.info("If a package is partially submitted, transactions included in mempool get broadcast")

0 commit comments

Comments
 (0)