@@ -1305,6 +1305,11 @@ pub(crate) struct ChannelMonitorImpl<Signer: EcdsaChannelSigner> {
13051305 // found at `Self::funding`. We don't use the term "renegotiated", as the currently locked
13061306 // `FundingScope` could be one that was renegotiated.
13071307 alternative_funding_confirmed : Option < ( Txid , u32 ) > ,
1308+
1309+ /// [`ChannelMonitor`]s written by LDK prior to 0.1 need to be re-persisted after startup. To
1310+ /// make deciding whether to do so simple, here we track whether this monitor was last written
1311+ /// prior to 0.1.
1312+ written_by_0_1_or_later : bool ,
13081313}
13091314
13101315// Returns a `&FundingScope` for the one we are currently observing/handling commitment transactions
@@ -1887,6 +1892,8 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
18871892 prev_holder_htlc_data : None ,
18881893
18891894 alternative_funding_confirmed : None ,
1895+
1896+ written_by_0_1_or_later : true ,
18901897 } )
18911898 }
18921899
@@ -2020,6 +2027,10 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
20202027 self . inner . lock ( ) . unwrap ( ) . get_funding_txo ( )
20212028 }
20222029
2030+ pub ( crate ) fn written_by_0_1_or_later ( & self ) -> bool {
2031+ self . inner . lock ( ) . unwrap ( ) . written_by_0_1_or_later
2032+ }
2033+
20232034 /// Gets the funding script of the channel this ChannelMonitor is monitoring for.
20242035 pub fn get_funding_script ( & self ) -> ScriptBuf {
20252036 self . inner . lock ( ) . unwrap ( ) . get_funding_script ( )
@@ -6372,6 +6383,9 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
63726383 ( 32 , pending_funding, optional_vec) ,
63736384 ( 34 , alternative_funding_confirmed, option) ,
63746385 } ) ;
6386+ // Note that `payment_preimages_with_info` was added (and is always written) in LDK 0.1, so
6387+ // we can use it to determine if this monitor was last written by LDK 0.1 or later.
6388+ let written_by_0_1_or_later = payment_preimages_with_info. is_some ( ) ;
63756389 if let Some ( payment_preimages_with_info) = payment_preimages_with_info {
63766390 if payment_preimages_with_info. len ( ) != payment_preimages. len ( ) {
63776391 return Err ( DecodeError :: InvalidValue ) ;
@@ -6542,6 +6556,8 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
65426556 prev_holder_htlc_data,
65436557
65446558 alternative_funding_confirmed,
6559+
6560+ written_by_0_1_or_later,
65456561 } ) ) )
65466562 }
65476563}
0 commit comments