Commit b283ca5c authored by smartcontracts's avatar smartcontracts Committed by GitHub

Merge pull request #2363 from ethereum-optimism/sc/fix-gas-oracle

fix(go): bug causing gas oracle to crash locally
parents 44c5ce37 162ff89c
---
'@eth-optimism/gas-oracle': patch
---
Fixes a bug that would cause the service to crash on startup if the RPC URLs were not immediately available
...@@ -187,11 +187,15 @@ func NewGasPriceOracle(cfg *Config) (*GasPriceOracle, error) { ...@@ -187,11 +187,15 @@ func NewGasPriceOracle(cfg *Config) (*GasPriceOracle, error) {
} }
// Ensure that we can actually connect to both backends // Ensure that we can actually connect to both backends
log.Info("Connecting to layer two")
if err := ensureConnection(l2Client); err != nil { if err := ensureConnection(l2Client); err != nil {
log.Error("Unable to connect to layer two", "addr", cfg.layerTwoHttpUrl) log.Error("Unable to connect to layer two")
return nil, err
} }
log.Info("Connecting to layer one")
if err := ensureConnection(l1Client); err != nil { if err := ensureConnection(l1Client); err != nil {
log.Error("Unable to connect to layer one", "addr", cfg.ethereumHttpUrl) log.Error("Unable to connect to layer one")
return nil, err
} }
address := cfg.gasPriceOracleAddress address := cfg.gasPriceOracleAddress
...@@ -315,14 +319,18 @@ func NewGasPriceOracle(cfg *Config) (*GasPriceOracle, error) { ...@@ -315,14 +319,18 @@ func NewGasPriceOracle(cfg *Config) (*GasPriceOracle, error) {
// Ensure that we can actually connect // Ensure that we can actually connect
func ensureConnection(client *ethclient.Client) error { func ensureConnection(client *ethclient.Client) error {
t := time.NewTicker(5 * time.Second) t := time.NewTicker(1 * time.Second)
retries := 0
defer t.Stop() defer t.Stop()
for ; true; <-t.C { for ; true; <-t.C {
_, err := client.ChainID(context.Background()) _, err := client.ChainID(context.Background())
if err == nil { if err == nil {
break break
} else { } else {
return err retries += 1
if retries > 90 {
return err
}
} }
} }
return nil return nil
......
...@@ -224,11 +224,11 @@ services: ...@@ -224,11 +224,11 @@ services:
context: .. context: ..
dockerfile: ./ops/docker/Dockerfile.gas-oracle dockerfile: ./ops/docker/Dockerfile.gas-oracle
image: ethereumoptimism/gas-oracle:${DOCKER_TAG_GAS_ORACLE:-latest} image: ethereumoptimism/gas-oracle:${DOCKER_TAG_GAS_ORACLE:-latest}
entrypoint: ./gas-oracle.sh
environment: environment:
GAS_PRICE_ORACLE_ETHEREUM_HTTP_URL: http://l2geth:8545 GAS_PRICE_ORACLE_ETHEREUM_HTTP_URL: http://l1_chain:8545
GAS_PRICE_ORACLE_LAYER_TWO_HTTP_URL: http://l2geth:8545
# Default hardhat account 5 # Default hardhat account 5
GAS_PRICE_ORACLE_PRIVATE_KEY: '0x8b3a350cf5c34c9194ca85829a2df0ec3153be0318b5e2d3348e872092edffba' GAS_PRICE_ORACLE_PRIVATE_KEY: "0x8b3a350cf5c34c9194ca85829a2df0ec3153be0318b5e2d3348e872092edffba"
batch_submitter: batch_submitter:
depends_on: depends_on:
......
...@@ -11,5 +11,4 @@ RUN apk add --no-cache ca-certificates jq curl ...@@ -11,5 +11,4 @@ RUN apk add --no-cache ca-certificates jq curl
COPY --from=builder /gas-oracle/gas-oracle /usr/local/bin/ COPY --from=builder /gas-oracle/gas-oracle /usr/local/bin/
WORKDIR /usr/local/bin/ WORKDIR /usr/local/bin/
COPY ./ops/scripts/gas-oracle.sh .
ENTRYPOINT ["gas-oracle"] ENTRYPOINT ["gas-oracle"]
#!/bin/sh
RETRIES=${RETRIES:-40}
if [[ -z $GAS_PRICE_ORACLE_ETHEREUM_HTTP_URL ]]; then
echo "Must set env GAS_PRICE_ORACLE_ETHEREUM_HTTP_URL"
exit 1
fi
# waits for l2geth to be up
curl --fail \
--show-error \
--silent \
--retry-connrefused \
--retry $RETRIES \
--retry-delay 1 \
--output /dev/null \
$GAS_PRICE_ORACLE_ETHEREUM_HTTP_URL
exec gas-oracle "$@"
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