Commit 34b26718 authored by mergify[bot]'s avatar mergify[bot] Committed by GitHub

Merge branch 'develop' into aj/challenger-server-in-docker

parents 4f550389 d8526825
...@@ -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,
......
...@@ -147,7 +147,7 @@ TODO: the connection gater does currently not gate by IP address on the dial Acc ...@@ -147,7 +147,7 @@ TODO: the connection gater does currently not gate by IP address on the dial Acc
#### Transport security #### Transport security
[Libp2p-noise][libp2p-noise], `XX` handshake, with the the `secp256k1` P2P identity, as popularized in Eth2. [Libp2p-noise][libp2p-noise], `XX` handshake, with the `secp256k1` P2P identity, as popularized in Eth2.
The TLS option is available as well, but `noise` should be prioritized in negotiation. The TLS option is available as well, but `noise` should be prioritized in negotiation.
#### Protocol negotiation #### Protocol negotiation
......
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