diff --git a/op-node/rollup/derive/channel_out.go b/op-node/rollup/derive/channel_out.go index 49589acb80574..f946a7f17c3ce 100644 --- a/op-node/rollup/derive/channel_out.go +++ b/op-node/rollup/derive/channel_out.go @@ -13,6 +13,8 @@ import ( "github.com/ethereum/go-ethereum/rlp" ) +var ErrNotDepositTx = errors.New("first transaction in block is not a deposit tx") + type ChannelOut struct { id ChannelID // Frame ID of the next frame to emit. Increment after emitting @@ -153,6 +155,9 @@ func blockToBatch(block *types.Block, w io.Writer) error { opaqueTxs = append(opaqueTxs, otx) } l1InfoTx := block.Transactions()[0] + if l1InfoTx.Type() != types.DepositTxType { + return ErrNotDepositTx + } l1Info, err := L1InfoDepositTxData(l1InfoTx.Data()) if err != nil { return err // TODO: wrap err diff --git a/op-node/rollup/derive/channel_out_test.go b/op-node/rollup/derive/channel_out_test.go new file mode 100644 index 0000000000000..683608b79ce9e --- /dev/null +++ b/op-node/rollup/derive/channel_out_test.go @@ -0,0 +1,27 @@ +package derive + +import ( + "math/big" + "testing" + + "github.com/ethereum/go-ethereum/core/types" + "github.com/stretchr/testify/require" +) + +func TestChannelOutAddBlock(t *testing.T) { + cout, err := NewChannelOut() + require.NoError(t, err) + + t.Run("returns err if first tx is not an l1info tx", func(t *testing.T) { + header := &types.Header{Number: big.NewInt(1), Difficulty: big.NewInt(100)} + block := types.NewBlockWithHeader(header).WithBody( + []*types.Transaction{ + types.NewTx(&types.DynamicFeeTx{}), + }, + nil, + ) + err := cout.AddBlock(block) + require.Error(t, err) + require.Equal(t, ErrNotDepositTx, err) + }) +}