Skip to content

Commit 0c6cb6c

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 0c6cb6c

File tree

2 files changed

+57
-55
lines changed

2 files changed

+57
-55
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

+56-53
Original file line numberDiff line numberDiff line change
@@ -9455,44 +9455,62 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
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> {
94579457
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 {
9458+
if let Some(msgs) = phase.signer_maybe_unblocked(self.chain_hash, &self.logger) {
9459+
if let Some(msg) = msgs.open_channel {
9460+
pending_msg_events.push(events::MessageSendEvent::SendOpenChannel {
94619461
node_id,
9462-
updates,
9462+
msg,
94639463
});
9464-
let raa_msg = msgs.revoke_and_ack.map(|msg| events::MessageSendEvent::SendRevokeAndACK {
9464+
}
9465+
if let Some(msg) = msgs.funding_created {
9466+
pending_msg_events.push(events::MessageSendEvent::SendFundingCreated {
94659467
node_id,
94669468
msg,
94679469
});
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-
}
9470+
}
9471+
if let Some(msg) = msgs.accept_channel {
9472+
pending_msg_events.push(events::MessageSendEvent::SendAcceptChannel {
9473+
node_id,
9474+
msg,
9475+
});
9476+
}
9477+
let cu_msg = msgs.commitment_update.map(|updates| events::MessageSendEvent::UpdateHTLCs {
9478+
node_id,
9479+
updates,
9480+
});
9481+
let raa_msg = msgs.revoke_and_ack.map(|msg| events::MessageSendEvent::SendRevokeAndACK {
9482+
node_id,
9483+
msg,
9484+
});
9485+
match (cu_msg, raa_msg) {
9486+
(Some(cu), Some(raa)) if msgs.order == RAACommitmentOrder::CommitmentFirst => {
9487+
pending_msg_events.push(cu);
9488+
pending_msg_events.push(raa);
9489+
},
9490+
(Some(cu), Some(raa)) if msgs.order == RAACommitmentOrder::RevokeAndACKFirst => {
9491+
pending_msg_events.push(raa);
9492+
pending_msg_events.push(cu);
9493+
},
9494+
(Some(cu), _) => pending_msg_events.push(cu),
9495+
(_, Some(raa)) => pending_msg_events.push(raa),
9496+
(_, _) => {},
9497+
}
9498+
if let Some(msg) = msgs.funding_signed {
9499+
pending_msg_events.push(events::MessageSendEvent::SendFundingSigned {
9500+
node_id,
9501+
msg,
9502+
});
9503+
}
9504+
if let Some(msg) = msgs.closing_signed {
9505+
pending_msg_events.push(events::MessageSendEvent::SendClosingSigned {
9506+
node_id,
9507+
msg,
9508+
});
9509+
}
9510+
if let Some(chan) = phase.as_funded() {
94879511
if let Some(msg) = msgs.channel_ready {
94889512
send_channel_ready!(self, pending_msg_events, chan, msg);
94899513
}
9490-
if let Some(msg) = msgs.closing_signed {
9491-
pending_msg_events.push(events::MessageSendEvent::SendClosingSigned {
9492-
node_id,
9493-
msg,
9494-
});
9495-
}
94969514
if let Some(broadcast_tx) = msgs.signed_closing_tx {
94979515
let channel_id = chan.context.channel_id();
94989516
let counterparty_node_id = chan.context.get_counterparty_node_id();
@@ -9506,30 +9524,15 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
95069524
});
95079525
}
95089526
}
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
9527+
} else {
9528+
// We don't know how to handle a channel_ready or signed_closing_tx for a
9529+
// non-funded channel.
9530+
debug_assert!(msgs.channel_ready.is_none());
9531+
debug_assert!(msgs.signed_closing_tx.is_none());
95319532
}
9532-
(None, _) => None,
9533+
msgs.shutdown_result
9534+
} else {
9535+
None
95339536
}
95349537
};
95359538

0 commit comments

Comments
 (0)