0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-02 09:46:52 -05:00

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.
This commit is contained in:
kouloumos 2022-09-06 20:52:41 +03:00
parent 718304d222
commit cc434cbf58
2 changed files with 22 additions and 0 deletions

View file

@ -1414,6 +1414,11 @@ RPCHelpMan sendall()
}
}
// If this transaction is too large, e.g. because the wallet has many UTXOs, it will be rejected by the node's mempool.
if (tx_size.weight > MAX_STANDARD_TX_WEIGHT) {
throw JSONRPCError(RPC_WALLET_ERROR, "Transaction too large.");
}
CAmount output_amounts_claimed{0};
for (const CTxOut& out : rawTx.vout) {
output_amounts_claimed += out.nValue;

View file

@ -276,6 +276,20 @@ class SendallTest(BitcoinTestFramework):
recipients=[self.remainder_target],
fee_rate=100000)
# This tests needs to be the last one otherwise @cleanup will fail with "Transaction too large" error
def sendall_fails_with_transaction_too_large(self):
self.log.info("Test that sendall fails if resulting transaction is too large")
# create many inputs
outputs = {self.wallet.getnewaddress(): 0.000025 for _ in range(1600)}
self.def_wallet.sendmany(amounts=outputs)
self.generate(self.nodes[0], 1)
assert_raises_rpc_error(
-4,
"Transaction too large.",
self.wallet.sendall,
recipients=[self.remainder_target])
def run_test(self):
self.nodes[0].createwallet("activewallet")
self.wallet = self.nodes[0].get_wallet_rpc("activewallet")
@ -327,5 +341,8 @@ class SendallTest(BitcoinTestFramework):
# Sendall fails when providing a fee that is too high
self.sendall_fails_on_high_fee()
# Sendall fails when many inputs result to too large transaction
self.sendall_fails_with_transaction_too_large()
if __name__ == '__main__':
SendallTest().main()