Skip to content

Commit

Permalink
unexpose
Browse files Browse the repository at this point in the history
  • Loading branch information
pcw109550 committed Apr 18, 2024
1 parent 9ad972a commit a43ef85
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 39 deletions.
8 changes: 1 addition & 7 deletions op-e2e/e2eutils/disputegame/output_alphabet_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,7 @@ func (g *OutputAlphabetGameHelper) CreateHonestActor(ctx context.Context, l2Node
prestateProvider := outputs.NewPrestateProvider(rollupClient, prestateBlock)
correctTrace, err := outputs.NewOutputAlphabetTraceAccessor(logger, metrics.NoopMetrics, prestateProvider, rollupClient, l1Head, splitDepth, prestateBlock, poststateBlock)
g.Require.NoError(err, "Create trace accessor")
return &OutputHonestHelper{
T: g.T,
Require: g.Require,
Game: &g.OutputGameHelper,
Contract: contract,
CorrectTrace: correctTrace,
}
return NewOutputHonestHelper(g.T, g.Require, &g.OutputGameHelper, contract, correctTrace)
}

func (g *OutputAlphabetGameHelper) CreateDishonestHelper(ctx context.Context, l2Node string, defender bool) *DishonestHelper {
Expand Down
8 changes: 1 addition & 7 deletions op-e2e/e2eutils/disputegame/output_cannon_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,7 @@ func (g *OutputCannonGameHelper) CreateHonestActor(ctx context.Context, l2Node s
accessor, err := outputs.NewOutputCannonTraceAccessor(
logger, metrics.NoopMetrics, cfg, l2Client, prestateProvider, rollupClient, dir, l1Head, splitDepth, prestateBlock, poststateBlock)
g.Require.NoError(err, "Failed to create output cannon trace accessor")
return &OutputHonestHelper{
T: g.T,
Require: g.Require,
Game: &g.OutputGameHelper,
Contract: contract,
CorrectTrace: accessor,
}
return NewOutputHonestHelper(g.T, g.Require, &g.OutputGameHelper, contract, accessor)
}

type PreimageLoadCheck func(types.TraceProvider, uint64) error
Expand Down
60 changes: 35 additions & 25 deletions op-e2e/e2eutils/disputegame/output_honest_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,27 @@ import (
const getTraceTimeout = 10 * time.Minute

type OutputHonestHelper struct {
T *testing.T
Require *require.Assertions
Game *OutputGameHelper
Contract *contracts.FaultDisputeGameContract
CorrectTrace types.TraceAccessor
t *testing.T
require *require.Assertions
game *OutputGameHelper
contract *contracts.FaultDisputeGameContract
correctTrace types.TraceAccessor
}

func NewOutputHonestHelper(t *testing.T, require *require.Assertions, game *OutputGameHelper, contract *contracts.FaultDisputeGameContract, correctTrace types.TraceAccessor) *OutputHonestHelper {
return &OutputHonestHelper{
t: t,
require: require,
game: game,
contract: contract,
correctTrace: correctTrace,
}
}

func (h *OutputHonestHelper) CounterClaim(ctx context.Context, claim *ClaimHelper, opts ...MoveOpt) *ClaimHelper {
game, target := h.loadState(ctx, claim.Index)
value, err := h.CorrectTrace.Get(ctx, game, target, target.Position)
h.Require.NoErrorf(err, "Failed to determine correct claim at position %v with g index %v", target.Position, target.Position.ToGIndex())
value, err := h.correctTrace.Get(ctx, game, target, target.Position)
h.require.NoErrorf(err, "Failed to determine correct claim at position %v with g index %v", target.Position, target.Position.ToGIndex())
if value == claim.claim {
return h.DefendClaim(ctx, claim, opts...)
} else {
Expand All @@ -44,32 +54,32 @@ func (h *OutputHonestHelper) DefendClaim(ctx context.Context, claim *ClaimHelper

func (h *OutputHonestHelper) Attack(ctx context.Context, claimIdx int64, opts ...MoveOpt) {
// Ensure the claim exists
h.Game.WaitForClaimCount(ctx, claimIdx+1)
h.game.WaitForClaimCount(ctx, claimIdx+1)

ctx, cancel := context.WithTimeout(ctx, getTraceTimeout)
defer cancel()

game, claim := h.loadState(ctx, claimIdx)
attackPos := claim.Position.Attack()
h.T.Logf("Attacking claim %v at position %v with g index %v", claimIdx, attackPos, attackPos.ToGIndex())
value, err := h.CorrectTrace.Get(ctx, game, claim, attackPos)
h.Require.NoErrorf(err, "Get correct claim at position %v with g index %v", attackPos, attackPos.ToGIndex())
h.T.Log("Performing attack")
h.Game.Attack(ctx, claimIdx, value, opts...)
h.T.Log("Attack complete")
h.t.Logf("Attacking claim %v at position %v with g index %v", claimIdx, attackPos, attackPos.ToGIndex())
value, err := h.correctTrace.Get(ctx, game, claim, attackPos)
h.require.NoErrorf(err, "Get correct claim at position %v with g index %v", attackPos, attackPos.ToGIndex())
h.t.Log("Performing attack")
h.game.Attack(ctx, claimIdx, value, opts...)
h.t.Log("Attack complete")
}

func (h *OutputHonestHelper) Defend(ctx context.Context, claimIdx int64, opts ...MoveOpt) {
// Ensure the claim exists
h.Game.WaitForClaimCount(ctx, claimIdx+1)
h.game.WaitForClaimCount(ctx, claimIdx+1)

ctx, cancel := context.WithTimeout(ctx, getTraceTimeout)
defer cancel()
game, claim := h.loadState(ctx, claimIdx)
defendPos := claim.Position.Defend()
value, err := h.CorrectTrace.Get(ctx, game, claim, defendPos)
h.Game.Require.NoErrorf(err, "Get correct claim at position %v with g index %v", defendPos, defendPos.ToGIndex())
h.Game.Defend(ctx, claimIdx, value, opts...)
value, err := h.correctTrace.Get(ctx, game, claim, defendPos)
h.game.Require.NoErrorf(err, "Get correct claim at position %v with g index %v", defendPos, defendPos.ToGIndex())
h.game.Defend(ctx, claimIdx, value, opts...)
}

func (h *OutputHonestHelper) StepClaimFails(ctx context.Context, claim *ClaimHelper, isAttack bool) {
Expand All @@ -78,7 +88,7 @@ func (h *OutputHonestHelper) StepClaimFails(ctx context.Context, claim *ClaimHel

func (h *OutputHonestHelper) StepFails(ctx context.Context, claimIdx int64, isAttack bool) {
// Ensure the claim exists
h.Game.WaitForClaimCount(ctx, claimIdx+1)
h.game.WaitForClaimCount(ctx, claimIdx+1)

ctx, cancel := context.WithTimeout(ctx, 2*time.Minute)
defer cancel()
Expand All @@ -89,15 +99,15 @@ func (h *OutputHonestHelper) StepFails(ctx context.Context, claimIdx int64, isAt
// If we're defending, then the step will be from the trace to the next one
pos = pos.MoveRight()
}
prestate, proofData, _, err := h.CorrectTrace.GetStepData(ctx, game, claim, pos)
h.Require.NoError(err, "Get step data")
h.Game.StepFails(claimIdx, isAttack, prestate, proofData)
prestate, proofData, _, err := h.correctTrace.GetStepData(ctx, game, claim, pos)
h.require.NoError(err, "Get step data")
h.game.StepFails(claimIdx, isAttack, prestate, proofData)
}

func (h *OutputHonestHelper) loadState(ctx context.Context, claimIdx int64) (types.Game, types.Claim) {
claims, err := h.Contract.GetAllClaims(ctx, rpcblock.Latest)
h.Require.NoError(err, "Failed to load claims from game")
game := types.NewGameState(claims, h.Game.MaxDepth(ctx))
claims, err := h.contract.GetAllClaims(ctx, rpcblock.Latest)
h.require.NoError(err, "Failed to load claims from game")
game := types.NewGameState(claims, h.game.MaxDepth(ctx))

claim := game.Claims()[claimIdx]
return game, claim
Expand Down

0 comments on commit a43ef85

Please sign in to comment.