kona-derive defines an entirely trait-abstracted, no_std derivation
pipeline for the OP Stack. It can be used through the Pipeline trait,
which is implemented for the concrete DerivationPipeline object.
This document dives into the inner workings of the derivation pipeline, its
stages, and how to build and interface with Kona’s pipeline. Other documents
in this section will provide a comprehensive overview of Derivation Pipeline
extensibility including trait-abstracted providers, custom stages, signaling,
and hardfork activation including multiplexed stages.
- Swapping out a stage
- Defining a custom Provider
- Extending Pipeline Signals
- Implementing Hardfork Activations
What is a Derivation Pipeline?
Simply put, an OP Stack Derivation Pipeline transforms data on L1 into L2 payload attributes that can be executed to produce the canonical L2 block. Within a pipeline, there are a set of stages that break up this transformation further. When composed, these stages operate over the input data, sequentially producing payload attributes. Inkona-derive, stages are architected using composition - each sequential
stage owns the previous one, forming a stack. For example, let’s define stage A
as the first stage, accepting raw L1 input data, and stage C produces the pipeline
output - payload attributes. Stage B “owns” stage A, and stage C then owns stage B.
Using this example, the DerivationPipeline type in kona-derive only
holds stage C, since ownership of the other stages is nested within stage C.
In a future architecture of the derivation pipeline, stages could be made
standalone such that communication between stages happens through channels.
In a multi-threaded, non-fault-proof environment, these stages can then
run in parallel since stage ownership is decoupled.
Kona’s Derivation Pipeline
The top-level stage inkona-derive that produces
OpAttributesWithParent is the AttributesQueue.
Post-Holocene (the Holocene hardfork), the following stages are composed by
the DerivationPipeline.
Notice, from top to bottom, each stage owns the stage nested below it.
Where the IndexedTraversal or PollingTraversal stage iterates over L1 data, the
AttributesQueue stage produces
OpAttributesWithParent, creating a function that transforms
L1 data into payload attributes.
The Pipeline interface
Now that we’ve broken down the stages inside the DerivationPipeline
type, let’s move up another level to break down how the DerivationPipeline
type functions itself. At the highest level, kona-derive defines the
interface for working with the pipeline through the Pipeline trait.
Pipeline provides two core methods.
peek() -> Option<&OpAttributesWithParent>async step() -> StepResult
peek() method provides a way to check if attributes are prepared.
Beyond peek() returning Option::Some(&OpAttributesWithParent), the Pipeline
extends the Iterator trait, providing a way to consume the generated payload
attributes.
Constructing a Derivation Pipeline
kona-derive provides a PipelineBuilder to abstract the complexity
of generics away from the downstream consumers. Below we provide an example for using
the PipelineBuilder to instantiate a DerivationPipeline.
Producing Payload Attributes
Since thePipeline trait extends the Iterator trait,
producing OpAttributesWithParent is as simple as calling
Iterator::next() method on the DerivationPipeline.
Extending the example from above, producing the attributes is shown below.
StepResults to handle when
stepping on the pipeline, including advancing the origin, re-orgs, and pipeline resets.
In the next section, pipeline resets are outlined.
For an up-to-date driver that runs the derivation pipeline as part of the fault proof
program, reference kona’s client driver.
Resets
When stepping on theDerivationPipeline produces a reset error, the driver
of the pipeline must perform a reset on the pipeline. This is done by sending a “signal”
through the DerivationPipeline. Below demonstrates this.
Learn More
kona-derive is one implementation of the OP Stack derivation pipeline.
To learn more, it is highly encouraged to read the “first” derivation pipeline
written in golang. It is often colloquially referred to as the “reference”
implementation and provides the basis for how much of Kona’s derivation pipeline
was built.
Provenance
The lore do be bountiful.The kona project spawned out of the need to build a secondary fault proof for the OP Stack. Initially, we sought to re-use magi’s derivation pipeline, but the ethereum-rust ecosystem moves quickly and magi was behind by a generation of types - using ethers-rs instead of new alloy types. Additionally, magi’s derivation pipeline was not
- Bard XVIII of the Logic Gates
no_std compatible - a hard requirement for running a rust fault proof
program on top of the RISCV or MIPS ISAs.
So, @clabby and @refcell stood up kona in a few months.