Skip to content

Commit 92c6f77

Browse files
committed
f - revert to unfunded state
1 parent 332efd0 commit 92c6f77

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

lightning/src/ln/channel.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,6 +1402,29 @@ impl<SP: Deref> Channel<SP> where
14021402
debug_assert!(!matches!(self.phase, ChannelPhase::Undefined));
14031403
result.map(|monitor| (self.as_funded_mut().expect("Channel should be funded"), monitor))
14041404
}
1405+
1406+
pub fn unset_funding_info(&mut self, temporary_channel_id: ChannelId) {
1407+
let phase = core::mem::replace(&mut self.phase, ChannelPhase::Undefined);
1408+
if let ChannelPhase::Funded(mut funded_chan) = phase {
1409+
funded_chan.unset_funding_info(temporary_channel_id);
1410+
1411+
let context = funded_chan.context;
1412+
let unfunded_context = UnfundedChannelContext {
1413+
unfunded_channel_age_ticks: 0,
1414+
holder_commitment_point: HolderCommitmentPoint::new(&context.holder_signer, &context.secp_ctx),
1415+
};
1416+
let unfunded_chan = OutboundV1Channel {
1417+
context,
1418+
unfunded_context,
1419+
signer_pending_open_channel: false,
1420+
};
1421+
self.phase = ChannelPhase::UnfundedOutboundV1(unfunded_chan);
1422+
} else {
1423+
self.phase = phase;
1424+
};
1425+
1426+
debug_assert!(!matches!(self.phase, ChannelPhase::Undefined));
1427+
}
14051428
}
14061429

14071430
impl<SP: Deref> From<OutboundV1Channel<SP>> for Channel<SP>

lightning/src/ln/channelmanager.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8164,22 +8164,24 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
81648164
.and_then(|(funded_chan, monitor)| {
81658165
self.chain_monitor
81668166
.watch_channel(funded_chan.context.get_funding_txo().unwrap(), monitor)
8167+
.map(|persist_status| (funded_chan, persist_status))
81678168
.map_err(|()| {
8168-
// We weren't able to watch the channel to begin with, so no
8169-
// updates should be made on it. Previously, full_stack_target
8170-
// found an (unreachable) panic when the monitor update contained
8171-
// within `shutdown_finish` was applied.
8172-
funded_chan.unset_funding_info(msg.channel_id);
81738169
ChannelError::close("Channel funding outpoint was a duplicate".to_owned())
81748170
})
8175-
.map(|persist_status| (funded_chan, persist_status))
81768171
})
81778172
{
81788173
Ok((funded_chan, persist_status)) => {
81798174
handle_new_monitor_update!(self, persist_status, peer_state_lock, peer_state, per_peer_state, funded_chan, INITIAL_MONITOR);
81808175
Ok(())
81818176
},
8182-
Err(e) => try_channel_entry!(self, peer_state, Err(e), chan_entry),
8177+
Err(e) => {
8178+
// We weren't able to watch the channel to begin with, so no
8179+
// updates should be made on it. Previously, full_stack_target
8180+
// found an (unreachable) panic when the monitor update contained
8181+
// within `shutdown_finish` was applied.
8182+
chan.unset_funding_info(msg.channel_id);
8183+
try_channel_entry!(self, peer_state, Err(e), chan_entry)
8184+
},
81838185
}
81848186
},
81858187
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)