Skip to content

Commit 59da806

Browse files
committed
Reduce chan state logic from ChannelManager when unblocking signer
After #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 695c612 commit 59da806

File tree

2 files changed

+58
-58
lines changed

2 files changed

+58
-58
lines changed

lightning/src/ln/channel.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,8 +1266,7 @@ impl<SP: Deref> Channel<SP> where
12661266
})
12671267
},
12681268
ChannelPhase::UnfundedInboundV1(chan) => {
1269-
let logger = WithChannelContext::from(logger, &chan.context, None);
1270-
let accept_channel = chan.signer_maybe_unblocked(&&logger);
1269+
let accept_channel = chan.signer_maybe_unblocked(logger);
12711270
Some(SignerResumeUpdates {
12721271
commitment_update: None,
12731272
revoke_and_ack: None,

lightning/src/ln/channelmanager.rs

Lines changed: 57 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -9372,49 +9372,65 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
93729372

93739373
// Returns whether we should remove this channel as it's just been closed.
93749374
let unblock_chan = |chan: &mut Channel<SP>, pending_msg_events: &mut Vec<MessageSendEvent>| -> Option<ShutdownResult> {
9375+
let logger = WithChannelContext::from(&self.logger, &chan.context(), None);
93759376
let node_id = chan.context().get_counterparty_node_id();
9376-
match (chan.signer_maybe_unblocked(self.chain_hash, &self.logger), chan.as_funded()) {
9377-
(Some(msgs), Some(funded_chan)) => {
9378-
let cu_msg = msgs.commitment_update.map(|updates| events::MessageSendEvent::UpdateHTLCs {
9377+
if let Some(msgs) = chan.signer_maybe_unblocked(self.chain_hash, &&logger) {
9378+
if let Some(msg) = msgs.open_channel {
9379+
pending_msg_events.push(events::MessageSendEvent::SendOpenChannel {
93799380
node_id,
9380-
updates,
9381+
msg,
93819382
});
9382-
let raa_msg = msgs.revoke_and_ack.map(|msg| events::MessageSendEvent::SendRevokeAndACK {
9383+
}
9384+
if let Some(msg) = msgs.funding_created {
9385+
pending_msg_events.push(events::MessageSendEvent::SendFundingCreated {
93839386
node_id,
93849387
msg,
93859388
});
9386-
match (cu_msg, raa_msg) {
9387-
(Some(cu), Some(raa)) if msgs.order == RAACommitmentOrder::CommitmentFirst => {
9388-
pending_msg_events.push(cu);
9389-
pending_msg_events.push(raa);
9390-
},
9391-
(Some(cu), Some(raa)) if msgs.order == RAACommitmentOrder::RevokeAndACKFirst => {
9392-
pending_msg_events.push(raa);
9393-
pending_msg_events.push(cu);
9394-
},
9395-
(Some(cu), _) => pending_msg_events.push(cu),
9396-
(_, Some(raa)) => pending_msg_events.push(raa),
9397-
(_, _) => {},
9398-
}
9399-
if let Some(msg) = msgs.funding_signed {
9400-
pending_msg_events.push(events::MessageSendEvent::SendFundingSigned {
9401-
node_id,
9402-
msg,
9403-
});
9404-
}
9389+
}
9390+
if let Some(msg) = msgs.accept_channel {
9391+
pending_msg_events.push(events::MessageSendEvent::SendAcceptChannel {
9392+
node_id,
9393+
msg,
9394+
});
9395+
}
9396+
let cu_msg = msgs.commitment_update.map(|updates| events::MessageSendEvent::UpdateHTLCs {
9397+
node_id,
9398+
updates,
9399+
});
9400+
let raa_msg = msgs.revoke_and_ack.map(|msg| events::MessageSendEvent::SendRevokeAndACK {
9401+
node_id,
9402+
msg,
9403+
});
9404+
match (cu_msg, raa_msg) {
9405+
(Some(cu), Some(raa)) if msgs.order == RAACommitmentOrder::CommitmentFirst => {
9406+
pending_msg_events.push(cu);
9407+
pending_msg_events.push(raa);
9408+
},
9409+
(Some(cu), Some(raa)) if msgs.order == RAACommitmentOrder::RevokeAndACKFirst => {
9410+
pending_msg_events.push(raa);
9411+
pending_msg_events.push(cu);
9412+
},
9413+
(Some(cu), _) => pending_msg_events.push(cu),
9414+
(_, Some(raa)) => pending_msg_events.push(raa),
9415+
(_, _) => {},
9416+
}
9417+
if let Some(msg) = msgs.funding_signed {
9418+
pending_msg_events.push(events::MessageSendEvent::SendFundingSigned {
9419+
node_id,
9420+
msg,
9421+
});
9422+
}
9423+
if let Some(msg) = msgs.closing_signed {
9424+
pending_msg_events.push(events::MessageSendEvent::SendClosingSigned {
9425+
node_id,
9426+
msg,
9427+
});
9428+
}
9429+
if let Some(funded_chan) = chan.as_funded() {
94059430
if let Some(msg) = msgs.channel_ready {
94069431
send_channel_ready!(self, pending_msg_events, funded_chan, msg);
94079432
}
9408-
if let Some(msg) = msgs.closing_signed {
9409-
pending_msg_events.push(events::MessageSendEvent::SendClosingSigned {
9410-
node_id,
9411-
msg,
9412-
});
9413-
}
94149433
if let Some(broadcast_tx) = msgs.signed_closing_tx {
9415-
let channel_id = funded_chan.context.channel_id();
9416-
let counterparty_node_id = funded_chan.context.get_counterparty_node_id();
9417-
let logger = WithContext::from(&self.logger, Some(counterparty_node_id), Some(channel_id), None);
94189434
log_info!(logger, "Broadcasting closing tx {}", log_tx!(broadcast_tx));
94199435
self.tx_broadcaster.broadcast_transactions(&[&broadcast_tx]);
94209436

@@ -9424,30 +9440,15 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
94249440
});
94259441
}
94269442
}
9427-
msgs.shutdown_result
9428-
},
9429-
(Some(msgs), None) => {
9430-
if let Some(msg) = msgs.open_channel {
9431-
pending_msg_events.push(events::MessageSendEvent::SendOpenChannel {
9432-
node_id,
9433-
msg,
9434-
});
9435-
}
9436-
if let Some(msg) = msgs.funding_created {
9437-
pending_msg_events.push(events::MessageSendEvent::SendFundingCreated {
9438-
node_id,
9439-
msg,
9440-
});
9441-
}
9442-
if let Some(msg) = msgs.accept_channel {
9443-
pending_msg_events.push(events::MessageSendEvent::SendAcceptChannel {
9444-
node_id,
9445-
msg,
9446-
});
9447-
}
9448-
None
9443+
} else {
9444+
// We don't know how to handle a channel_ready or signed_closing_tx for a
9445+
// non-funded channel.
9446+
debug_assert!(msgs.channel_ready.is_none());
9447+
debug_assert!(msgs.signed_closing_tx.is_none());
94499448
}
9450-
(None, _) => None,
9449+
msgs.shutdown_result
9450+
} else {
9451+
None
94519452
}
94529453
};
94539454

0 commit comments

Comments
 (0)