Commit 3891726b authored by OptimismBot's avatar OptimismBot Committed by GitHub

Merge pull request #6431 from ethereum-optimism/op-e2e/shanghai-l1

op-e2e: enable shanghai on L1
parents 4ca169c0 807f237d
...@@ -40,11 +40,19 @@ type Deployment struct { ...@@ -40,11 +40,19 @@ type Deployment struct {
type Deployer func(*backends.SimulatedBackend, *bind.TransactOpts, Constructor) (*types.Transaction, error) type Deployer func(*backends.SimulatedBackend, *bind.TransactOpts, Constructor) (*types.Transaction, error)
func NewBackend() *backends.SimulatedBackend { // NewL1Backend returns a SimulatedBackend suitable for L1. It has
return NewBackendWithGenesisTimestamp(0) // the latest L1 hardforks enabled.
func NewL1Backend() *backends.SimulatedBackend {
return NewBackendWithGenesisTimestamp(0, true)
} }
func NewBackendWithGenesisTimestamp(ts uint64) *backends.SimulatedBackend { // NewL2Backend returns a SimulatedBackend suitable for L2.
// It has the latest L2 hardforks enabled.
func NewL2Backend() *backends.SimulatedBackend {
return NewBackendWithGenesisTimestamp(0, false)
}
func NewBackendWithGenesisTimestamp(ts uint64, shanghai bool) *backends.SimulatedBackend {
chainConfig := params.ChainConfig{ chainConfig := params.ChainConfig{
ChainID: ChainID, ChainID: ChainID,
HomesteadBlock: big.NewInt(0), HomesteadBlock: big.NewInt(0),
...@@ -70,6 +78,10 @@ func NewBackendWithGenesisTimestamp(ts uint64) *backends.SimulatedBackend { ...@@ -70,6 +78,10 @@ func NewBackendWithGenesisTimestamp(ts uint64) *backends.SimulatedBackend {
TerminalTotalDifficultyPassed: true, TerminalTotalDifficultyPassed: true,
} }
if shanghai {
chainConfig.ShanghaiTime = u64ptr(0)
}
return backends.NewSimulatedBackendWithOpts( return backends.NewSimulatedBackendWithOpts(
backends.WithCacheConfig(&core.CacheConfig{ backends.WithCacheConfig(&core.CacheConfig{
Preimages: true, Preimages: true,
...@@ -132,3 +144,7 @@ func Deploy(backend *backends.SimulatedBackend, constructors []Constructor, cb D ...@@ -132,3 +144,7 @@ func Deploy(backend *backends.SimulatedBackend, constructors []Constructor, cb D
return results, nil return results, nil
} }
func u64ptr(n uint64) *uint64 {
return &n
}
...@@ -127,6 +127,7 @@ func NewL1Genesis(config *DeployConfig) (*core.Genesis, error) { ...@@ -127,6 +127,7 @@ func NewL1Genesis(config *DeployConfig) (*core.Genesis, error) {
LondonBlock: big.NewInt(0), LondonBlock: big.NewInt(0),
ArrowGlacierBlock: big.NewInt(0), ArrowGlacierBlock: big.NewInt(0),
GrayGlacierBlock: big.NewInt(0), GrayGlacierBlock: big.NewInt(0),
ShanghaiTime: u64ptr(0),
} }
if config.CliqueSignerAddress != (common.Address{}) { if config.CliqueSignerAddress != (common.Address{}) {
...@@ -180,3 +181,7 @@ func NewL1Genesis(config *DeployConfig) (*core.Genesis, error) { ...@@ -180,3 +181,7 @@ func NewL1Genesis(config *DeployConfig) (*core.Genesis, error) {
Alloc: map[common.Address]core.GenesisAccount{}, Alloc: map[common.Address]core.GenesisAccount{},
}, nil }, nil
} }
func u64ptr(n uint64) *uint64 {
return &n
}
...@@ -76,7 +76,8 @@ func BuildL1DeveloperGenesis(config *DeployConfig) (*core.Genesis, error) { ...@@ -76,7 +76,8 @@ func BuildL1DeveloperGenesis(config *DeployConfig) (*core.Genesis, error) {
return nil, err return nil, err
} }
backend := deployer.NewBackendWithGenesisTimestamp(uint64(config.L1GenesisBlockTimestamp)) // Enable shanghai
backend := deployer.NewBackendWithGenesisTimestamp(uint64(config.L1GenesisBlockTimestamp), true)
deployments, err := deployL1Contracts(config, backend) deployments, err := deployL1Contracts(config, backend)
if err != nil { if err != nil {
......
...@@ -158,7 +158,7 @@ func BuildOptimism(immutable ImmutableConfig) (DeploymentResults, error) { ...@@ -158,7 +158,7 @@ func BuildOptimism(immutable ImmutableConfig) (DeploymentResults, error) {
// can be properly set. The bytecode returned in the results is suitable to be // can be properly set. The bytecode returned in the results is suitable to be
// inserted into the state via state surgery. // inserted into the state via state surgery.
func BuildL2(constructors []deployer.Constructor) (DeploymentResults, error) { func BuildL2(constructors []deployer.Constructor) (DeploymentResults, error) {
deployments, err := deployer.Deploy(deployer.NewBackend(), constructors, l2Deployer) deployments, err := deployer.Deploy(deployer.NewL2Backend(), constructors, l2Deployer)
if err != nil { if err != nil {
return nil, err return nil, err
} }
......
package actions
import (
"testing"
"github.com/ethereum/go-ethereum/log"
"github.com/stretchr/testify/require"
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils"
"github.com/ethereum-optimism/optimism/op-node/testlog"
)
func TestShapellaL1Fork(gt *testing.T) {
t := NewDefaultTesting(gt)
dp := e2eutils.MakeDeployParams(t, defaultRollupTestParams)
sd := e2eutils.Setup(t, dp, defaultAlloc)
activation := sd.L1Cfg.Timestamp + 24
sd.L1Cfg.Config.ShanghaiTime = &activation
log := testlog.Logger(t, log.LvlDebug)
_, _, miner, sequencer, _, verifier, _, batcher := setupReorgTestActors(t, dp, sd, log)
require.False(t, sd.L1Cfg.Config.IsShanghai(miner.l1Chain.CurrentBlock().Time), "not active yet")
// start op-nodes
sequencer.ActL2PipelineFull(t)
verifier.ActL2PipelineFull(t)
// build empty L1 blocks, crossing the fork boundary
miner.ActEmptyBlock(t)
miner.ActEmptyBlock(t)
miner.ActEmptyBlock(t)
// verify Shanghai is active
l1Head := miner.l1Chain.CurrentBlock()
require.True(t, sd.L1Cfg.Config.IsShanghai(l1Head.Time))
// build L2 chain up to and including L2 blocks referencing shanghai L1 blocks
sequencer.ActL1HeadSignal(t)
sequencer.ActBuildToL1Head(t)
miner.ActL1StartBlock(12)(t)
batcher.ActSubmitAll(t)
miner.ActL1IncludeTx(batcher.batcherAddr)(t)
miner.ActL1EndBlock(t)
// sync verifier
verifier.ActL1HeadSignal(t)
verifier.ActL2PipelineFull(t)
// verify verifier accepted shanghai L1 inputs
require.Equal(t, l1Head.Hash(), verifier.SyncStatus().SafeL2.L1Origin.Hash, "verifier synced L1 chain that includes shanghai headers")
require.Equal(t, sequencer.SyncStatus().UnsafeL2, verifier.SyncStatus().UnsafeL2, "verifier and sequencer agree")
}
...@@ -7,6 +7,7 @@ import ( ...@@ -7,6 +7,7 @@ import (
"github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/beacon/engine" "github.com/ethereum/go-ethereum/beacon/engine"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/eth/catalyst" "github.com/ethereum/go-ethereum/eth/catalyst"
"github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/event"
...@@ -63,7 +64,7 @@ func (f *fakePoS) Start() error { ...@@ -63,7 +64,7 @@ func (f *fakePoS) Start() error {
// We're a long way behind, let's skip some blocks... // We're a long way behind, let's skip some blocks...
newBlockTime = uint64(f.clock.Now().Unix()) newBlockTime = uint64(f.clock.Now().Unix())
} }
res, err := f.engineAPI.ForkchoiceUpdatedV1(engine.ForkchoiceStateV1{ res, err := f.engineAPI.ForkchoiceUpdatedV2(engine.ForkchoiceStateV1{
HeadBlockHash: head.Hash(), HeadBlockHash: head.Hash(),
SafeBlockHash: safe.Hash(), SafeBlockHash: safe.Hash(),
FinalizedBlockHash: finalized.Hash(), FinalizedBlockHash: finalized.Hash(),
...@@ -71,6 +72,7 @@ func (f *fakePoS) Start() error { ...@@ -71,6 +72,7 @@ func (f *fakePoS) Start() error {
Timestamp: newBlockTime, Timestamp: newBlockTime,
Random: common.Hash{}, Random: common.Hash{},
SuggestedFeeRecipient: head.Coinbase, SuggestedFeeRecipient: head.Coinbase,
Withdrawals: make([]*types.Withdrawal, 0),
}) })
if err != nil { if err != nil {
f.log.Error("failed to start building L1 block", "err", err) f.log.Error("failed to start building L1 block", "err", err)
...@@ -90,17 +92,17 @@ func (f *fakePoS) Start() error { ...@@ -90,17 +92,17 @@ func (f *fakePoS) Start() error {
tim.Stop() tim.Stop()
return nil return nil
} }
payload, err := f.engineAPI.GetPayloadV1(*res.PayloadID) envelope, err := f.engineAPI.GetPayloadV2(*res.PayloadID)
if err != nil { if err != nil {
f.log.Error("failed to finish building L1 block", "err", err) f.log.Error("failed to finish building L1 block", "err", err)
continue continue
} }
if _, err := f.engineAPI.NewPayloadV1(*payload); err != nil { if _, err := f.engineAPI.NewPayloadV2(*envelope.ExecutionPayload); err != nil {
f.log.Error("failed to insert built L1 block", "err", err) f.log.Error("failed to insert built L1 block", "err", err)
continue continue
} }
if _, err := f.engineAPI.ForkchoiceUpdatedV1(engine.ForkchoiceStateV1{ if _, err := f.engineAPI.ForkchoiceUpdatedV2(engine.ForkchoiceStateV1{
HeadBlockHash: payload.BlockHash, HeadBlockHash: envelope.ExecutionPayload.BlockHash,
SafeBlockHash: safe.Hash(), SafeBlockHash: safe.Hash(),
FinalizedBlockHash: finalized.Hash(), FinalizedBlockHash: finalized.Hash(),
}, nil); err != nil { }, nil); err != nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment