Skip to content

Commit

Permalink
op-challenger: Do not resolve games in selective mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ajsutton committed Aug 9, 2024
1 parent b1dfa22 commit b5904bd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
5 changes: 5 additions & 0 deletions op-challenger/game/fault/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ func (a *Agent) tryResolve(ctx context.Context) bool {
a.log.Error("Failed to resolve claims", "err", err)
return false
}
if a.selective {
// Never resolve games in selective mode as it won't unlock any bonds for us.
// Assume the game is still in progress or the player wouldn't have told us to act.
return false
}
status, err := a.responder.CallResolve(ctx)
if err != nil || status == gameTypes.GameStatusInProgress {
return false
Expand Down
33 changes: 24 additions & 9 deletions op-challenger/game/fault/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,31 @@ func TestAgent_SelectiveClaimResolution(t *testing.T) {
},
}

for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
for _, tCase := range tests {
tCase := tCase
t.Run(tCase.name, func(t *testing.T) {
agent, claimLoader, responder := setupTestAgent(t)
agent.selective = test.selective
agent.claimants = test.claimants
agent.selective = tCase.selective
agent.claimants = tCase.claimants
claimLoader.maxLoads = 1
claimLoader.claims = test.claims
responder.callResolveStatus = test.callResolveStatus
if tCase.selective {
claimLoader.maxLoads = 0
}
claimLoader.claims = tCase.claims
responder.callResolveStatus = tCase.callResolveStatus
responder.onResolveClaims = func(claims ...uint64) {
// Ensure there are no more claims for us to resolve, otherwise we loop forever trying to resolve them
claimLoader.claims = []types.Claim{test.NewClaimBuilder(t, 4, alphabet.NewTraceProvider(big.NewInt(0), 4)).CreateRootClaim()}
}

require.NoError(t, agent.Act(ctx))

require.Equal(t, test.expectedResolveCount, responder.callResolveClaimCount, "should check if game is resolvable")
require.Equal(t, test.expectedResolveCount, responder.resolveClaimCount, "should check if game is resolvable")
require.Equal(t, tCase.expectedResolveCount, responder.callResolveClaimCount, "should check if game is resolvable")
require.Equal(t, tCase.expectedResolveCount, responder.resolveClaimCount, "should check if game is resolvable")
if tCase.selective {
require.Equal(t, 0, responder.callResolveCount, "should not resolve game in selective mode")
require.Equal(t, 0, responder.resolveCount, "should not resolve game in selective mode")
}
})
}
}
Expand Down Expand Up @@ -230,6 +241,7 @@ type stubResponder struct {
callResolveClaimCount int
callResolveClaimErr error
resolveClaimCount int
onResolveClaims func(claims ...uint64)
}

func (s *stubResponder) CallResolve(_ context.Context) (gameTypes.GameStatus, error) {
Expand Down Expand Up @@ -257,6 +269,9 @@ func (s *stubResponder) ResolveClaims(claims ...uint64) error {
s.l.Lock()
defer s.l.Unlock()
s.resolveClaimCount += len(claims)
if s.onResolveClaims != nil {
s.onResolveClaims(claims...)
}
return nil
}

Expand Down

0 comments on commit b5904bd

Please sign in to comment.