Commit 951e46e9 authored by Adrian Sutton's avatar Adrian Sutton Committed by GitHub

op-challenger: Allow claim bonds from games in the allow list (#9822)

parent ce4c8ba6
...@@ -124,9 +124,6 @@ func (m *gameMonitor) progressGames(ctx context.Context, blockHash common.Hash, ...@@ -124,9 +124,6 @@ func (m *gameMonitor) progressGames(ctx context.Context, blockHash common.Hash,
if err != nil { if err != nil {
return fmt.Errorf("failed to load games: %w", err) return fmt.Errorf("failed to load games: %w", err)
} }
if err := m.claimer.Schedule(blockNumber, games); err != nil {
return fmt.Errorf("failed to schedule bond claims: %w", err)
}
var gamesToPlay []types.GameMetadata var gamesToPlay []types.GameMetadata
for _, game := range games { for _, game := range games {
if !m.allowedGame(game.Proxy) { if !m.allowedGame(game.Proxy) {
...@@ -135,6 +132,9 @@ func (m *gameMonitor) progressGames(ctx context.Context, blockHash common.Hash, ...@@ -135,6 +132,9 @@ func (m *gameMonitor) progressGames(ctx context.Context, blockHash common.Hash,
} }
gamesToPlay = append(gamesToPlay, game) gamesToPlay = append(gamesToPlay, game)
} }
if err := m.claimer.Schedule(blockNumber, gamesToPlay); err != nil {
return fmt.Errorf("failed to schedule bond claims: %w", err)
}
if err := m.scheduler.Schedule(gamesToPlay, blockNumber); errors.Is(err, scheduler.ErrBusy) { if err := m.scheduler.Schedule(gamesToPlay, blockNumber); errors.Is(err, scheduler.ErrBusy) {
m.logger.Info("Scheduler still busy with previous update") m.logger.Info("Scheduler still busy with previous update")
} else if err != nil { } else if err != nil {
......
...@@ -24,13 +24,13 @@ func TestMonitorMinGameTimestamp(t *testing.T) { ...@@ -24,13 +24,13 @@ func TestMonitorMinGameTimestamp(t *testing.T) {
t.Parallel() t.Parallel()
t.Run("zero game window returns zero", func(t *testing.T) { t.Run("zero game window returns zero", func(t *testing.T) {
monitor, _, _, _, _ := setupMonitorTest(t, []common.Address{}) monitor, _, _, _, _, _ := setupMonitorTest(t, []common.Address{})
monitor.gameWindow = time.Duration(0) monitor.gameWindow = time.Duration(0)
require.Equal(t, monitor.minGameTimestamp(), uint64(0)) require.Equal(t, monitor.minGameTimestamp(), uint64(0))
}) })
t.Run("non-zero game window with zero clock", func(t *testing.T) { t.Run("non-zero game window with zero clock", func(t *testing.T) {
monitor, _, _, _, _ := setupMonitorTest(t, []common.Address{}) monitor, _, _, _, _, _ := setupMonitorTest(t, []common.Address{})
monitor.gameWindow = time.Minute monitor.gameWindow = time.Minute
monitor.clock = clock.NewSimpleClock() monitor.clock = clock.NewSimpleClock()
monitor.clock.SetTime(0) monitor.clock.SetTime(0)
...@@ -38,7 +38,7 @@ func TestMonitorMinGameTimestamp(t *testing.T) { ...@@ -38,7 +38,7 @@ func TestMonitorMinGameTimestamp(t *testing.T) {
}) })
t.Run("minimum computed correctly", func(t *testing.T) { t.Run("minimum computed correctly", func(t *testing.T) {
monitor, _, _, _, _ := setupMonitorTest(t, []common.Address{}) monitor, _, _, _, _, _ := setupMonitorTest(t, []common.Address{})
monitor.gameWindow = time.Minute monitor.gameWindow = time.Minute
monitor.clock = clock.NewSimpleClock() monitor.clock = clock.NewSimpleClock()
frozen := uint64(time.Hour.Seconds()) frozen := uint64(time.Hour.Seconds())
...@@ -54,7 +54,7 @@ func TestMonitorGames(t *testing.T) { ...@@ -54,7 +54,7 @@ func TestMonitorGames(t *testing.T) {
t.Run("Schedules games", func(t *testing.T) { t.Run("Schedules games", func(t *testing.T) {
addr1 := common.Address{0xaa} addr1 := common.Address{0xaa}
addr2 := common.Address{0xbb} addr2 := common.Address{0xbb}
monitor, source, sched, mockHeadSource, preimages := setupMonitorTest(t, []common.Address{}) monitor, source, sched, mockHeadSource, preimages, _ := setupMonitorTest(t, []common.Address{})
source.games = []types.GameMetadata{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())
...@@ -99,7 +99,7 @@ func TestMonitorGames(t *testing.T) { ...@@ -99,7 +99,7 @@ func TestMonitorGames(t *testing.T) {
t.Run("Resubscribes on error", func(t *testing.T) { t.Run("Resubscribes on error", func(t *testing.T) {
addr1 := common.Address{0xaa} addr1 := common.Address{0xaa}
addr2 := common.Address{0xbb} addr2 := common.Address{0xbb}
monitor, source, sched, mockHeadSource, preimages := setupMonitorTest(t, []common.Address{}) monitor, source, sched, mockHeadSource, preimages, _ := setupMonitorTest(t, []common.Address{})
source.games = []types.GameMetadata{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())
...@@ -146,7 +146,7 @@ func TestMonitorGames(t *testing.T) { ...@@ -146,7 +146,7 @@ func TestMonitorGames(t *testing.T) {
} }
func TestMonitorCreateAndProgressGameAgents(t *testing.T) { func TestMonitorCreateAndProgressGameAgents(t *testing.T) {
monitor, source, sched, _, _ := setupMonitorTest(t, []common.Address{}) monitor, source, sched, _, _, _ := setupMonitorTest(t, []common.Address{})
addr1 := common.Address{0xaa} addr1 := common.Address{0xaa}
addr2 := common.Address{0xbb} addr2 := common.Address{0xbb}
...@@ -161,13 +161,14 @@ func TestMonitorCreateAndProgressGameAgents(t *testing.T) { ...@@ -161,13 +161,14 @@ func TestMonitorCreateAndProgressGameAgents(t *testing.T) {
func TestMonitorOnlyScheduleSpecifiedGame(t *testing.T) { 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, _, _, stubClaimer := setupMonitorTest(t, []common.Address{addr2})
source.games = []types.GameMetadata{newFDG(addr1, 9999), newFDG(addr2, 9999)} source.games = []types.GameMetadata{newFDG(addr1, 9999), newFDG(addr2, 9999)}
require.NoError(t, monitor.progressGames(context.Background(), common.Hash{0x01}, 0)) require.NoError(t, monitor.progressGames(context.Background(), common.Hash{0x01}, 0))
require.Len(t, sched.Scheduled(), 1) require.Len(t, sched.Scheduled(), 1)
require.Equal(t, []common.Address{addr2}, sched.Scheduled()[0]) require.Equal(t, []common.Address{addr2}, sched.Scheduled()[0])
require.Equal(t, 1, stubClaimer.scheduledGames)
} }
func newFDG(proxy common.Address, timestamp uint64) types.GameMetadata { func newFDG(proxy common.Address, timestamp uint64) types.GameMetadata {
...@@ -180,7 +181,7 @@ func newFDG(proxy common.Address, timestamp uint64) types.GameMetadata { ...@@ -180,7 +181,7 @@ func newFDG(proxy common.Address, timestamp uint64) types.GameMetadata {
func setupMonitorTest( func setupMonitorTest(
t *testing.T, t *testing.T,
allowedGames []common.Address, allowedGames []common.Address,
) (*gameMonitor, *stubGameSource, *stubScheduler, *mockNewHeadSource, *stubPreimageScheduler) { ) (*gameMonitor, *stubGameSource, *stubScheduler, *mockNewHeadSource, *stubPreimageScheduler, *mockScheduler) {
logger := testlog.Logger(t, log.LevelDebug) logger := testlog.Logger(t, log.LevelDebug)
source := &stubGameSource{} source := &stubGameSource{}
i := uint64(1) i := uint64(1)
...@@ -191,7 +192,7 @@ func setupMonitorTest( ...@@ -191,7 +192,7 @@ func setupMonitorTest(
sched := &stubScheduler{} sched := &stubScheduler{}
preimages := &stubPreimageScheduler{} preimages := &stubPreimageScheduler{}
mockHeadSource := &mockNewHeadSource{} mockHeadSource := &mockNewHeadSource{}
mockScheduler := &mockScheduler{} stubClaimer := &mockScheduler{}
monitor := newGameMonitor( monitor := newGameMonitor(
logger, logger,
clock.NewSimpleClock(), clock.NewSimpleClock(),
...@@ -199,12 +200,12 @@ func setupMonitorTest( ...@@ -199,12 +200,12 @@ func setupMonitorTest(
sched, sched,
preimages, preimages,
time.Duration(0), time.Duration(0),
mockScheduler, stubClaimer,
fetchBlockNum, fetchBlockNum,
allowedGames, allowedGames,
mockHeadSource, mockHeadSource,
) )
return monitor, source, sched, mockHeadSource, preimages return monitor, source, sched, mockHeadSource, preimages, stubClaimer
} }
type mockNewHeadSource struct { type mockNewHeadSource struct {
...@@ -248,11 +249,11 @@ func (m *mockNewHeadSource) EthSubscribe( ...@@ -248,11 +249,11 @@ func (m *mockNewHeadSource) EthSubscribe(
type mockScheduler struct { type mockScheduler struct {
scheduleErr error scheduleErr error
scheduleCalls int scheduledGames int
} }
func (m *mockScheduler) Schedule(uint64, []types.GameMetadata) error { func (m *mockScheduler) Schedule(_ uint64, games []types.GameMetadata) error {
m.scheduleCalls++ m.scheduledGames += len(games)
return m.scheduleErr return m.scheduleErr
} }
......
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