Skip to content

Commit 8c894d1

Browse files
committed
fixup: Serialise ChannelMonitors and send them over inside Peer
1 parent db0d505 commit 8c894d1

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

lightning/src/chain/chainmonitor.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -813,9 +813,9 @@ where
813813
}
814814

815815
fn send_peer_storage(&self, their_node_id: PublicKey) {
816-
static MAX_PEER_STORAGE_SIZE: usize = 65000;
816+
const MAX_PEER_STORAGE_SIZE: usize = 65531;
817817
let random_bytes = self.entropy_source.get_secure_random_bytes();
818-
let random_usize = usize::from_le_bytes(random_bytes[0..8].try_into().unwrap());
818+
let random_usize = usize::from_le_bytes(random_bytes[0..core::mem::size_of::<usize>()].try_into().unwrap());
819819

820820
let monitors = self.monitors.read().unwrap();
821821
let mut monitors_list = PeerStorageMonitorHolderList { monitors: Vec::new() };
@@ -833,22 +833,22 @@ where
833833
let mut ser_chan = VecWriter(Vec::new());
834834
let min_seen_secret = mon.monitor.get_min_seen_secret();
835835
let counterparty_node_id = mon.monitor.get_counterparty_node_id();
836+
let chan_mon = mon.monitor.inner.lock().unwrap();
836837

837-
match write_util(&mon.monitor.inner.lock().unwrap(), true, &mut ser_chan) {
838+
match write_util(&chan_mon, true, &mut ser_chan) {
838839
Ok(_) => {
839-
let mut ser_channel = Vec::new();
840+
// Adding size of peer_storage_monitor.
841+
curr_size += ser_chan.0.len() + 32 + 8 + 32 + 14;
842+
if curr_size > MAX_PEER_STORAGE_SIZE {
843+
break;
844+
}
845+
840846
let peer_storage_monitor = PeerStorageMonitorHolder {
841847
channel_id: *chan_id,
842848
min_seen_secret,
843849
counterparty_node_id,
844850
monitor_bytes: ser_chan.0,
845851
};
846-
peer_storage_monitor.write(&mut ser_channel).unwrap();
847-
848-
curr_size += ser_channel.len();
849-
if curr_size > MAX_PEER_STORAGE_SIZE {
850-
break;
851-
}
852852

853853
monitors_list.monitors.push(peer_storage_monitor);
854854
},

0 commit comments

Comments
 (0)