Skip to content

Commit dcf5477

Browse files
authored
fix(l1): removed unnecesary state clone (#4117)
After spawned upgrade, there is no need to clone `RLPxConnection` state. But we left a `clone()` in the code that was causing performance issues on high load of peer messages. This was discovered analyzing a flame graph by @juan518munoz : <img width="2934" height="1598" alt="image" src="https://github.com/user-attachments/assets/041264cd-63c9-4855-85ad-8d277bdaac8e" /> **Description** This removes the cost of the inner state `clone()` showing some nice improvement on a high load test (two reth and one ethrex nodes being spammed by about 10.000 transactions per slot) Ggas/s on the ethrex node: After: (the second peak is due to peers disconnecting) <img width="410" height="299" alt="image" src="https://github.com/user-attachments/assets/3ef44258-0390-4cff-8083-b96d710f7d53" /> Before: (peers remained connected through all the test) <img width="438" height="300" alt="image" src="https://github.com/user-attachments/assets/eed2a1b4-3106-4498-8bbc-9d7f994b11e7" />
1 parent b4e7286 commit dcf5477

File tree

1 file changed

+10
-14
lines changed
  • crates/networking/p2p/rlpx/connection

1 file changed

+10
-14
lines changed

crates/networking/p2p/rlpx/connection/server.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -266,48 +266,48 @@ impl GenServer for RLPxConnection {
266266
message: Self::CastMsg,
267267
_handle: &RLPxConnectionHandle,
268268
) -> CastResponse {
269-
if let InnerState::Established(mut established_state) = self.inner_state.clone() {
269+
if let InnerState::Established(ref mut established_state) = self.inner_state {
270270
let peer_supports_l2 = established_state.l2_state.connection_state().is_ok();
271271
let result = match message {
272272
Self::CastMsg::PeerMessage(message) => {
273273
log_peer_debug(
274274
&established_state.node,
275275
&format!("Received peer message: {message}"),
276276
);
277-
handle_peer_message(&mut established_state, message).await
277+
handle_peer_message(established_state, message).await
278278
}
279279
Self::CastMsg::BackendMessage(message) => {
280280
log_peer_debug(
281281
&established_state.node,
282282
&format!("Received backend message: {message}"),
283283
);
284-
handle_backend_message(&mut established_state, message).await
284+
handle_backend_message(established_state, message).await
285285
}
286286
Self::CastMsg::SendPing => {
287-
send(&mut established_state, Message::Ping(PingMessage {})).await
287+
send(established_state, Message::Ping(PingMessage {})).await
288288
}
289289
Self::CastMsg::SendNewPooledTxHashes => {
290-
send_new_pooled_tx_hashes(&mut established_state).await
290+
send_new_pooled_tx_hashes(established_state).await
291291
}
292292
Self::CastMsg::BroadcastMessage(id, msg) => {
293293
log_peer_debug(
294294
&established_state.node,
295295
&format!("Received broadcasted message: {msg}"),
296296
);
297-
handle_broadcast(&mut established_state, (id, msg)).await
297+
handle_broadcast(established_state, (id, msg)).await
298298
}
299299
Self::CastMsg::BlockRangeUpdate => {
300300
log_peer_debug(&established_state.node, "Block Range Update");
301-
handle_block_range_update(&mut established_state).await
301+
handle_block_range_update(established_state).await
302302
}
303303
Self::CastMsg::L2(msg) if peer_supports_l2 => {
304304
log_peer_debug(&established_state.node, "Handling cast for L2 msg: {msg:?}");
305305
match msg {
306306
L2Cast::BatchBroadcast => {
307-
l2_connection::send_sealed_batch(&mut established_state).await
307+
l2_connection::send_sealed_batch(established_state).await
308308
}
309309
L2Cast::BlockBroadcast => {
310-
l2::l2_connection::send_new_block(&mut established_state).await
310+
l2::l2_connection::send_new_block(established_state).await
311311
}
312312
}
313313
}
@@ -345,15 +345,11 @@ impl GenServer for RLPxConnection {
345345
}
346346
}
347347
}
348-
349-
// Update the state
350-
self.inner_state = InnerState::Established(established_state);
351-
CastResponse::NoReply
352348
} else {
353349
// Received a Cast message but connection is not ready. Log an error but keep the connection alive.
354350
error!("Connection not yet established");
355-
CastResponse::NoReply
356351
}
352+
CastResponse::NoReply
357353
}
358354

359355
async fn teardown(self, _handle: &GenServerHandle<Self>) -> Result<(), Self::Error> {

0 commit comments

Comments
 (0)