@@ -9454,49 +9454,65 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
9454
9454
9455
9455
// Returns whether we should remove this channel as it's just been closed.
9456
9456
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);
9457
9458
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 {
9461
9462
node_id,
9462
- updates ,
9463
+ msg ,
9463
9464
});
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 {
9465
9468
node_id,
9466
9469
msg,
9467
9470
});
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() {
9487
9512
if let Some(msg) = msgs.channel_ready {
9488
9513
send_channel_ready!(self, pending_msg_events, chan, msg);
9489
9514
}
9490
- if let Some(msg) = msgs.closing_signed {
9491
- pending_msg_events.push(events::MessageSendEvent::SendClosingSigned {
9492
- node_id,
9493
- msg,
9494
- });
9495
- }
9496
9515
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);
9500
9516
log_info!(logger, "Broadcasting closing tx {}", log_tx!(broadcast_tx));
9501
9517
self.tx_broadcaster.broadcast_transactions(&[&broadcast_tx]);
9502
9518
@@ -9506,30 +9522,15 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
9506
9522
});
9507
9523
}
9508
9524
}
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());
9531
9530
}
9532
- (None, _) => None,
9531
+ msgs.shutdown_result
9532
+ } else {
9533
+ None
9533
9534
}
9534
9535
};
9535
9536
0 commit comments