mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-02-25 07:17:40 +01:00
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.
This commit is contained in:
parent
6f119eb20c
commit
307e0485d2
2 changed files with 12 additions and 5 deletions
|
@ -1180,6 +1180,14 @@ impl<'a, SP: Deref> ChannelPhase<SP> where
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn as_unfunded_v2_mut(&mut self) -> Option<&mut PendingV2Channel<SP>> {
|
||||||
|
if let ChannelPhase::UnfundedV2(channel) = self {
|
||||||
|
Some(channel)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Contains all state common to unfunded inbound/outbound channels.
|
/// Contains all state common to unfunded inbound/outbound channels.
|
||||||
|
|
|
@ -8425,9 +8425,9 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
|
||||||
match peer_state.channel_by_id.entry(msg.channel_id) {
|
match peer_state.channel_by_id.entry(msg.channel_id) {
|
||||||
hash_map::Entry::Occupied(mut chan_phase_entry) => {
|
hash_map::Entry::Occupied(mut chan_phase_entry) => {
|
||||||
let channel_phase = chan_phase_entry.get_mut();
|
let channel_phase = chan_phase_entry.get_mut();
|
||||||
let tx_constructor = match channel_phase {
|
let tx_constructor = match channel_phase.as_unfunded_v2_mut() {
|
||||||
ChannelPhase::UnfundedV2(chan) => &mut chan.interactive_tx_constructor,
|
Some(chan) => &mut chan.interactive_tx_constructor,
|
||||||
ChannelPhase::Funded(_) => {
|
None => if channel_phase.is_funded() {
|
||||||
// TODO(splicing)/TODO(RBF): We'll also be doing interactive tx construction
|
// TODO(splicing)/TODO(RBF): We'll also be doing interactive tx construction
|
||||||
// for a "ChannelPhase::Funded" when we want to bump the fee on an interactively
|
// for a "ChannelPhase::Funded" when we want to bump the fee on an interactively
|
||||||
// constructed funding tx or during splicing. For now we send an error as we would
|
// 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/
|
||||||
splicing and RBF attempts of interactive funding transactions are not supported yet so \
|
splicing and RBF attempts of interactive funding transactions are not supported yet so \
|
||||||
we don't have any negotiation in progress".into(),
|
we don't have any negotiation in progress".into(),
|
||||||
)), chan_phase_entry)
|
)), chan_phase_entry)
|
||||||
}
|
} else {
|
||||||
ChannelPhase::UnfundedInboundV1(_) | ChannelPhase::UnfundedOutboundV1(_) => {
|
|
||||||
try_chan_phase_entry!(self, peer_state, Err(ChannelError::Warn(
|
try_chan_phase_entry!(self, peer_state, Err(ChannelError::Warn(
|
||||||
"Got an unexpected tx_abort message: This is an unfunded channel created with V1 channel \
|
"Got an unexpected tx_abort message: This is an unfunded channel created with V1 channel \
|
||||||
establishment".into(),
|
establishment".into(),
|
||||||
|
|
Loading…
Add table
Reference in a new issue