Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR modifies the block processing logic to skip unnecessary operations when no new block heads are available. The change prevents the code from attempting to receive block heads when the receiver queue is empty, improving efficiency.
- Restructures the conditional logic to check if the receiver queue is empty first
- Adds an early
continuestatement when no block heads are available - Maintains the existing 60-second timeout warning functionality
| tracing::warn!("No new block heads received for 60 seconds, waiting..."); | ||
| receiver_state_update_timestamp = Instant::now(); | ||
| } | ||
| continue; |
There was a problem hiding this comment.
The continue statement will skip the block_heads_rx.recv().await call entirely when the queue is empty, but this creates a busy loop that consumes CPU unnecessarily. The original logic allowed the recv().await call to block and wait for new messages, which is more efficient than continuously polling.
|
why are we having If so, we can just do it in a tokio::select so that we don't need to poll as fast just to check if a block is ready or not since our warning is every 60s. We can probably just do 20s, and leave it up to the runtime to wake the recv when a new block is ready. let mut interval = tokio::time::interval(Duration::from_secs(20));
tokio::select! {
_ = interval.tick() => {
if update.elapsed() > Duration::from_secs(60) { ... }
}
block_heads.recv() => {
...
}
} |
No description provided.