@@ -7180,9 +7180,19 @@ where
7180
7180
}
7181
7181
7182
7182
let events = self . pending_events . lock ( ) . unwrap ( ) ;
7183
- ( events. len ( ) as u64 ) . write ( writer) ?;
7184
- for ( event, _) in events. iter ( ) {
7185
- event. write ( writer) ?;
7183
+ // LDK versions prior to 0.0.115 don't support post-event actions, thus if there's no
7184
+ // actions at all, skip writing the required TLV. Otherwise, pre-0.0.114 versions will
7185
+ // refuse to read the new ChannelManager.
7186
+ let events_not_backwards_compatible = events. iter ( ) . any ( |( _, action) | action. is_some ( ) ) ;
7187
+ if events_not_backwards_compatible {
7188
+ // If we're gonna write a even TLV that will overwrite our events anyway we might as
7189
+ // well save the space and not write any events here.
7190
+ 0u64 . write ( writer) ?;
7191
+ } else {
7192
+ ( events. len ( ) as u64 ) . write ( writer) ?;
7193
+ for ( event, _) in events. iter ( ) {
7194
+ event. write ( writer) ?;
7195
+ }
7186
7196
}
7187
7197
7188
7198
let background_events = self . pending_background_events . lock ( ) . unwrap ( ) ;
@@ -7263,10 +7273,7 @@ where
7263
7273
( 5 , self . our_network_pubkey, required) ,
7264
7274
( 6 , monitor_update_blocked_actions_per_peer, option) ,
7265
7275
( 7 , self . fake_scid_rand_bytes, required) ,
7266
- // LDK versions prior to 0.0.115 don't support post-event actions, thus if there's no
7267
- // actions at all, skip writing the required TLV. Otherwise, pre-0.0.114 versions will
7268
- // refuse to read the new ChannelManager.
7269
- ( 8 , if events. iter( ) . any( |( _, action) | action. is_some( ) ) { Some ( & * events) } else { None } , option) ,
7276
+ ( 8 , if events_not_backwards_compatible { Some ( & * events) } else { None } , option) ,
7270
7277
( 9 , htlc_purposes, vec_type) ,
7271
7278
( 11 , self . probing_cookie_secret, required) ,
7272
7279
} ) ;
0 commit comments