Commit 51eca4ff authored by Andreas Bigger's avatar Andreas Bigger

Challenger resolution

parent 5f3aed08
package op_challenger package op_challenger
import ( import (
"context"
"fmt" "fmt"
"time" "time"
...@@ -48,8 +49,14 @@ func Main(logger log.Logger, cfg *config.Config) error { ...@@ -48,8 +49,14 @@ func Main(logger log.Logger, cfg *config.Config) error {
for { for {
logger.Info("Performing action") logger.Info("Performing action")
_ = agent.Act() _ = agent.Act(context.Background())
caller.LogGameInfo() status, _ := caller.GetGameStatus(context.Background())
if status != 0 {
caller.LogGameStatus()
return nil
} else {
caller.LogGameInfo()
}
time.Sleep(300 * time.Millisecond) time.Sleep(300 * time.Millisecond)
} }
} }
...@@ -29,8 +29,11 @@ func NewAgent(loader Loader, maxDepth int, trace TraceProvider, responder Respon ...@@ -29,8 +29,11 @@ func NewAgent(loader Loader, maxDepth int, trace TraceProvider, responder Respon
} }
// Act iterates the game & performs all of the next actions. // Act iterates the game & performs all of the next actions.
func (a *Agent) Act() error { func (a *Agent) Act(ctx context.Context) error {
game, err := a.newGameFromContracts(context.Background()) if a.tryResolve(ctx) {
return nil
}
game, err := a.newGameFromContracts(ctx)
if err != nil { if err != nil {
a.log.Error("Failed to create new game", "err", err) a.log.Error("Failed to create new game", "err", err)
return err return err
...@@ -50,6 +53,19 @@ func (a *Agent) Act() error { ...@@ -50,6 +53,19 @@ func (a *Agent) Act() error {
return nil return nil
} }
// tryResolve resolves the game if it is in a terminal state
// and returns true if the game resolves successfully.
func (a *Agent) tryResolve(ctx context.Context) bool {
if a.responder.CanResolve(ctx) {
err := a.responder.Resolve(ctx)
if err != nil {
return true
}
a.log.Error("failed to resolve the game", "err", err)
}
return false
}
// newGameFromContracts initializes a new game state from the state in the contract // newGameFromContracts initializes a new game state from the state in the contract
func (a *Agent) newGameFromContracts(ctx context.Context) (Game, error) { func (a *Agent) newGameFromContracts(ctx context.Context) (Game, error) {
claims, err := a.loader.FetchClaims(ctx) claims, err := a.loader.FetchClaims(ctx)
......
...@@ -76,6 +76,8 @@ func (c *Claim) DefendsParent() bool { ...@@ -76,6 +76,8 @@ func (c *Claim) DefendsParent() bool {
// Responder takes a response action & executes. // Responder takes a response action & executes.
// For full op-challenger this means executing the transaction on chain. // For full op-challenger this means executing the transaction on chain.
type Responder interface { type Responder interface {
CanResolve(ctx context.Context) bool
Resolve(ctx context.Context) error
Respond(ctx context.Context, response Claim) error Respond(ctx context.Context, response Claim) error
Step(ctx context.Context, stepData StepCallData) error Step(ctx context.Context, stepData StepCallData) error
} }
...@@ -46,5 +46,5 @@ ...@@ -46,5 +46,5 @@
"l2GenesisRegolithTimeOffset": "0x0", "l2GenesisRegolithTimeOffset": "0x0",
"faultGameAbsolutePrestate": 96, "faultGameAbsolutePrestate": 96,
"faultGameMaxDepth": 4, "faultGameMaxDepth": 4,
"faultGameMaxDuration": 604800 "faultGameMaxDuration": 120
} }
\ No newline at end of file
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