Skip to content

Commit

Permalink
op-batcher: Test requeuing of transactions
Browse files Browse the repository at this point in the history
Regression test for #4937
  • Loading branch information
sebastianst committed Mar 11, 2023
1 parent e710934 commit 6661bb2
Showing 1 changed file with 46 additions and 3 deletions.
49 changes: 46 additions & 3 deletions op-batcher/batcher/channel_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ package batcher_test
import (
"io"
"math/big"
"math/rand"
"testing"
"time"

"github.com/ethereum-optimism/optimism/op-batcher/batcher"
"github.com/ethereum-optimism/optimism/op-node/eth"
"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-node/testlog"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -54,15 +57,15 @@ func TestChannelManagerReturnsErrReorgWhenDrained(t *testing.T) {
log := testlog.Logger(t, log.LvlCrit)
m := batcher.NewChannelManager(log, batcher.ChannelConfig{
TargetFrameSize: 0,
MaxFrameSize: 100,
MaxFrameSize: 120_000,
ApproxComprRatio: 1.0,
})
lBlock := types.NewBlock(&types.Header{
l1Block := types.NewBlock(&types.Header{
BaseFee: big.NewInt(10),
Difficulty: common.Big0,
Number: big.NewInt(100),
}, nil, nil, nil, trie.NewStackTrie(nil))
l1InfoTx, err := derive.L1InfoDeposit(0, lBlock, eth.SystemConfig{}, false)
l1InfoTx, err := derive.L1InfoDeposit(0, l1Block, eth.SystemConfig{}, false)
require.NoError(t, err)
txs := []*types.Transaction{types.NewTx(l1InfoTx)}

Expand All @@ -81,6 +84,46 @@ func TestChannelManagerReturnsErrReorgWhenDrained(t *testing.T) {
require.NoError(t, err)
_, err = m.TxData(eth.BlockID{})
require.ErrorIs(t, err, io.EOF)

err = m.AddL2Block(x)
require.ErrorIs(t, err, batcher.ErrReorg)
}

func TestChannelManager_TxResend(t *testing.T) {
require := require.New(t)
rng := rand.New(rand.NewSource(time.Now().UnixNano()))
log := testlog.Logger(t, log.LvlError)
m := batcher.NewChannelManager(log, batcher.ChannelConfig{
TargetFrameSize: 0,
MaxFrameSize: 120_000,
ApproxComprRatio: 1.0,
})

a, _ := derivetest.RandomL2Block(rng, 4)

err := m.AddL2Block(a)
require.NoError(err)

txdata0, err := m.TxData(eth.BlockID{})
require.NoError(err)
txdata0bytes := txdata0.Bytes()
data0 := make([]byte, len(txdata0bytes))
// make sure we have a clone for later comparison
copy(data0, txdata0bytes)

// ensure channel is drained
_, err = m.TxData(eth.BlockID{})
require.ErrorIs(err, io.EOF)

// requeue frame
m.TxFailed(txdata0.ID())

txdata1, err := m.TxData(eth.BlockID{})
require.NoError(err)

data1 := txdata1.Bytes()
require.Equal(data1, data0)
fs, err := derive.ParseFrames(data1)
require.NoError(err)
require.Len(fs, 1)
}

0 comments on commit 6661bb2

Please sign in to comment.