Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

op-challenger: Release agent resources once game is complete #11820

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions op-challenger/game/fault/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ type GameContract interface {
GetL1Head(ctx context.Context) (common.Hash, error)
}

var actNoop = func(ctx context.Context) error {
return nil
}

type resourceCreator func(ctx context.Context, logger log.Logger, gameDepth types.Depth, dir string) (types.TraceAccessor, error)

func NewGamePlayer(
Expand Down Expand Up @@ -98,9 +102,7 @@ func NewGamePlayer(
prestateValidators: validators,
status: status,
// Act function does nothing because the game is already complete
act: func(ctx context.Context) error {
return nil
},
act: actNoop,
}, nil
}

Expand Down Expand Up @@ -195,6 +197,10 @@ func (g *GamePlayer) ProgressGame(ctx context.Context) gameTypes.GameStatus {
}
g.logGameStatus(ctx, status)
g.status = status
if status != gameTypes.GameStatusInProgress {
// Release the agent as we will no longer need to act on this game.
g.act = actNoop
}
return status
}

Expand Down
5 changes: 5 additions & 0 deletions op-challenger/game/fault/player_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ func TestDoNotActOnCompleteGame(t *testing.T) {
fetched = game.ProgressGame(context.Background())
require.Equal(t, 1, gameState.callCount, "does not act after game is complete")
require.Equal(t, status, fetched)

// Should have replaced the act function with a noop so callCount doesn't update even when called directly
// This allows the agent resources to be GC'd
require.NoError(t, game.act(context.Background()))
require.Equal(t, 1, gameState.callCount)
})
}
}
Expand Down
Loading