Skip to content

Commit fc7c21f

Browse files
committed
Merge bitcoin/bitcoin#27271: RPC: Fix fund transaction crash when at 0-value, 0-fee
d7cc503 Fix fund transaction case at 0-value, 0-fee (Greg Sanders) Pull request description: and when no inputs are pre-selected. triggered via: walletcreatefundedpsbt '[]' '[{"data": "deadbeef"}]' 0 '{"fee_rate": "0"}' ACKs for top commit: achow101: ACK d7cc503 josibake: ACK bitcoin/bitcoin@d7cc503 furszy: Crashes sucks code ACK d7cc503 Tree-SHA512: 3f5e10875666aaf52c11d6a38b951aa75d0cbe684cc7f904e199f7a864923bf31d03a654687f8b746cae0eebb886a799bff2c6d200699438480d4c0ff8785f3a
2 parents a709114 + d7cc503 commit fc7c21f

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/wallet/spend.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,12 @@ static util::Result<CreatedTransactionResult> CreateTransactionInternal(
917917
const CAmount not_input_fees = coin_selection_params.m_effective_feerate.GetFee(coin_selection_params.m_subtract_fee_outputs ? 0 : coin_selection_params.tx_noinputs_size);
918918
CAmount selection_target = recipients_sum + not_input_fees;
919919

920+
// This can only happen if feerate is 0, and requested destinations are value of 0 (e.g. OP_RETURN)
921+
// and no pre-selected inputs. This will result in 0-input transaction, which is consensus-invalid anyways
922+
if (selection_target == 0 && !coin_control.HasSelected()) {
923+
return util::Error{_("Transaction requires one destination of non-0 value, a non-0 feerate, or a pre-selected input")};
924+
}
925+
920926
// Fetch manually selected coins
921927
PreSelectedInputs preset_inputs;
922928
if (coin_control.HasSelected()) {

test/functional/rpc_psbt.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,9 @@ def test_psbt_input_keys(psbt_input, keys):
941941
assert_equal(self.nodes[0].finalizepsbt(psbt.to_base64()),
942942
{'hex': '0200000001dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd0000000000000000000100000000000000000000000000', 'complete': True})
943943

944+
self.log.info("Test we don't crash when making a 0-value funded transaction at 0 fee without forcing an input selection")
945+
assert_raises_rpc_error(-4, "Transaction requires one destination of non-0 value, a non-0 feerate, or a pre-selected input", self.nodes[0].walletcreatefundedpsbt, [], [{"data": "deadbeef"}], 0, {"fee_rate": "0"})
946+
944947

945948
if __name__ == '__main__':
946949
PSBTTest().main()

0 commit comments

Comments
 (0)