Skip to content

Commit

Permalink
Update for channel phase changes
Browse files Browse the repository at this point in the history
Modifies `signer_unblocked` to use the phase rather than the channel: we only
need to worry about the `Funded` phase right now.
  • Loading branch information
waterson committed Sep 12, 2023
1 parent 5ef97d2 commit e5dfc2c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 28 deletions.
41 changes: 22 additions & 19 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6615,25 +6615,28 @@ where
pub fn signer_unblocked(&self, channel_opt: Option<(PublicKey, ChannelId)>) {
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);

let unblock_chan = |chan: &mut Channel<SP>, pending_msg_events: &mut Vec<MessageSendEvent>| {
let msgs = chan.signer_maybe_unblocked(&self.logger);
if let Some(updates) = msgs.commitment_update {
pending_msg_events.push(events::MessageSendEvent::UpdateHTLCs {
node_id: chan.context.get_counterparty_node_id(),
updates,
});
}
if let Some(msg) = msgs.funding_signed {
pending_msg_events.push(events::MessageSendEvent::SendFundingSigned {
node_id: chan.context.get_counterparty_node_id(),
msg,
});
}
if let Some(msg) = msgs.funding_created {
pending_msg_events.push(events::MessageSendEvent::SendFundingCreated {
node_id: chan.context.get_counterparty_node_id(),
msg,
});
let unblock_chan = |phase: &mut ChannelPhase<SP>, pending_msg_events: &mut Vec<MessageSendEvent>| {
if let ChannelPhase::Funded(chan) = phase {
let msgs = chan.signer_maybe_unblocked(&self.logger);
let node_id = phase.context().get_counterparty_node_id();
if let Some(updates) = msgs.commitment_update {
pending_msg_events.push(events::MessageSendEvent::UpdateHTLCs {
node_id,
updates,
});
}
if let Some(msg) = msgs.funding_signed {
pending_msg_events.push(events::MessageSendEvent::SendFundingSigned {
node_id,
msg,
});
}
if let Some(msg) = msgs.funding_created {
pending_msg_events.push(events::MessageSendEvent::SendFundingCreated {
node_id,
msg,
});
}
}
};

Expand Down
12 changes: 3 additions & 9 deletions lightning/src/ln/functional_test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,16 +427,10 @@ impl<'a, 'b, 'c> Node<'a, 'b, 'c> {
let per_peer_state = self.node.per_peer_state.read().unwrap();
let chan_lock = per_peer_state.get(peer_id).unwrap().lock().unwrap();
let signer = (|| {
if let Some(local_chan) = chan_lock.channel_by_id.get(chan_id) {
return local_chan.get_signer();
match chan_lock.channel_by_id.get(chan_id) {
Some(phase) => phase.context().get_signer(),
None => panic!("Couldn't find a channel with id {}", chan_id),
}
if let Some(local_chan) = chan_lock.inbound_v1_channel_by_id.get(chan_id) {
return local_chan.context.get_signer();
}
if let Some(local_chan) = chan_lock.outbound_v1_channel_by_id.get(chan_id) {
return local_chan.context.get_signer();
}
panic!("Couldn't find a channel with id {}", chan_id);
})();
log_debug!(self.logger, "Setting channel signer for {} as available={}", chan_id, available);
signer.as_ecdsa().unwrap().set_available(available);
Expand Down

0 comments on commit e5dfc2c

Please sign in to comment.