Skip to content

Commit a2d1724

Browse files
TheBlueMattAditya Sharma
authored and
Aditya Sharma
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 fa8c376 commit a2d1724

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
@@ -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

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

94019401
// Returns whether we should remove this channel as it's just been closed.
94029402
let unblock_chan = |chan: &mut Channel<SP>, pending_msg_events: &mut Vec<MessageSendEvent>| -> Option<ShutdownResult> {
9403+
let logger = WithChannelContext::from(&self.logger, &chan.context(), None);
94039404
let node_id = chan.context().get_counterparty_node_id();
9404-
match (chan.signer_maybe_unblocked(self.chain_hash, &self.logger), chan.as_funded()) {
9405-
(Some(msgs), Some(funded_chan)) => {
9406-
let cu_msg = msgs.commitment_update.map(|updates| events::MessageSendEvent::UpdateHTLCs {
9405+
if let Some(msgs) = chan.signer_maybe_unblocked(self.chain_hash, &&logger) {
9406+
if let Some(msg) = msgs.open_channel {
9407+
pending_msg_events.push(events::MessageSendEvent::SendOpenChannel {
94079408
node_id,
9408-
updates,
9409+
msg,
94099410
});
9410-
let raa_msg = msgs.revoke_and_ack.map(|msg| events::MessageSendEvent::SendRevokeAndACK {
9411+
}
9412+
if let Some(msg) = msgs.funding_created {
9413+
pending_msg_events.push(events::MessageSendEvent::SendFundingCreated {
94119414
node_id,
94129415
msg,
94139416
});
9414-
match (cu_msg, raa_msg) {
9415-
(Some(cu), Some(raa)) if msgs.order == RAACommitmentOrder::CommitmentFirst => {
9416-
pending_msg_events.push(cu);
9417-
pending_msg_events.push(raa);
9418-
},
9419-
(Some(cu), Some(raa)) if msgs.order == RAACommitmentOrder::RevokeAndACKFirst => {
9420-
pending_msg_events.push(raa);
9421-
pending_msg_events.push(cu);
9422-
},
9423-
(Some(cu), _) => pending_msg_events.push(cu),
9424-
(_, Some(raa)) => pending_msg_events.push(raa),
9425-
(_, _) => {},
9426-
}
9427-
if let Some(msg) = msgs.funding_signed {
9428-
pending_msg_events.push(events::MessageSendEvent::SendFundingSigned {
9429-
node_id,
9430-
msg,
9431-
});
9432-
}
9417+
}
9418+
if let Some(msg) = msgs.accept_channel {
9419+
pending_msg_events.push(events::MessageSendEvent::SendAcceptChannel {
9420+
node_id,
9421+
msg,
9422+
});
9423+
}
9424+
let cu_msg = msgs.commitment_update.map(|updates| events::MessageSendEvent::UpdateHTLCs {
9425+
node_id,
9426+
updates,
9427+
});
9428+
let raa_msg = msgs.revoke_and_ack.map(|msg| events::MessageSendEvent::SendRevokeAndACK {
9429+
node_id,
9430+
msg,
9431+
});
9432+
match (cu_msg, raa_msg) {
9433+
(Some(cu), Some(raa)) if msgs.order == RAACommitmentOrder::CommitmentFirst => {
9434+
pending_msg_events.push(cu);
9435+
pending_msg_events.push(raa);
9436+
},
9437+
(Some(cu), Some(raa)) if msgs.order == RAACommitmentOrder::RevokeAndACKFirst => {
9438+
pending_msg_events.push(raa);
9439+
pending_msg_events.push(cu);
9440+
},
9441+
(Some(cu), _) => pending_msg_events.push(cu),
9442+
(_, Some(raa)) => pending_msg_events.push(raa),
9443+
(_, _) => {},
9444+
}
9445+
if let Some(msg) = msgs.funding_signed {
9446+
pending_msg_events.push(events::MessageSendEvent::SendFundingSigned {
9447+
node_id,
9448+
msg,
9449+
});
9450+
}
9451+
if let Some(msg) = msgs.closing_signed {
9452+
pending_msg_events.push(events::MessageSendEvent::SendClosingSigned {
9453+
node_id,
9454+
msg,
9455+
});
9456+
}
9457+
if let Some(funded_chan) = chan.as_funded() {
94339458
if let Some(msg) = msgs.channel_ready {
94349459
send_channel_ready!(self, pending_msg_events, funded_chan, msg);
94359460
}
9436-
if let Some(msg) = msgs.closing_signed {
9437-
pending_msg_events.push(events::MessageSendEvent::SendClosingSigned {
9438-
node_id,
9439-
msg,
9440-
});
9441-
}
94429461
if let Some(broadcast_tx) = msgs.signed_closing_tx {
9443-
let channel_id = funded_chan.context.channel_id();
9444-
let counterparty_node_id = funded_chan.context.get_counterparty_node_id();
9445-
let logger = WithContext::from(&self.logger, Some(counterparty_node_id), Some(channel_id), None);
94469462
log_info!(logger, "Broadcasting closing tx {}", log_tx!(broadcast_tx));
94479463
self.tx_broadcaster.broadcast_transactions(&[&broadcast_tx]);
94489464

@@ -9452,30 +9468,15 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
94529468
});
94539469
}
94549470
}
9455-
msgs.shutdown_result
9456-
},
9457-
(Some(msgs), None) => {
9458-
if let Some(msg) = msgs.open_channel {
9459-
pending_msg_events.push(events::MessageSendEvent::SendOpenChannel {
9460-
node_id,
9461-
msg,
9462-
});
9463-
}
9464-
if let Some(msg) = msgs.funding_created {
9465-
pending_msg_events.push(events::MessageSendEvent::SendFundingCreated {
9466-
node_id,
9467-
msg,
9468-
});
9469-
}
9470-
if let Some(msg) = msgs.accept_channel {
9471-
pending_msg_events.push(events::MessageSendEvent::SendAcceptChannel {
9472-
node_id,
9473-
msg,
9474-
});
9475-
}
9476-
None
9471+
} else {
9472+
// We don't know how to handle a channel_ready or signed_closing_tx for a
9473+
// non-funded channel.
9474+
debug_assert!(msgs.channel_ready.is_none());
9475+
debug_assert!(msgs.signed_closing_tx.is_none());
94779476
}
9478-
(None, _) => None,
9477+
msgs.shutdown_result
9478+
} else {
9479+
None
94799480
}
94809481
};
94819482

0 commit comments

Comments
 (0)