Skip to content

Commit e93aa01

Browse files
committed
Fix debug panic in full_stack fuzz test
d4bd56f changed the logic for calling unset_funding_info such that it may be called on a channel that was already in ChannelPhase::Funded when handling funding_signed. This caused a debug panic in the full_stack fuzz test when calling FundedChannel::unset_funding_info. Fix this by only calling unset_funding_info on watch_channel error, as was previously the case. This also reverts moving the channel back into ChannelPhase::UnfundedOutboundV1, which should be fine since the channel is about to be removed.
1 parent 11d12d1 commit e93aa01

File tree

2 files changed

+7
-32
lines changed

2 files changed

+7
-32
lines changed

lightning/src/ln/channel.rs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,29 +1412,6 @@ impl<SP: Deref> Channel<SP> where
14121412
result.map(|monitor| (self.as_funded_mut().expect("Channel should be funded"), monitor))
14131413
}
14141414

1415-
pub fn unset_funding_info(&mut self) {
1416-
let phase = core::mem::replace(&mut self.phase, ChannelPhase::Undefined);
1417-
if let ChannelPhase::Funded(mut funded_chan) = phase {
1418-
funded_chan.unset_funding_info();
1419-
1420-
let context = funded_chan.context;
1421-
let unfunded_context = UnfundedChannelContext {
1422-
unfunded_channel_age_ticks: 0,
1423-
holder_commitment_point: HolderCommitmentPoint::new(&context.holder_signer, &context.secp_ctx),
1424-
};
1425-
let unfunded_chan = OutboundV1Channel {
1426-
context,
1427-
unfunded_context,
1428-
signer_pending_open_channel: false,
1429-
};
1430-
self.phase = ChannelPhase::UnfundedOutboundV1(unfunded_chan);
1431-
} else {
1432-
self.phase = phase;
1433-
};
1434-
1435-
debug_assert!(!matches!(self.phase, ChannelPhase::Undefined));
1436-
}
1437-
14381415
pub fn funding_tx_constructed<L: Deref>(
14391416
&mut self, signing_session: InteractiveTxSigningSession, logger: &L
14401417
) -> 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
@@ -8241,24 +8241,22 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
82418241
.and_then(|(funded_chan, monitor)| {
82428242
self.chain_monitor
82438243
.watch_channel(funded_chan.context.channel_id(), monitor)
8244-
.map(|persist_status| (funded_chan, persist_status))
82458244
.map_err(|()| {
8245+
// We weren't able to watch the channel to begin with, so no
8246+
// updates should be made on it. Previously, full_stack_target
8247+
// found an (unreachable) panic when the monitor update contained
8248+
// within `shutdown_finish` was applied.
8249+
funded_chan.unset_funding_info();
82468250
ChannelError::close("Channel ID was a duplicate".to_owned())
82478251
})
8252+
.map(|persist_status| (funded_chan, persist_status))
82488253
})
82498254
{
82508255
Ok((funded_chan, persist_status)) => {
82518256
handle_new_monitor_update!(self, persist_status, peer_state_lock, peer_state, per_peer_state, funded_chan, INITIAL_MONITOR);
82528257
Ok(())
82538258
},
8254-
Err(e) => {
8255-
// We weren't able to watch the channel to begin with, so no
8256-
// updates should be made on it. Previously, full_stack_target
8257-
// found an (unreachable) panic when the monitor update contained
8258-
// within `shutdown_finish` was applied.
8259-
chan.unset_funding_info();
8260-
try_channel_entry!(self, peer_state, Err(e), chan_entry)
8261-
},
8259+
Err(e) => try_channel_entry!(self, peer_state, Err(e), chan_entry),
82628260
}
82638261
},
82648262
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)