Skip to content

Commit

Permalink
op-challenger: Do not resolve games in selective mode (#11430)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajsutton authored Aug 13, 2024
1 parent 97aac00 commit 2b19d08
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 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: 23 additions & 10 deletions op-challenger/game/fault/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"math/big"
"slices"
"sync"
"testing"
"time"
Expand Down Expand Up @@ -127,20 +128,27 @@ 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

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 +238,7 @@ type stubResponder struct {
callResolveClaimCount int
callResolveClaimErr error
resolveClaimCount int
resolvedClaims []uint64
}

func (s *stubResponder) CallResolve(_ context.Context) (gameTypes.GameStatus, error) {
Expand All @@ -246,9 +255,12 @@ func (s *stubResponder) Resolve() error {
return s.resolveErr
}

func (s *stubResponder) CallResolveClaim(_ context.Context, _ uint64) error {
func (s *stubResponder) CallResolveClaim(_ context.Context, idx uint64) error {
s.l.Lock()
defer s.l.Unlock()
if slices.Contains(s.resolvedClaims, idx) {
return errors.New("already resolved")
}
s.callResolveClaimCount++
return s.callResolveClaimErr
}
Expand All @@ -257,6 +269,7 @@ func (s *stubResponder) ResolveClaims(claims ...uint64) error {
s.l.Lock()
defer s.l.Unlock()
s.resolveClaimCount += len(claims)
s.resolvedClaims = append(s.resolvedClaims, claims...)
return nil
}

Expand Down

0 comments on commit 2b19d08

Please sign in to comment.