Skip to content

Commit c9dc38f

Browse files
committed
f doc why we have the u32::MAX/2 limit
1 parent fdabe11 commit c9dc38f

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

lightning/src/routing/gossip.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,6 +1474,8 @@ impl<L: Deref> ReadableArgs<L> for NetworkGraph<L> where L::Target: Logger {
14741474
channels.insert(chan_id, chan_info);
14751475
}
14761476
let nodes_count: u64 = Readable::read(reader)?;
1477+
// There shouln't be any where near `u32::MAX` nodes, and we need some headroom to insert
1478+
// new nodes during sync, so reject any graphs claiming more than `u32::MAX / 2` nodes.
14771479
if nodes_count > u32::max_value() as u64 / 2 { return Err(DecodeError::InvalidValue); }
14781480
// In Nov, 2023 there were about 69K channels; we cap allocations to 1.5x that.
14791481
let mut nodes = IndexedMap::with_capacity(cmp::min(nodes_count as usize, 103500));

0 commit comments

Comments
 (0)