-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
op-e2e/actions: test interop safety checks
- Loading branch information
1 parent
c6d86b9
commit 6934085
Showing
11 changed files
with
265 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
package actions | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/mock" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/log" | ||
|
||
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils" | ||
"github.com/ethereum-optimism/optimism/op-node/rollup/interop" | ||
"github.com/ethereum-optimism/optimism/op-node/rollup/sync" | ||
"github.com/ethereum-optimism/optimism/op-service/testlog" | ||
"github.com/ethereum-optimism/optimism/op-supervisor/supervisor/types" | ||
) | ||
|
||
type mockSupervisor struct { | ||
Mock mock.Mock | ||
} | ||
|
||
func (m *mockSupervisor) ExpectCheckBlock(chainID types.ChainID, blockNumber uint64, safety types.SafetyLevel, err error) { | ||
m.Mock.On("CheckBlock", chainID, blockNumber).Once().Return(safety, &err) | ||
} | ||
|
||
func (m *mockSupervisor) CheckBlock(ctx context.Context, chainID types.ChainID, blockHash common.Hash, blockNumber uint64) (types.SafetyLevel, error) { | ||
result := m.Mock.MethodCalled("CheckBlock", chainID, blockNumber) | ||
return result.Get(0).(types.SafetyLevel), *result.Get(1).(*error) | ||
} | ||
|
||
var _ interop.InteropBackend = (*mockSupervisor)(nil) | ||
|
||
func TestInteropVerifier(gt *testing.T) { | ||
t := NewDefaultTesting(gt) | ||
dp := e2eutils.MakeDeployParams(t, defaultRollupTestParams) | ||
sd := e2eutils.Setup(t, dp, defaultAlloc) | ||
// Temporary work-around: interop needs to be active, for cross-safety to not be instant. | ||
// The state genesis in this test is pre-interop however. | ||
sd.RollupCfg.InteropTime = new(uint64) | ||
logger := testlog.Logger(t, log.LevelDebug) | ||
seqMockBackend := &mockSupervisor{} | ||
l1Miner, seqEng, seq := setupSequencerTest(t, sd, logger, | ||
WithVerifierOpts(WithInteropBackend(seqMockBackend))) | ||
|
||
batcher := NewL2Batcher(logger, sd.RollupCfg, DefaultBatcherCfg(dp), | ||
seq.RollupClient(), l1Miner.EthClient(), seqEng.EthClient(), seqEng.EngineClient(t, sd.RollupCfg)) | ||
|
||
verMockBackend := &mockSupervisor{} | ||
_, ver := setupVerifier(t, sd, logger, | ||
l1Miner.L1Client(t, sd.RollupCfg), l1Miner.BlobStore(), &sync.Config{}, | ||
WithInteropBackend(verMockBackend)) | ||
|
||
seq.ActL2PipelineFull(t) | ||
ver.ActL2PipelineFull(t) | ||
|
||
l2ChainID := types.ChainIDFromBig(sd.RollupCfg.L2ChainID) | ||
seqMockBackend.ExpectCheckBlock(l2ChainID, 1, types.Unsafe, nil) | ||
// create an unsafe L2 block | ||
seq.ActL2StartBlock(t) | ||
seq.ActL2EndBlock(t) | ||
seq.ActL2PipelineFull(t) | ||
seqMockBackend.Mock.AssertExpectations(t) | ||
status := seq.SyncStatus() | ||
require.Equal(t, uint64(1), status.UnsafeL2.Number) | ||
require.Equal(t, uint64(0), status.CrossUnsafeL2.Number) | ||
require.Equal(t, uint64(0), status.LocalSafeL2.Number) | ||
require.Equal(t, uint64(0), status.SafeL2.Number) | ||
|
||
// promote it to cross-unsafe in the backend | ||
// and see if the node picks up on it | ||
seqMockBackend.ExpectCheckBlock(l2ChainID, 1, types.CrossUnsafe, nil) | ||
seq.ActInteropBackendCheck(t) | ||
seq.ActL2PipelineFull(t) | ||
seqMockBackend.Mock.AssertExpectations(t) | ||
status = seq.SyncStatus() | ||
require.Equal(t, uint64(1), status.UnsafeL2.Number) | ||
require.Equal(t, uint64(1), status.CrossUnsafeL2.Number, "cross unsafe now") | ||
require.Equal(t, uint64(0), status.LocalSafeL2.Number) | ||
require.Equal(t, uint64(0), status.SafeL2.Number) | ||
|
||
// submit all new L2 blocks | ||
batcher.ActSubmitAll(t) | ||
// new L1 block with L2 batch | ||
l1Miner.ActL1StartBlock(12)(t) | ||
l1Miner.ActL1IncludeTx(sd.RollupCfg.Genesis.SystemConfig.BatcherAddr)(t) | ||
l1Miner.ActL1EndBlock(t) | ||
|
||
// Sync the L1 block, to verify the L2 block as local-safe. | ||
seqMockBackend.ExpectCheckBlock(l2ChainID, 1, types.CrossUnsafe, nil) // not cross-safe yet | ||
seq.ActL1HeadSignal(t) | ||
seq.ActL2PipelineFull(t) | ||
seqMockBackend.Mock.AssertExpectations(t) | ||
|
||
status = seq.SyncStatus() | ||
require.Equal(t, uint64(1), status.UnsafeL2.Number) | ||
require.Equal(t, uint64(1), status.CrossUnsafeL2.Number) | ||
require.Equal(t, uint64(1), status.LocalSafeL2.Number, "local safe changed") | ||
require.Equal(t, uint64(0), status.SafeL2.Number) | ||
|
||
// Now mark it as cross-safe | ||
seqMockBackend.ExpectCheckBlock(l2ChainID, 1, types.CrossSafe, nil) | ||
seq.ActInteropBackendCheck(t) | ||
seq.ActL2PipelineFull(t) | ||
seqMockBackend.Mock.AssertExpectations(t) | ||
|
||
status = seq.SyncStatus() | ||
require.Equal(t, uint64(1), status.UnsafeL2.Number) | ||
require.Equal(t, uint64(1), status.CrossUnsafeL2.Number) | ||
require.Equal(t, uint64(1), status.LocalSafeL2.Number) | ||
require.Equal(t, uint64(1), status.SafeL2.Number, "cross-safe reached") | ||
require.Equal(t, uint64(0), status.FinalizedL2.Number) | ||
|
||
// The verifier might not see the L2 block that was just derived from L1 as cross-verified yet. | ||
verMockBackend.ExpectCheckBlock(l2ChainID, 1, types.Unsafe, nil) // for the local unsafe check | ||
verMockBackend.ExpectCheckBlock(l2ChainID, 1, types.Unsafe, nil) // for the local safe check | ||
ver.ActL1HeadSignal(t) | ||
ver.ActL2PipelineFull(t) | ||
verMockBackend.Mock.AssertExpectations(t) | ||
status = ver.SyncStatus() | ||
require.Equal(t, uint64(1), status.UnsafeL2.Number, "synced the block") | ||
require.Equal(t, uint64(0), status.CrossUnsafeL2.Number, "not cross-verified yet") | ||
require.Equal(t, uint64(1), status.LocalSafeL2.Number, "derived from L1, thus local-safe") | ||
require.Equal(t, uint64(0), status.SafeL2.Number, "not yet cross-safe") | ||
require.Equal(t, uint64(0), status.FinalizedL2.Number) | ||
|
||
// signal that L1 finalized; the cross-safe block we have should get finalized too | ||
l1Miner.ActL1SafeNext(t) | ||
l1Miner.ActL1FinalizeNext(t) | ||
seq.ActL1SafeSignal(t) | ||
seq.ActL1FinalizedSignal(t) | ||
seq.ActL2PipelineFull(t) | ||
seqMockBackend.Mock.AssertExpectations(t) | ||
|
||
status = seq.SyncStatus() | ||
require.Equal(t, uint64(1), status.FinalizedL2.Number, "finalized the block") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.