Skip to content

Commit f889222

Browse files
authored
Merge pull request #4015 from TheBlueMatt/2025-08-fst-funding
Fix panic when calling `batch_funding_transaction_generated` early
2 parents 9724d19 + c1fefcf commit f889222

File tree

7 files changed

+2648
-2571
lines changed

7 files changed

+2648
-2571
lines changed

fuzz/src/full_stack.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -857,21 +857,15 @@ pub fn do_test(mut data: &[u8], logger: &Arc<dyn Logger>) {
857857
}
858858
if tx.version.0 <= 0xff && !channels.is_empty() {
859859
let chans = channels.iter().map(|(a, b)| (a, b)).collect::<Vec<_>>();
860-
if let Err(e) =
861-
channelmanager.batch_funding_transaction_generated(&chans, tx.clone())
862-
{
863-
// It's possible the channel has been closed in the mean time, but any other
864-
// failure may be a bug.
865-
if let APIError::ChannelUnavailable { .. } = e {
866-
} else {
867-
panic!();
860+
let res =
861+
channelmanager.batch_funding_transaction_generated(&chans, tx.clone());
862+
if res.is_ok() {
863+
let funding_txid = tx.compute_txid();
864+
for idx in 0..tx.output.len() {
865+
let outpoint = OutPoint { txid: funding_txid, index: idx as u16 };
866+
pending_funding_signatures.insert(outpoint, tx.clone());
868867
}
869868
}
870-
let funding_txid = tx.compute_txid();
871-
for idx in 0..tx.output.len() {
872-
let outpoint = OutPoint { txid: funding_txid, index: idx as u16 };
873-
pending_funding_signatures.insert(outpoint, tx.clone());
874-
}
875869
}
876870
},
877871
11 => {

lightning/src/ln/channel.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1551,6 +1551,22 @@ where
15511551
)
15521552
}
15531553

1554+
/// Returns true if this channel is waiting on a (batch) funding transaction to be provided.
1555+
///
1556+
/// If this method returns true, [`Self::into_unfunded_outbound_v1`] will also succeed.
1557+
pub fn ready_to_fund(&self) -> bool {
1558+
if !self.funding().is_outbound() {
1559+
return false;
1560+
}
1561+
match self.context().channel_state {
1562+
ChannelState::NegotiatingFunding(flags) => {
1563+
debug_assert!(matches!(self.phase, ChannelPhase::UnfundedOutboundV1(_)));
1564+
flags.is_our_init_sent() && flags.is_their_init_sent()
1565+
},
1566+
_ => false,
1567+
}
1568+
}
1569+
15541570
pub fn into_unfunded_outbound_v1(self) -> Result<OutboundV1Channel<SP>, Self> {
15551571
if let ChannelPhase::UnfundedOutboundV1(channel) = self.phase {
15561572
Ok(channel)

0 commit comments

Comments
 (0)