Baker application’s architecture#
The Octez baker is an executable responsible for the creation of blocks and consensus operations on the Tezos blockchain according to the Tenderbake consensus algorithm.
The baker is designed as finite-state machine, with states, transitions and specific consensus-related events .
The machine is orchestrated by a scheduler, which operates in a never-ending loop to listen for ongoing events, trigger transitions accordingly, and perform side-effects.
It relies on two workers running alongside the main scheduling loop to manage auxiliary tasks:
the operation worker monitors consensus operations from the node via the
/mempool/monitor_operations
RPC, reportingPrequorum_reached
andQuorum_reached
events to the main scheduler.the forge worker is responsible for crafting blocks and operations. It receives crafting requests from the scheduler and notifies completion with
New_forge_event (Block_ready block)
,New_forge_event (Preattestation_ready op)
, orNew_forge_event (Attestation_ready op)
events.
Scheduling#
Alongside the operation and forge workers, the scheduler tracks the following events itself:
new blocks via the
/monitor/heads
and/monitor/validated_blocks
RPCs, where new inputs are converted intoNew_head_proposal p
andNew_valid_proposal p
events, respectively.end of rounds and baking times by spawning timers that trigger
Timeout
events.
Upon receiving a new event, the scheduler applies the corresponding transition based on the current state and the event. The transition function returns a new state and an action. These actions are side-effect requests, such as injecting operations, forging blocks, or monitoring prequorums.
The scheduler then executes the current action and prepares for the next loop iteration: it sets a timer to track the next timeout according to the current state and then sleeps until the next event.