Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
5f1b1b21
Unverified
Commit
5f1b1b21
authored
Feb 15, 2024
by
refcell
Committed by
GitHub
Feb 15, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(op-dispute-mon): wire in extractor (#9565)
parent
bb4fe5d5
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
97 additions
and
165 deletions
+97
-165
detector.go
op-dispute-mon/mon/detector.go
+3
-23
detector_test.go
op-dispute-mon/mon/detector_test.go
+4
-41
forecast.go
op-dispute-mon/mon/forecast.go
+13
-18
forecast_test.go
op-dispute-mon/mon/forecast_test.go
+38
-55
monitor.go
op-dispute-mon/mon/monitor.go
+10
-10
monitor_test.go
op-dispute-mon/mon/monitor_test.go
+21
-17
service.go
op-dispute-mon/mon/service.go
+8
-1
No files found.
op-dispute-mon/mon/detector.go
View file @
5f1b1b21
...
...
@@ -2,7 +2,6 @@ package mon
import
(
"context"
"fmt"
"github.com/ethereum-optimism/optimism/op-challenger/game/types"
"github.com/ethereum-optimism/optimism/op-dispute-mon/mon/extract"
...
...
@@ -41,19 +40,12 @@ func newDetector(logger log.Logger, metrics DetectorMetrics, creator GameCallerC
}
}
func
(
d
*
detector
)
Detect
(
ctx
context
.
Context
,
games
[]
types
.
GameMetad
ata
)
{
func
(
d
*
detector
)
Detect
(
ctx
context
.
Context
,
games
[]
monTypes
.
EnrichedGameD
ata
)
{
statBatch
:=
monTypes
.
StatusBatch
{}
detectBatch
:=
monTypes
.
DetectionBatch
{}
for
_
,
game
:=
range
games
{
// Fetch the game metadata to ensure the game status is recorded
// regardless of whether the game agreement is checked.
l2BlockNum
,
rootClaim
,
status
,
err
:=
d
.
fetchGameMetadata
(
ctx
,
game
)
if
err
!=
nil
{
d
.
logger
.
Error
(
"Failed to fetch game metadata"
,
"err"
,
err
)
continue
}
statBatch
.
Add
(
status
)
processed
,
err
:=
d
.
checkAgreement
(
ctx
,
game
.
Proxy
,
l2BlockNum
,
rootClaim
,
status
)
statBatch
.
Add
(
game
.
Status
)
processed
,
err
:=
d
.
checkAgreement
(
ctx
,
game
.
Proxy
,
game
.
L2BlockNumber
,
game
.
RootClaim
,
game
.
Status
)
if
err
!=
nil
{
d
.
logger
.
Error
(
"Failed to process game"
,
"err"
,
err
)
continue
...
...
@@ -73,18 +65,6 @@ func (d *detector) recordBatch(batch monTypes.DetectionBatch) {
d
.
metrics
.
RecordGameAgreement
(
"disagree_challenger_wins"
,
batch
.
DisagreeChallengerWins
)
}
func
(
d
*
detector
)
fetchGameMetadata
(
ctx
context
.
Context
,
game
types
.
GameMetadata
)
(
uint64
,
common
.
Hash
,
types
.
GameStatus
,
error
)
{
loader
,
err
:=
d
.
creator
.
CreateContract
(
game
)
if
err
!=
nil
{
return
0
,
common
.
Hash
{},
0
,
fmt
.
Errorf
(
"failed to create contract: %w"
,
err
)
}
blockNum
,
rootClaim
,
status
,
err
:=
loader
.
GetGameMetadata
(
ctx
)
if
err
!=
nil
{
return
0
,
common
.
Hash
{},
0
,
fmt
.
Errorf
(
"failed to fetch game metadata: %w"
,
err
)
}
return
blockNum
,
rootClaim
,
status
,
nil
}
func
(
d
*
detector
)
checkAgreement
(
ctx
context
.
Context
,
addr
common
.
Address
,
blockNum
uint64
,
rootClaim
common
.
Hash
,
status
types
.
GameStatus
)
(
monTypes
.
DetectionBatch
,
error
)
{
agree
,
expectedClaim
,
err
:=
d
.
validator
.
CheckRootAgreement
(
ctx
,
blockNum
,
rootClaim
)
if
err
!=
nil
{
...
...
op-dispute-mon/mon/detector_test.go
View file @
5f1b1b21
...
...
@@ -20,15 +20,7 @@ func TestDetector_Detect(t *testing.T) {
t
.
Run
(
"NoGames"
,
func
(
t
*
testing
.
T
)
{
detector
,
metrics
,
_
,
_
,
_
:=
setupDetectorTest
(
t
)
detector
.
Detect
(
context
.
Background
(),
[]
types
.
GameMetadata
{})
metrics
.
Equals
(
t
,
0
,
0
,
0
)
metrics
.
Mapped
(
t
,
map
[
string
]
int
{})
})
t
.
Run
(
"MetadataFetchFails"
,
func
(
t
*
testing
.
T
)
{
detector
,
metrics
,
creator
,
_
,
_
:=
setupDetectorTest
(
t
)
creator
.
err
=
errors
.
New
(
"boom"
)
detector
.
Detect
(
context
.
Background
(),
[]
types
.
GameMetadata
{{}})
detector
.
Detect
(
context
.
Background
(),
[]
monTypes
.
EnrichedGameData
{})
metrics
.
Equals
(
t
,
0
,
0
,
0
)
metrics
.
Mapped
(
t
,
map
[
string
]
int
{})
})
...
...
@@ -38,7 +30,7 @@ func TestDetector_Detect(t *testing.T) {
rollup
.
err
=
errors
.
New
(
"boom"
)
creator
.
caller
.
status
=
[]
types
.
GameStatus
{
types
.
GameStatusInProgress
}
creator
.
caller
.
rootClaim
=
[]
common
.
Hash
{{}}
detector
.
Detect
(
context
.
Background
(),
[]
types
.
GameMetad
ata
{{}})
detector
.
Detect
(
context
.
Background
(),
[]
monTypes
.
EnrichedGameD
ata
{{}})
metrics
.
Equals
(
t
,
1
,
0
,
0
)
// Status should still be metriced here!
metrics
.
Mapped
(
t
,
map
[
string
]
int
{})
})
...
...
@@ -47,7 +39,7 @@ func TestDetector_Detect(t *testing.T) {
detector
,
metrics
,
creator
,
_
,
_
:=
setupDetectorTest
(
t
)
creator
.
caller
.
status
=
[]
types
.
GameStatus
{
types
.
GameStatusInProgress
}
creator
.
caller
.
rootClaim
=
[]
common
.
Hash
{{}}
detector
.
Detect
(
context
.
Background
(),
[]
types
.
GameMetad
ata
{{}})
detector
.
Detect
(
context
.
Background
(),
[]
monTypes
.
EnrichedGameD
ata
{{}})
metrics
.
Equals
(
t
,
1
,
0
,
0
)
metrics
.
Mapped
(
t
,
map
[
string
]
int
{
"in_progress"
:
1
})
})
...
...
@@ -60,7 +52,7 @@ func TestDetector_Detect(t *testing.T) {
types
.
GameStatusInProgress
,
}
creator
.
caller
.
rootClaim
=
[]
common
.
Hash
{{},
{},
{}}
detector
.
Detect
(
context
.
Background
(),
[]
types
.
GameMetad
ata
{{},
{},
{}})
detector
.
Detect
(
context
.
Background
(),
[]
monTypes
.
EnrichedGameD
ata
{{},
{},
{}})
metrics
.
Equals
(
t
,
3
,
0
,
0
)
metrics
.
Mapped
(
t
,
map
[
string
]
int
{
"in_progress"
:
3
})
})
...
...
@@ -124,35 +116,6 @@ func TestDetector_RecordBatch(t *testing.T) {
}
}
func
TestDetector_FetchGameMetadata
(
t
*
testing
.
T
)
{
t
.
Parallel
()
t
.
Run
(
"CreateContractFails"
,
func
(
t
*
testing
.
T
)
{
detector
,
_
,
creator
,
_
,
_
:=
setupDetectorTest
(
t
)
creator
.
err
=
errors
.
New
(
"boom"
)
_
,
_
,
_
,
err
:=
detector
.
fetchGameMetadata
(
context
.
Background
(),
types
.
GameMetadata
{})
require
.
ErrorIs
(
t
,
err
,
creator
.
err
)
})
t
.
Run
(
"GetGameMetadataFails"
,
func
(
t
*
testing
.
T
)
{
detector
,
_
,
creator
,
_
,
_
:=
setupDetectorTest
(
t
)
creator
.
caller
=
&
mockGameCaller
{
err
:
errors
.
New
(
"boom"
)}
creator
.
caller
.
status
=
[]
types
.
GameStatus
{
types
.
GameStatusInProgress
}
creator
.
caller
.
rootClaim
=
[]
common
.
Hash
{{}}
_
,
_
,
_
,
err
:=
detector
.
fetchGameMetadata
(
context
.
Background
(),
types
.
GameMetadata
{})
require
.
Error
(
t
,
err
)
})
t
.
Run
(
"Success"
,
func
(
t
*
testing
.
T
)
{
detector
,
_
,
creator
,
_
,
_
:=
setupDetectorTest
(
t
)
creator
.
caller
.
status
=
[]
types
.
GameStatus
{
types
.
GameStatusInProgress
}
creator
.
caller
.
rootClaim
=
[]
common
.
Hash
{{}}
_
,
_
,
status
,
err
:=
detector
.
fetchGameMetadata
(
context
.
Background
(),
types
.
GameMetadata
{})
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
types
.
GameStatusInProgress
,
status
)
})
}
func
TestDetector_CheckAgreement_Fails
(
t
*
testing
.
T
)
{
detector
,
_
,
_
,
rollup
,
_
:=
setupDetectorTest
(
t
)
rollup
.
err
=
errors
.
New
(
"boom"
)
...
...
op-dispute-mon/mon/forecast.go
View file @
5f1b1b21
...
...
@@ -39,7 +39,7 @@ func newForecast(logger log.Logger, metrics ForecastMetrics, creator GameCallerC
}
}
func
(
f
*
forecast
)
Forecast
(
ctx
context
.
Context
,
games
[]
types
.
GameMetad
ata
)
{
func
(
f
*
forecast
)
Forecast
(
ctx
context
.
Context
,
games
[]
monTypes
.
EnrichedGameD
ata
)
{
batch
:=
monTypes
.
ForecastBatch
{}
for
_
,
game
:=
range
games
{
if
err
:=
f
.
forecastGame
(
ctx
,
game
,
&
batch
);
err
!=
nil
{
...
...
@@ -56,20 +56,15 @@ func (f *forecast) recordBatch(batch monTypes.ForecastBatch) {
f
.
metrics
.
RecordGameAgreement
(
"disagree_defender_ahead"
,
batch
.
DisagreeDefenderAhead
)
}
func
(
f
*
forecast
)
forecastGame
(
ctx
context
.
Context
,
game
types
.
GameMetad
ata
,
metrics
*
monTypes
.
ForecastBatch
)
error
{
loader
,
err
:=
f
.
creator
.
CreateContract
(
game
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"%w: %w"
,
ErrContractCreation
,
err
)
func
(
f
*
forecast
)
forecastGame
(
ctx
context
.
Context
,
game
monTypes
.
EnrichedGameD
ata
,
metrics
*
monTypes
.
ForecastBatch
)
error
{
if
game
.
Status
!=
types
.
GameStatusInProgress
{
f
.
logger
.
Debug
(
"Game is not in progress, skipping forecast"
,
"game"
,
game
.
Proxy
,
"status"
,
game
.
Status
)
return
nil
}
// Get the game status, it must be in progress to forecast.
l2BlockNum
,
rootClaim
,
status
,
err
:=
loader
.
GetGameMetadata
(
ctx
)
loader
,
err
:=
f
.
creator
.
CreateContract
(
game
.
GameMetadata
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"%w: %w"
,
ErrMetadataFetch
,
err
)
}
if
status
!=
types
.
GameStatusInProgress
{
f
.
logger
.
Debug
(
"Game is not in progress, skipping forecast"
,
"game"
,
game
,
"status"
,
status
)
return
nil
return
fmt
.
Errorf
(
"%w: %w"
,
ErrContractCreation
,
err
)
}
// Load all claims for the game.
...
...
@@ -82,10 +77,10 @@ func (f *forecast) forecastGame(ctx context.Context, game types.GameMetadata, me
tree
:=
transform
.
CreateBidirectionalTree
(
claims
)
// Compute the resolution status of the game.
status
=
Resolve
(
tree
)
status
:
=
Resolve
(
tree
)
// Check the root agreement.
agreement
,
expected
,
err
:=
f
.
validator
.
CheckRootAgreement
(
ctx
,
l2BlockNum
,
r
ootClaim
)
agreement
,
expected
,
err
:=
f
.
validator
.
CheckRootAgreement
(
ctx
,
game
.
L2BlockNumber
,
game
.
R
ootClaim
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"%w: %w"
,
ErrRootAgreement
,
err
)
}
...
...
@@ -94,19 +89,19 @@ func (f *forecast) forecastGame(ctx context.Context, game types.GameMetadata, me
// If we agree with the output root proposal, the Defender should win, defending that claim.
if
status
==
types
.
GameStatusChallengerWon
{
metrics
.
AgreeChallengerAhead
++
f
.
logger
.
Warn
(
"Forecasting unexpected game result"
,
"status"
,
status
,
"game"
,
game
,
"rootClaim"
,
r
ootClaim
,
"expected"
,
expected
)
f
.
logger
.
Warn
(
"Forecasting unexpected game result"
,
"status"
,
status
,
"game"
,
game
.
Proxy
,
"rootClaim"
,
game
.
R
ootClaim
,
"expected"
,
expected
)
}
else
{
metrics
.
AgreeDefenderAhead
++
f
.
logger
.
Debug
(
"Forecasting expected game result"
,
"status"
,
status
,
"game"
,
game
,
"rootClaim"
,
r
ootClaim
,
"expected"
,
expected
)
f
.
logger
.
Debug
(
"Forecasting expected game result"
,
"status"
,
status
,
"game"
,
game
.
Proxy
,
"rootClaim"
,
game
.
R
ootClaim
,
"expected"
,
expected
)
}
}
else
{
// If we disagree with the output root proposal, the Challenger should win, challenging that claim.
if
status
==
types
.
GameStatusDefenderWon
{
metrics
.
DisagreeDefenderAhead
++
f
.
logger
.
Warn
(
"Forecasting unexpected game result"
,
"status"
,
status
,
"game"
,
game
,
"rootClaim"
,
r
ootClaim
,
"expected"
,
expected
)
f
.
logger
.
Warn
(
"Forecasting unexpected game result"
,
"status"
,
status
,
"game"
,
game
.
Proxy
,
"rootClaim"
,
game
.
R
ootClaim
,
"expected"
,
expected
)
}
else
{
metrics
.
DisagreeChallengerAhead
++
f
.
logger
.
Debug
(
"Forecasting expected game result"
,
"status"
,
status
,
"game"
,
game
,
"rootClaim"
,
r
ootClaim
,
"expected"
,
expected
)
f
.
logger
.
Debug
(
"Forecasting expected game result"
,
"status"
,
status
,
"game"
,
game
.
Proxy
,
"rootClaim"
,
game
.
R
ootClaim
,
"expected"
,
expected
)
}
}
...
...
op-dispute-mon/mon/forecast_test.go
View file @
5f1b1b21
This diff is collapsed.
Click to expand it.
op-dispute-mon/mon/monitor.go
View file @
5f1b1b21
...
...
@@ -6,18 +6,18 @@ import (
"math/big"
"time"
"github.com/ethereum-optimism/optimism/op-
challenger/game
/types"
"github.com/ethereum-optimism/optimism/op-
dispute-mon/mon
/types"
"github.com/ethereum-optimism/optimism/op-service/clock"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
)
type
Detect
func
(
ctx
context
.
Context
,
games
[]
types
.
GameMetad
ata
)
type
Forecast
func
(
ctx
context
.
Context
,
games
[]
types
.
GameMetad
ata
)
type
Detect
func
(
ctx
context
.
Context
,
games
[]
types
.
EnrichedGameD
ata
)
type
Forecast
func
(
ctx
context
.
Context
,
games
[]
types
.
EnrichedGameD
ata
)
type
BlockHashFetcher
func
(
ctx
context
.
Context
,
number
*
big
.
Int
)
(
common
.
Hash
,
error
)
type
BlockNumberFetcher
func
(
ctx
context
.
Context
)
(
uint64
,
error
)
type
FactoryGameFetcher
func
(
ctx
context
.
Context
,
blockHash
common
.
Hash
,
earliestTimestamp
uint64
)
([]
types
.
GameMetad
ata
,
error
)
type
Extract
func
(
ctx
context
.
Context
,
blockHash
common
.
Hash
,
minTimestamp
uint64
)
([]
types
.
EnrichedGameD
ata
,
error
)
type
gameMonitor
struct
{
logger
log
.
Logger
...
...
@@ -32,7 +32,7 @@ type gameMonitor struct {
detect
Detect
forecast
Forecast
fetchGames
FactoryGameFetcher
extract
Extract
fetchBlockHash
BlockHashFetcher
fetchBlockNumber
BlockNumberFetcher
}
...
...
@@ -45,7 +45,7 @@ func newGameMonitor(
gameWindow
time
.
Duration
,
detect
Detect
,
forecast
Forecast
,
factory
FactoryGameFetcher
,
extract
Extract
,
fetchBlockNumber
BlockNumberFetcher
,
fetchBlockHash
BlockHashFetcher
,
)
*
gameMonitor
{
...
...
@@ -58,7 +58,7 @@ func newGameMonitor(
gameWindow
:
gameWindow
,
detect
:
detect
,
forecast
:
forecast
,
fetchGames
:
factory
,
extract
:
extract
,
fetchBlockNumber
:
fetchBlockNumber
,
fetchBlockHash
:
fetchBlockHash
,
}
...
...
@@ -86,12 +86,12 @@ func (m *gameMonitor) monitorGames() error {
if
err
!=
nil
{
return
fmt
.
Errorf
(
"Failed to fetch block hash: %w"
,
err
)
}
games
,
err
:=
m
.
fetchGames
(
m
.
ctx
,
blockHash
,
m
.
minGameTimestamp
())
enrichedGames
,
err
:=
m
.
extract
(
m
.
ctx
,
blockHash
,
m
.
minGameTimestamp
())
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to load games: %w"
,
err
)
}
m
.
detect
(
m
.
ctx
,
g
ames
)
m
.
forecast
(
m
.
ctx
,
g
ames
)
m
.
detect
(
m
.
ctx
,
enrichedG
ames
)
m
.
forecast
(
m
.
ctx
,
enrichedG
ames
)
return
nil
}
...
...
op-dispute-mon/mon/monitor_test.go
View file @
5f1b1b21
...
...
@@ -8,6 +8,7 @@ import (
"time"
"github.com/ethereum-optimism/optimism/op-challenger/game/types"
monTypes
"github.com/ethereum-optimism/optimism/op-dispute-mon/mon/types"
"github.com/ethereum-optimism/optimism/op-service/clock"
"github.com/ethereum-optimism/optimism/op-service/testlog"
"github.com/ethereum/go-ethereum/common"
...
...
@@ -70,7 +71,7 @@ func TestMonitor_MonitorGames(t *testing.T) {
t
.
Run
(
"DetectsWithNoGames"
,
func
(
t
*
testing
.
T
)
{
monitor
,
factory
,
detector
,
_
:=
setupMonitorTest
(
t
)
factory
.
games
=
[]
types
.
GameMetad
ata
{}
factory
.
games
=
[]
monTypes
.
EnrichedGameD
ata
{}
err
:=
monitor
.
monitorGames
()
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
1
,
detector
.
calls
)
...
...
@@ -78,7 +79,7 @@ func TestMonitor_MonitorGames(t *testing.T) {
t
.
Run
(
"DetectsMultipleGames"
,
func
(
t
*
testing
.
T
)
{
monitor
,
factory
,
detector
,
_
:=
setupMonitorTest
(
t
)
factory
.
games
=
[]
types
.
GameMetad
ata
{{},
{},
{}}
factory
.
games
=
[]
monTypes
.
EnrichedGameD
ata
{{},
{},
{}}
err
:=
monitor
.
monitorGames
()
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
1
,
detector
.
calls
)
...
...
@@ -90,7 +91,7 @@ func TestMonitor_StartMonitoring(t *testing.T) {
addr1
:=
common
.
Address
{
0xaa
}
addr2
:=
common
.
Address
{
0xbb
}
monitor
,
factory
,
detector
,
_
:=
setupMonitorTest
(
t
)
factory
.
games
=
[]
types
.
GameMetad
ata
{
newFDG
(
addr1
,
9999
),
newFDG
(
addr2
,
9999
)}
factory
.
games
=
[]
monTypes
.
EnrichedGameD
ata
{
newFDG
(
addr1
,
9999
),
newFDG
(
addr2
,
9999
)}
factory
.
maxSuccess
=
len
(
factory
.
games
)
// Only allow two successful fetches
monitor
.
StartMonitoring
()
...
...
@@ -114,14 +115,17 @@ func TestMonitor_StartMonitoring(t *testing.T) {
})
}
func
newFDG
(
proxy
common
.
Address
,
timestamp
uint64
)
types
.
GameMetadata
{
return
types
.
GameMetadata
{
Proxy
:
proxy
,
Timestamp
:
timestamp
,
func
newFDG
(
proxy
common
.
Address
,
timestamp
uint64
)
monTypes
.
EnrichedGameData
{
return
monTypes
.
EnrichedGameData
{
GameMetadata
:
types
.
GameMetadata
{
Proxy
:
proxy
,
Timestamp
:
timestamp
,
},
Status
:
types
.
GameStatusInProgress
,
}
}
func
setupMonitorTest
(
t
*
testing
.
T
)
(
*
gameMonitor
,
*
mock
Factory
,
*
mockDetector
,
*
mockForecast
)
{
func
setupMonitorTest
(
t
*
testing
.
T
)
(
*
gameMonitor
,
*
mock
Extractor
,
*
mockDetector
,
*
mockForecast
)
{
logger
:=
testlog
.
Logger
(
t
,
log
.
LvlDebug
)
fetchBlockNum
:=
func
(
ctx
context
.
Context
)
(
uint64
,
error
)
{
return
1
,
nil
...
...
@@ -132,7 +136,7 @@ func setupMonitorTest(t *testing.T) (*gameMonitor, *mockFactory, *mockDetector,
monitorInterval
:=
time
.
Duration
(
100
*
time
.
Millisecond
)
cl
:=
clock
.
NewAdvancingClock
(
10
*
time
.
Millisecond
)
cl
.
Start
()
factory
:=
&
mockFactory
{}
extractor
:=
&
mockExtractor
{}
detect
:=
&
mockDetector
{}
forecast
:=
&
mockForecast
{}
monitor
:=
newGameMonitor
(
...
...
@@ -143,18 +147,18 @@ func setupMonitorTest(t *testing.T) (*gameMonitor, *mockFactory, *mockDetector,
time
.
Duration
(
10
*
time
.
Second
),
detect
.
Detect
,
forecast
.
Forecast
,
factory
.
GetGamesAtOrAfter
,
extractor
.
Extract
,
fetchBlockNum
,
fetchBlockHash
,
)
return
monitor
,
factory
,
detect
,
forecast
return
monitor
,
extractor
,
detect
,
forecast
}
type
mockForecast
struct
{
calls
int
}
func
(
m
*
mockForecast
)
Forecast
(
ctx
context
.
Context
,
games
[]
types
.
GameMetad
ata
)
{
func
(
m
*
mockForecast
)
Forecast
(
ctx
context
.
Context
,
games
[]
monTypes
.
EnrichedGameD
ata
)
{
m
.
calls
++
}
...
...
@@ -162,22 +166,22 @@ type mockDetector struct {
calls
int
}
func
(
m
*
mockDetector
)
Detect
(
ctx
context
.
Context
,
games
[]
types
.
GameMetad
ata
)
{
func
(
m
*
mockDetector
)
Detect
(
ctx
context
.
Context
,
games
[]
monTypes
.
EnrichedGameD
ata
)
{
m
.
calls
++
}
type
mock
Factory
struct
{
type
mock
Extractor
struct
{
fetchErr
error
calls
int
maxSuccess
int
games
[]
types
.
GameMetad
ata
games
[]
monTypes
.
EnrichedGameD
ata
}
func
(
m
*
mock
Factory
)
GetGamesAtOrAfter
(
func
(
m
*
mock
Extractor
)
Extract
(
_
context
.
Context
,
_
common
.
Hash
,
_
uint64
,
)
([]
types
.
GameMetad
ata
,
error
)
{
)
([]
monTypes
.
EnrichedGameD
ata
,
error
)
{
m
.
calls
++
if
m
.
fetchErr
!=
nil
{
return
nil
,
m
.
fetchErr
...
...
op-dispute-mon/mon/service.go
View file @
5f1b1b21
...
...
@@ -35,6 +35,7 @@ type Service struct {
cl
clock
.
Clock
extractor
*
extract
.
Extractor
forecast
*
forecast
game
*
extract
.
GameCallerCreator
rollupClient
*
sources
.
RollupClient
...
...
@@ -84,6 +85,8 @@ func (s *Service) initFromConfig(ctx context.Context, cfg *config.Config) error
s
.
initOutputValidator
()
// Must be called before initForecast
s
.
initGameCallerCreator
()
// Must be called before initForecast
s
.
initExtractor
()
s
.
initForecast
(
cfg
)
s
.
initDetector
()
...
...
@@ -103,6 +106,10 @@ func (s *Service) initGameCallerCreator() {
s
.
game
=
extract
.
NewGameCallerCreator
(
s
.
metrics
,
batching
.
NewMultiCaller
(
s
.
l1Client
.
Client
(),
batching
.
DefaultBatchSize
))
}
func
(
s
*
Service
)
initExtractor
()
{
s
.
extractor
=
extract
.
NewExtractor
(
s
.
logger
,
s
.
game
.
CreateContract
,
s
.
factoryContract
.
GetGamesAtOrAfter
)
}
func
(
s
*
Service
)
initForecast
(
cfg
*
config
.
Config
)
{
s
.
forecast
=
newForecast
(
s
.
logger
,
s
.
metrics
,
s
.
game
,
s
.
validator
)
}
...
...
@@ -190,7 +197,7 @@ func (s *Service) initMonitor(ctx context.Context, cfg *config.Config) {
cfg
.
GameWindow
,
s
.
detector
.
Detect
,
s
.
forecast
.
Forecast
,
s
.
factoryContract
.
GetGamesAtOrAfter
,
s
.
extractor
.
Extract
,
s
.
l1Client
.
BlockNumber
,
blockHashFetcher
,
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment