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