Skip to content

Commit

Permalink
devnet/e2e: run L1 Deneb and L2 Fjord by default (ethereum-optimism#1…
Browse files Browse the repository at this point in the history
…1359)

* devnet/e2e: run L1 Deneb and L2 Fjord by default

* op-e2e: fix TestPostUnsafePayload

* op-e2e: Fix TestGasPriceOracleFeeUpdates

* op-e2e/actions: fix some tests

The L2EngineAPI test needs more fixing

* tests: fixes to support Ecotone/Fjord in more tests

* op-e2e: one more fix

---------

Co-authored-by: Sebastian Stammler <[email protected]>
  • Loading branch information
protolambda and sebastianst authored Aug 8, 2024
1 parent b047e1f commit 2f295d0
Show file tree
Hide file tree
Showing 11 changed files with 155 additions and 132 deletions.
34 changes: 6 additions & 28 deletions op-e2e/actions/dencun_fork_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ func TestDencunL1ForkAfterGenesis(gt *testing.T) {
func TestDencunL1ForkAtGenesis(gt *testing.T) {
t := NewDefaultTesting(gt)
dp := e2eutils.MakeDeployParams(t, defaultRollupTestParams)
offset := hexutil.Uint64(0)
dp.DeployConfig.L1CancunTimeOffset = &offset
require.Zero(t, *dp.DeployConfig.L1CancunTimeOffset)
sd := e2eutils.Setup(t, dp, defaultAlloc)
log := testlog.Logger(t, log.LevelDebug)
_, _, miner, sequencer, _, verifier, _, batcher := setupReorgTestActors(t, dp, sd, log)
Expand Down Expand Up @@ -120,14 +119,13 @@ func verifyEcotoneBlock(gt *testing.T, header *types.Header) {
func TestDencunL2ForkAfterGenesis(gt *testing.T) {
t := NewDefaultTesting(gt)
dp := e2eutils.MakeDeployParams(t, defaultRollupTestParams)

cancunOffset := hexutil.Uint64(0)
dp.DeployConfig.L1CancunTimeOffset = &cancunOffset
require.Zero(t, *dp.DeployConfig.L1CancunTimeOffset)
// This test wil fork on the second block
offset := hexutil.Uint64(dp.DeployConfig.L2BlockTime * 2)
dp.DeployConfig.L2GenesisCanyonTimeOffset = &offset
dp.DeployConfig.L2GenesisDeltaTimeOffset = &offset
dp.DeployConfig.L2GenesisEcotoneTimeOffset = &offset
dp.DeployConfig.L2GenesisFjordTimeOffset = nil
dp.DeployConfig.L2GenesisGraniteTimeOffset = nil
// New forks have to be added here, after changing the default deploy config!

sd := e2eutils.Setup(t, dp, defaultAlloc)
log := testlog.Logger(t, log.LevelDebug)
Expand Down Expand Up @@ -159,12 +157,7 @@ func TestDencunL2ForkAfterGenesis(gt *testing.T) {
func TestDencunL2ForkAtGenesis(gt *testing.T) {
t := NewDefaultTesting(gt)
dp := e2eutils.MakeDeployParams(t, defaultRollupTestParams)
offset := hexutil.Uint64(0)
dp.DeployConfig.L2GenesisRegolithTimeOffset = &offset
dp.DeployConfig.L1CancunTimeOffset = &offset
dp.DeployConfig.L2GenesisCanyonTimeOffset = &offset
dp.DeployConfig.L2GenesisDeltaTimeOffset = &offset
dp.DeployConfig.L2GenesisEcotoneTimeOffset = &offset
require.Zero(t, *dp.DeployConfig.L2GenesisEcotoneTimeOffset)

sd := e2eutils.Setup(t, dp, defaultAlloc)
log := testlog.Logger(t, log.LevelDebug)
Expand Down Expand Up @@ -202,11 +195,6 @@ func newEngine(t Testing, sd *e2eutils.SetupData, log log.Logger) *L2Engine {
func TestDencunBlobTxRPC(gt *testing.T) {
t := NewDefaultTesting(gt)
dp := e2eutils.MakeDeployParams(t, defaultRollupTestParams)
offset := hexutil.Uint64(0)
dp.DeployConfig.L2GenesisRegolithTimeOffset = &offset
dp.DeployConfig.L2GenesisCanyonTimeOffset = &offset
dp.DeployConfig.L2GenesisDeltaTimeOffset = &offset
dp.DeployConfig.L2GenesisEcotoneTimeOffset = &offset

sd := e2eutils.Setup(t, dp, defaultAlloc)
log := testlog.Logger(t, log.LevelDebug)
Expand All @@ -221,11 +209,6 @@ func TestDencunBlobTxRPC(gt *testing.T) {
func TestDencunBlobTxInTxPool(gt *testing.T) {
t := NewDefaultTesting(gt)
dp := e2eutils.MakeDeployParams(t, defaultRollupTestParams)
offset := hexutil.Uint64(0)
dp.DeployConfig.L2GenesisRegolithTimeOffset = &offset
dp.DeployConfig.L2GenesisCanyonTimeOffset = &offset
dp.DeployConfig.L2GenesisDeltaTimeOffset = &offset
dp.DeployConfig.L2GenesisEcotoneTimeOffset = &offset

sd := e2eutils.Setup(t, dp, defaultAlloc)
log := testlog.Logger(t, log.LevelDebug)
Expand All @@ -239,11 +222,6 @@ func TestDencunBlobTxInTxPool(gt *testing.T) {
func TestDencunBlobTxInclusion(gt *testing.T) {
t := NewDefaultTesting(gt)
dp := e2eutils.MakeDeployParams(t, defaultRollupTestParams)
offset := hexutil.Uint64(0)
dp.DeployConfig.L2GenesisRegolithTimeOffset = &offset
dp.DeployConfig.L2GenesisCanyonTimeOffset = &offset
dp.DeployConfig.L2GenesisDeltaTimeOffset = &offset
dp.DeployConfig.L2GenesisEcotoneTimeOffset = &offset

sd := e2eutils.Setup(t, dp, defaultAlloc)
log := testlog.Logger(t, log.LevelDebug)
Expand Down
10 changes: 4 additions & 6 deletions op-e2e/actions/ecotone_fork_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,16 @@ func verifyCodeHashMatches(t Testing, client *ethclient.Client, address common.A
func TestEcotoneNetworkUpgradeTransactions(gt *testing.T) {
t := NewDefaultTesting(gt)
dp := e2eutils.MakeDeployParams(t, defaultRollupTestParams)
genesisBlock := hexutil.Uint64(0)
ecotoneOffset := hexutil.Uint64(4)

log := testlog.Logger(t, log.LevelDebug)

dp.DeployConfig.L1CancunTimeOffset = &genesisBlock // can be removed once Cancun on L1 is the default

require.Zero(t, *dp.DeployConfig.L1CancunTimeOffset)
// Activate all forks at genesis, and schedule Ecotone the block after
dp.DeployConfig.L2GenesisRegolithTimeOffset = &genesisBlock
dp.DeployConfig.L2GenesisCanyonTimeOffset = &genesisBlock
dp.DeployConfig.L2GenesisDeltaTimeOffset = &genesisBlock
dp.DeployConfig.L2GenesisEcotoneTimeOffset = &ecotoneOffset
dp.DeployConfig.L2GenesisFjordTimeOffset = nil
dp.DeployConfig.L2GenesisGraniteTimeOffset = nil
// New forks have to be added here...
require.NoError(t, dp.DeployConfig.Check(log), "must have valid config")

sd := e2eutils.Setup(t, dp, defaultAlloc)
Expand Down
56 changes: 38 additions & 18 deletions op-e2e/actions/l2_engine_test.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
package actions

import (
"encoding/binary"
"errors"
"math/big"
"testing"

"github.com/ethereum-optimism/optimism/op-program/client/l2/engineapi"
"github.com/ethereum-optimism/optimism/op-program/client/l2/engineapi/test"
"github.com/stretchr/testify/require"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus/beacon"
"github.com/ethereum/go-ethereum/consensus/ethash"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/triedb"
"github.com/ethereum/go-ethereum/triedb/hashdb"
"github.com/stretchr/testify/require"

"github.com/ethereum/go-ethereum/log"

"github.com/ethereum-optimism/optimism/op-e2e/e2eutils"
"github.com/ethereum-optimism/optimism/op-program/client/l2/engineapi"
"github.com/ethereum-optimism/optimism/op-program/client/l2/engineapi/test"
"github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/ethereum-optimism/optimism/op-service/sources"
"github.com/ethereum-optimism/optimism/op-service/testlog"
Expand All @@ -44,50 +46,62 @@ func TestL2EngineAPI(gt *testing.T) {
require.NoError(t, err)

// build an empty block
chainA, _ := core.GenerateChain(sd.L2Cfg.Config, genesisBlock, consensus, db, 1, func(i int, gen *core.BlockGen) {
chainA, _ := core.GenerateChain(sd.L2Cfg.Config, genesisBlock, consensus, db, 1, func(n int, gen *core.BlockGen) {
gen.SetCoinbase(common.Address{'A'})
if sd.L2Cfg.Config.IsCancun(gen.Number(), gen.Timestamp()) {
root := crypto.Keccak256Hash([]byte("A"), binary.BigEndian.AppendUint64(nil, uint64(n)))
gen.SetParentBeaconRoot(root)
}
})
payloadA, err := eth.BlockAsPayload(chainA[0], sd.RollupCfg.CanyonTime)

payloadA, err := eth.BlockAsPayloadEnv(chainA[0], sd.RollupCfg.CanyonTime)
require.NoError(t, err)

// apply the payload
status, err := l2Cl.NewPayload(t.Ctx(), payloadA, nil)
status, err := l2Cl.NewPayload(t.Ctx(), payloadA.ExecutionPayload, payloadA.ParentBeaconBlockRoot)
require.NoError(t, err)
require.Equal(t, status.Status, eth.ExecutionValid)
require.Equal(t, eth.ExecutionValid, status.Status)
require.Equal(t, genesisBlock.Hash(), engine.l2Chain.CurrentBlock().Hash(), "processed payloads are not immediately canonical")

// recognize the payload as canonical
fcRes, err := l2Cl.ForkchoiceUpdate(t.Ctx(), &eth.ForkchoiceState{
HeadBlockHash: payloadA.BlockHash,
HeadBlockHash: payloadA.ExecutionPayload.BlockHash,
SafeBlockHash: genesisBlock.Hash(),
FinalizedBlockHash: genesisBlock.Hash(),
}, nil)
require.NoError(t, err)

require.Equal(t, fcRes.PayloadStatus.Status, eth.ExecutionValid)
require.Equal(t, payloadA.BlockHash, engine.l2Chain.CurrentBlock().Hash(), "now payload A is canonical")
require.Equal(t, payloadA.ExecutionPayload.BlockHash, engine.l2Chain.CurrentBlock().Hash(), "now payload A is canonical")

// build an alternative block
chainB, _ := core.GenerateChain(sd.L2Cfg.Config, genesisBlock, consensus, db, 1, func(i int, gen *core.BlockGen) {
chainB, _ := core.GenerateChain(sd.L2Cfg.Config, genesisBlock, consensus, db, 1, func(n int, gen *core.BlockGen) {
gen.SetCoinbase(common.Address{'B'})
if sd.L2Cfg.Config.IsCancun(gen.Number(), gen.Timestamp()) {
root := crypto.Keccak256Hash([]byte("A"), binary.BigEndian.AppendUint64(nil, uint64(n)))
gen.SetParentBeaconRoot(root)
}
})
payloadB, err := eth.BlockAsPayload(chainB[0], sd.RollupCfg.CanyonTime)

payloadB, err := eth.BlockAsPayloadEnv(chainB[0], sd.RollupCfg.CanyonTime)
require.NoError(t, err)

// apply the payload
status, err = l2Cl.NewPayload(t.Ctx(), payloadB, nil)
status, err = l2Cl.NewPayload(t.Ctx(), payloadB.ExecutionPayload, payloadB.ParentBeaconBlockRoot)
require.NoError(t, err)
require.Equal(t, status.Status, eth.ExecutionValid)
require.Equal(t, payloadA.BlockHash, engine.l2Chain.CurrentBlock().Hash(), "processed payloads are not immediately canonical")
require.Equal(t, payloadA.ExecutionPayload.BlockHash, engine.l2Chain.CurrentBlock().Hash(), "processed payloads are not immediately canonical")

// reorg block A in favor of block B
fcRes, err = l2Cl.ForkchoiceUpdate(t.Ctx(), &eth.ForkchoiceState{
HeadBlockHash: payloadB.BlockHash,
HeadBlockHash: payloadB.ExecutionPayload.BlockHash,
SafeBlockHash: genesisBlock.Hash(),
FinalizedBlockHash: genesisBlock.Hash(),
}, nil)
require.NoError(t, err)
require.Equal(t, fcRes.PayloadStatus.Status, eth.ExecutionValid)
require.Equal(t, payloadB.BlockHash, engine.l2Chain.CurrentBlock().Hash(), "now payload B is canonical")
require.Equal(t, payloadB.ExecutionPayload.BlockHash, engine.l2Chain.CurrentBlock().Hash(), "now payload B is canonical")

}

func TestL2EngineAPIBlockBuilding(gt *testing.T) {
Expand Down Expand Up @@ -133,6 +147,11 @@ func TestL2EngineAPIBlockBuilding(gt *testing.T) {
w = &types.Withdrawals{}
}

var parentBeaconBlockRoot *common.Hash
if sd.RollupCfg.IsEcotone(uint64(nextBlockTime)) {
parentBeaconBlockRoot = &common.Hash{}
}

// Now let's ask the engine to build a block
fcRes, err := l2Cl.ForkchoiceUpdate(t.Ctx(), &eth.ForkchoiceState{
HeadBlockHash: parent.Hash(),
Expand All @@ -146,6 +165,7 @@ func TestL2EngineAPIBlockBuilding(gt *testing.T) {
NoTxPool: false,
GasLimit: (*eth.Uint64Quantity)(&sd.RollupCfg.Genesis.SystemConfig.GasLimit),
Withdrawals: w,
ParentBeaconBlockRoot: parentBeaconBlockRoot,
})
require.NoError(t, err)
require.Equal(t, fcRes.PayloadStatus.Status, eth.ExecutionValid)
Expand All @@ -161,7 +181,7 @@ func TestL2EngineAPIBlockBuilding(gt *testing.T) {
require.Equal(t, parent.Hash(), payload.ParentHash, "block builds on parent block")

// apply the payload
status, err := l2Cl.NewPayload(t.Ctx(), payload, nil)
status, err := l2Cl.NewPayload(t.Ctx(), payload, envelope.ParentBeaconBlockRoot)
require.NoError(t, err)
require.Equal(t, status.Status, eth.ExecutionValid)
require.Equal(t, parent.Hash(), engine.l2Chain.CurrentBlock().Hash(), "processed payloads are not immediately canonical")
Expand Down
5 changes: 5 additions & 0 deletions op-e2e/actions/span_batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ func TestHardforkMiddleOfSpanBatch(gt *testing.T) {
// Activate HF in the middle of the first epoch
deltaOffset := hexutil.Uint64(6)
applyDeltaTimeOffset(dp, &deltaOffset)
// Applies to HF that goes into Delta. Otherwise we end up with more upgrade txs and things during this case.
dp.DeployConfig.L2GenesisEcotoneTimeOffset = nil
dp.DeployConfig.L2GenesisFjordTimeOffset = nil
dp.DeployConfig.L2GenesisGraniteTimeOffset = nil

sd := e2eutils.Setup(t, dp, defaultAlloc)
log := testlog.Logger(t, log.LevelError)
miner, seqEngine, sequencer := setupSequencerTest(t, sd, log)
Expand Down
8 changes: 8 additions & 0 deletions op-e2e/actions/system_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,14 @@ func GPOParamsChange(gt *testing.T, deltaTimeOffset *hexutil.Uint64) {
t := NewDefaultTesting(gt)
dp := e2eutils.MakeDeployParams(t, defaultRollupTestParams)
applyDeltaTimeOffset(dp, deltaTimeOffset)

// activating Delta only, not Ecotone and further:
// the GPO change assertions here all apply only for the Delta transition.
// Separate tests cover Ecotone GPO changes.
dp.DeployConfig.L2GenesisEcotoneTimeOffset = nil
dp.DeployConfig.L2GenesisFjordTimeOffset = nil
dp.DeployConfig.L2GenesisGraniteTimeOffset = nil

sd := e2eutils.Setup(t, dp, defaultAlloc)
log := testlog.Logger(t, log.LevelDebug)
miner, seqEngine, sequencer := setupSequencerTest(t, sd, log)
Expand Down
10 changes: 5 additions & 5 deletions op-e2e/system_adminrpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,19 +198,19 @@ func TestPostUnsafePayload(t *testing.T) {

blockNumberOne, err := l2Seq.BlockByNumber(ctx, big.NewInt(1))
require.NoError(t, err)
payload, err := eth.BlockAsPayload(blockNumberOne, sys.RollupConfig.CanyonTime)
payloadEnv, err := eth.BlockAsPayloadEnv(blockNumberOne, sys.RollupConfig.CanyonTime)
require.NoError(t, err)
err = rollupClient.PostUnsafePayload(ctx, &eth.ExecutionPayloadEnvelope{ExecutionPayload: payload})
err = rollupClient.PostUnsafePayload(ctx, payloadEnv)
require.NoError(t, err)
require.NoError(t, wait.ForUnsafeBlock(ctx, rollupClient, 1), "Chain did not advance after posting payload")

// Test validation
blockNumberTwo, err := l2Seq.BlockByNumber(ctx, big.NewInt(2))
require.NoError(t, err)
payload, err = eth.BlockAsPayload(blockNumberTwo, sys.RollupConfig.CanyonTime)
payloadEnv, err = eth.BlockAsPayloadEnv(blockNumberTwo, sys.RollupConfig.CanyonTime)
require.NoError(t, err)
payload.BlockHash = common.Hash{0xaa}
err = rollupClient.PostUnsafePayload(ctx, &eth.ExecutionPayloadEnvelope{ExecutionPayload: payload})
payloadEnv.ExecutionPayload.BlockHash = common.Hash{0xaa}
err = rollupClient.PostUnsafePayload(ctx, payloadEnv)
require.ErrorContains(t, err, "payload has bad block hash")
}

Expand Down
Loading

0 comments on commit 2f295d0

Please sign in to comment.