Skip to content

Commit a56876e

Browse files
committed
Merge bitcoin/bitcoin#26024: wallet: fix sendall creates tx that fails tx-size check
cc434cb wallet: fix sendall creates tx that fails tx-size check (kouloumos) Pull request description: Fixes bitcoin/bitcoin#26011 The `sendall` RPC doesn't use `CreateTransactionInternal` as the rest of the wallet RPCs. [This has already been discussed in the original PR](bitcoin/bitcoin#24118 (comment)). By not going through that path, it never checks the transaction's weight against the maximum tx weight for transactions we're willing to relay. https://github.com/bitcoin/bitcoin/blob/447f50e4aed9a8b1d80e1891cda85801aeb80b4e/src/wallet/spend.cpp#L1013-L1018 This PR adds a check for tx-size as well as test coverage for that case. _Note: It seems that the test takes a bit of time on slower machines, I'm not sure if dropping it might be for the better._ ACKs for top commit: glozow: re ACK cc434cb via range-diff. Changes were addressing bitcoin/bitcoin#26024 (comment) and bitcoin/bitcoin#26024 (comment). achow101: ACK cc434cb w0xlt: reACK bitcoin/bitcoin@cc434cb Tree-SHA512: 64a1d8f2c737b39f3ccee90689eda1dd9c1b65f11b2c7bc0ec8bfe72f0202ce90ab4033bb0ecfc6080af8c947575059588a00938fe48e7fd553f7fb5ee03b3cc
2 parents 96f1b2d + cc434cb commit a56876e

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)