@@ -171,7 +171,11 @@ impl Writer for VecWriter {
171171/// Note that such "being persisted" `ChannelMonitor`s are stored in `ChannelManager` and will
172172/// simply be replayed on startup.
173173struct LatestMonitorState {
174- /// The latest monitor id which we told LDK we've persisted
174+ /// The latest monitor id which we told LDK we've persisted.
175+ ///
176+ /// Note that there may still be earlier pending monitor updates in [`Self::pending_monitors`]
177+ /// which we haven't yet completed. We're allowed to reload with those as well, at least until
178+ /// they're completed.
175179 persisted_monitor_id : u64 ,
176180 /// The latest serialized `ChannelMonitor` that we told LDK we persisted.
177181 persisted_monitor : Vec < u8 > ,
@@ -726,18 +730,18 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
726730 let mut monitors = new_hash_map ( ) ;
727731 let mut old_monitors = old_monitors. latest_monitors . lock ( ) . unwrap ( ) ;
728732 for ( channel_id, mut prev_state) in old_monitors. drain ( ) {
729- let serialized_mon = if use_old_mons % 3 == 0 {
733+ let ( mon_id , serialized_mon) = if use_old_mons % 3 == 0 {
730734 // Reload with the oldest `ChannelMonitor` (the one that we already told
731735 // `ChannelManager` we finished persisting).
732- prev_state. persisted_monitor
736+ ( prev_state. persisted_monitor_id , prev_state . persisted_monitor )
733737 } else if use_old_mons % 3 == 1 {
734738 // Reload with the second-oldest `ChannelMonitor`
735- let old_mon = prev_state. persisted_monitor ;
736- prev_state. pending_monitors . drain ( ..) . next ( ) . map ( | ( _ , v ) | v ) . unwrap_or ( old_mon)
739+ let old_mon = ( prev_state. persisted_monitor_id , prev_state . persisted_monitor ) ;
740+ prev_state. pending_monitors . drain ( ..) . next ( ) . unwrap_or ( old_mon)
737741 } else {
738742 // Reload with the newest `ChannelMonitor`
739- let old_mon = prev_state. persisted_monitor ;
740- prev_state. pending_monitors . pop ( ) . map ( | ( _ , v ) | v ) . unwrap_or ( old_mon)
743+ let old_mon = ( prev_state. persisted_monitor_id , prev_state . persisted_monitor ) ;
744+ prev_state. pending_monitors . pop ( ) . unwrap_or ( old_mon)
741745 } ;
742746 // Use a different value of `use_old_mons` if we have another monitor (only for node B)
743747 // by shifting `use_old_mons` one in base-3.
@@ -750,6 +754,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
750754 monitors. insert ( channel_id, mon. 1 ) ;
751755 // Update the latest `ChannelMonitor` state to match what we just told LDK.
752756 prev_state. persisted_monitor = serialized_mon;
757+ prev_state. persisted_monitor_id = mon_id;
753758 // Wipe any `ChannelMonitor`s which we never told LDK we finished persisting,
754759 // considering them discarded. LDK should replay these for us as they're stored in
755760 // the `ChannelManager`.
0 commit comments