Skip to main content

run_mining_engine

Function run_mining_engine 

Source
pub async fn run_mining_engine(engine: Arc<MiningEngine>)
Expand description

Run the mining engine background task.

This is the main event loop that handles block production based on the current mining mode. It monitors for mining mode changes, manages stream selectors for different trigger types (intervals, transactions), and coordinates block sealing operations.

The function runs indefinitely until the mining engine is shut down or a fatal error occurs.

§Arguments

  • engine - Shared reference to the mining engine to control

§Behavior

  • Monitors for mining mode changes and rebuilds event streams accordingly
  • Handles interval-based mining triggers using tokio timers
  • Handles transaction-based mining triggers from the transaction pool
  • Processes block sealing commands and logs results
  • Gracefully handles non-fatal errors and continues operation
  • Terminates on fatal errors (communication failures)

§Error Handling

  • Fatal errors (Canceled, SendError): Breaks the main loop and terminates
  • Non-fatal errors: Logged and operation continues
  • Successful operations: Block hash is logged at debug level