Commit 2ebc5d8c authored by Andreas Bigger's avatar Andreas Bigger

Refactors

parent ba9629c0
......@@ -3,6 +3,7 @@ package game
import (
"context"
"fmt"
"regexp"
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum-optimism/optimism/op-challenger/config"
......@@ -10,6 +11,7 @@ import (
"github.com/ethereum-optimism/optimism/op-challenger/game/scheduler"
"github.com/ethereum-optimism/optimism/op-challenger/metrics"
"github.com/ethereum-optimism/optimism/op-challenger/version"
opClient "github.com/ethereum-optimism/optimism/op-node/client"
"github.com/ethereum-optimism/optimism/op-service/client"
"github.com/ethereum-optimism/optimism/op-service/clock"
oppprof "github.com/ethereum-optimism/optimism/op-service/pprof"
......@@ -76,12 +78,11 @@ func NewService(ctx context.Context, logger log.Logger, cfg *config.Config) (*Se
return fault.NewGamePlayer(ctx, logger, m, cfg, dir, addr, txMgr, l1Client)
})
polledClient, err := client.DialPolledClientWithTimeout(ctx, client.DefaultDialTimeout, logger, cfg.L1EthRpc, cfg.PollInterval)
if err != nil {
return nil, fmt.Errorf("failed to dial L1: %w", err)
var rpcClient opClient.RPC = opClient.NewBaseRPCClient(l1Client.Client())
if regexp.MustCompile("^http(s)?://").MatchString(cfg.L1EthRpc) {
rpcClient = opClient.NewPollingClient(ctx, logger, rpcClient, opClient.WithPollRate(cfg.PollInterval))
}
monitor := newGameMonitor(logger, cl, loader, sched, cfg.GameWindow, l1Client.BlockNumber, cfg.GameAllowlist, polledClient)
monitor := newGameMonitor(logger, cl, loader, sched, cfg.GameWindow, l1Client.BlockNumber, cfg.GameAllowlist, rpcClient)
m.RecordInfo(version.SimpleWithMeta)
m.RecordUp()
......
......@@ -146,7 +146,7 @@ func NewChallengerConfig(t *testing.T, l1Endpoint string, options ...Option) *co
require.NoError(t, err, "cannon pre-state should be built. Make sure you've run make cannon-prestate")
}
if cfg.PollInterval == 0 {
cfg.PollInterval = 2 * time.Second
cfg.PollInterval = time.Second
}
return &cfg
......
......@@ -47,16 +47,6 @@ func DialRollupClientWithTimeout(timeout time.Duration, log log.Logger, url stri
return sources.NewRollupClient(client.NewBaseRPCClient(rpcCl)), nil
}
// DialPolledClientWithTimeout attempts to dial the RPC provider using the provided URL.
// If the dial doesn't complete within timeout seconds, this method will return an error.
func DialPolledClientWithTimeout(ctx context.Context, timeout time.Duration, log log.Logger, url string, pollInterval time.Duration) (client.RPC, error) {
opts := []client.RPCOption{
client.WithHttpPollInterval(pollInterval),
client.WithDialBackoff(defaultRetryCount),
}
return client.NewRPC(ctx, log, url, opts...)
}
// Dials a JSON-RPC endpoint repeatedly, with a backoff, until a client connection is established. Auth is optional.
func dialRPCClientWithBackoff(ctx context.Context, log log.Logger, addr string) (*rpc.Client, error) {
bOff := retry.Fixed(defaultRetryTime)
......
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