Commit 4cd7b947 authored by Adrian Sutton's avatar Adrian Sutton

op-challenger: Rename GameData to GameMetadata.

parent 33328e78
......@@ -38,7 +38,7 @@ func NewGameLoader(caller MinimalDisputeGameFactoryCaller) *GameLoader {
}
// FetchAllGamesAtBlock fetches all dispute games from the factory at a given block number.
func (l *GameLoader) FetchAllGamesAtBlock(ctx context.Context, earliestTimestamp uint64, blockNumber *big.Int) ([]types.GameData, error) {
func (l *GameLoader) FetchAllGamesAtBlock(ctx context.Context, earliestTimestamp uint64, blockNumber *big.Int) ([]types.GameMetadata, error) {
if blockNumber == nil {
return nil, ErrMissingBlockNumber
}
......@@ -51,7 +51,7 @@ func (l *GameLoader) FetchAllGamesAtBlock(ctx context.Context, earliestTimestamp
return nil, fmt.Errorf("failed to fetch game count: %w", err)
}
games := make([]types.GameData, 0)
games := make([]types.GameMetadata, 0)
if gameCount.Uint64() == 0 {
return games, nil
}
......
......@@ -79,18 +79,18 @@ func TestGameLoader_FetchAllGames(t *testing.T) {
expectedGames := test.caller.games
expectedGames = expectedGames[len(expectedGames)-test.expectedLen:]
if test.expectedErr != nil {
expectedGames = make([]types.GameData, 0)
expectedGames = make([]types.GameMetadata, 0)
}
require.ElementsMatch(t, expectedGames, translateGames(games))
})
}
}
func generateMockGames(count uint64) []types.GameData {
games := make([]types.GameData, count)
func generateMockGames(count uint64) []types.GameMetadata {
games := make([]types.GameMetadata, count)
for i := uint64(0); i < count; i++ {
games[i] = types.GameData{
games[i] = types.GameMetadata{
Proxy: common.BigToAddress(big.NewInt(int64(i))),
Timestamp: i * 100,
}
......@@ -99,8 +99,8 @@ func generateMockGames(count uint64) []types.GameData {
return games
}
func translateGames(games []types.GameData) []types.GameData {
translated := make([]types.GameData, len(games))
func translateGames(games []types.GameMetadata) []types.GameMetadata {
translated := make([]types.GameMetadata, len(games))
for i, game := range games {
translated[i] = translateFaultDisputeGame(game)
......@@ -109,8 +109,8 @@ func translateGames(games []types.GameData) []types.GameData {
return translated
}
func translateFaultDisputeGame(game types.GameData) types.GameData {
return types.GameData{
func translateFaultDisputeGame(game types.GameMetadata) types.GameMetadata {
return types.GameMetadata{
Proxy: game.Proxy,
Timestamp: game.Timestamp,
}
......@@ -132,7 +132,7 @@ type mockMinimalDisputeGameFactoryCaller struct {
gameCountErr bool
indexErrors []bool
gameCount uint64
games []types.GameData
games []types.GameMetadata
}
func newMockMinimalDisputeGameFactoryCaller(count uint64, gameCountErr bool, indexErrors bool) *mockMinimalDisputeGameFactoryCaller {
......
......@@ -23,11 +23,11 @@ type blockNumberFetcher func(ctx context.Context) (uint64, error)
// gameSource loads information about the games available to play
type gameSource interface {
FetchAllGamesAtBlock(ctx context.Context, earliest uint64, blockNumber *big.Int) ([]types.GameData, error)
FetchAllGamesAtBlock(ctx context.Context, earliest uint64, blockNumber *big.Int) ([]types.GameMetadata, error)
}
type gameScheduler interface {
Schedule([]types.GameData) error
Schedule([]types.GameMetadata) error
}
type gameMonitor struct {
......@@ -105,7 +105,7 @@ func (m *gameMonitor) progressGames(ctx context.Context, blockNum uint64) error
if err != nil {
return fmt.Errorf("failed to load games: %w", err)
}
var gamesToPlay []types.GameData
var gamesToPlay []types.GameMetadata
for _, game := range games {
if !m.allowedGame(game.Proxy) {
m.logger.Debug("Skipping game not on allow list", "game", game.Proxy)
......
......@@ -52,7 +52,7 @@ func TestMonitorGames(t *testing.T) {
addr1 := common.Address{0xaa}
addr2 := common.Address{0xbb}
monitor, source, sched, mockHeadSource := setupMonitorTest(t, []common.Address{})
source.games = []types.GameData{newFDG(addr1, 9999), newFDG(addr2, 9999)}
source.games = []types.GameMetadata{newFDG(addr1, 9999), newFDG(addr2, 9999)}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
......@@ -94,7 +94,7 @@ func TestMonitorGames(t *testing.T) {
addr1 := common.Address{0xaa}
addr2 := common.Address{0xbb}
monitor, source, sched, mockHeadSource := setupMonitorTest(t, []common.Address{})
source.games = []types.GameData{newFDG(addr1, 9999), newFDG(addr2, 9999)}
source.games = []types.GameMetadata{newFDG(addr1, 9999), newFDG(addr2, 9999)}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
......@@ -140,7 +140,7 @@ func TestMonitorCreateAndProgressGameAgents(t *testing.T) {
addr1 := common.Address{0xaa}
addr2 := common.Address{0xbb}
source.games = []types.GameData{newFDG(addr1, 9999), newFDG(addr2, 9999)}
source.games = []types.GameMetadata{newFDG(addr1, 9999), newFDG(addr2, 9999)}
require.NoError(t, monitor.progressGames(context.Background(), uint64(1)))
......@@ -152,7 +152,7 @@ func TestMonitorOnlyScheduleSpecifiedGame(t *testing.T) {
addr1 := common.Address{0xaa}
addr2 := common.Address{0xbb}
monitor, source, sched, _ := setupMonitorTest(t, []common.Address{addr2})
source.games = []types.GameData{newFDG(addr1, 9999), newFDG(addr2, 9999)}
source.games = []types.GameMetadata{newFDG(addr1, 9999), newFDG(addr2, 9999)}
require.NoError(t, monitor.progressGames(context.Background(), uint64(1)))
......@@ -160,8 +160,8 @@ func TestMonitorOnlyScheduleSpecifiedGame(t *testing.T) {
require.Equal(t, []common.Address{addr2}, sched.scheduled[0])
}
func newFDG(proxy common.Address, timestamp uint64) types.GameData {
return types.GameData{
func newFDG(proxy common.Address, timestamp uint64) types.GameMetadata {
return types.GameMetadata{
Proxy: proxy,
Timestamp: timestamp,
}
......@@ -223,14 +223,14 @@ func (m *mockSubscription) Err() <-chan error {
}
type stubGameSource struct {
games []types.GameData
games []types.GameMetadata
}
func (s *stubGameSource) FetchAllGamesAtBlock(
ctx context.Context,
earliest uint64,
blockNumber *big.Int,
) ([]types.GameData, error) {
) ([]types.GameMetadata, error) {
return s.games, nil
}
......@@ -238,7 +238,7 @@ type stubScheduler struct {
scheduled [][]common.Address
}
func (s *stubScheduler) Schedule(games []types.GameData) error {
func (s *stubScheduler) Schedule(games []types.GameMetadata) error {
var addrs []common.Address
for _, game := range games {
addrs = append(addrs, game.Proxy)
......
......@@ -14,7 +14,7 @@ import (
var errUnknownGame = errors.New("unknown game")
type PlayerCreator func(game types.GameData, dir string) (GamePlayer, error)
type PlayerCreator func(game types.GameMetadata, dir string) (GamePlayer, error)
type gameState struct {
player GamePlayer
......@@ -44,10 +44,10 @@ type coordinator struct {
// To avoid deadlock, it may process results from the inbound resultQueue while adding jobs to the outbound jobQueue.
// Returns an error if a game couldn't be scheduled because of an error. It will continue attempting to progress
// all games even if an error occurs with one game.
func (c *coordinator) schedule(ctx context.Context, games []types.GameData) error {
func (c *coordinator) schedule(ctx context.Context, games []types.GameMetadata) error {
// First remove any game states we no longer require
for addr, state := range c.states {
if !state.inflight && !slices.ContainsFunc(games, func(candidate types.GameData) bool {
if !state.inflight && !slices.ContainsFunc(games, func(candidate types.GameMetadata) bool {
return candidate.Proxy == addr
}) {
delete(c.states, addr)
......@@ -96,7 +96,7 @@ func (c *coordinator) schedule(ctx context.Context, games []types.GameData) erro
// createJob updates the state for the specified game and returns the job to enqueue for it, if any
// Returns (nil, nil) when there is no error and no job to enqueue
func (c *coordinator) createJob(game types.GameData) (*job, error) {
func (c *coordinator) createJob(game types.GameMetadata) (*job, error) {
state, ok := c.states[game.Proxy]
if !ok {
state = &gameState{}
......
......@@ -263,7 +263,7 @@ type createdGames struct {
created map[common.Address]*stubGame
}
func (c *createdGames) CreateGame(fdg types.GameData, dir string) (GamePlayer, error) {
func (c *createdGames) CreateGame(fdg types.GameMetadata, dir string) (GamePlayer, error) {
addr := fdg.Proxy
if c.creationFails == addr {
return nil, fmt.Errorf("refusing to create player for game: %v", addr)
......@@ -305,10 +305,10 @@ func (s *stubDiskManager) RemoveAllExcept(addrs []common.Address) error {
return nil
}
func asGames(addrs ...common.Address) []types.GameData {
var games []types.GameData
func asGames(addrs ...common.Address) []types.GameMetadata {
var games []types.GameMetadata
for _, addr := range addrs {
games = append(games, types.GameData{
games = append(games, types.GameMetadata{
Proxy: addr,
})
}
......
......@@ -26,7 +26,7 @@ type Scheduler struct {
coordinator *coordinator
m SchedulerMetricer
maxConcurrency uint
scheduleQueue chan []types.GameData
scheduleQueue chan []types.GameMetadata
jobQueue chan job
resultQueue chan job
wg sync.WaitGroup
......@@ -41,7 +41,7 @@ func NewScheduler(logger log.Logger, m SchedulerMetricer, disk DiskManager, maxC
// scheduleQueue has a size of 1 so backpressure quickly propagates to the caller
// allowing them to potentially skip update cycles.
scheduleQueue := make(chan []types.GameData, 1)
scheduleQueue := make(chan []types.GameMetadata, 1)
return &Scheduler{
logger: logger,
......@@ -84,7 +84,7 @@ func (s *Scheduler) Close() error {
return nil
}
func (s *Scheduler) Schedule(games []types.GameData) error {
func (s *Scheduler) Schedule(games []types.GameMetadata) error {
select {
case s.scheduleQueue <- games:
return nil
......
......@@ -15,7 +15,7 @@ import (
func TestSchedulerProcessesGames(t *testing.T) {
logger := testlog.Logger(t, log.LvlInfo)
ctx := context.Background()
createPlayer := func(g types.GameData, dir string) (GamePlayer, error) {
createPlayer := func(g types.GameMetadata, dir string) (GamePlayer, error) {
return &stubPlayer{}, nil
}
removeExceptCalls := make(chan []common.Address)
......@@ -43,7 +43,7 @@ func TestSchedulerProcessesGames(t *testing.T) {
func TestReturnBusyWhenScheduleQueueFull(t *testing.T) {
logger := testlog.Logger(t, log.LvlInfo)
createPlayer := func(game types.GameData, dir string) (GamePlayer, error) {
createPlayer := func(game types.GameMetadata, dir string) (GamePlayer, error) {
return &stubPlayer{}, nil
}
removeExceptCalls := make(chan []common.Address)
......
......@@ -100,7 +100,7 @@ func NewService(ctx context.Context, logger log.Logger, cfg *config.Config) (*Se
m,
disk,
cfg.MaxConcurrency,
func(game types.GameData, dir string) (scheduler.GamePlayer, error) {
func(game types.GameMetadata, dir string) (scheduler.GamePlayer, error) {
return fault.NewGamePlayer(ctx, logger, m, cfg, dir, game.Proxy, txMgr, l1Client)
})
......
......@@ -36,7 +36,7 @@ func GameStatusFromUint8(i uint8) (GameStatus, error) {
return GameStatus(i), nil
}
type GameData struct {
type GameMetadata struct {
GameType uint8
Timestamp uint64
Proxy common.Address
......
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