@@ -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`
@@ -9863,6 +9866,9 @@ where
98639866 assert!(self.context.channel_state.is_monitor_update_in_progress());
98649867 self.context.channel_state.clear_monitor_update_in_progress();
98659868 assert_eq!(self.blocked_monitor_updates_pending(), 0);
9869+ // Some cases below may not strictly require ChannelManager persistence, but we err on
9870+ // the conservative side to avoid missing state changes.
9871+ let mut requires_channel_manager_persistence = false;
98669872
98679873 // We want to clear that the monitor update for our `tx_signatures` has completed, but
98689874 // we may still need to hold back the message until it's ready to be sent.
@@ -9890,6 +9896,7 @@ where
98909896 splice_negotiated: None,
98919897 splice_locked: None,
98929898 });
9899+ requires_channel_manager_persistence = true;
98939900 if let Some(funding_tx) = signing_session.signed_tx() {
98949901 self.on_tx_signatures_exchange(
98959902 funding_tx_signed.as_mut().unwrap(),
@@ -9914,7 +9921,8 @@ where
99149921 {
99159922 // Broadcast only if not yet confirmed
99169923 if self.funding.get_funding_tx_confirmation_height().is_none() {
9917- funding_broadcastable = Some(funding_transaction.clone())
9924+ funding_broadcastable = Some(funding_transaction.clone());
9925+ requires_channel_manager_persistence = true;
99189926 }
99199927 }
99209928 }
@@ -9940,36 +9948,45 @@ where
99409948 assert!(!self.funding.is_outbound() || self.context.minimum_depth == Some(0),
99419949 "Funding transaction broadcast by the local client before it should have - LDK didn't do it!");
99429950 self.context.monitor_pending_channel_ready = false;
9943- self.get_channel_ready(logger)
9951+ let channel_ready = self.get_channel_ready(logger);
9952+ requires_channel_manager_persistence |= channel_ready.is_some();
9953+ channel_ready
99449954 } else { None };
99459955
99469956 let announcement_sigs = self.get_announcement_sigs(node_signer, chain_hash, user_config, best_block_height, logger);
9957+ requires_channel_manager_persistence |= announcement_sigs.is_some();
99479958
99489959 let mut accepted_htlcs = Vec::new();
99499960 mem::swap(&mut accepted_htlcs, &mut self.context.monitor_pending_forwards);
9961+ requires_channel_manager_persistence |= !accepted_htlcs.is_empty();
99509962 let mut failed_htlcs = Vec::new();
99519963 mem::swap(&mut failed_htlcs, &mut self.context.monitor_pending_failures);
9964+ requires_channel_manager_persistence |= !failed_htlcs.is_empty();
99529965 let mut finalized_claimed_htlcs = Vec::new();
99539966 mem::swap(&mut finalized_claimed_htlcs, &mut self.context.monitor_pending_finalized_fulfills);
9967+ requires_channel_manager_persistence |= !finalized_claimed_htlcs.is_empty();
99549968 let mut pending_update_adds = Vec::new();
99559969 mem::swap(&mut pending_update_adds, &mut self.context.monitor_pending_update_adds);
9956- let committed_outbound_htlc_sources = self.context.pending_outbound_htlcs.iter().filter_map(|htlc| {
9970+ requires_channel_manager_persistence |= !pending_update_adds.is_empty();
9971+ let committed_outbound_htlc_sources: Vec<(HTLCPreviousHopData, u64)> = self.context.pending_outbound_htlcs.iter().filter_map(|htlc| {
99579972 if let &OutboundHTLCState::LocalAnnounced(_) = &htlc.state {
99589973 if let HTLCSource::PreviousHopData(prev_hop_data) = &htlc.source {
99599974 return Some((prev_hop_data.clone(), htlc.amount_msat))
99609975 }
99619976 }
99629977 None
99639978 }).collect();
9979+ requires_channel_manager_persistence |= !committed_outbound_htlc_sources.is_empty();
99649980
99659981 if self.context.channel_state.is_peer_disconnected() {
99669982 self.context.monitor_pending_revoke_and_ack = false;
99679983 self.context.monitor_pending_commitment_signed = false;
99689984 return MonitorRestoreUpdates {
99699985 raa: None, commitment_update: None, commitment_order: RAACommitmentOrder::RevokeAndACKFirst,
99709986 accepted_htlcs, failed_htlcs, finalized_claimed_htlcs, pending_update_adds,
9971- funding_broadcastable, channel_ready, announcement_sigs, funding_tx_signed,
9972- channel_ready_order, committed_outbound_htlc_sources
9987+ funding_broadcastable, channel_ready, channel_ready_order, announcement_sigs,
9988+ funding_tx_signed, committed_outbound_htlc_sources,
9989+ requires_channel_manager_persistence,
99739990 };
99749991 }
99759992
@@ -9999,8 +10016,9 @@ where
999910016 match commitment_order { RAACommitmentOrder::CommitmentFirst => "commitment", RAACommitmentOrder::RevokeAndACKFirst => "RAA"});
1000010017 MonitorRestoreUpdates {
1000110018 raa, commitment_update, commitment_order, accepted_htlcs, failed_htlcs, finalized_claimed_htlcs,
10002- pending_update_adds, funding_broadcastable, channel_ready, announcement_sigs, funding_tx_signed,
10003- channel_ready_order, committed_outbound_htlc_sources
10019+ pending_update_adds, funding_broadcastable, channel_ready, channel_ready_order,
10020+ announcement_sigs, funding_tx_signed, committed_outbound_htlc_sources,
10021+ requires_channel_manager_persistence,
1000410022 }
1000510023 }
1000610024
0 commit comments