@@ -1305,6 +1305,11 @@ pub(crate) struct ChannelMonitorImpl<Signer: EcdsaChannelSigner> {
1305
1305
// found at `Self::funding`. We don't use the term "renegotiated", as the currently locked
1306
1306
// `FundingScope` could be one that was renegotiated.
1307
1307
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 ,
1308
1313
}
1309
1314
1310
1315
// Returns a `&FundingScope` for the one we are currently observing/handling commitment transactions
@@ -1887,6 +1892,8 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
1887
1892
prev_holder_htlc_data : None ,
1888
1893
1889
1894
alternative_funding_confirmed : None ,
1895
+
1896
+ written_by_0_1_or_later : true ,
1890
1897
} )
1891
1898
}
1892
1899
@@ -2020,6 +2027,10 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
2020
2027
self . inner . lock ( ) . unwrap ( ) . get_funding_txo ( )
2021
2028
}
2022
2029
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
+
2023
2034
/// Gets the funding script of the channel this ChannelMonitor is monitoring for.
2024
2035
pub fn get_funding_script ( & self ) -> ScriptBuf {
2025
2036
self . inner . lock ( ) . unwrap ( ) . get_funding_script ( )
@@ -6372,6 +6383,9 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
6372
6383
( 32 , pending_funding, optional_vec) ,
6373
6384
( 34 , alternative_funding_confirmed, option) ,
6374
6385
} ) ;
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 ( ) ;
6375
6389
if let Some ( payment_preimages_with_info) = payment_preimages_with_info {
6376
6390
if payment_preimages_with_info. len ( ) != payment_preimages. len ( ) {
6377
6391
return Err ( DecodeError :: InvalidValue ) ;
@@ -6542,6 +6556,8 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
6542
6556
prev_holder_htlc_data,
6543
6557
6544
6558
alternative_funding_confirmed,
6559
+
6560
+ written_by_0_1_or_later,
6545
6561
} ) ) )
6546
6562
}
6547
6563
}
0 commit comments