Processes updates from the queue until the channel closes.
(&self)
| 250 | |
| 251 | /// Processes updates from the queue until the channel closes. |
| 252 | pub async fn start(&self) { |
| 253 | while let Some(update) = self.rx.lock().await.recv().await { |
| 254 | let prev_pending_blocks = self.load_pending_or_drop_stale(); |
| 255 | match update { |
| 256 | StateUpdate::Canonical(block) => { |
| 257 | debug!(message = "processing canonical block", block_number = block.number); |
| 258 | match self.process_canonical_block(prev_pending_blocks, &block) { |
| 259 | Ok(new_pending_blocks) => { |
| 260 | self.pending_blocks.swap(new_pending_blocks); |
| 261 | |
| 262 | let mut cache = self.cache.lock().await; |
| 263 | cache.update_canonical(block.number); |
| 264 | let cached = cache.drain(block.number + 1); |
| 265 | drop(cache); |
| 266 | |
| 267 | if !cached.is_empty() { |
| 268 | debug!( |
| 269 | message = "replaying cached flashblocks after canonical block", |
| 270 | canonical_block = block.number, |
| 271 | cached_count = cached.len(), |
| 272 | ); |
| 273 | for flashblock in cached { |
| 274 | let fb_prev = self.load_pending_or_drop_stale(); |
| 275 | self.apply_flashblock(fb_prev, flashblock).await; |
| 276 | } |
| 277 | } |
| 278 | } |
| 279 | Err(e) => { |
| 280 | error!(message = "could not process canonical block", error = %e); |
| 281 | } |
| 282 | } |
| 283 | } |
| 284 | StateUpdate::Flashblock(flashblock) => { |
| 285 | debug!( |
| 286 | message = "processing flashblock", |
| 287 | block_number = flashblock.metadata.block_number, |
| 288 | flashblock_index = flashblock.index |
| 289 | ); |
| 290 | self.apply_flashblock(prev_pending_blocks, flashblock).await; |
| 291 | } |
| 292 | } |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | /// Applies a flashblock, unless the node has already canonicalized its block. |
| 297 | /// |
no test coverage detected