From e4e2d30437c28603ad05af5c94ae5f320e652f45 Mon Sep 17 00:00:00 2001 From: Michael de Hoog Date: Tue, 7 Jan 2025 10:37:49 -1000 Subject: [PATCH] Only force-submit withdrawal batches if block is fresh (#41) --- op-batcher/batcher/channel_out.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/op-batcher/batcher/channel_out.go b/op-batcher/batcher/channel_out.go index 76f2d00..441e285 100644 --- a/op-batcher/batcher/channel_out.go +++ b/op-batcher/batcher/channel_out.go @@ -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" @@ -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 { @@ -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)