Skip to content

Commit 735e739

Browse files
committed
f avoid excess write space
1 parent c069f06 commit 735e739

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7180,9 +7180,19 @@ where
71807180
}
71817181

71827182
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+
}
71867196
}
71877197

71887198
let background_events = self.pending_background_events.lock().unwrap();
@@ -7263,10 +7273,7 @@ where
72637273
(5, self.our_network_pubkey, required),
72647274
(6, monitor_update_blocked_actions_per_peer, option),
72657275
(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),
72707277
(9, htlc_purposes, vec_type),
72717278
(11, self.probing_cookie_secret, required),
72727279
});

0 commit comments

Comments
 (0)