Skip to content

Commit

Permalink
Pass empty ChainConfig to all types.NewBlock calls
Browse files Browse the repository at this point in the history
This uses pre-Isthmus blocks in all tests for now.
  • Loading branch information
sebastianst committed Dec 10, 2024
1 parent f9bed86 commit 50d6e5b
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 21 deletions.
4 changes: 2 additions & 2 deletions op-batcher/batcher/channel_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func newMiniL2BlockWithNumberParentAndL1Information(numTx int, l2Number *big.Int
Difficulty: common.Big0,
Number: big.NewInt(l1Number),
Time: blockTime,
}, nil, nil, trie.NewStackTrie(nil))
}, nil, nil, trie.NewStackTrie(nil), emptyChainCfg)
l1InfoTx, err := derive.L1InfoDeposit(defaultTestRollupConfig, eth.SystemConfig{}, 0, eth.BlockToInfo(l1Block), blockTime)
if err != nil {
panic(err)
Expand All @@ -90,7 +90,7 @@ func newMiniL2BlockWithNumberParentAndL1Information(numTx int, l2Number *big.Int
return types.NewBlock(&types.Header{
Number: l2Number,
ParentHash: parent,
}, &types.Body{Transactions: txs}, nil, trie.NewStackTrie(nil))
}, &types.Body{Transactions: txs}, nil, trie.NewStackTrie(nil), emptyChainCfg)
}

// addTooManyBlocks adds blocks to the channel until it hits an error,
Expand Down
26 changes: 13 additions & 13 deletions op-batcher/batcher/channel_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -56,6 +57,8 @@ func TestChannelManagerBatchType(t *testing.T) {
}
}

var emptyChainCfg = &params.ChainConfig{} // no Isthmus

// ChannelManagerReturnsErrReorg ensures that the channel manager
// detects a reorg when it has cached L1 blocks.
func ChannelManagerReturnsErrReorg(t *testing.T, batchType uint) {
Expand All @@ -65,19 +68,19 @@ func ChannelManagerReturnsErrReorg(t *testing.T, batchType uint) {

a := types.NewBlock(&types.Header{
Number: big.NewInt(0),
}, nil, nil, nil)
}, nil, nil, nil, emptyChainCfg)
b := types.NewBlock(&types.Header{
Number: big.NewInt(1),
ParentHash: a.Hash(),
}, nil, nil, nil)
}, nil, nil, nil, emptyChainCfg)
c := types.NewBlock(&types.Header{
Number: big.NewInt(2),
ParentHash: b.Hash(),
}, nil, nil, nil)
}, nil, nil, nil, emptyChainCfg)
x := types.NewBlock(&types.Header{
Number: big.NewInt(2),
ParentHash: common.Hash{0xff},
}, nil, nil, nil)
}, nil, nil, nil, emptyChainCfg)

require.NoError(t, m.AddL2Block(a))
require.NoError(t, m.AddL2Block(b))
Expand Down Expand Up @@ -166,7 +169,7 @@ func ChannelManager_Clear(t *testing.T, batchType uint) {
b := types.NewBlock(&types.Header{
Number: big.NewInt(1),
ParentHash: a.Hash(),
}, nil, nil, nil)
}, nil, nil, nil, emptyChainCfg)
require.NoError(m.AddL2Block(b))
require.Equal(m.blockCursor, len(m.blocks)-1)
require.Equal(b.Hash(), m.tip)
Expand Down Expand Up @@ -285,8 +288,8 @@ func (f *FakeDynamicEthChannelConfig) ChannelConfig() ChannelConfig {
}

func newFakeDynamicEthChannelConfig(lgr log.Logger,
reqTimeout time.Duration) *FakeDynamicEthChannelConfig {

reqTimeout time.Duration,
) *FakeDynamicEthChannelConfig {
calldataCfg := ChannelConfig{
MaxFrameSize: 120_000 - 1,
TargetNumFrames: 1,
Expand Down Expand Up @@ -316,7 +319,6 @@ func newFakeDynamicEthChannelConfig(lgr log.Logger,
// set of market conditions. The test asserts that the DA type is changed at channel
// submission time.
func TestChannelManager_TxData(t *testing.T) {

type TestCase struct {
name string
chooseBlobsWhenChannelCreated bool
Expand Down Expand Up @@ -389,7 +391,6 @@ func TestChannelManager_TxData(t *testing.T) {
require.Equal(t, tc.chooseBlobsWhenChannelSubmitted, m.defaultCfg.UseBlobs)
})
}

}

// TestChannelManager_handleChannelInvalidated seeds the channel manager with blocks,
Expand Down Expand Up @@ -467,15 +468,15 @@ func TestChannelManager_PruneBlocks(t *testing.T) {
cfg.InitNoneCompressor()
a := types.NewBlock(&types.Header{
Number: big.NewInt(0),
}, nil, nil, nil)
}, nil, nil, nil, emptyChainCfg)
b := types.NewBlock(&types.Header{
Number: big.NewInt(1),
ParentHash: a.Hash(),
}, nil, nil, nil)
}, nil, nil, nil, emptyChainCfg)
c := types.NewBlock(&types.Header{
Number: big.NewInt(2),
ParentHash: b.Hash(),
}, nil, nil, nil)
}, nil, nil, nil, emptyChainCfg)

type testCase struct {
name string
Expand Down Expand Up @@ -557,7 +558,6 @@ func TestChannelManager_PruneBlocks(t *testing.T) {
}
})
}

}

func TestChannelManager_PruneChannels(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion op-e2e/actions/helpers/l1_miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/trie"
"github.com/ethereum/go-ethereum/triedb"

Expand Down Expand Up @@ -218,7 +219,7 @@ func (s *L1Miner) ActL1EndBlock(t Testing) *types.Block {
withdrawals = make([]*types.Withdrawal, 0)
}

block := types.NewBlock(s.l1BuildingHeader, &types.Body{Transactions: s.L1Transactions, Withdrawals: withdrawals}, s.l1Receipts, trie.NewStackTrie(nil))
block := types.NewBlock(s.l1BuildingHeader, &types.Body{Transactions: s.L1Transactions, Withdrawals: withdrawals}, s.l1Receipts, trie.NewStackTrie(nil), &params.ChainConfig{})
if s.l1Cfg.Config.IsCancun(s.l1BuildingHeader.Number, s.l1BuildingHeader.Time) {
parent := s.l1Chain.GetHeaderByHash(s.l1BuildingHeader.ParentHash)
var (
Expand Down
5 changes: 3 additions & 2 deletions op-node/rollup/derive/test/random.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ import (
"github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/ethereum-optimism/optimism/op-service/testutils"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/trie"
)

// RandomL2Block returns a random block whose first transaction is a random pre-Ecotone upgrade
// L1 Info Deposit transaction.
func RandomL2Block(rng *rand.Rand, txCount int, t time.Time) (*types.Block, []*types.Receipt) {
body := types.Body{}
l1Block := types.NewBlock(testutils.RandomHeader(rng), &body, nil, trie.NewStackTrie(nil))
emptyChainCfg := &params.ChainConfig{} // no Isthmus
l1Block := types.NewBlock(testutils.RandomHeader(rng), &body, nil, trie.NewStackTrie(nil), emptyChainCfg)
rollupCfg := rollup.Config{}
if testutils.RandomBool(rng) {
t := uint64(0)
Expand All @@ -32,7 +34,6 @@ func RandomL2Block(rng *rand.Rand, txCount int, t time.Time) (*types.Block, []*t
} else {
return testutils.RandomBlockPrependTxsWithTime(rng, txCount, uint64(t.Unix()), types.NewTx(l1InfoTx))
}

}

func RandomL2BlockWithChainId(rng *rand.Rand, txCount int, chainId *big.Int) *types.Block {
Expand Down
3 changes: 2 additions & 1 deletion op-program/client/l2/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ func createL2Block(t *testing.T, number int) *types.Block {
body := &types.Body{
Transactions: []*types.Transaction{types.NewTx(tx)},
}
return types.NewBlock(header, body, nil, trie.NewStackTrie(nil))
emptyChainCfg := &params.ChainConfig{} // no Isthmus
return types.NewBlock(header, body, nil, trie.NewStackTrie(nil), emptyChainCfg)
}

type stubEngineBackend struct {
Expand Down
2 changes: 1 addition & 1 deletion op-program/client/l2/engineapi/l2_engine_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ func (ea *L2EngineAPI) newPayload(_ context.Context, payload *eth.ExecutionPaylo
Withdrawals: toGethWithdrawals(payload),
ExcessBlobGas: (*uint64)(payload.ExcessBlobGas),
BlobGasUsed: (*uint64)(payload.BlobGasUsed),
}, hashes, root)
}, hashes, root, ea.config())
if err != nil {
log.Debug("Invalid NewPayload params", "params", payload, "error", err)
return &eth.PayloadStatusV1{Status: eth.ExecutionInvalidBlockHash}, nil
Expand Down
3 changes: 2 additions & 1 deletion op-service/testutils/random.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ func RandomBlock(rng *rand.Rand, txCount uint64) (*types.Block, []*types.Receipt
return RandomBlockPrependTxs(rng, int(txCount))
}

// RandomBlockPrependTxsWithTime will generate a random pre-Isthmus block.
func RandomBlockPrependTxsWithTime(rng *rand.Rand, txCount int, t uint64, ptxs ...*types.Transaction) (*types.Block, []*types.Receipt) {
header := RandomHeaderWithTime(rng, t)
signer := types.NewLondonSigner(big.NewInt(rng.Int63n(1000)))
Expand All @@ -302,7 +303,7 @@ func RandomBlockPrependTxsWithTime(rng *rand.Rand, txCount int, t uint64, ptxs .
body := types.Body{
Transactions: txs,
}
block := types.NewBlock(header, &body, receipts, trie.NewStackTrie(nil))
block := types.NewBlock(header, &body, receipts, trie.NewStackTrie(nil), &params.ChainConfig{})
logIndex := uint(0)
for i, r := range receipts {
r.BlockHash = block.Hash()
Expand Down

0 comments on commit 50d6e5b

Please sign in to comment.