Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

challenger: Allow interrupting subcommands #10765

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion op-challenger/cmd/create_game.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,6 @@ var CreateGameCommand = &cli.Command{
Name: "create-game",
Usage: "Creates a dispute game via the factory",
Description: "Creates a dispute game via the factory",
Action: CreateGame,
Action: Interruptible(CreateGame),
Flags: createGameFlags(),
}
2 changes: 1 addition & 1 deletion op-challenger/cmd/credits.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,6 @@ var ListCreditsCommand = &cli.Command{
Name: "list-credits",
Usage: "List the credits in a dispute game",
Description: "Lists the credits in a dispute game",
Action: ListCredits,
Action: Interruptible(ListCredits),
Flags: listCreditsFlags(),
}
2 changes: 1 addition & 1 deletion op-challenger/cmd/list_claims.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,6 @@ var ListClaimsCommand = &cli.Command{
Name: "list-claims",
Usage: "List the claims in a dispute game",
Description: "Lists the claims in a dispute game",
Action: ListClaims,
Action: Interruptible(ListClaims),
Flags: listClaimsFlags(),
}
2 changes: 1 addition & 1 deletion op-challenger/cmd/list_games.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,6 @@ var ListGamesCommand = &cli.Command{
Name: "list-games",
Usage: "List the games created by a dispute game factory",
Description: "Lists the games created by a dispute game factory",
Action: ListGames,
Action: Interruptible(ListGames),
Flags: listGamesFlags(),
}
2 changes: 1 addition & 1 deletion op-challenger/cmd/move.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,6 @@ var MoveCommand = &cli.Command{
Name: "move",
Usage: "Creates and sends a move transaction to the dispute game",
Description: "Creates and sends a move transaction to the dispute game",
Action: Move,
Action: Interruptible(Move),
Flags: moveFlags(),
}
2 changes: 1 addition & 1 deletion op-challenger/cmd/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ var ResolveCommand = &cli.Command{
Name: "resolve",
Usage: "Resolves the specified dispute game if possible",
Description: "Resolves the specified dispute game if possible",
Action: Resolve,
Action: Interruptible(Resolve),
Flags: resolveFlags(),
}
2 changes: 1 addition & 1 deletion op-challenger/cmd/resolve_claim.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ var ResolveClaimCommand = &cli.Command{
Name: "resolve-claim",
Usage: "Resolves the specified claim if possible",
Description: "Resolves the specified claim if possible",
Action: ResolveClaim,
Action: Interruptible(ResolveClaim),
Flags: resolveClaimFlags(),
}
7 changes: 7 additions & 0 deletions op-challenger/cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
contractMetrics "github.com/ethereum-optimism/optimism/op-challenger/game/fault/contracts/metrics"
opservice "github.com/ethereum-optimism/optimism/op-service"
"github.com/ethereum-optimism/optimism/op-service/dial"
"github.com/ethereum-optimism/optimism/op-service/opio"
"github.com/ethereum-optimism/optimism/op-service/sources/batching"
"github.com/ethereum-optimism/optimism/op-service/txmgr"
"github.com/ethereum-optimism/optimism/op-service/txmgr/metrics"
Expand All @@ -17,6 +18,12 @@ import (

type ContractCreator[T any] func(context.Context, contractMetrics.ContractMetricer, common.Address, *batching.MultiCaller) (T, error)

func Interruptible(action cli.ActionFunc) cli.ActionFunc {
return func(ctx *cli.Context) error {
ctx.Context = opio.CancelOnInterrupt(ctx.Context)
return action(ctx)
}
}
func AddrFromFlag(flagName string) func(ctx *cli.Context) (common.Address, error) {
return func(ctx *cli.Context) (common.Address, error) {
gameAddr, err := opservice.ParseAddress(ctx.String(flagName))
Expand Down