Skip to content

Commit ff9c956

Browse files
committed
Tighten peer storage regression test to verify boundary
Increase num_monitors from 200 to 600 and add a lower-bound assertion to ensure the test actually reaches the MAX_PEER_STORAGE_SIZE boundary. This prevents the test from silently passing when PEER_STORAGE_OVERHEAD is not properly accounted for (e.g., set to 0). Addresses joostjager's review feedback on PR #4746.
1 parent 4fed989 commit ff9c956

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

lightning/src/chain/chainmonitor.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2253,9 +2253,13 @@ mod tests {
22532253
false,
22542254
);
22552255

2256-
// Create enough monitors to stress the peer storage size limit. Each dummy monitor
2257-
// is ~500 bytes, so ~200 monitors is enough to exceed 65531.
2258-
let num_monitors = 200;
2256+
// Create enough monitors to stress the peer storage size limit such that the total
2257+
// plaintext serialized_length() exceeds MAX_PEER_STORAGE_SIZE, ensuring the selection
2258+
// loop actually hits the cap. 600 monitors at ~300 bytes each = ~180K, well above the
2259+
// 65531 max, so the encrypted output will be forced to the boundary regardless of
2260+
// the random selection order. This guarantees the test catches the difference when
2261+
// PEER_STORAGE_OVERHEAD is not accounted for.
2262+
let num_monitors = 600;
22592263
let mut counterparty_id = None;
22602264
for i in 0..num_monitors {
22612265
let mut chan_id = [0u8; 32];
@@ -2287,6 +2291,13 @@ mod tests {
22872291
msg.data.len(),
22882292
MAX_PEER_STORAGE_SIZE,
22892293
);
2294+
assert!(
2295+
msg.data.len() > MAX_PEER_STORAGE_SIZE - 500,
2296+
"peer_storage blob length {} is too far from the {} byte limit, \
2297+
boundary was not meaningfully tested",
2298+
msg.data.len(),
2299+
MAX_PEER_STORAGE_SIZE,
2300+
);
22902301
}
22912302
}
22922303
assert!(saw_peer_storage, "expected a SendPeerStorage message");

0 commit comments

Comments
 (0)