Skip to content

Commit 313f7d9

Browse files
committed
Reduce chan state logic from ChannelManager when unblocking signer
After lightningdevkit#3513 we have a bit more encapsulation of channel logic in channel.rs with channelmanager.rs needing a bit less knowledge of which specific state a channel is in. This continues that trend slightly when unblocking the signer.
1 parent c37b1cd commit 313f7d9

File tree

2 files changed

+58
-58
lines changed

2 files changed

+58
-58
lines changed

lightning/src/ln/channel.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1259,8 +1259,7 @@ impl<SP: Deref> Channel<SP> where
12591259
})
12601260
},
12611261
Channel::UnfundedInboundV1(chan) => {
1262-
let logger = WithChannelContext::from(logger, &chan.context, None);
1263-
let accept_channel = chan.signer_maybe_unblocked(&&logger);
1262+
let accept_channel = chan.signer_maybe_unblocked(logger);
12641263
Some(SignerResumeUpdates {
12651264
commitment_update: None,
12661265
revoke_and_ack: None,

lightning/src/ln/channelmanager.rs

+57-56
Original file line numberDiff line numberDiff line change
@@ -9454,49 +9454,65 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
94549454

94559455
// Returns whether we should remove this channel as it's just been closed.
94569456
let unblock_chan = |phase: &mut Channel<SP>, pending_msg_events: &mut Vec<MessageSendEvent>| -> Option<ShutdownResult> {
9457+
let logger = WithChannelContext::from(&self.logger, &phase.context(), None);
94579458
let node_id = phase.context().get_counterparty_node_id();
9458-
match (phase.signer_maybe_unblocked(self.chain_hash, &self.logger), phase.as_funded()) {
9459-
(Some(msgs), Some(chan)) => {
9460-
let cu_msg = msgs.commitment_update.map(|updates| events::MessageSendEvent::UpdateHTLCs {
9459+
if let Some(msgs) = phase.signer_maybe_unblocked(self.chain_hash, &&logger) {
9460+
if let Some(msg) = msgs.open_channel {
9461+
pending_msg_events.push(events::MessageSendEvent::SendOpenChannel {
94619462
node_id,
9462-
updates,
9463+
msg,
94639464
});
9464-
let raa_msg = msgs.revoke_and_ack.map(|msg| events::MessageSendEvent::SendRevokeAndACK {
9465+
}
9466+
if let Some(msg) = msgs.funding_created {
9467+
pending_msg_events.push(events::MessageSendEvent::SendFundingCreated {
94659468
node_id,
94669469
msg,
94679470
});
9468-
match (cu_msg, raa_msg) {
9469-
(Some(cu), Some(raa)) if msgs.order == RAACommitmentOrder::CommitmentFirst => {
9470-
pending_msg_events.push(cu);
9471-
pending_msg_events.push(raa);
9472-
},
9473-
(Some(cu), Some(raa)) if msgs.order == RAACommitmentOrder::RevokeAndACKFirst => {
9474-
pending_msg_events.push(raa);
9475-
pending_msg_events.push(cu);
9476-
},
9477-
(Some(cu), _) => pending_msg_events.push(cu),
9478-
(_, Some(raa)) => pending_msg_events.push(raa),
9479-
(_, _) => {},
9480-
}
9481-
if let Some(msg) = msgs.funding_signed {
9482-
pending_msg_events.push(events::MessageSendEvent::SendFundingSigned {
9483-
node_id,
9484-
msg,
9485-
});
9486-
}
9471+
}
9472+
if let Some(msg) = msgs.accept_channel {
9473+
pending_msg_events.push(events::MessageSendEvent::SendAcceptChannel {
9474+
node_id,
9475+
msg,
9476+
});
9477+
}
9478+
let cu_msg = msgs.commitment_update.map(|updates| events::MessageSendEvent::UpdateHTLCs {
9479+
node_id,
9480+
updates,
9481+
});
9482+
let raa_msg = msgs.revoke_and_ack.map(|msg| events::MessageSendEvent::SendRevokeAndACK {
9483+
node_id,
9484+
msg,
9485+
});
9486+
match (cu_msg, raa_msg) {
9487+
(Some(cu), Some(raa)) if msgs.order == RAACommitmentOrder::CommitmentFirst => {
9488+
pending_msg_events.push(cu);
9489+
pending_msg_events.push(raa);
9490+
},
9491+
(Some(cu), Some(raa)) if msgs.order == RAACommitmentOrder::RevokeAndACKFirst => {
9492+
pending_msg_events.push(raa);
9493+
pending_msg_events.push(cu);
9494+
},
9495+
(Some(cu), _) => pending_msg_events.push(cu),
9496+
(_, Some(raa)) => pending_msg_events.push(raa),
9497+
(_, _) => {},
9498+
}
9499+
if let Some(msg) = msgs.funding_signed {
9500+
pending_msg_events.push(events::MessageSendEvent::SendFundingSigned {
9501+
node_id,
9502+
msg,
9503+
});
9504+
}
9505+
if let Some(msg) = msgs.closing_signed {
9506+
pending_msg_events.push(events::MessageSendEvent::SendClosingSigned {
9507+
node_id,
9508+
msg,
9509+
});
9510+
}
9511+
if let Some(chan) = phase.as_funded() {
94879512
if let Some(msg) = msgs.channel_ready {
94889513
send_channel_ready!(self, pending_msg_events, chan, msg);
94899514
}
9490-
if let Some(msg) = msgs.closing_signed {
9491-
pending_msg_events.push(events::MessageSendEvent::SendClosingSigned {
9492-
node_id,
9493-
msg,
9494-
});
9495-
}
94969515
if let Some(broadcast_tx) = msgs.signed_closing_tx {
9497-
let channel_id = chan.context.channel_id();
9498-
let counterparty_node_id = chan.context.get_counterparty_node_id();
9499-
let logger = WithContext::from(&self.logger, Some(counterparty_node_id), Some(channel_id), None);
95009516
log_info!(logger, "Broadcasting closing tx {}", log_tx!(broadcast_tx));
95019517
self.tx_broadcaster.broadcast_transactions(&[&broadcast_tx]);
95029518

@@ -9506,30 +9522,15 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
95069522
});
95079523
}
95089524
}
9509-
msgs.shutdown_result
9510-
},
9511-
(Some(msgs), None) => {
9512-
if let Some(msg) = msgs.open_channel {
9513-
pending_msg_events.push(events::MessageSendEvent::SendOpenChannel {
9514-
node_id,
9515-
msg,
9516-
});
9517-
}
9518-
if let Some(msg) = msgs.funding_created {
9519-
pending_msg_events.push(events::MessageSendEvent::SendFundingCreated {
9520-
node_id,
9521-
msg,
9522-
});
9523-
}
9524-
if let Some(msg) = msgs.accept_channel {
9525-
pending_msg_events.push(events::MessageSendEvent::SendAcceptChannel {
9526-
node_id,
9527-
msg,
9528-
});
9529-
}
9530-
None
9525+
} else {
9526+
// We don't know how to handle a channel_ready or signed_closing_tx for a
9527+
// non-funded channel.
9528+
debug_assert!(msgs.channel_ready.is_none());
9529+
debug_assert!(msgs.signed_closing_tx.is_none());
95319530
}
9532-
(None, _) => None,
9531+
msgs.shutdown_result
9532+
} else {
9533+
None
95339534
}
95349535
};
95359536

0 commit comments

Comments
 (0)