Skip to content

Commit

Permalink
feat: ignore KromaMPT block payload
Browse files Browse the repository at this point in the history
Prevents KromaMPT block from being handled as unsafe payload over P2P.
This ensures that nodes can continue the migration process, even if they
receive a new unsafe payload from the sequencer before receiving the batch
containing the KromaMPT parent block, allowing them to still process the
safe attribute.
  • Loading branch information
Pangssu committed Jan 20, 2025
1 parent fb4d02c commit 53bc25a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
14 changes: 11 additions & 3 deletions op-batcher/batcher/channel_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ var (
ErrSeqWindowClose = errors.New("close to sequencer window timeout")
ErrTerminated = errors.New("channel terminated")
// [Kroma: START]
ErrJustBeforeKromaMPTTime = errors.New("reached the block just before KromaMPTTime")
ErrReachedKromaMPTParentBlock = errors.New("reached the parent block of KromaMPT")
ErrReachedKromaMPTBlock = errors.New("reached the KromaMPT block")
// [Kroma: END]
)

Expand Down Expand Up @@ -177,8 +178,15 @@ func (c *ChannelBuilder) AddBlock(block *types.Block) (*derive.L1BlockInfo, erro
if err = c.co.FullErr(); err != nil {
c.setFullErr(err)
// Adding this block still worked, so don't return error, just mark as full
} else /* [Kroma: START] */ if c.rollupCfg.KromaMPTTime != nil && block.Time() == *c.rollupCfg.KromaMPTTime-c.rollupCfg.BlockTime {
c.setFullErr(ErrJustBeforeKromaMPTTime)
}

// [Kroma: START]
if c.rollupCfg.KromaMPTTime != nil {
if c.rollupCfg.IsKromaMPTParentBlock(block.Time() - c.rollupCfg.BlockTime) {
c.setFullErr(ErrReachedKromaMPTParentBlock)
} else if c.rollupCfg.IsKromaMPTActivationBlock(block.Time()) {
c.setFullErr(ErrReachedKromaMPTBlock)
}
}
// [Kroma: END]

Expand Down
11 changes: 6 additions & 5 deletions op-batcher/batcher/channel_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ import (
"testing"
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
"github.com/stretchr/testify/require"

"github.com/ethereum-optimism/optimism/op-batcher/metrics"
"github.com/ethereum-optimism/optimism/op-node/rollup"
"github.com/ethereum-optimism/optimism/op-node/rollup/derive"
derivetest "github.com/ethereum-optimism/optimism/op-node/rollup/derive/test"
"github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/ethereum-optimism/optimism/op-service/testlog"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
"github.com/stretchr/testify/require"
)

func channelManagerTestConfig(maxFrameSize uint64, batchType uint) ChannelConfig {
Expand Down Expand Up @@ -529,7 +530,7 @@ func TestChannelManager_Close_BeforeMPTBlock(t *testing.T) {
txdata, err := m.TxData(eth.BlockID{})
require.NoError(err)
ch1 := m.txChannels[txdata.ID().String()]
require.ErrorIs(ch1.FullErr(), ErrJustBeforeKromaMPTTime)
require.ErrorIs(ch1.FullErr(), ErrReachedKromaMPTParentBlock)

// current channel is not full yet
_, err = m.TxData(eth.BlockID{})
Expand Down
7 changes: 7 additions & 0 deletions op-node/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,13 @@ func (n *OpNode) OnUnsafeL2Payload(ctx context.Context, from peer.ID, envelope *
return nil
}

// [Kroma: START]
if n.runCfg.rollupCfg.IsKromaMPTActivationBlock(uint64(envelope.ExecutionPayload.Timestamp)) {
n.log.Info("Received the payload of the KromaMPT block from p2p but ignored it", "id", envelope.ExecutionPayload.ID(), "peer", from)
return nil
}
// [Kroma: END]

n.tracer.OnUnsafeL2Payload(ctx, from, envelope)

n.log.Info("Received signed execution payload from p2p", "id", envelope.ExecutionPayload.ID(), "peer", from)
Expand Down
8 changes: 8 additions & 0 deletions op-node/rollup/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,14 @@ func (c *Config) IsKromaMPT(timestamp uint64) bool {
return c.KromaMPTTime != nil && timestamp >= *c.KromaMPTTime
}

// IsKromaMPTActivationBlock returns whether the specified block is the first block subject to the
// KromaMPT upgrade. KromaMPT activation at genesis does not count.
func (c *Config) IsKromaMPTActivationBlock(l2BlockTime uint64) bool {
return c.IsKromaMPT(l2BlockTime) &&
l2BlockTime >= c.BlockTime &&
!c.IsKromaMPT(l2BlockTime-c.BlockTime)
}

// IsKromaMPTParentBlock returns whether the specified block is the parent block subject to the
// KromaMPT upgrade. KromaMPT activation at genesis does not count.
func (c *Config) IsKromaMPTParentBlock(l2BlockTime uint64) bool {
Expand Down

0 comments on commit 53bc25a

Please sign in to comment.