Skip to content

Only force-submit withdrawal batches if block is fresh #41

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

Merged
merged 1 commit into from
Jan 7, 2025
Merged
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
12 changes: 11 additions & 1 deletion op-batcher/batcher/channel_out.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package batcher

import (
"errors"
"time"

"github.com/ethereum-optimism/optimism/op-batcher/batcher"
"github.com/ethereum-optimism/optimism/op-node/rollup"
Expand All @@ -12,6 +13,8 @@ import (

var ErrWithdrawalDetected = errors.New("withdrawal detected")

const minBlockFreshness = 10 * time.Second

func NewChannelOut(cfg batcher.ChannelConfig, rollupCfg *rollup.Config) (derive.ChannelOut, error) {
co, err := batcher.NewChannelOut(cfg, rollupCfg)
if err != nil {
Expand All @@ -24,11 +27,18 @@ func NewChannelOut(cfg batcher.ChannelConfig, rollupCfg *rollup.Config) (derive.

type channelOut struct {
derive.ChannelOut
fullErr error
fullErr error
withdrawalDetected bool
}

func (c *channelOut) AddBlock(config *rollup.Config, block *types.Block) (*derive.L1BlockInfo, error) {
if block.Bloom().Test(predeploys.L2ToL1MessagePasserAddr.Bytes()) {
c.withdrawalDetected = true
}
// If this channel contains a withdrawal, and the block is recent, we can submit the batch immediately.
// We care about the block freshness because otherwise users could cause the batch submission to slow
// down significantly by submitting at least 1 withdrawal each block.
if c.withdrawalDetected && time.Unix(int64(block.Time()), 0).Add(minBlockFreshness).After(time.Now()) {
c.fullErr = ErrWithdrawalDetected
}
return c.ChannelOut.AddBlock(config, block)
Expand Down
Loading