@@ -48,7 +48,7 @@ use crate::events::{self, Event, EventHandler, EventsProvider, InboundChannelFun
48
48
use crate::ln::inbound_payment;
49
49
use crate::ln::types::ChannelId;
50
50
use crate::types::payment::{PaymentHash, PaymentPreimage, PaymentSecret};
51
- use crate::ln::channel::{self, Channel, ChannelError, ChannelUpdateStatus, FundedChannel, ShutdownResult, UpdateFulfillCommitFetch, OutboundV1Channel, InboundV1Channel, WithChannelContext};
51
+ use crate::ln::channel::{self, Channel, ChannelError, ChannelUpdateStatus, FundedChannel, ShutdownResult, UpdateFulfillCommitFetch, OutboundV1Channel, ReconnectionMsg, InboundV1Channel, WithChannelContext};
52
52
#[cfg(any(dual_funding, splicing))]
53
53
use crate::ln::channel::PendingV2Channel;
54
54
use crate::ln::channel_state::ChannelDetails;
@@ -6540,12 +6540,11 @@ where
6540
6540
chan.context_mut().maybe_expire_prev_config();
6541
6541
let unfunded_context = chan.unfunded_context_mut().expect("channel should be unfunded");
6542
6542
if unfunded_context.should_expire_unfunded_channel() {
6543
- let context = chan.context ();
6543
+ let context = chan.context_mut ();
6544
6544
let logger = WithChannelContext::from(&self.logger, context, None);
6545
6545
log_error!(logger,
6546
6546
"Force-closing pending channel with ID {} for not establishing in a timely manner",
6547
6547
context.channel_id());
6548
- let context = chan.context_mut();
6549
6548
let mut close_res = context.force_shutdown(false, ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) });
6550
6549
locked_close_channel!(self, peer_state, context, close_res);
6551
6550
shutdown_channels.push(close_res);
@@ -9401,49 +9400,65 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
9401
9400
9402
9401
// Returns whether we should remove this channel as it's just been closed.
9403
9402
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);
9404
9404
let node_id = chan.context().get_counterparty_node_id();
9405
- match ( chan.signer_maybe_unblocked(self.chain_hash, &self. logger), chan.as_funded() ) {
9406
- (Some(msgs), Some(funded_chan)) => {
9407
- 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 {
9408
9408
node_id,
9409
- updates ,
9409
+ msg ,
9410
9410
});
9411
- 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 {
9412
9414
node_id,
9413
9415
msg,
9414
9416
});
9415
- match (cu_msg, raa_msg) {
9416
- (Some(cu), Some(raa)) if msgs.order == RAACommitmentOrder::CommitmentFirst => {
9417
- pending_msg_events.push(cu);
9418
- pending_msg_events.push(raa);
9419
- },
9420
- (Some(cu), Some(raa)) if msgs.order == RAACommitmentOrder::RevokeAndACKFirst => {
9421
- pending_msg_events.push(raa);
9422
- pending_msg_events.push(cu);
9423
- },
9424
- (Some(cu), _) => pending_msg_events.push(cu),
9425
- (_, Some(raa)) => pending_msg_events.push(raa),
9426
- (_, _) => {},
9427
- }
9428
- if let Some(msg) = msgs.funding_signed {
9429
- pending_msg_events.push(events::MessageSendEvent::SendFundingSigned {
9430
- node_id,
9431
- msg,
9432
- });
9433
- }
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() {
9434
9458
if let Some(msg) = msgs.channel_ready {
9435
9459
send_channel_ready!(self, pending_msg_events, funded_chan, msg);
9436
9460
}
9437
- if let Some(msg) = msgs.closing_signed {
9438
- pending_msg_events.push(events::MessageSendEvent::SendClosingSigned {
9439
- node_id,
9440
- msg,
9441
- });
9442
- }
9443
9461
if let Some(broadcast_tx) = msgs.signed_closing_tx {
9444
- let channel_id = funded_chan.context.channel_id();
9445
- let counterparty_node_id = funded_chan.context.get_counterparty_node_id();
9446
- let logger = WithContext::from(&self.logger, Some(counterparty_node_id), Some(channel_id), None);
9447
9462
log_info!(logger, "Broadcasting closing tx {}", log_tx!(broadcast_tx));
9448
9463
self.tx_broadcaster.broadcast_transactions(&[&broadcast_tx]);
9449
9464
@@ -9453,30 +9468,15 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
9453
9468
});
9454
9469
}
9455
9470
}
9456
- msgs.shutdown_result
9457
- },
9458
- (Some(msgs), None) => {
9459
- if let Some(msg) = msgs.open_channel {
9460
- pending_msg_events.push(events::MessageSendEvent::SendOpenChannel {
9461
- node_id,
9462
- msg,
9463
- });
9464
- }
9465
- if let Some(msg) = msgs.funding_created {
9466
- pending_msg_events.push(events::MessageSendEvent::SendFundingCreated {
9467
- node_id,
9468
- msg,
9469
- });
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
- 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());
9478
9476
}
9479
- (None, _) => None,
9477
+ msgs.shutdown_result
9478
+ } else {
9479
+ None
9480
9480
}
9481
9481
};
9482
9482
@@ -11528,26 +11528,10 @@ where
11528
11528
let peer_state = &mut *peer_state_lock;
11529
11529
let pending_msg_events = &mut peer_state.pending_msg_events;
11530
11530
peer_state.channel_by_id.retain(|_, chan| {
11531
- match chan.as_funded_mut() {
11532
- Some(funded_chan) => {
11533
- let logger = WithChannelContext::from(&self.logger, &funded_chan.context, None);
11534
- if funded_chan.remove_uncommitted_htlcs_and_mark_paused(&&logger).is_ok() {
11535
- // We only retain funded channels that are not shutdown.
11536
- return true;
11537
- }
11538
- },
11539
- // If we get disconnected and haven't yet committed to a funding
11540
- // transaction, we can replay the `open_channel` on reconnection, so don't
11541
- // bother dropping the channel here. However, if we already committed to
11542
- // the funding transaction we don't yet support replaying the funding
11543
- // handshake (and bailing if the peer rejects it), so we force-close in
11544
- // that case.
11545
- None => {
11546
- if chan.is_resumable() {
11547
- return true;
11548
- }
11549
- },
11550
- };
11531
+ let logger = WithChannelContext::from(&self.logger, &chan.context(), None);
11532
+ if chan.peer_disconnected_is_resumable(&&logger) {
11533
+ return true;
11534
+ }
11551
11535
// Clean up for removal.
11552
11536
let context = chan.context_mut();
11553
11537
let mut close_res = context.force_shutdown(false, ClosureReason::DisconnectedPeer);
@@ -11691,30 +11675,25 @@ where
11691
11675
let pending_msg_events = &mut peer_state.pending_msg_events;
11692
11676
11693
11677
for (_, chan) in peer_state.channel_by_id.iter_mut() {
11694
- match chan.as_funded_mut() {
11695
- Some(funded_chan) => {
11696
- let logger = WithChannelContext::from(&self.logger, &funded_chan.context, None);
11678
+ let logger = WithChannelContext::from(&self.logger, & chan.context(), None);
11679
+ match chan.peer_connected_get_handshake(self.chain_hash, &&logger) {
11680
+ ReconnectionMsg::Reestablish(msg) =>
11697
11681
pending_msg_events.push(events::MessageSendEvent::SendChannelReestablish {
11698
- node_id: funded_chan.context.get_counterparty_node_id(),
11699
- msg: funded_chan.get_channel_reestablish(&&logger),
11700
- });
11701
- },
11702
- None => match chan.maybe_get_open_channel(self.chain_hash, &self.logger) {
11703
- Some(OpenChannelMessage::V1(msg)) => {
11704
- pending_msg_events.push(events::MessageSendEvent::SendOpenChannel {
11705
- node_id: chan.context().get_counterparty_node_id(),
11706
- msg,
11707
- });
11708
- },
11709
- #[cfg(dual_funding)]
11710
- Some(OpenChannelMessage::V2(msg)) => {
11711
- pending_msg_events.push(events::MessageSendEvent::SendOpenChannelV2 {
11712
- node_id: chan.context().get_counterparty_node_id(),
11713
- msg,
11714
- });
11715
- },
11716
- None => {},
11717
- },
11682
+ node_id: chan.context().get_counterparty_node_id(),
11683
+ msg,
11684
+ }),
11685
+ ReconnectionMsg::Open(OpenChannelMessage::V1(msg)) =>
11686
+ pending_msg_events.push(events::MessageSendEvent::SendOpenChannel {
11687
+ node_id: chan.context().get_counterparty_node_id(),
11688
+ msg,
11689
+ }),
11690
+ #[cfg(dual_funding)]
11691
+ ReconnectionMsg::Open(OpenChannelMessage::V2(msg)) =>
11692
+ pending_msg_events.push(events::MessageSendEvent::SendOpenChannelV2 {
11693
+ node_id: chan.context().get_counterparty_node_id(),
11694
+ msg,
11695
+ }),
11696
+ ReconnectionMsg::None => {},
11718
11697
}
11719
11698
}
11720
11699
}
0 commit comments