Applies a flashblock, unless the node has already canonicalized its block. Executing a flashblock for an already-canonical block cannot produce a publishable snapshot, and doing it anyway is what let the queue lag sustain itself: the backlog of superseded payloads consumed the processor while fresh payloads waited behind them. `FlashblocksState` rejects payloads that are already superseded when t
(
&self,
prev_pending_blocks: Option<Arc<PendingBlocks>>,
flashblock: Flashblock,
)
| 302 | /// what reaches here is a payload that was fresh when queued and went stale while waiting, |
| 303 | /// or one replayed from the cache after its canonical block landed. |
| 304 | async fn apply_flashblock( |
| 305 | &self, |
| 306 | prev_pending_blocks: Option<Arc<PendingBlocks>>, |
| 307 | flashblock: Flashblock, |
| 308 | ) { |
| 309 | if self.is_superseded(&flashblock) { |
| 310 | debug!( |
| 311 | message = "skipping flashblock for already canonical block", |
| 312 | block_number = flashblock.metadata.block_number, |
| 313 | flashblock_index = flashblock.index, |
| 314 | ); |
| 315 | Metrics::flashblock_superseded().increment(1); |
| 316 | return; |
| 317 | } |
| 318 | |
| 319 | let start_time = Instant::now(); |
| 320 | match self.process_flashblock(prev_pending_blocks, &flashblock) { |
| 321 | Ok(new_pending_blocks) => { |
| 322 | if let Some(ref pb) = new_pending_blocks { |
| 323 | _ = self.sender.send(Arc::clone(pb)); |
| 324 | } |
| 325 | self.pending_blocks.swap(new_pending_blocks); |
| 326 | Metrics::block_processing_duration().record(start_time.elapsed()); |
| 327 | } |
| 328 | Err(e) => { |
| 329 | match e { |
| 330 | StateProcessorError::Provider(ProviderError::MissingCanonicalHeader { |
| 331 | .. |
| 332 | }) => { |
| 333 | let inserted = self.cache.lock().await.insert(flashblock); |
| 334 | if inserted { |
| 335 | debug!(message = "cached flashblock pending canonical block", error = %e); |
| 336 | return; |
| 337 | } |
| 338 | } |
| 339 | StateProcessorError::MissingFirstFlashblock => { |
| 340 | let mut cache = self.cache.lock().await; |
| 341 | // this error should only occur for non-zero index flashblocks, but check here for index safety |
| 342 | if flashblock.index > 0 |
| 343 | && cache.has_flashblock( |
| 344 | flashblock.metadata.block_number, |
| 345 | flashblock.index - 1, |
| 346 | ) |
| 347 | && cache.insert(flashblock) |
| 348 | { |
| 349 | return; |
| 350 | } |
| 351 | // we should ignore this error since it doesn't necessarily indicate a problem |
| 352 | return; |
| 353 | } |
| 354 | _ => {} |
| 355 | } |
| 356 | |
| 357 | // skip logging expected caching case |
| 358 | if !matches!( |
| 359 | e, |
| 360 | StateProcessorError::Provider(ProviderError::MissingCanonicalHeader { .. }) |
| 361 | ) { |
no test coverage detected