Skip to content

Commit

Permalink
op-challenger: Share providers across different asterisc game instanc…
Browse files Browse the repository at this point in the history
…es (ethereum-optimism#10314)

* op-challenger: Share providers across different asterisc game instances

Avoids loading the full state to extract the commitment for each individual game.

* Fix flag error
  • Loading branch information
pcw109550 authored Apr 26, 2024
1 parent 8447d16 commit 8c19065
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion op-challenger/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ func NewConfigFromCLI(ctx *cli.Context, logger log.Logger) (*config.Config, erro
if ctx.IsSet(AsteriscPreStatesURLFlag.Name) {
parsed, err := url.Parse(ctx.String(AsteriscPreStatesURLFlag.Name))
if err != nil {
return nil, fmt.Errorf("invalid asterisc pre states url (%v): %w", ctx.String(CannonPreStatesURLFlag.Name), err)
return nil, fmt.Errorf("invalid asterisc pre states url (%v): %w", ctx.String(AsteriscPreStatesURLFlag.Name), err)
}
asteriscPreStatesURL = parsed
}
Expand Down
10 changes: 8 additions & 2 deletions op-challenger/game/fault/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,13 @@ func registerAsterisc(
} else {
prestateSource = prestates.NewSinglePrestateSource(cfg.AsteriscAbsolutePreState)
}
prestateProviderCache := prestates.NewPrestateProviderCache(m, fmt.Sprintf("prestates-%v", gameType), func(prestateHash common.Hash) (faultTypes.PrestateProvider, error) {
prestatePath, err := prestateSource.PrestatePath(prestateHash)
if err != nil {
return nil, fmt.Errorf("required prestate %v not available: %w", prestateHash, err)
}
return asterisc.NewPrestateProvider(prestatePath), nil
})
playerCreator := func(game types.GameMetadata, dir string) (scheduler.GamePlayer, error) {
contract, err := contracts.NewFaultDisputeGameContract(ctx, m, game.Proxy, caller)
if err != nil {
Expand All @@ -218,11 +225,10 @@ func registerAsterisc(
if err != nil {
return nil, fmt.Errorf("failed to load prestate hash for game %v: %w", game.Proxy, err)
}
prestatePath, err := prestateSource.PrestatePath(requiredPrestatehash)
asteriscPrestateProvider, err := prestateProviderCache.GetOrCreate(requiredPrestatehash)
if err != nil {
return nil, fmt.Errorf("required prestate %v not available for game %v: %w", requiredPrestatehash, game.Proxy, err)
}
asteriscPrestateProvider := asterisc.NewPrestateProvider(prestatePath)

oracle, err := contract.GetOracle(ctx)
if err != nil {
Expand Down

0 comments on commit 8c19065

Please sign in to comment.