Skip to content

Commit

Permalink
Merge pull request #25 from ethereum-optimism/develop
Browse files Browse the repository at this point in the history
merge from optimism develop
  • Loading branch information
qizhou authored May 2, 2024
2 parents 8fe7796 + 4fb32c1 commit 8366449
Show file tree
Hide file tree
Showing 69 changed files with 1,113 additions and 627 deletions.
1 change: 1 addition & 0 deletions .github/workflows/tag-service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ on:
- proxyd
- ufm-metamask
- op-contracts
- op-conductor
prerelease:
description: Increment major/minor/patch as prerelease?
required: false
Expand Down
4 changes: 2 additions & 2 deletions op-challenger/game/fault/solver/game_rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/ethereum-optimism/optimism/op-challenger/game/fault/types"
gameTypes "github.com/ethereum-optimism/optimism/op-challenger/game/types"
"github.com/ethereum-optimism/optimism/op-dispute-mon/mon/resolution"
"github.com/ethereum-optimism/optimism/op-dispute-mon/mon"
"github.com/ethereum-optimism/optimism/op-dispute-mon/mon/transform"
disputeTypes "github.com/ethereum-optimism/optimism/op-dispute-mon/mon/types"
"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -90,7 +90,7 @@ func enrichClaims(claims []types.Claim) []disputeTypes.EnrichedClaim {

func gameResult(game types.Game) (gameTypes.GameStatus, *disputeTypes.BidirectionalTree, types.Game) {
tree := transform.CreateBidirectionalTree(enrichClaims(game.Claims()))
result := resolution.Resolve(tree)
result := mon.Resolve(tree)
resolvedClaims := make([]types.Claim, 0, len(tree.Claims))
for _, claim := range tree.Claims {
resolvedClaims = append(resolvedClaims, *claim.Claim)
Expand Down
13 changes: 0 additions & 13 deletions op-dispute-mon/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ type Metricer interface {

RecordWithdrawalRequests(delayedWeth common.Address, matches bool, count int)

RecordClaimResolutionDelayMax(delay float64)

RecordOutputFetchTime(timestamp float64)

RecordGameAgreement(status GameAgreementStatus, count int)
Expand Down Expand Up @@ -129,8 +127,6 @@ type Metrics struct {

lastOutputFetch prometheus.Gauge

claimResolutionDelayMax prometheus.Gauge

gamesAgreement prometheus.GaugeVec
ignoredGames prometheus.Gauge

Expand Down Expand Up @@ -173,11 +169,6 @@ func NewMetrics() *Metrics {
Name: "last_output_fetch",
Help: "Timestamp of the last output fetch",
}),
claimResolutionDelayMax: factory.NewGauge(prometheus.GaugeOpts{
Namespace: Namespace,
Name: "claim_resolution_delay_max",
Help: "Maximum claim resolution delay in seconds",
}),
honestActorClaims: *factory.NewGaugeVec(prometheus.GaugeOpts{
Namespace: Namespace,
Name: "honest_actor_claims",
Expand Down Expand Up @@ -367,10 +358,6 @@ func (m *Metrics) RecordWithdrawalRequests(delayedWeth common.Address, matches b
m.withdrawalRequests.WithLabelValues(delayedWeth.Hex(), credits).Set(float64(count))
}

func (m *Metrics) RecordClaimResolutionDelayMax(delay float64) {
m.claimResolutionDelayMax.Set(delay)
}

func (m *Metrics) Document() []opmetrics.DocumentedMetric {
return m.factory.Document()
}
Expand Down
2 changes: 0 additions & 2 deletions op-dispute-mon/metrics/noop.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ func (*NoopMetricsImpl) RecordClaims(_ ClaimStatus, _ int) {}

func (*NoopMetricsImpl) RecordWithdrawalRequests(_ common.Address, _ bool, _ int) {}

func (*NoopMetricsImpl) RecordClaimResolutionDelayMax(_ float64) {}

func (*NoopMetricsImpl) RecordOutputFetchTime(_ float64) {}

func (*NoopMetricsImpl) RecordGameAgreement(_ GameAgreementStatus, _ int) {}
Expand Down
2 changes: 1 addition & 1 deletion op-dispute-mon/mon/claims.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (c *ClaimMonitor) checkUpdateHonestActorStats(proxy common.Address, claim *
if claim.CounteredBy != (common.Address{}) {
honest[actor].InvalidClaimCount++
honest[actor].LostBonds = new(big.Int).Add(honest[actor].LostBonds, claim.Bond)
c.logger.Error("Claim resolved against honest actor", "game", proxy, "honest_actor", actor, "countered_by", claim.CounteredBy, "claim_contract_index", claim.ContractIndex)
c.logger.Error("Claim resolved against honest actor", "game", proxy, "honestActor", actor, "counteredBy", claim.CounteredBy, "claimContractIndex", claim.ContractIndex, "bondAmount", claim.Bond)
} else {
honest[actor].ValidClaimCount++
// Note that we don't count refunded bonds as won
Expand Down
4 changes: 1 addition & 3 deletions op-dispute-mon/mon/forecast.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"github.com/ethereum-optimism/optimism/op-challenger/game/types"
"github.com/ethereum-optimism/optimism/op-dispute-mon/metrics"
"github.com/ethereum-optimism/optimism/op-dispute-mon/mon/resolution"
"github.com/ethereum-optimism/optimism/op-dispute-mon/mon/transform"
monTypes "github.com/ethereum-optimism/optimism/op-dispute-mon/mon/types"
"github.com/ethereum/go-ethereum/common"
Expand All @@ -24,7 +23,6 @@ type OutputValidator interface {
}

type ForecastMetrics interface {
RecordClaimResolutionDelayMax(delay float64)
RecordGameAgreement(status metrics.GameAgreementStatus, count int)
RecordIgnoredGames(count int)
}
Expand Down Expand Up @@ -107,7 +105,7 @@ func (f *forecast) forecastGame(ctx context.Context, game *monTypes.EnrichedGame
tree := transform.CreateBidirectionalTree(game.Claims)

// Compute the resolution status of the game.
forecastStatus := resolution.Resolve(tree)
forecastStatus := Resolve(tree)

if agreement {
// If we agree with the output root proposal, the Defender should win, defending that claim.
Expand Down
9 changes: 2 additions & 7 deletions op-dispute-mon/mon/forecast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,8 @@ func zeroGameAgreement() map[metrics.GameAgreementStatus]int {
}

type mockForecastMetrics struct {
gameAgreement map[metrics.GameAgreementStatus]int
ignoredGames int
claimResolutionDelayMax float64
gameAgreement map[metrics.GameAgreementStatus]int
ignoredGames int
}

func (m *mockForecastMetrics) RecordGameAgreement(status metrics.GameAgreementStatus, count int) {
Expand All @@ -297,10 +296,6 @@ func (m *mockForecastMetrics) RecordIgnoredGames(count int) {
m.ignoredGames = count
}

func (m *mockForecastMetrics) RecordClaimResolutionDelayMax(delay float64) {
m.claimResolutionDelayMax = delay
}

func createDeepClaimList() []monTypes.EnrichedClaim {
return []monTypes.EnrichedClaim{
{
Expand Down
5 changes: 0 additions & 5 deletions op-dispute-mon/mon/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ type MonitorWithdrawals func(games []*types.EnrichedGameData)
type BlockHashFetcher func(ctx context.Context, number *big.Int) (common.Hash, error)
type BlockNumberFetcher func(ctx context.Context) (uint64, error)
type Extract func(ctx context.Context, blockHash common.Hash, minTimestamp uint64) ([]*types.EnrichedGameData, int, error)
type RecordClaimResolutionDelayMax func([]*types.EnrichedGameData)

type gameMonitor struct {
logger log.Logger
Expand All @@ -34,7 +33,6 @@ type gameMonitor struct {
gameWindow time.Duration
monitorInterval time.Duration

delays RecordClaimResolutionDelayMax
forecast Forecast
bonds Bonds
resolutions Resolutions
Expand All @@ -51,7 +49,6 @@ func newGameMonitor(
cl clock.Clock,
monitorInterval time.Duration,
gameWindow time.Duration,
delays RecordClaimResolutionDelayMax,
forecast Forecast,
bonds Bonds,
resolutions Resolutions,
Expand All @@ -68,7 +65,6 @@ func newGameMonitor(
done: make(chan struct{}),
monitorInterval: monitorInterval,
gameWindow: gameWindow,
delays: delays,
forecast: forecast,
bonds: bonds,
resolutions: resolutions,
Expand Down Expand Up @@ -96,7 +92,6 @@ func (m *gameMonitor) monitorGames() error {
return fmt.Errorf("failed to load games: %w", err)
}
m.resolutions(enrichedGames)
m.delays(enrichedGames)
m.forecast(m.ctx, enrichedGames, ignored)
m.bonds(enrichedGames)
m.claims(enrichedGames)
Expand Down
28 changes: 8 additions & 20 deletions op-dispute-mon/mon/monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestMonitor_MonitorGames(t *testing.T) {
t.Parallel()

t.Run("FailedFetchBlocknumber", func(t *testing.T) {
monitor, _, _, _, _, _, _, _ := setupMonitorTest(t)
monitor, _, _, _, _, _, _ := setupMonitorTest(t)
boom := errors.New("boom")
monitor.fetchBlockNumber = func(ctx context.Context) (uint64, error) {
return 0, boom
Expand All @@ -34,7 +34,7 @@ func TestMonitor_MonitorGames(t *testing.T) {
})

t.Run("FailedFetchBlockHash", func(t *testing.T) {
monitor, _, _, _, _, _, _, _ := setupMonitorTest(t)
monitor, _, _, _, _, _, _ := setupMonitorTest(t)
boom := errors.New("boom")
monitor.fetchBlockHash = func(ctx context.Context, number *big.Int) (common.Hash, error) {
return common.Hash{}, boom
Expand All @@ -44,25 +44,23 @@ func TestMonitor_MonitorGames(t *testing.T) {
})

t.Run("MonitorsWithNoGames", func(t *testing.T) {
monitor, factory, forecast, delays, bonds, withdrawals, resolutions, claims := setupMonitorTest(t)
monitor, factory, forecast, bonds, withdrawals, resolutions, claims := setupMonitorTest(t)
factory.games = []*monTypes.EnrichedGameData{}
err := monitor.monitorGames()
require.NoError(t, err)
require.Equal(t, 1, forecast.calls)
require.Equal(t, 1, delays.calls)
require.Equal(t, 1, bonds.calls)
require.Equal(t, 1, resolutions.calls)
require.Equal(t, 1, claims.calls)
require.Equal(t, 1, withdrawals.calls)
})

t.Run("MonitorsMultipleGames", func(t *testing.T) {
monitor, factory, forecast, delays, bonds, withdrawals, resolutions, claims := setupMonitorTest(t)
monitor, factory, forecast, bonds, withdrawals, resolutions, claims := setupMonitorTest(t)
factory.games = []*monTypes.EnrichedGameData{{}, {}, {}}
err := monitor.monitorGames()
require.NoError(t, err)
require.Equal(t, 1, forecast.calls)
require.Equal(t, 1, delays.calls)
require.Equal(t, 1, bonds.calls)
require.Equal(t, 1, resolutions.calls)
require.Equal(t, 1, claims.calls)
Expand All @@ -74,7 +72,7 @@ func TestMonitor_StartMonitoring(t *testing.T) {
t.Run("MonitorsGames", func(t *testing.T) {
addr1 := common.Address{0xaa}
addr2 := common.Address{0xbb}
monitor, factory, forecaster, _, _, _, _, _ := setupMonitorTest(t)
monitor, factory, forecaster, _, _, _, _ := setupMonitorTest(t)
factory.games = []*monTypes.EnrichedGameData{newEnrichedGameData(addr1, 9999), newEnrichedGameData(addr2, 9999)}
factory.maxSuccess = len(factory.games) // Only allow two successful fetches

Expand All @@ -87,7 +85,7 @@ func TestMonitor_StartMonitoring(t *testing.T) {
})

t.Run("FailsToFetchGames", func(t *testing.T) {
monitor, factory, forecaster, _, _, _, _, _ := setupMonitorTest(t)
monitor, factory, forecaster, _, _, _, _ := setupMonitorTest(t)
factory.fetchErr = errors.New("boom")

monitor.StartMonitoring()
Expand All @@ -109,7 +107,7 @@ func newEnrichedGameData(proxy common.Address, timestamp uint64) *monTypes.Enric
}
}

func setupMonitorTest(t *testing.T) (*gameMonitor, *mockExtractor, *mockForecast, *mockDelayCalculator, *mockBonds, *mockWithdrawalMonitor, *mockResolutionMonitor, *mockClaimMonitor) {
func setupMonitorTest(t *testing.T) (*gameMonitor, *mockExtractor, *mockForecast, *mockBonds, *mockWithdrawalMonitor, *mockResolutionMonitor, *mockClaimMonitor) {
logger := testlog.Logger(t, log.LvlDebug)
fetchBlockNum := func(ctx context.Context) (uint64, error) {
return 1, nil
Expand All @@ -126,14 +124,12 @@ func setupMonitorTest(t *testing.T) (*gameMonitor, *mockExtractor, *mockForecast
resolutions := &mockResolutionMonitor{}
claims := &mockClaimMonitor{}
withdrawals := &mockWithdrawalMonitor{}
delays := &mockDelayCalculator{}
monitor := newGameMonitor(
context.Background(),
logger,
cl,
monitorInterval,
10*time.Second,
delays.RecordClaimResolutionDelayMax,
forecast.Forecast,
bonds.CheckBonds,
resolutions.CheckResolutions,
Expand All @@ -143,7 +139,7 @@ func setupMonitorTest(t *testing.T) (*gameMonitor, *mockExtractor, *mockForecast
fetchBlockNum,
fetchBlockHash,
)
return monitor, extractor, forecast, delays, bonds, withdrawals, resolutions, claims
return monitor, extractor, forecast, bonds, withdrawals, resolutions, claims
}

type mockResolutionMonitor struct {
Expand All @@ -170,14 +166,6 @@ func (m *mockWithdrawalMonitor) CheckWithdrawals(games []*monTypes.EnrichedGameD
m.calls++
}

type mockDelayCalculator struct {
calls int
}

func (m *mockDelayCalculator) RecordClaimResolutionDelayMax(games []*monTypes.EnrichedGameData) {
m.calls++
}

type mockForecast struct {
calls int
}
Expand Down
52 changes: 0 additions & 52 deletions op-dispute-mon/mon/resolution/delay.go

This file was deleted.

Loading

0 comments on commit 8366449

Please sign in to comment.