Commit 996230de authored by Conner Fromknecht's avatar Conner Fromknecht

feat: switch L2 provider to use l2geth/ethclient

parent 2fe9b9ee
...@@ -9,6 +9,7 @@ import ( ...@@ -9,6 +9,7 @@ import (
"strconv" "strconv"
"time" "time"
l2ethclient "github.com/ethereum-optimism/optimism/l2geth/ethclient"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient" "github.com/ethereum/go-ethereum/ethclient"
...@@ -57,7 +58,7 @@ type BatchSubmitter struct { ...@@ -57,7 +58,7 @@ type BatchSubmitter struct {
ctx context.Context ctx context.Context
cfg Config cfg Config
l1Client *ethclient.Client l1Client *ethclient.Client
l2Client *ethclient.Client l2Client *l2ethclient.Client
sequencerPrivKey *ecdsa.PrivateKey sequencerPrivKey *ecdsa.PrivateKey
proposerPrivKey *ecdsa.PrivateKey proposerPrivKey *ecdsa.PrivateKey
ctcAddress common.Address ctcAddress common.Address
...@@ -118,14 +119,14 @@ func NewBatchSubmitter(cfg Config, gitVersion string) (*BatchSubmitter, error) { ...@@ -118,14 +119,14 @@ func NewBatchSubmitter(cfg Config, gitVersion string) (*BatchSubmitter, error) {
return nil, err return nil, err
} }
// Connect to L1 and L2 providers. Perform these lastsince they are the // Connect to L1 and L2 providers. Perform these last since they are the
// most expensive. // most expensive.
l1Client, err := dialEthClientWithTimeout(ctx, cfg.L1EthRpc) l1Client, err := dialL1EthClientWithTimeout(ctx, cfg.L1EthRpc)
if err != nil { if err != nil {
return nil, err return nil, err
} }
l2Client, err := dialEthClientWithTimeout(ctx, cfg.L2EthRpc) l2Client, err := dialL2EthClientWithTimeout(ctx, cfg.L2EthRpc)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -191,10 +192,10 @@ func runMetricsServer(hostname string, port uint64) { ...@@ -191,10 +192,10 @@ func runMetricsServer(hostname string, port uint64) {
_ = http.ListenAndServe(metricsAddr, nil) _ = http.ListenAndServe(metricsAddr, nil)
} }
// dialEthClientWithTimeout attempts to dial the L1 or L2 provider using the // dialL1EthClientWithTimeout attempts to dial the L1 provider using the
// provided URL. If the dial doesn't complete within defaultDialTimeout seconds, // provided URL. If the dial doesn't complete within defaultDialTimeout seconds,
// this method will return an error. // this method will return an error.
func dialEthClientWithTimeout(ctx context.Context, url string) ( func dialL1EthClientWithTimeout(ctx context.Context, url string) (
*ethclient.Client, error) { *ethclient.Client, error) {
ctxt, cancel := context.WithTimeout(ctx, defaultDialTimeout) ctxt, cancel := context.WithTimeout(ctx, defaultDialTimeout)
...@@ -203,6 +204,18 @@ func dialEthClientWithTimeout(ctx context.Context, url string) ( ...@@ -203,6 +204,18 @@ func dialEthClientWithTimeout(ctx context.Context, url string) (
return ethclient.DialContext(ctxt, url) return ethclient.DialContext(ctxt, url)
} }
// dialL2EthClientWithTimeout attempts to dial the L2 provider using the
// provided URL. If the dial doesn't complete within defaultDialTimeout seconds,
// this method will return an error.
func dialL2EthClientWithTimeout(ctx context.Context, url string) (
*l2ethclient.Client, error) {
ctxt, cancel := context.WithTimeout(ctx, defaultDialTimeout)
defer cancel()
return l2ethclient.DialContext(ctxt, url)
}
// traceRateToFloat64 converts a time.Duration into a valid float64 for the // traceRateToFloat64 converts a time.Duration into a valid float64 for the
// Sentry client. The client only accepts values between 0.0 and 1.0, so this // Sentry client. The client only accepts values between 0.0 and 1.0, so this
// method clamps anything greater than 1 second to 1.0. // method clamps anything greater than 1 second to 1.0.
......
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