Commit 833e3558 authored by Adrian Sutton's avatar Adrian Sutton Committed by clabby

Fix output_cannon e2e test.

Load the split depth from the contract when creating output_cannon games
Increase the max game depth so the cannon trace completes.
Legacy cannon games now have a fixed depth of 30 to avoid making those tests even slower.
Fix extra data creation in e2e helpers so the l2 block number is set correctly.
parent 595e8ace
...@@ -121,7 +121,11 @@ func registerOutputCannon( ...@@ -121,7 +121,11 @@ func registerOutputCannon(
if err != nil { if err != nil {
return nil, err return nil, err
} }
accessor, err := outputs.NewOutputCannonTraceAccessor(ctx, logger, m, cfg, l2Client, contract, dir, gameDepth, agreed, disputed) splitDepth, err := contract.GetSplitDepth(ctx)
if err != nil {
return nil, fmt.Errorf("failed to load split depth: %w", err)
}
accessor, err := outputs.NewOutputCannonTraceAccessor(ctx, logger, m, cfg, l2Client, contract, dir, gameDepth, splitDepth, agreed, disputed)
if err != nil { if err != nil {
return nil, err return nil, err
} }
......
...@@ -25,13 +25,12 @@ func NewOutputCannonTraceAccessor( ...@@ -25,13 +25,12 @@ func NewOutputCannonTraceAccessor(
contract cannon.L1HeadSource, contract cannon.L1HeadSource,
dir string, dir string,
gameDepth uint64, gameDepth uint64,
splitDepth uint64,
prestateBlock uint64, prestateBlock uint64,
poststateBlock uint64, poststateBlock uint64,
) (*trace.Accessor, error) { ) (*trace.Accessor, error) {
// TODO(client-pod#43): Load depths from the contract bottomDepth := gameDepth - splitDepth
topDepth := gameDepth / 2 outputProvider, err := NewTraceProvider(ctx, logger, cfg.RollupRpc, splitDepth, prestateBlock, poststateBlock)
bottomDepth := gameDepth - topDepth
outputProvider, err := NewTraceProvider(ctx, logger, cfg.RollupRpc, topDepth, prestateBlock, poststateBlock)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -48,6 +47,6 @@ func NewOutputCannonTraceAccessor( ...@@ -48,6 +47,6 @@ func NewOutputCannonTraceAccessor(
} }
cache := NewProviderCache(m, "output_cannon_provider", cannonCreator) cache := NewProviderCache(m, "output_cannon_provider", cannonCreator)
selector := split.NewSplitProviderSelector(outputProvider, int(topDepth), OutputRootSplitAdapter(outputProvider, cache.GetOrCreate)) selector := split.NewSplitProviderSelector(outputProvider, int(splitDepth), OutputRootSplitAdapter(outputProvider, cache.GetOrCreate))
return trace.NewAccessor(selector), nil return trace.NewAccessor(selector), nil
} }
...@@ -143,6 +143,7 @@ func (h *FactoryHelper) StartAlphabetGame(ctx context.Context, claimedAlphabet s ...@@ -143,6 +143,7 @@ func (h *FactoryHelper) StartAlphabetGame(ctx context.Context, claimedAlphabet s
func (h *FactoryHelper) StartOutputCannonGame(ctx context.Context, rollupEndpoint string, rootClaim common.Hash) *OutputCannonGameHelper { func (h *FactoryHelper) StartOutputCannonGame(ctx context.Context, rollupEndpoint string, rootClaim common.Hash) *OutputCannonGameHelper {
rollupClient, err := dial.DialRollupClientWithTimeout(ctx, 30*time.Second, testlog.Logger(h.t, log.LvlInfo), rollupEndpoint) rollupClient, err := dial.DialRollupClientWithTimeout(ctx, 30*time.Second, testlog.Logger(h.t, log.LvlInfo), rollupEndpoint)
h.require.NoError(err) h.require.NoError(err)
h.t.Cleanup(rollupClient.Close)
extraData, _ := h.createBisectionGameExtraData(ctx, rollupClient) extraData, _ := h.createBisectionGameExtraData(ctx, rollupClient)
...@@ -279,11 +280,22 @@ func (h *FactoryHelper) createCannonGame(ctx context.Context, rootClaim common.H ...@@ -279,11 +280,22 @@ func (h *FactoryHelper) createCannonGame(ctx context.Context, rootClaim common.H
} }
func (h *FactoryHelper) createBisectionGameExtraData(ctx context.Context, client *sources.RollupClient) (extraData []byte, l2BlockNumber uint64) { func (h *FactoryHelper) createBisectionGameExtraData(ctx context.Context, client *sources.RollupClient) (extraData []byte, l2BlockNumber uint64) {
timeoutCtx, cancel := context.WithTimeout(ctx, 1*time.Minute)
defer cancel()
err := wait.For(timeoutCtx, time.Second, func() (bool, error) {
status, err := client.SyncStatus(ctx)
if err != nil {
return false, err
}
return status.SafeL2.Number > 0, nil
})
h.require.NoError(err, "Safe head did not progress past genesis")
syncStatus, err := client.SyncStatus(ctx) syncStatus, err := client.SyncStatus(ctx)
h.require.NoError(err, "failed to get sync status") h.require.NoError(err, "failed to get sync status")
l2BlockNumber = syncStatus.SafeL2.Number l2BlockNumber = syncStatus.SafeL2.Number
h.t.Logf("Creating game with l2 block number: %v", l2BlockNumber)
extraData = make([]byte, 32) extraData = make([]byte, 32)
binary.BigEndian.PutUint64(extraData, l2BlockNumber) binary.BigEndian.PutUint64(extraData[24:], l2BlockNumber)
return return
} }
......
...@@ -402,10 +402,12 @@ func (g *OutputGameHelper) gameData(ctx context.Context) string { ...@@ -402,10 +402,12 @@ func (g *OutputGameHelper) gameData(ctx context.Context) string {
info = info + fmt.Sprintf("%v - Position: %v, Depth: %v, IndexAtDepth: %v Trace Index: %v, Value: %v, Countered: %v, ParentIndex: %v\n", info = info + fmt.Sprintf("%v - Position: %v, Depth: %v, IndexAtDepth: %v Trace Index: %v, Value: %v, Countered: %v, ParentIndex: %v\n",
i, claim.Position.Int64(), pos.Depth(), pos.IndexAtDepth(), pos.TraceIndex(maxDepth), common.Hash(claim.Claim).Hex(), claim.Countered, claim.ParentIndex) i, claim.Position.Int64(), pos.Depth(), pos.IndexAtDepth(), pos.TraceIndex(maxDepth), common.Hash(claim.Claim).Hex(), claim.Countered, claim.ParentIndex)
} }
l2BlockNum, err := g.game.L2BlockNumber(opts)
g.require.NoError(err, "Load l2 block number")
status, err := g.game.Status(opts) status, err := g.game.Status(opts)
g.require.NoError(err, "Load game status") g.require.NoError(err, "Load game status")
return fmt.Sprintf("Game %v - %v - Split Depth: %v - Max Depth: %v:\n%v\n", return fmt.Sprintf("Game %v - %v - L2 Block: %v - Split Depth: %v - Max Depth: %v:\n%v\n",
g.addr, Status(status), splitDepth, maxDepth, info) g.addr, Status(status), l2BlockNum.Uint64(), splitDepth, maxDepth, info)
} }
func (g *OutputGameHelper) LogGameData(ctx context.Context) { func (g *OutputGameHelper) LogGameData(ctx context.Context) {
......
...@@ -38,12 +38,8 @@ func TestOutputCannonGame(t *testing.T) { ...@@ -38,12 +38,8 @@ func TestOutputCannonGame(t *testing.T) {
game.Attack(ctx, i, common.Hash{0xaa}) game.Attack(ctx, i, common.Hash{0xaa})
game.LogGameData(ctx) game.LogGameData(ctx)
} }
game.WaitForCorrectOutputRoot(ctx, splitDepth)
// Post the first cannon output root (with 01 status code to show the output root is invalid) // Wait for the challenger to post the first claim in the cannon trace
game.Attack(ctx, splitDepth, common.Hash{0x01}) game.WaitForClaimAtDepth(ctx, int(splitDepth+1))
// Challenger should counter
game.WaitForClaimAtDepth(ctx, int(splitDepth+2))
game.LogGameData(ctx) game.LogGameData(ctx)
} }
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
"l2GenesisDeltaTimeOffset": null, "l2GenesisDeltaTimeOffset": null,
"l2GenesisCanyonTimeOffset": "0x0", "l2GenesisCanyonTimeOffset": "0x0",
"faultGameAbsolutePrestate": "0x03c7ae758795765c6664a5d39bf63841c71ff191e9189522bad8ebff5d4eca98", "faultGameAbsolutePrestate": "0x03c7ae758795765c6664a5d39bf63841c71ff191e9189522bad8ebff5d4eca98",
"faultGameMaxDepth": 30, "faultGameMaxDepth": 44,
"faultGameMaxDuration": 1200, "faultGameMaxDuration": 1200,
"outputBisectionGameGenesisBlock": 0, "outputBisectionGameGenesisBlock": 0,
"outputBisectionGameGenesisOutputRoot": "0x0000000000000000000000000000000000000000000000000000000000000000", "outputBisectionGameGenesisOutputRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
......
...@@ -1027,8 +1027,8 @@ contract Deploy is Deployer { ...@@ -1027,8 +1027,8 @@ contract Deploy is Deployer {
_gameType: GameTypes.FAULT, _gameType: GameTypes.FAULT,
_absolutePrestate: loadMipsAbsolutePrestate(), _absolutePrestate: loadMipsAbsolutePrestate(),
_faultVm: IBigStepper(mustGetAddress("Mips")), _faultVm: IBigStepper(mustGetAddress("Mips")),
_maxGameDepth: cfg.faultGameMaxDepth() _maxGameDepth: 30 // Hard code depth for legacy game to keep e2e tests fast
}); });
} }
/// @notice Sets the implementation for the `OUTPUT_CANNON` game type in the `DisputeGameFactory` /// @notice Sets the implementation for the `OUTPUT_CANNON` game type in the `DisputeGameFactory`
......
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