Commit bad663e1 authored by OptimismBot's avatar OptimismBot Committed by GitHub

Merge pull request #6393 from ethereum-optimism/aj/challenger-ctx

op-challenger: Pass context through correctly
parents 21983e0f ae696da1
...@@ -52,10 +52,10 @@ func Main(ctx context.Context, logger log.Logger, cfg *config.Config) error { ...@@ -52,10 +52,10 @@ func Main(ctx context.Context, logger log.Logger, cfg *config.Config) error {
_ = agent.Act(ctx) _ = agent.Act(ctx)
status, _ := caller.GetGameStatus(ctx) status, _ := caller.GetGameStatus(ctx)
if status != 0 { if status != 0 {
caller.LogGameStatus() caller.LogGameStatus(ctx)
return nil return nil
} else { } else {
caller.LogGameInfo() caller.LogGameInfo(ctx)
} }
select { select {
case <-time.After(300 * time.Millisecond): case <-time.After(300 * time.Millisecond):
......
...@@ -40,13 +40,13 @@ func (a *Agent) Act(ctx context.Context) error { ...@@ -40,13 +40,13 @@ func (a *Agent) Act(ctx context.Context) error {
} }
// Create counter claims // Create counter claims
for _, claim := range game.Claims() { for _, claim := range game.Claims() {
if err := a.move(claim, game); err != nil { if err := a.move(ctx, claim, game); err != nil {
log.Error("Failed to move", "err", err) log.Error("Failed to move", "err", err)
} }
} }
// Step on all leaf claims // Step on all leaf claims
for _, claim := range game.Claims() { for _, claim := range game.Claims() {
if err := a.step(claim, game); err != nil { if err := a.step(ctx, claim, game); err != nil {
log.Error("Failed to step", "err", err) log.Error("Failed to step", "err", err)
} }
} }
...@@ -83,7 +83,7 @@ func (a *Agent) newGameFromContracts(ctx context.Context) (Game, error) { ...@@ -83,7 +83,7 @@ func (a *Agent) newGameFromContracts(ctx context.Context) (Game, error) {
} }
// move determines & executes the next move given a claim // move determines & executes the next move given a claim
func (a *Agent) move(claim Claim, game Game) error { func (a *Agent) move(ctx context.Context, claim Claim, game Game) error {
nextMove, err := a.solver.NextMove(claim, game.AgreeWithClaimLevel(claim)) nextMove, err := a.solver.NextMove(claim, game.AgreeWithClaimLevel(claim))
if err != nil { if err != nil {
a.log.Warn("Failed to execute the next move", "err", err) a.log.Warn("Failed to execute the next move", "err", err)
...@@ -102,11 +102,11 @@ func (a *Agent) move(claim Claim, game Game) error { ...@@ -102,11 +102,11 @@ func (a *Agent) move(claim Claim, game Game) error {
return nil return nil
} }
log.Info("Performing move") log.Info("Performing move")
return a.responder.Respond(context.TODO(), move) return a.responder.Respond(ctx, move)
} }
// step determines & executes the next step against a leaf claim through the responder // step determines & executes the next step against a leaf claim through the responder
func (a *Agent) step(claim Claim, game Game) error { func (a *Agent) step(ctx context.Context, claim Claim, game Game) error {
if claim.Depth() != a.maxDepth { if claim.Depth() != a.maxDepth {
return nil return nil
} }
...@@ -136,5 +136,5 @@ func (a *Agent) step(claim Claim, game Game) error { ...@@ -136,5 +136,5 @@ func (a *Agent) step(claim Claim, game Game) error {
IsAttack: step.IsAttack, IsAttack: step.IsAttack,
StateData: step.PreState, StateData: step.PreState,
} }
return a.responder.Step(context.TODO(), callData) return a.responder.Step(ctx, callData)
} }
...@@ -44,13 +44,13 @@ func NewFaultCallerFromBindings(fdgAddr common.Address, client *ethclient.Client ...@@ -44,13 +44,13 @@ func NewFaultCallerFromBindings(fdgAddr common.Address, client *ethclient.Client
} }
// LogGameInfo logs the game info. // LogGameInfo logs the game info.
func (fc *FaultCaller) LogGameInfo() { func (fc *FaultCaller) LogGameInfo(ctx context.Context) {
status, err := fc.GetGameStatus(context.Background()) status, err := fc.GetGameStatus(ctx)
if err != nil { if err != nil {
fc.log.Error("failed to get game status", "err", err) fc.log.Error("failed to get game status", "err", err)
return return
} }
claimLen, err := fc.GetClaimDataLength(context.Background()) claimLen, err := fc.GetClaimDataLength(ctx)
if err != nil { if err != nil {
fc.log.Error("failed to get claim count", "err", err) fc.log.Error("failed to get claim count", "err", err)
return return
...@@ -66,8 +66,8 @@ func (fc *FaultCaller) GetGameStatus(ctx context.Context) (uint8, error) { ...@@ -66,8 +66,8 @@ func (fc *FaultCaller) GetGameStatus(ctx context.Context) (uint8, error) {
return fc.Status(&bind.CallOpts{Context: ctx}) return fc.Status(&bind.CallOpts{Context: ctx})
} }
func (fc *FaultCaller) LogGameStatus() { func (fc *FaultCaller) LogGameStatus(ctx context.Context) {
status, err := fc.GetGameStatus(context.Background()) status, err := fc.GetGameStatus(ctx)
if err != nil { if err != nil {
fc.log.Error("failed to get game status", "err", err) fc.log.Error("failed to get game status", "err", err)
return return
...@@ -80,8 +80,8 @@ func (fc *FaultCaller) GetClaimDataLength(ctx context.Context) (*big.Int, error) ...@@ -80,8 +80,8 @@ func (fc *FaultCaller) GetClaimDataLength(ctx context.Context) (*big.Int, error)
return fc.ClaimDataLen(&bind.CallOpts{Context: ctx}) return fc.ClaimDataLen(&bind.CallOpts{Context: ctx})
} }
func (fc *FaultCaller) LogClaimDataLength() { func (fc *FaultCaller) LogClaimDataLength(ctx context.Context) {
claimLen, err := fc.GetClaimDataLength(context.Background()) claimLen, err := fc.GetClaimDataLength(ctx)
if err != nil { if err != nil {
fc.log.Error("failed to get claim count", "err", err) fc.log.Error("failed to get claim count", "err", err)
return return
......
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