You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Rate limit the number of certificate requests sent to the peer.
@@ -1357,14 +1412,29 @@ impl<N: Network> Transport<N> for Gateway<N> {
1357
1412
}
1358
1413
1359
1414
/// Broadcasts the given event to all connected peers.
1360
-
// TODO(ljedrz): the event should be checked for the presence of Data::Object, and
1361
-
// serialized in advance if it's there.
1362
-
fnbroadcast(&self,event:Event<N>){
1415
+
fnbroadcast(&self,mutevent:Event<N>){
1363
1416
// Ensure there are connected peers.
1364
1417
ifself.number_of_connected_peers() > 0{
1365
1418
let self_ = self.clone();
1366
1419
let connected_peers = self.connected_peers();
1367
1420
tokio::spawn(asyncmove{
1421
+
// Serialize the event's payload once, rather than once per recipient; every
1422
+
// recipient then shares the resulting buffer. `Transport::send` would otherwise do
1423
+
// this separately for each peer below.
1424
+
if event.has_unserialized_payload(){
1425
+
let name = event.name();
1426
+
event = matchspawn_blocking!({
1427
+
letmut event = event;
1428
+
event.serialize_payload()?;
1429
+
Ok(event)
1430
+
}){
1431
+
Ok(event) => event,
1432
+
Err(err) => {
1433
+
error!("{CONTEXT} Unable to serialize '{name}' for broadcast - {err}");
1434
+
return;
1435
+
}
1436
+
};
1437
+
}
1368
1438
// Iterate through all connected peers.
1369
1439
for peer_ip in connected_peers {
1370
1440
// Send the event to the peer.
@@ -1408,12 +1478,11 @@ impl<N: Network> Reading for Gateway<N> {
1408
1478
Ok(())
1409
1479
}
1410
1480
1411
-
/// Computes the depth of per-connection queues used to process inbound messages, sufficient to process the maximum expected load at any givent moment.
1481
+
/// Computes the depth of per-connection queues used to process inbound messages, sufficient to process the maximum expected load at any given moment.
1412
1482
/// The greater it is, the more inbound messages the node can enqueue, but a too large value can make the node more susceptible to DoS attacks.
1483
+
/// See [`per_connection_queue_depth`] for the derivation.
1413
1484
fnmessage_queue_depth(&self) -> usize{
1414
-
2*BatchHeader::<N>::MAX_GC_ROUNDS
1415
-
*N::LATEST_MAX_CERTIFICATES()asusize
1416
-
*BatchHeader::<N>::MAX_TRANSMISSIONS_PER_BATCH
1485
+
per_connection_queue_depth::<N>()
1417
1486
}
1418
1487
}
1419
1488
@@ -1428,13 +1497,12 @@ impl<N: Network> Writing for Gateway<N> {
1428
1497
Default::default()
1429
1498
}
1430
1499
1431
-
/// Computes the depth of per-connection queues used to send outbound messages, sufficient to process the maximum expected load at any givent moment.
1432
-
/// The greater it is, the more outbound messages the node can enqueue. A too large value large value might obscure potential issues with your implementation
1433
-
/// (like slow serialization) or network.
1500
+
/// Computes the depth of per-connection queues used to send outbound messages, sufficient to process the maximum expected load at any given moment.
1501
+
/// The greater it is, the more outbound messages the node can enqueue. A too large value might obscure potential issues with your implementation
1502
+
/// (like slow serialization) or network, and lets a peer that stops reading its socket pin an unreasonable amount of our heap.
1503
+
/// See [`per_connection_queue_depth`] for the derivation.
1434
1504
fnmessage_queue_depth(&self) -> usize{
1435
-
2*BatchHeader::<N>::MAX_GC_ROUNDS
1436
-
*N::LATEST_MAX_CERTIFICATES()asusize
1437
-
*BatchHeader::<N>::MAX_TRANSMISSIONS_PER_BATCH
1505
+
per_connection_queue_depth::<N>()
1438
1506
}
1439
1507
}
1440
1508
@@ -2333,6 +2401,31 @@ mod prop_tests {
2333
2401
2334
2402
typeCurrentNetwork = MainnetV0;
2335
2403
2404
+
/// The per-connection queues are sized from the fetch-timeout window, not the GC window.
2405
+
///
2406
+
/// Each slot can hold a full `Transmission`, so the depth is a direct multiplier on the heap a
2407
+
/// single peer can pin by not reading its socket. Pin the derivation so a regression is loud.
0 commit comments