Skip to content

Commit

Permalink
Merge pull request #34 from EspressoSystems/feat/espresso-sequencer
Browse files Browse the repository at this point in the history
Implement Espresso mode for the OP sequencer
  • Loading branch information
jbearer authored Aug 17, 2023
2 parents c36d46f + 6474ea4 commit 825aaab
Show file tree
Hide file tree
Showing 11 changed files with 1,089 additions and 193 deletions.
6 changes: 5 additions & 1 deletion op-e2e/actions/l2_sequencer.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ func (m *MockL1OriginSelector) FindL1Origin(ctx context.Context, l2Head eth.L2Bl
return m.actual.FindL1Origin(ctx, l2Head)
}

func (m *MockL1OriginSelector) FindL1OriginByNumber(ctx context.Context, number uint64) (eth.L1BlockRef, error) {
return m.actual.FindL1OriginByNumber(ctx, number)
}

// L2Sequencer is an actor that functions like a rollup node,
// without the full P2P/API/Node stack, but just the derivation state, and simplified driver with sequencing ability.
type L2Sequencer struct {
Expand All @@ -49,7 +53,7 @@ func NewL2Sequencer(t Testing, log log.Logger, l1 derive.L1Fetcher, eng L2API, c
}
return &L2Sequencer{
L2Verifier: *ver,
sequencer: driver.NewSequencer(log, cfg, ver.derivation, attrBuilder, l1OriginSelector, metrics.NoopMetrics),
sequencer: driver.NewSequencer(log, cfg, ver.derivation, attrBuilder, l1OriginSelector, nil, metrics.NoopMetrics),
mockL1OriginSelector: l1OriginSelector,
failL2GossipUnsafeBlock: nil,
}
Expand Down
6 changes: 6 additions & 0 deletions op-node/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,12 @@ var (
Required: false,
Value: false,
}
EspressoUrl = &cli.StringFlag{
Name: "espresso",
Usage: "Sets the URL for fetching data from the Espresso Sequencer. Required only if sequencing for an Espresso-enabled OP-chain",
EnvVars: prefixEnvVars("ESPRESSO_URL"),
Required: false,
}
)

var requiredFlags = []cli.Flag{
Expand Down
3 changes: 3 additions & 0 deletions op-node/node/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ type Config struct {
L2 L2EndpointSetup
L2Sync L2SyncEndpointSetup

// Address of Espresso query service
EspressoUrl string

Driver driver.Config

Rollup rollup.Config
Expand Down
11 changes: 10 additions & 1 deletion op-node/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/ethereum-optimism/optimism/op-node/p2p"
"github.com/ethereum-optimism/optimism/op-node/rollup/driver"
"github.com/ethereum-optimism/optimism/op-node/sources"
"github.com/ethereum-optimism/optimism/op-service/espresso"
"github.com/ethereum-optimism/optimism/op-service/eth"
)

Expand Down Expand Up @@ -199,7 +200,15 @@ func (n *OpNode) initL2(ctx context.Context, cfg *Config, snapshotLog log.Logger
return err
}

n.l2Driver = driver.NewDriver(&cfg.Driver, &cfg.Rollup, n.l2Source, n.l1Source, n, n, n.log, snapshotLog, n.metrics, cfg.ConfigPersistence, &cfg.Sync)
var espressoClient *espresso.Client
if cfg.EspressoUrl != "" {
espressoClient, err = espresso.NewClient(cfg.EspressoUrl)
if err != nil {
return err
}
}

n.l2Driver = driver.NewDriver(&cfg.Driver, &cfg.Rollup, n.l2Source, n.l1Source, espressoClient, n, n, n.log, snapshotLog, n.metrics, cfg.ConfigPersistence, &cfg.Sync)

return nil
}
Expand Down
5 changes: 3 additions & 2 deletions op-node/rollup/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/ethereum-optimism/optimism/op-node/rollup"
"github.com/ethereum-optimism/optimism/op-node/rollup/derive"
"github.com/ethereum-optimism/optimism/op-node/rollup/sync"
"github.com/ethereum-optimism/optimism/op-service/espresso"
"github.com/ethereum-optimism/optimism/op-service/eth"
)

Expand Down Expand Up @@ -110,7 +111,7 @@ type SequencerStateListener interface {
}

// NewDriver composes an events handler that tracks L1 state, triggers L2 derivation, and optionally sequences new L2 blocks.
func NewDriver(driverCfg *Config, cfg *rollup.Config, l2 L2Chain, l1 L1Chain, altSync AltSync, network Network, log log.Logger, snapshotLog log.Logger, metrics Metrics, sequencerStateListener SequencerStateListener, syncCfg *sync.Config) *Driver {
func NewDriver(driverCfg *Config, cfg *rollup.Config, l2 L2Chain, l1 L1Chain, espressoClient *espresso.Client, altSync AltSync, network Network, log log.Logger, snapshotLog log.Logger, metrics Metrics, sequencerStateListener SequencerStateListener, syncCfg *sync.Config) *Driver {
l1 = NewMeteredL1Fetcher(l1, metrics)
l1State := NewL1State(log, metrics)
sequencerConfDepth := NewConfDepth(driverCfg.SequencerConfDepth, l1State.L1Head, l1)
Expand All @@ -120,7 +121,7 @@ func NewDriver(driverCfg *Config, cfg *rollup.Config, l2 L2Chain, l1 L1Chain, al
attrBuilder := derive.NewFetchingAttributesBuilder(cfg, l1, l2)
engine := derivationPipeline
meteredEngine := NewMeteredEngine(cfg, engine, metrics, log)
sequencer := NewSequencer(log, cfg, meteredEngine, attrBuilder, findL1Origin, metrics)
sequencer := NewSequencer(log, cfg, meteredEngine, attrBuilder, findL1Origin, espressoClient, metrics)

return &Driver{
l1State: l1State,
Expand Down
4 changes: 4 additions & 0 deletions op-node/rollup/driver/origin_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,7 @@ func (los *L1OriginSelector) FindL1Origin(ctx context.Context, l2Head eth.L2Bloc

return currentOrigin, nil
}

func (los *L1OriginSelector) FindL1OriginByNumber(ctx context.Context, number uint64) (eth.L1BlockRef, error) {
return los.l1.L1BlockRefByNumber(ctx, number)
}
Loading

0 comments on commit 825aaab

Please sign in to comment.