MCPcopy Create free account
hub / github.com/base/base / drain

Method drain

crates/consensus/engine/src/task_queue/core.rs:532–555  ·  view source on GitHub ↗

Attempts to drain the queue by executing all [`EngineTask`]s in-order. If any task returns an error along the way, it is not popped from the queue (in case it must be retried) and the error is returned. Exception: tasks that fail with [`EngineTaskErrorSeverity::Flush`] are popped from the queue before the error is returned. The poisoned task must not be retried in-place — the engine processor wil

(&mut self)

Source from the content-addressed store, hash-verified

530 /// to popping, mirroring the success path so watch consumers (e.g. the RPC state view) stay
531 /// in sync.
532 pub async fn drain(&mut self) -> Result<(), EngineTaskErrors> {
533 // Drain tasks in order of priority, halting on errors for a retry to be attempted.
534 while let Some((task, _)) = self.tasks.peek() {
535 // Execute the task.
536 let outcome = match task.execute(&mut self.state).await {
537 Ok(()) => Ok(()),
538 Err(err) if err.severity() == EngineTaskErrorSeverity::Flush => Err(err),
539 Err(err) => return Err(err),
540 };
541
542 // Update the state and notify the engine actor.
543 self.state_sender.send_replace(self.state);
544
545 // Pop the task from the queue now that it's been executed.
546 self.tasks.pop();
547
548 self.task_queue_length.send_replace(self.tasks.len());
549 Metrics::engine_task_queue_depth().set(self.tasks.len() as f64);
550
551 outcome?;
552 }
553
554 Ok(())
555 }
556}
557
558/// An error occurred while attempting to reset the [`Engine`].

Callers 5

checkpoint_revertMethod · 0.45
resize_from_rightMethod · 0.45
pruneMethod · 0.45
next_batchMethod · 0.45
update_originsMethod · 0.45

Calls 6

popMethod · 0.80
peekMethod · 0.45
executeMethod · 0.45
severityMethod · 0.45
lenMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected