@@ -1236,6 +1236,9 @@ pub(super) struct MonitorRestoreUpdates {
12361236 /// (the outbound edge), along with their outbound amounts. Useful to store in the inbound HTLC
12371237 /// to ensure it gets resolved.
12381238 pub committed_outbound_htlc_sources: Vec<(HTLCPreviousHopData, u64)>,
1239+ /// Whether the restoration changed serialized channel state that needs ChannelManager
1240+ /// persistence.
1241+ pub requires_channel_manager_persistence: bool,
12391242}
12401243
12411244/// The return value of `signer_maybe_unblocked`
@@ -9860,6 +9863,9 @@ where
98609863 assert!(self.context.channel_state.is_monitor_update_in_progress());
98619864 self.context.channel_state.clear_monitor_update_in_progress();
98629865 assert_eq!(self.blocked_monitor_updates_pending(), 0);
9866+ // Some cases below may not strictly require ChannelManager persistence, but we err on
9867+ // the conservative side to avoid missing state changes.
9868+ let mut requires_channel_manager_persistence = false;
98639869
98649870 // We want to clear that the monitor update for our `tx_signatures` has completed, but
98659871 // we may still need to hold back the message until it's ready to be sent.
@@ -9887,6 +9893,7 @@ where
98879893 splice_negotiated: None,
98889894 splice_locked: None,
98899895 });
9896+ requires_channel_manager_persistence = true;
98909897 if let Some(funding_tx) = signing_session.signed_tx() {
98919898 self.on_tx_signatures_exchange(
98929899 funding_tx_signed.as_mut().unwrap(),
@@ -9911,7 +9918,8 @@ where
99119918 {
99129919 // Broadcast only if not yet confirmed
99139920 if self.funding.get_funding_tx_confirmation_height().is_none() {
9914- funding_broadcastable = Some(funding_transaction.clone())
9921+ funding_broadcastable = Some(funding_transaction.clone());
9922+ requires_channel_manager_persistence = true;
99159923 }
99169924 }
99179925 }
@@ -9937,36 +9945,45 @@ where
99379945 assert!(!self.funding.is_outbound() || self.context.minimum_depth == Some(0),
99389946 "Funding transaction broadcast by the local client before it should have - LDK didn't do it!");
99399947 self.context.monitor_pending_channel_ready = false;
9940- self.get_channel_ready(logger)
9948+ let channel_ready = self.get_channel_ready(logger);
9949+ requires_channel_manager_persistence |= channel_ready.is_some();
9950+ channel_ready
99419951 } else { None };
99429952
99439953 let announcement_sigs = self.get_announcement_sigs(node_signer, chain_hash, user_config, best_block_height, logger);
9954+ requires_channel_manager_persistence |= announcement_sigs.is_some();
99449955
99459956 let mut accepted_htlcs = Vec::new();
99469957 mem::swap(&mut accepted_htlcs, &mut self.context.monitor_pending_forwards);
9958+ requires_channel_manager_persistence |= !accepted_htlcs.is_empty();
99479959 let mut failed_htlcs = Vec::new();
99489960 mem::swap(&mut failed_htlcs, &mut self.context.monitor_pending_failures);
9961+ requires_channel_manager_persistence |= !failed_htlcs.is_empty();
99499962 let mut finalized_claimed_htlcs = Vec::new();
99509963 mem::swap(&mut finalized_claimed_htlcs, &mut self.context.monitor_pending_finalized_fulfills);
9964+ requires_channel_manager_persistence |= !finalized_claimed_htlcs.is_empty();
99519965 let mut pending_update_adds = Vec::new();
99529966 mem::swap(&mut pending_update_adds, &mut self.context.monitor_pending_update_adds);
9953- let committed_outbound_htlc_sources = self.context.pending_outbound_htlcs.iter().filter_map(|htlc| {
9967+ requires_channel_manager_persistence |= !pending_update_adds.is_empty();
9968+ let committed_outbound_htlc_sources: Vec<(HTLCPreviousHopData, u64)> = self.context.pending_outbound_htlcs.iter().filter_map(|htlc| {
99549969 if let &OutboundHTLCState::LocalAnnounced(_) = &htlc.state {
99559970 if let HTLCSource::PreviousHopData(prev_hop_data) = &htlc.source {
99569971 return Some((prev_hop_data.clone(), htlc.amount_msat))
99579972 }
99589973 }
99599974 None
99609975 }).collect();
9976+ requires_channel_manager_persistence |= !committed_outbound_htlc_sources.is_empty();
99619977
99629978 if self.context.channel_state.is_peer_disconnected() {
99639979 self.context.monitor_pending_revoke_and_ack = false;
99649980 self.context.monitor_pending_commitment_signed = false;
99659981 return MonitorRestoreUpdates {
99669982 raa: None, commitment_update: None, commitment_order: RAACommitmentOrder::RevokeAndACKFirst,
99679983 accepted_htlcs, failed_htlcs, finalized_claimed_htlcs, pending_update_adds,
9968- funding_broadcastable, channel_ready, announcement_sigs, funding_tx_signed,
9969- channel_ready_order, committed_outbound_htlc_sources
9984+ funding_broadcastable, channel_ready, channel_ready_order, announcement_sigs,
9985+ funding_tx_signed, committed_outbound_htlc_sources,
9986+ requires_channel_manager_persistence,
99709987 };
99719988 }
99729989
@@ -9996,8 +10013,9 @@ where
999610013 match commitment_order { RAACommitmentOrder::CommitmentFirst => "commitment", RAACommitmentOrder::RevokeAndACKFirst => "RAA"});
999710014 MonitorRestoreUpdates {
999810015 raa, commitment_update, commitment_order, accepted_htlcs, failed_htlcs, finalized_claimed_htlcs,
9999- pending_update_adds, funding_broadcastable, channel_ready, announcement_sigs, funding_tx_signed,
10000- channel_ready_order, committed_outbound_htlc_sources
10016+ pending_update_adds, funding_broadcastable, channel_ready, channel_ready_order,
10017+ announcement_sigs, funding_tx_signed, committed_outbound_htlc_sources,
10018+ requires_channel_manager_persistence,
1000110019 }
1000210020 }
1000310021
0 commit comments