Skip to content

Commit

Permalink
force l1 origin to be finalized block: by the finalized block via rpc…
Browse files Browse the repository at this point in the history
… instead of confDepth
  • Loading branch information
claymega committed Oct 16, 2024
1 parent cfd5610 commit 3802586
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
14 changes: 10 additions & 4 deletions op-node/rollup/confdepth/conf_depth.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,24 @@ import (
type confDepth struct {
// everything fetched by hash is trusted already, so we implement those by embedding the fetcher
derive.L1Fetcher
l1Head func() eth.L1BlockRef
depth uint64
l1Head func() eth.L1BlockRef
depth uint64
l1Finalized func() eth.L1BlockRef
}

func NewConfDepth(depth uint64, l1Head func() eth.L1BlockRef, fetcher derive.L1Fetcher) *confDepth {
return &confDepth{L1Fetcher: fetcher, l1Head: l1Head, depth: depth}
func NewConfDepth(depth uint64, l1Head func() eth.L1BlockRef, l1Finalized func() eth.L1BlockRef, fetcher derive.L1Fetcher) *confDepth {
return &confDepth{L1Fetcher: fetcher, l1Head: l1Head, l1Finalized: l1Finalized, depth: depth}
}

// L1BlockRefByNumber is used for L1 traversal and for finding a safe common point between the L2 engine and L1 chain.
// Any block numbers that are within confirmation depth of the L1 head are mocked to be "not found",
// effectively hiding the uncertain part of the L1 chain.
func (c *confDepth) L1BlockRefByNumber(ctx context.Context, num uint64) (eth.L1BlockRef, error) {
// Need num <= l1 finalized block number
l1Finalized := c.l1Finalized()
if num > l1Finalized.Number {
return eth.L1BlockRef{}, ethereum.NotFound
}
// Don't apply the conf depth if l1Head is empty (as it is during the startup case before the l1State is initialized).
l1Head := c.l1Head()
if l1Head == (eth.L1BlockRef{}) {
Expand Down
4 changes: 2 additions & 2 deletions op-node/rollup/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func NewDriver(
sys.Register("l1-blocks", l1Tracker, opts)

l1 = NewMeteredL1Fetcher(l1Tracker, metrics)
verifConfDepth := confdepth.NewConfDepth(driverCfg.VerifierConfDepth, statusTracker.L1Head, l1)
verifConfDepth := confdepth.NewConfDepth(driverCfg.VerifierConfDepth, statusTracker.L1Head, statusTracker.L1Finalized, l1)

ec := engine.NewEngineController(l2, log, metrics, cfg, syncCfg,
sys.Register("engine-controller", nil, opts))
Expand Down Expand Up @@ -239,7 +239,7 @@ func NewDriver(
if driverCfg.SequencerEnabled {
asyncGossiper := async.NewAsyncGossiper(driverCtx, network, log, metrics)
attrBuilder := derive.NewFetchingAttributesBuilder(cfg, l1, l2)
sequencerConfDepth := confdepth.NewConfDepth(driverCfg.SequencerConfDepth, statusTracker.L1Head, l1)
sequencerConfDepth := confdepth.NewConfDepth(driverCfg.SequencerConfDepth, statusTracker.L1Head, statusTracker.L1Finalized, l1)
findL1Origin := sequencing.NewL1OriginSelector(log, cfg, sequencerConfDepth)
sequencer = sequencing.NewSequencer(driverCtx, log, cfg, attrBuilder, findL1Origin,
sequencerStateListener, sequencerConductor, asyncGossiper, metrics)
Expand Down
5 changes: 5 additions & 0 deletions op-node/rollup/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,8 @@ func (st *StatusTracker) SyncStatus() *eth.SyncStatus {
func (st *StatusTracker) L1Head() eth.L1BlockRef {
return st.SyncStatus().HeadL1
}

// L1Finalized is a helper function
func (st *StatusTracker) L1Finalized() eth.L1BlockRef {
return st.SyncStatus().FinalizedL1
}

0 comments on commit 3802586

Please sign in to comment.