@@ -732,9 +732,11 @@ where
732
732
& self , funding_txo : OutPoint , update : Option < & ChannelMonitorUpdate > ,
733
733
monitor : & ChannelMonitor < ChannelSigner > ,
734
734
) -> chain:: ChannelMonitorUpdateStatus {
735
+ const LEGACY_CLOSED_CHANNEL_UPDATE_ID : u64 = u64:: MAX ;
735
736
if let Some ( update) = update {
736
- if update. update_id != u64:: MAX && update. update_id % self . maximum_pending_updates != 0
737
- {
737
+ let persist_update = update. update_id != LEGACY_CLOSED_CHANNEL_UPDATE_ID
738
+ && update. update_id % self . maximum_pending_updates != 0 ;
739
+ if persist_update {
738
740
let monitor_name = MonitorName :: from ( funding_txo) ;
739
741
let update_name = UpdateName :: from ( update. update_id ) ;
740
742
match self . kv_store . write (
@@ -761,22 +763,24 @@ where
761
763
// In case of channel-close monitor update, we need to read old monitor before persisting
762
764
// the new one in order to determine the cleanup range.
763
765
let maybe_old_monitor = match monitor. get_latest_update_id ( ) {
764
- u64 :: MAX => self . read_monitor ( & monitor_name) . ok ( ) ,
766
+ LEGACY_CLOSED_CHANNEL_UPDATE_ID => self . read_monitor ( & monitor_name) . ok ( ) ,
765
767
_ => None ,
766
768
} ;
767
769
768
770
// We could write this update, but it meets criteria of our design that calls for a full monitor write.
769
771
let monitor_update_status = self . persist_new_channel ( funding_txo, monitor) ;
770
772
771
773
if let chain:: ChannelMonitorUpdateStatus :: Completed = monitor_update_status {
772
- let cleanup_range = if monitor. get_latest_update_id ( ) == u64:: MAX {
774
+ let channel_closed_legacy =
775
+ monitor. get_latest_update_id ( ) == LEGACY_CLOSED_CHANNEL_UPDATE_ID ;
776
+ let cleanup_range = if channel_closed_legacy {
773
777
// If there is an error while reading old monitor, we skip clean up.
774
778
maybe_old_monitor. map ( |( _, ref old_monitor) | {
775
779
let start = old_monitor. get_latest_update_id ( ) ;
776
- // We never persist an update with update_id = u64::MAX
780
+ // We never persist an update with the leagacy closed update_id
777
781
let end = cmp:: min (
778
782
start. saturating_add ( self . maximum_pending_updates ) ,
779
- u64 :: MAX - 1 ,
783
+ LEGACY_CLOSED_CHANNEL_UPDATE_ID - 1 ,
780
784
) ;
781
785
( start, end)
782
786
} )
0 commit comments