Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

force L1 origin to be finalized L1 block #3

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion op-node/cmd/genesis/systemconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func NewSystemConfigContract(caller *batching.MultiCaller, addr common.Address)
}

func (c *SystemConfigContract) StartBlock(ctx context.Context) (*big.Int, error) {
result, err := c.caller.SingleCall(ctx, rpcblock.Latest, c.contract.Call(methodStartBlock))
result, err := c.caller.SingleCall(ctx, rpcblock.Finalized, c.contract.Call(methodStartBlock))
if err != nil {
return nil, fmt.Errorf("failed to call startBlock: %w", err)
}
Expand Down
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()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since l1Head is always ahead of l1Finalized, the following code (the original logic) is effectively dead code. I am not sure whether we should remove them in this PR or just keep them for reference.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dead code是指37行以后吗?如果是的,它不会是dead code, 因为num = previous_l1_origin + 1,正常运行情况下是走37行后面逻辑的

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我意思是其原来的获取l1Head的相关的逻辑。我们现在应该是不需要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
}