Skip to content

Commit cc434cb

Browse files
committed
wallet: fix sendall creates tx that fails tx-size check
The `sendall` RPC doesn't use `CreateTransactionInternal`as the rest of the wallet RPCs and it never checks against the tx-size mempool limit. Add a check for tx-size as well as test coverage for that case.
1 parent 718304d commit cc434cb

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/wallet/rpc/spend.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,6 +1414,11 @@ RPCHelpMan sendall()
14141414
}
14151415
}
14161416

1417+
// If this transaction is too large, e.g. because the wallet has many UTXOs, it will be rejected by the node's mempool.
1418+
if (tx_size.weight > MAX_STANDARD_TX_WEIGHT) {
1419+
throw JSONRPCError(RPC_WALLET_ERROR, "Transaction too large.");
1420+
}
1421+
14171422
CAmount output_amounts_claimed{0};
14181423
for (const CTxOut& out : rawTx.vout) {
14191424
output_amounts_claimed += out.nValue;

test/functional/wallet_sendall.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,20 @@ def sendall_fails_on_high_fee(self):
276276
recipients=[self.remainder_target],
277277
fee_rate=100000)
278278

279+
# This tests needs to be the last one otherwise @cleanup will fail with "Transaction too large" error
280+
def sendall_fails_with_transaction_too_large(self):
281+
self.log.info("Test that sendall fails if resulting transaction is too large")
282+
# create many inputs
283+
outputs = {self.wallet.getnewaddress(): 0.000025 for _ in range(1600)}
284+
self.def_wallet.sendmany(amounts=outputs)
285+
self.generate(self.nodes[0], 1)
286+
287+
assert_raises_rpc_error(
288+
-4,
289+
"Transaction too large.",
290+
self.wallet.sendall,
291+
recipients=[self.remainder_target])
292+
279293
def run_test(self):
280294
self.nodes[0].createwallet("activewallet")
281295
self.wallet = self.nodes[0].get_wallet_rpc("activewallet")
@@ -327,5 +341,8 @@ def run_test(self):
327341
# Sendall fails when providing a fee that is too high
328342
self.sendall_fails_on_high_fee()
329343

344+
# Sendall fails when many inputs result to too large transaction
345+
self.sendall_fails_with_transaction_too_large()
346+
330347
if __name__ == '__main__':
331348
SendallTest().main()

0 commit comments

Comments
 (0)