Skip to content

Commit ec19ba1

Browse files
authored
Merge pull request #3602 from jkczyz/2025-02-unset-funding-info
Fix debug panic in `full_stack` fuzz test
2 parents 1613f87 + 9164f7e commit ec19ba1

File tree

2 files changed

+10
-32
lines changed

2 files changed

+10
-32
lines changed

lightning/src/ln/channel.rs

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,13 +1393,16 @@ impl<SP: Deref> Channel<SP> where
13931393
{
13941394
let phase = core::mem::replace(&mut self.phase, ChannelPhase::Undefined);
13951395
let result = if let ChannelPhase::UnfundedOutboundV1(chan) = phase {
1396+
let channel_state = chan.context.channel_state;
13961397
let logger = WithChannelContext::from(logger, &chan.context, None);
13971398
match chan.funding_signed(msg, best_block, signer_provider, &&logger) {
13981399
Ok((chan, monitor)) => {
1400+
debug_assert!(matches!(chan.context.channel_state, ChannelState::AwaitingChannelReady(_)));
13991401
self.phase = ChannelPhase::Funded(chan);
14001402
Ok(monitor)
14011403
},
14021404
Err((chan, e)) => {
1405+
debug_assert_eq!(chan.context.channel_state, channel_state);
14031406
self.phase = ChannelPhase::UnfundedOutboundV1(chan);
14041407
Err(e)
14051408
},
@@ -1413,29 +1416,6 @@ impl<SP: Deref> Channel<SP> where
14131416
result.map(|monitor| (self.as_funded_mut().expect("Channel should be funded"), monitor))
14141417
}
14151418

1416-
pub fn unset_funding_info(&mut self) {
1417-
let phase = core::mem::replace(&mut self.phase, ChannelPhase::Undefined);
1418-
if let ChannelPhase::Funded(mut funded_chan) = phase {
1419-
funded_chan.unset_funding_info();
1420-
1421-
let context = funded_chan.context;
1422-
let unfunded_context = UnfundedChannelContext {
1423-
unfunded_channel_age_ticks: 0,
1424-
holder_commitment_point: HolderCommitmentPoint::new(&context.holder_signer, &context.secp_ctx),
1425-
};
1426-
let unfunded_chan = OutboundV1Channel {
1427-
context,
1428-
unfunded_context,
1429-
signer_pending_open_channel: false,
1430-
};
1431-
self.phase = ChannelPhase::UnfundedOutboundV1(unfunded_chan);
1432-
} else {
1433-
self.phase = phase;
1434-
};
1435-
1436-
debug_assert!(!matches!(self.phase, ChannelPhase::Undefined));
1437-
}
1438-
14391419
pub fn funding_tx_constructed<L: Deref>(
14401420
&mut self, signing_session: InteractiveTxSigningSession, logger: &L
14411421
) -> Result<(msgs::CommitmentSigned, Option<Event>), ChannelError>

lightning/src/ln/channelmanager.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8288,24 +8288,22 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
82888288
.and_then(|(funded_chan, monitor)| {
82898289
self.chain_monitor
82908290
.watch_channel(funded_chan.context.channel_id(), monitor)
8291-
.map(|persist_status| (funded_chan, persist_status))
82928291
.map_err(|()| {
8292+
// We weren't able to watch the channel to begin with, so no
8293+
// updates should be made on it. Previously, full_stack_target
8294+
// found an (unreachable) panic when the monitor update contained
8295+
// within `shutdown_finish` was applied.
8296+
funded_chan.unset_funding_info();
82938297
ChannelError::close("Channel ID was a duplicate".to_owned())
82948298
})
8299+
.map(|persist_status| (funded_chan, persist_status))
82958300
})
82968301
{
82978302
Ok((funded_chan, persist_status)) => {
82988303
handle_new_monitor_update!(self, persist_status, peer_state_lock, peer_state, per_peer_state, funded_chan, INITIAL_MONITOR);
82998304
Ok(())
83008305
},
8301-
Err(e) => {
8302-
// We weren't able to watch the channel to begin with, so no
8303-
// updates should be made on it. Previously, full_stack_target
8304-
// found an (unreachable) panic when the monitor update contained
8305-
// within `shutdown_finish` was applied.
8306-
chan.unset_funding_info();
8307-
try_channel_entry!(self, peer_state, Err(e), chan_entry)
8308-
},
8306+
Err(e) => try_channel_entry!(self, peer_state, Err(e), chan_entry),
83098307
}
83108308
},
83118309
hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel".to_owned(), msg.channel_id))

0 commit comments

Comments
 (0)