Commit d27ee1b5 authored by Andrew Huang's avatar Andrew Huang Committed by GitHub

Merge branch 'ethereum-optimism:develop' into netrestrict

parents 4f35b852 66af76fe
...@@ -6,6 +6,8 @@ RUN apk add --no-cache make gcc musl-dev linux-headers git jq bash ...@@ -6,6 +6,8 @@ RUN apk add --no-cache make gcc musl-dev linux-headers git jq bash
# build op-challenger with the shared go.mod & go.sum files # build op-challenger with the shared go.mod & go.sum files
COPY ./op-challenger /app/op-challenger COPY ./op-challenger /app/op-challenger
COPY ./op-program /app/op-program
COPY ./op-preimage /app/op-preimage
COPY ./op-bindings /app/op-bindings COPY ./op-bindings /app/op-bindings
COPY ./op-node /app/op-node COPY ./op-node /app/op-node
COPY ./op-service /app/op-service COPY ./op-service /app/op-service
...@@ -19,16 +21,25 @@ COPY ./cannon /app/cannon ...@@ -19,16 +21,25 @@ COPY ./cannon /app/cannon
COPY ./op-preimage /app/op-preimage COPY ./op-preimage /app/op-preimage
COPY ./op-chain-ops /app/op-chain-ops COPY ./op-chain-ops /app/op-chain-ops
WORKDIR /app/op-challenger WORKDIR /app/op-program
RUN go mod download RUN go mod download
ARG TARGETOS TARGETARCH ARG TARGETOS TARGETARCH
RUN make op-program-host VERSION="$VERSION" GOOS=$TARGETOS GOARCH=$TARGETARCH
WORKDIR /app/op-challenger
RUN make op-challenger VERSION="$VERSION" GOOS=$TARGETOS GOARCH=$TARGETARCH RUN make op-challenger VERSION="$VERSION" GOOS=$TARGETOS GOARCH=$TARGETARCH
FROM alpine:3.18 FROM alpine:3.18
# Make the bundled op-program the default cannon server
ENV OP_CHALLENGER_CANNON_SERVER /usr/local/bin/op-program
COPY --from=builder /app/op-challenger/bin/op-challenger /usr/local/bin COPY --from=builder /app/op-challenger/bin/op-challenger /usr/local/bin
COPY --from=builder /app/op-program/bin/op-program /usr/local/bin
CMD ["op-challenger"] CMD ["op-challenger"]
...@@ -18,9 +18,7 @@ import ( ...@@ -18,9 +18,7 @@ import (
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
) )
type Actor interface { type actor func(ctx context.Context) error
Act(ctx context.Context) error
}
type GameInfo interface { type GameInfo interface {
GetGameStatus(context.Context) (types.GameStatus, error) GetGameStatus(context.Context) (types.GameStatus, error)
...@@ -28,7 +26,7 @@ type GameInfo interface { ...@@ -28,7 +26,7 @@ type GameInfo interface {
} }
type GamePlayer struct { type GamePlayer struct {
agent Actor act actor
agreeWithProposedOutput bool agreeWithProposedOutput bool
loader GameInfo loader GameInfo
logger log.Logger logger log.Logger
...@@ -53,6 +51,25 @@ func NewGamePlayer( ...@@ -53,6 +51,25 @@ func NewGamePlayer(
loader := NewLoader(contract) loader := NewLoader(contract)
status, err := loader.GetGameStatus(ctx)
if err != nil {
return nil, fmt.Errorf("failed to fetch game status: %w", err)
}
if status != types.GameStatusInProgress {
logger.Info("Game already resolved", "status", status)
// Game is already complete so skip creating the trace provider, loading game inputs etc.
return &GamePlayer{
logger: logger,
loader: loader,
agreeWithProposedOutput: cfg.AgreeWithProposedOutput,
completed: true,
// Act function does nothing because the game is already complete
act: func(ctx context.Context) error {
return nil
},
}, nil
}
gameDepth, err := loader.FetchGameDepth(ctx) gameDepth, err := loader.FetchGameDepth(ctx)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to fetch the game depth: %w", err) return nil, fmt.Errorf("failed to fetch the game depth: %w", err)
...@@ -88,10 +105,11 @@ func NewGamePlayer( ...@@ -88,10 +105,11 @@ func NewGamePlayer(
} }
return &GamePlayer{ return &GamePlayer{
agent: NewAgent(loader, int(gameDepth), provider, responder, updater, cfg.AgreeWithProposedOutput, logger), act: NewAgent(loader, int(gameDepth), provider, responder, updater, cfg.AgreeWithProposedOutput, logger).Act,
agreeWithProposedOutput: cfg.AgreeWithProposedOutput, agreeWithProposedOutput: cfg.AgreeWithProposedOutput,
loader: loader, loader: loader,
logger: logger, logger: logger,
completed: status != types.GameStatusInProgress,
}, nil }, nil
} }
...@@ -102,7 +120,7 @@ func (g *GamePlayer) ProgressGame(ctx context.Context) bool { ...@@ -102,7 +120,7 @@ func (g *GamePlayer) ProgressGame(ctx context.Context) bool {
return true return true
} }
g.logger.Trace("Checking if actions are required") g.logger.Trace("Checking if actions are required")
if err := g.agent.Act(ctx); err != nil { if err := g.act(ctx); err != nil {
g.logger.Error("Error when acting on game", "err", err) g.logger.Error("Error when acting on game", "err", err)
} }
if status, err := g.loader.GetGameStatus(ctx); err != nil { if status, err := g.loader.GetGameStatus(ctx); err != nil {
......
...@@ -157,7 +157,7 @@ func setupProgressGameTest(t *testing.T, agreeWithProposedRoot bool) (*testlog.C ...@@ -157,7 +157,7 @@ func setupProgressGameTest(t *testing.T, agreeWithProposedRoot bool) (*testlog.C
logger.SetHandler(handler) logger.SetHandler(handler)
gameState := &stubGameState{claimCount: 1} gameState := &stubGameState{claimCount: 1}
game := &GamePlayer{ game := &GamePlayer{
agent: gameState, act: gameState.Act,
agreeWithProposedOutput: agreeWithProposedRoot, agreeWithProposedOutput: agreeWithProposedRoot,
loader: gameState, loader: gameState,
logger: logger, logger: logger,
......
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