Skip to content

Commit

Permalink
chore(op-dispute-mon): isolate game caller package (#9544)
Browse files Browse the repository at this point in the history
  • Loading branch information
refcell authored Feb 15, 2024
1 parent 0341b83 commit 0b4fb00
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
3 changes: 2 additions & 1 deletion op-dispute-mon/mon/detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

"github.com/ethereum-optimism/optimism/op-challenger/game/types"
"github.com/ethereum-optimism/optimism/op-dispute-mon/mon/extract"
monTypes "github.com/ethereum-optimism/optimism/op-dispute-mon/mon/types"

"github.com/ethereum/go-ethereum/common"
Expand All @@ -16,7 +17,7 @@ type OutputValidator interface {
}

type GameCallerCreator interface {
CreateContract(game types.GameMetadata) (GameCaller, error)
CreateContract(game types.GameMetadata) (extract.GameCaller, error)
}

type DetectorMetrics interface {
Expand Down
3 changes: 2 additions & 1 deletion op-dispute-mon/mon/detector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

faultTypes "github.com/ethereum-optimism/optimism/op-challenger/game/fault/types"
"github.com/ethereum-optimism/optimism/op-challenger/game/types"
"github.com/ethereum-optimism/optimism/op-dispute-mon/mon/extract"
monTypes "github.com/ethereum-optimism/optimism/op-dispute-mon/mon/types"
"github.com/ethereum-optimism/optimism/op-service/testlog"
"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -266,7 +267,7 @@ type mockGameCallerCreator struct {
caller *mockGameCaller
}

func (m *mockGameCallerCreator) CreateContract(game types.GameMetadata) (GameCaller, error) {
func (m *mockGameCallerCreator) CreateContract(game types.GameMetadata) (extract.GameCaller, error) {
m.calls++
if m.err != nil {
return nil, m.err
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package mon
package extract

import (
"context"
Expand All @@ -20,19 +20,19 @@ type GameCaller interface {
GetAllClaims(ctx context.Context) ([]faultTypes.Claim, error)
}

type gameCallerCreator struct {
type GameCallerCreator struct {
cache *caching.LRUCache[common.Address, *contracts.FaultDisputeGameContract]
caller *batching.MultiCaller
}

func NewGameCallerCreator(m caching.Metrics, caller *batching.MultiCaller) *gameCallerCreator {
return &gameCallerCreator{
func NewGameCallerCreator(m caching.Metrics, caller *batching.MultiCaller) *GameCallerCreator {
return &GameCallerCreator{
caller: caller,
cache: caching.NewLRUCache[common.Address, *contracts.FaultDisputeGameContract](m, metricsLabel, 100),
}
}

func (g *gameCallerCreator) CreateContract(game types.GameMetadata) (GameCaller, error) {
func (g *GameCallerCreator) CreateContract(game types.GameMetadata) (GameCaller, error) {
if fdg, ok := g.cache.Get(game.Proxy); ok {
return fdg, nil
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package mon
package extract

import (
"fmt"
Expand Down
9 changes: 5 additions & 4 deletions op-dispute-mon/mon/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import (
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/log"

"github.com/ethereum-optimism/optimism/op-challenger/game/fault/contracts"

"github.com/ethereum-optimism/optimism/op-dispute-mon/config"
"github.com/ethereum-optimism/optimism/op-dispute-mon/metrics"
"github.com/ethereum-optimism/optimism/op-dispute-mon/mon/extract"
"github.com/ethereum-optimism/optimism/op-dispute-mon/version"

"github.com/ethereum-optimism/optimism/op-challenger/game/fault/contracts"
"github.com/ethereum-optimism/optimism/op-service/clock"
"github.com/ethereum-optimism/optimism/op-service/dial"
"github.com/ethereum-optimism/optimism/op-service/httputil"
Expand All @@ -35,7 +36,7 @@ type Service struct {
cl clock.Clock

forecast *forecast
game *gameCallerCreator
game *extract.GameCallerCreator
rollupClient *sources.RollupClient
detector *detector
validator *outputValidator
Expand Down Expand Up @@ -99,7 +100,7 @@ func (s *Service) initOutputValidator() {
}

func (s *Service) initGameCallerCreator() {
s.game = NewGameCallerCreator(s.metrics, batching.NewMultiCaller(s.l1Client.Client(), batching.DefaultBatchSize))
s.game = extract.NewGameCallerCreator(s.metrics, batching.NewMultiCaller(s.l1Client.Client(), batching.DefaultBatchSize))
}

func (s *Service) initForecast(cfg *config.Config) {
Expand Down

0 comments on commit 0b4fb00

Please sign in to comment.