Skip to content

Commit ff00c63

Browse files
committed
Ensure we never try to broadcast a transaction <= 64 bytes
While these are consensus-valid, they have been nonstandard for quite some time and will not relay nor confirm.
1 parent 7e513f9 commit ff00c63

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

lightning/src/events/bump_transaction.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -582,11 +582,25 @@ where
582582
// match, but we still need to have at least one output in the transaction for it to be
583583
// considered standard. We choose to go with an empty OP_RETURN as it is the cheapest
584584
// way to include a dummy output.
585-
log_debug!(self.logger, "Including dummy OP_RETURN output since an output is needed and a change output was not provided");
586-
tx.output.push(TxOut {
587-
value: Amount::ZERO,
588-
script_pubkey: ScriptBuf::new_op_return(&[]),
589-
});
585+
if tx.input.len() <= 1 {
586+
// Transactions have to be at least 65 bytes in non-witness data, which we can run
587+
// under if we have too few witness inputs.
588+
log_debug!(self.logger, "Including large OP_RETURN output since an output is needed and a change output was not provided and the transaction is small");
589+
debug_assert!(!tx.input.is_empty());
590+
tx.output.push(TxOut {
591+
value: Amount::ZERO,
592+
// Minimum transaction size is 60 bytes, so we need a 5-byte script to get a
593+
// 65 byte transaction. We do that as OP_RETURN <3 0 bytes, plus 1 byte len>.
594+
script_pubkey: ScriptBuf::new_op_return(&[0, 0, 0]),
595+
});
596+
debug_assert_eq!(tx.base_size(), 65);
597+
} else {
598+
log_debug!(self.logger, "Including dummy OP_RETURN output since an output is needed and a change output was not provided");
599+
tx.output.push(TxOut {
600+
value: Amount::ZERO,
601+
script_pubkey: ScriptBuf::new_op_return(&[]),
602+
});
603+
}
590604
}
591605
}
592606

0 commit comments

Comments
 (0)