mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-01-19 05:43:55 +01:00
Rewrite ChannelManager::signer_unblocked
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::signer_unblocked to use ChannelPhase::as_funded and a new method on ChannelPhase dispatching to each variant's signer_maybe_unblocked method.
This commit is contained in:
parent
307e0485d2
commit
cae893af64
@ -909,6 +909,9 @@ pub(super) struct MonitorRestoreUpdates {
|
||||
pub(super) struct SignerResumeUpdates {
|
||||
pub commitment_update: Option<msgs::CommitmentUpdate>,
|
||||
pub revoke_and_ack: Option<msgs::RevokeAndACK>,
|
||||
pub open_channel: Option<msgs::OpenChannel>,
|
||||
pub accept_channel: Option<msgs::AcceptChannel>,
|
||||
pub funding_created: Option<msgs::FundingCreated>,
|
||||
pub funding_signed: Option<msgs::FundingSigned>,
|
||||
pub channel_ready: Option<msgs::ChannelReady>,
|
||||
pub order: RAACommitmentOrder,
|
||||
@ -1188,6 +1191,48 @@ impl<'a, SP: Deref> ChannelPhase<SP> where
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn signer_maybe_unblocked<L: Deref>(
|
||||
&mut self, chain_hash: ChainHash, logger: &L,
|
||||
) -> Option<SignerResumeUpdates> where L::Target: Logger {
|
||||
match self {
|
||||
ChannelPhase::Funded(chan) => Some(chan.signer_maybe_unblocked(logger)),
|
||||
ChannelPhase::UnfundedOutboundV1(chan) => {
|
||||
let (open_channel, funding_created) = chan.signer_maybe_unblocked(chain_hash, logger);
|
||||
Some(SignerResumeUpdates {
|
||||
commitment_update: None,
|
||||
revoke_and_ack: None,
|
||||
open_channel,
|
||||
accept_channel: None,
|
||||
funding_created,
|
||||
funding_signed: None,
|
||||
channel_ready: None,
|
||||
order: chan.context.resend_order.clone(),
|
||||
closing_signed: None,
|
||||
signed_closing_tx: None,
|
||||
shutdown_result: None,
|
||||
})
|
||||
},
|
||||
ChannelPhase::UnfundedInboundV1(chan) => {
|
||||
let logger = WithChannelContext::from(logger, &chan.context, None);
|
||||
let accept_channel = chan.signer_maybe_unblocked(&&logger);
|
||||
Some(SignerResumeUpdates {
|
||||
commitment_update: None,
|
||||
revoke_and_ack: None,
|
||||
open_channel: None,
|
||||
accept_channel,
|
||||
funding_created: None,
|
||||
funding_signed: None,
|
||||
channel_ready: None,
|
||||
order: chan.context.resend_order.clone(),
|
||||
closing_signed: None,
|
||||
signed_closing_tx: None,
|
||||
shutdown_result: None,
|
||||
})
|
||||
},
|
||||
ChannelPhase::UnfundedV2(_) => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Contains all state common to unfunded inbound/outbound channels.
|
||||
@ -6178,6 +6223,9 @@ impl<SP: Deref> Channel<SP> where
|
||||
SignerResumeUpdates {
|
||||
commitment_update,
|
||||
revoke_and_ack,
|
||||
open_channel: None,
|
||||
accept_channel: None,
|
||||
funding_created: None,
|
||||
funding_signed,
|
||||
channel_ready,
|
||||
order: self.context.resend_order.clone(),
|
||||
|
@ -9468,9 +9468,8 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
|
||||
// Returns whether we should remove this channel as it's just been closed.
|
||||
let unblock_chan = |phase: &mut ChannelPhase<SP>, pending_msg_events: &mut Vec<MessageSendEvent>| -> Option<ShutdownResult> {
|
||||
let node_id = phase.context().get_counterparty_node_id();
|
||||
match phase {
|
||||
ChannelPhase::Funded(chan) => {
|
||||
let msgs = chan.signer_maybe_unblocked(&self.logger);
|
||||
match (phase.signer_maybe_unblocked(self.chain_hash, &self.logger), phase.as_funded()) {
|
||||
(Some(msgs), Some(chan)) => {
|
||||
let cu_msg = msgs.commitment_update.map(|updates| events::MessageSendEvent::UpdateHTLCs {
|
||||
node_id,
|
||||
updates,
|
||||
@ -9521,34 +9520,29 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
|
||||
}
|
||||
}
|
||||
msgs.shutdown_result
|
||||
}
|
||||
ChannelPhase::UnfundedOutboundV1(chan) => {
|
||||
let (open_channel, funding_created) = chan.signer_maybe_unblocked(self.chain_hash.clone(), &self.logger);
|
||||
if let Some(msg) = open_channel {
|
||||
},
|
||||
(Some(msgs), None) => {
|
||||
if let Some(msg) = msgs.open_channel {
|
||||
pending_msg_events.push(events::MessageSendEvent::SendOpenChannel {
|
||||
node_id,
|
||||
msg,
|
||||
});
|
||||
}
|
||||
if let Some(msg) = funding_created {
|
||||
if let Some(msg) = msgs.funding_created {
|
||||
pending_msg_events.push(events::MessageSendEvent::SendFundingCreated {
|
||||
node_id,
|
||||
msg,
|
||||
});
|
||||
}
|
||||
None
|
||||
}
|
||||
ChannelPhase::UnfundedInboundV1(chan) => {
|
||||
let logger = WithChannelContext::from(&self.logger, &chan.context, None);
|
||||
if let Some(msg) = chan.signer_maybe_unblocked(&&logger) {
|
||||
if let Some(msg) = msgs.accept_channel {
|
||||
pending_msg_events.push(events::MessageSendEvent::SendAcceptChannel {
|
||||
node_id,
|
||||
msg,
|
||||
});
|
||||
}
|
||||
None
|
||||
},
|
||||
ChannelPhase::UnfundedV2(_) => None,
|
||||
}
|
||||
(None, _) => None,
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user