Skip to content

Commit 924ca82

Browse files
committed
Handle tx_abort without using ChannelPhase
Exposing ChannelPhase in ChannelManager has led to verbose match statements, which need to be modified each time a ChannelPhase is added. Making ChannelPhase an implementation detail of Channel would help avoid this. As a step in this direction, update ChannelManager::internal_tx_abort to use ChannelPhase::is_funded and a new ChannelPhase::as_unfunded_v2_mut method.
1 parent 94c8b72 commit 924ca82

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

lightning/src/ln/channel.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,6 +1180,14 @@ impl<'a, SP: Deref> ChannelPhase<SP> where
11801180
None
11811181
}
11821182
}
1183+
1184+
pub fn as_unfunded_v2_mut(&mut self) -> Option<&mut PendingV2Channel<SP>> {
1185+
if let ChannelPhase::UnfundedV2(channel) = self {
1186+
Some(channel)
1187+
} else {
1188+
None
1189+
}
1190+
}
11831191
}
11841192

11851193
/// Contains all state common to unfunded inbound/outbound channels.

lightning/src/ln/channelmanager.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8425,9 +8425,9 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
84258425
match peer_state.channel_by_id.entry(msg.channel_id) {
84268426
hash_map::Entry::Occupied(mut chan_phase_entry) => {
84278427
let channel_phase = chan_phase_entry.get_mut();
8428-
let tx_constructor = match channel_phase {
8429-
ChannelPhase::UnfundedV2(chan) => &mut chan.interactive_tx_constructor,
8430-
ChannelPhase::Funded(_) => {
8428+
let tx_constructor = match channel_phase.as_unfunded_v2_mut() {
8429+
Some(chan) => &mut chan.interactive_tx_constructor,
8430+
None => if channel_phase.is_funded() {
84318431
// TODO(splicing)/TODO(RBF): We'll also be doing interactive tx construction
84328432
// for a "ChannelPhase::Funded" when we want to bump the fee on an interactively
84338433
// constructed funding tx or during splicing. For now we send an error as we would
@@ -8437,8 +8437,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
84378437
splicing and RBF attempts of interactive funding transactions are not supported yet so \
84388438
we don't have any negotiation in progress".into(),
84398439
)), chan_phase_entry)
8440-
}
8441-
ChannelPhase::UnfundedInboundV1(_) | ChannelPhase::UnfundedOutboundV1(_) => {
8440+
} else {
84428441
try_chan_phase_entry!(self, peer_state, Err(ChannelError::Warn(
84438442
"Got an unexpected tx_abort message: This is an unfunded channel created with V1 channel \
84448443
establishment".into(),

0 commit comments

Comments
 (0)