mirror of
https://github.com/scroll-tech/scroll.git
synced 2026-01-15 00:48:01 -05:00
Compare commits
7 Commits
v4.4.7-deb
...
test/code
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dbfca54907 | ||
|
|
849765242e | ||
|
|
41ce22be05 | ||
|
|
3353e36d16 | ||
|
|
f2a656d67b | ||
|
|
d6b9176ef2 | ||
|
|
09f087ab16 |
15
.coderabbit.yaml
Normal file
15
.coderabbit.yaml
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
|
||||||
|
language: "en-US"
|
||||||
|
early_access: false
|
||||||
|
reviews:
|
||||||
|
profile: "chill"
|
||||||
|
request_changes_workflow: false
|
||||||
|
high_level_summary: true
|
||||||
|
poem: true
|
||||||
|
review_status: true
|
||||||
|
collapse_walkthrough: false
|
||||||
|
auto_review:
|
||||||
|
enabled: true
|
||||||
|
drafts: false
|
||||||
|
chat:
|
||||||
|
auto_reply: true
|
||||||
32
.github/workflows/docker.yml
vendored
32
.github/workflows/docker.yml
vendored
@@ -49,8 +49,8 @@ jobs:
|
|||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64,linux/arm64
|
||||||
push: true
|
push: true
|
||||||
tags: |
|
tags: |
|
||||||
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.REPOSITORY }}:${{ env.IMAGE_TAG }}
|
scrolltech/${{ env.REPOSITORY }}:${{ env.IMAGE_TAG }}
|
||||||
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.REPOSITORY }}:latest
|
scrolltech/${{ env.REPOSITORY }}:latest
|
||||||
${{ env.ECR_REGISTRY }}/${{ env.REPOSITORY }}:${{ env.IMAGE_TAG }}
|
${{ env.ECR_REGISTRY }}/${{ env.REPOSITORY }}:${{ env.IMAGE_TAG }}
|
||||||
${{ env.ECR_REGISTRY }}/${{ env.REPOSITORY }}:latest
|
${{ env.ECR_REGISTRY }}/${{ env.REPOSITORY }}:latest
|
||||||
|
|
||||||
@@ -94,8 +94,8 @@ jobs:
|
|||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64,linux/arm64
|
||||||
push: true
|
push: true
|
||||||
tags: |
|
tags: |
|
||||||
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.REPOSITORY }}:${{ env.IMAGE_TAG }}
|
scrolltech/${{ env.REPOSITORY }}:${{ env.IMAGE_TAG }}
|
||||||
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.REPOSITORY }}:latest
|
scrolltech/${{ env.REPOSITORY }}:latest
|
||||||
${{ env.ECR_REGISTRY }}/${{ env.REPOSITORY }}:${{ env.IMAGE_TAG }}
|
${{ env.ECR_REGISTRY }}/${{ env.REPOSITORY }}:${{ env.IMAGE_TAG }}
|
||||||
${{ env.ECR_REGISTRY }}/${{ env.REPOSITORY }}:latest
|
${{ env.ECR_REGISTRY }}/${{ env.REPOSITORY }}:latest
|
||||||
|
|
||||||
@@ -139,8 +139,8 @@ jobs:
|
|||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64,linux/arm64
|
||||||
push: true
|
push: true
|
||||||
tags: |
|
tags: |
|
||||||
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.REPOSITORY }}:${{ env.IMAGE_TAG }}
|
scrolltech/${{ env.REPOSITORY }}:${{ env.IMAGE_TAG }}
|
||||||
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.REPOSITORY }}:latest
|
scrolltech/${{ env.REPOSITORY }}:latest
|
||||||
${{ env.ECR_REGISTRY }}/${{ env.REPOSITORY }}:${{ env.IMAGE_TAG }}
|
${{ env.ECR_REGISTRY }}/${{ env.REPOSITORY }}:${{ env.IMAGE_TAG }}
|
||||||
${{ env.ECR_REGISTRY }}/${{ env.REPOSITORY }}:latest
|
${{ env.ECR_REGISTRY }}/${{ env.REPOSITORY }}:latest
|
||||||
|
|
||||||
@@ -184,8 +184,8 @@ jobs:
|
|||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64,linux/arm64
|
||||||
push: true
|
push: true
|
||||||
tags: |
|
tags: |
|
||||||
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.REPOSITORY }}:${{ env.IMAGE_TAG }}
|
scrolltech/${{ env.REPOSITORY }}:${{ env.IMAGE_TAG }}
|
||||||
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.REPOSITORY }}:latest
|
scrolltech/${{ env.REPOSITORY }}:latest
|
||||||
${{ env.ECR_REGISTRY }}/${{ env.REPOSITORY }}:${{ env.IMAGE_TAG }}
|
${{ env.ECR_REGISTRY }}/${{ env.REPOSITORY }}:${{ env.IMAGE_TAG }}
|
||||||
${{ env.ECR_REGISTRY }}/${{ env.REPOSITORY }}:latest
|
${{ env.ECR_REGISTRY }}/${{ env.REPOSITORY }}:latest
|
||||||
|
|
||||||
@@ -229,8 +229,8 @@ jobs:
|
|||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64,linux/arm64
|
||||||
push: true
|
push: true
|
||||||
tags: |
|
tags: |
|
||||||
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.REPOSITORY }}:${{ env.IMAGE_TAG }}
|
scrolltech/${{ env.REPOSITORY }}:${{ env.IMAGE_TAG }}
|
||||||
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.REPOSITORY }}:latest
|
scrolltech/${{ env.REPOSITORY }}:latest
|
||||||
${{ env.ECR_REGISTRY }}/${{ env.REPOSITORY }}:${{ env.IMAGE_TAG }}
|
${{ env.ECR_REGISTRY }}/${{ env.REPOSITORY }}:${{ env.IMAGE_TAG }}
|
||||||
${{ env.ECR_REGISTRY }}/${{ env.REPOSITORY }}:latest
|
${{ env.ECR_REGISTRY }}/${{ env.REPOSITORY }}:latest
|
||||||
|
|
||||||
@@ -274,8 +274,8 @@ jobs:
|
|||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64,linux/arm64
|
||||||
push: true
|
push: true
|
||||||
tags: |
|
tags: |
|
||||||
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.REPOSITORY }}:${{ env.IMAGE_TAG }}
|
scrolltech/${{ env.REPOSITORY }}:${{ env.IMAGE_TAG }}
|
||||||
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.REPOSITORY }}:latest
|
scrolltech/${{ env.REPOSITORY }}:latest
|
||||||
${{ env.ECR_REGISTRY }}/${{ env.REPOSITORY }}:${{ env.IMAGE_TAG }}
|
${{ env.ECR_REGISTRY }}/${{ env.REPOSITORY }}:${{ env.IMAGE_TAG }}
|
||||||
${{ env.ECR_REGISTRY }}/${{ env.REPOSITORY }}:latest
|
${{ env.ECR_REGISTRY }}/${{ env.REPOSITORY }}:latest
|
||||||
|
|
||||||
@@ -318,8 +318,8 @@ jobs:
|
|||||||
file: ./build/dockerfiles/coordinator-api.Dockerfile
|
file: ./build/dockerfiles/coordinator-api.Dockerfile
|
||||||
push: true
|
push: true
|
||||||
tags: |
|
tags: |
|
||||||
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.REPOSITORY }}:${{ env.IMAGE_TAG }}
|
scrolltech/${{ env.REPOSITORY }}:${{ env.IMAGE_TAG }}
|
||||||
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.REPOSITORY }}:latest
|
scrolltech/${{ env.REPOSITORY }}:latest
|
||||||
${{ env.ECR_REGISTRY }}/${{ env.REPOSITORY }}:${{ env.IMAGE_TAG }}
|
${{ env.ECR_REGISTRY }}/${{ env.REPOSITORY }}:${{ env.IMAGE_TAG }}
|
||||||
${{ env.ECR_REGISTRY }}/${{ env.REPOSITORY }}:latest
|
${{ env.ECR_REGISTRY }}/${{ env.REPOSITORY }}:latest
|
||||||
|
|
||||||
@@ -363,7 +363,7 @@ jobs:
|
|||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64,linux/arm64
|
||||||
push: true
|
push: true
|
||||||
tags: |
|
tags: |
|
||||||
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.REPOSITORY }}:${{ env.IMAGE_TAG }}
|
scrolltech/${{ env.REPOSITORY }}:${{ env.IMAGE_TAG }}
|
||||||
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.REPOSITORY }}:latest
|
scrolltech/${{ env.REPOSITORY }}:latest
|
||||||
${{ env.ECR_REGISTRY }}/${{ env.REPOSITORY }}:${{ env.IMAGE_TAG }}
|
${{ env.ECR_REGISTRY }}/${{ env.REPOSITORY }}:${{ env.IMAGE_TAG }}
|
||||||
${{ env.ECR_REGISTRY }}/${{ env.REPOSITORY }}:latest
|
${{ env.ECR_REGISTRY }}/${{ env.REPOSITORY }}:latest
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ RUN --mount=target=. \
|
|||||||
FROM ubuntu:20.04
|
FROM ubuntu:20.04
|
||||||
|
|
||||||
ENV CGO_LDFLAGS="-Wl,--no-as-needed -ldl"
|
ENV CGO_LDFLAGS="-Wl,--no-as-needed -ldl"
|
||||||
|
RUN apt update && apt install vim netcat-openbsd net-tools curl -y
|
||||||
COPY --from=builder /bin/bridgehistoryapi-api /bin/
|
COPY --from=builder /bin/bridgehistoryapi-api /bin/
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
ENTRYPOINT ["bridgehistoryapi-api"]
|
ENTRYPOINT ["bridgehistoryapi-api"]
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ RUN --mount=target=. \
|
|||||||
FROM ubuntu:20.04
|
FROM ubuntu:20.04
|
||||||
|
|
||||||
ENV CGO_LDFLAGS="-Wl,--no-as-needed -ldl"
|
ENV CGO_LDFLAGS="-Wl,--no-as-needed -ldl"
|
||||||
RUN apt update && apt install ca-certificates -y
|
RUN apt update && apt install ca-certificates vim netcat-openbsd net-tools curl -y
|
||||||
RUN update-ca-certificates
|
RUN update-ca-certificates
|
||||||
COPY --from=builder /bin/bridgehistoryapi-fetcher /bin/
|
COPY --from=builder /bin/bridgehistoryapi-fetcher /bin/
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ FROM ubuntu:20.04
|
|||||||
ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/src/coordinator/internal/logic/verifier/lib
|
ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/src/coordinator/internal/logic/verifier/lib
|
||||||
ENV CGO_LDFLAGS="-Wl,--no-as-needed -ldl"
|
ENV CGO_LDFLAGS="-Wl,--no-as-needed -ldl"
|
||||||
# ENV CHAIN_ID=534353
|
# ENV CHAIN_ID=534353
|
||||||
|
RUN apt update && apt install vim netcat-openbsd net-tools curl jq -y
|
||||||
RUN mkdir -p /src/coordinator/internal/logic/verifier/lib
|
RUN mkdir -p /src/coordinator/internal/logic/verifier/lib
|
||||||
COPY --from=builder /bin/lib /src/coordinator/internal/logic/verifier/lib
|
COPY --from=builder /bin/lib /src/coordinator/internal/logic/verifier/lib
|
||||||
COPY --from=builder /bin/coordinator_api /bin/
|
COPY --from=builder /bin/coordinator_api /bin/
|
||||||
|
|||||||
@@ -19,9 +19,8 @@ RUN --mount=target=. \
|
|||||||
|
|
||||||
# Pull coordinator into a second stage deploy ubuntu container
|
# Pull coordinator into a second stage deploy ubuntu container
|
||||||
FROM ubuntu:20.04
|
FROM ubuntu:20.04
|
||||||
|
|
||||||
ENV CGO_LDFLAGS="-Wl,--no-as-needed -ldl"
|
ENV CGO_LDFLAGS="-Wl,--no-as-needed -ldl"
|
||||||
|
RUN apt update && apt install vim netcat-openbsd net-tools curl -y
|
||||||
COPY --from=builder /bin/coordinator_cron /bin/
|
COPY --from=builder /bin/coordinator_cron /bin/
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
ENTRYPOINT ["coordinator_cron"]
|
ENTRYPOINT ["coordinator_cron"]
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ RUN --mount=target=. \
|
|||||||
# Pull gas_oracle into a second stage deploy ubuntu container
|
# Pull gas_oracle into a second stage deploy ubuntu container
|
||||||
FROM ubuntu:20.04
|
FROM ubuntu:20.04
|
||||||
|
|
||||||
RUN apt update && apt install ca-certificates -y
|
RUN apt update && apt install vim netcat-openbsd net-tools curl ca-certificates -y
|
||||||
|
|
||||||
ENV CGO_LDFLAGS="-ldl"
|
ENV CGO_LDFLAGS="-ldl"
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ RUN --mount=target=. \
|
|||||||
# Pull rollup_relayer into a second stage deploy ubuntu container
|
# Pull rollup_relayer into a second stage deploy ubuntu container
|
||||||
FROM ubuntu:20.04
|
FROM ubuntu:20.04
|
||||||
|
|
||||||
RUN apt update && apt install ca-certificates -y
|
RUN apt update && apt install vim netcat-openbsd net-tools curl ca-certificates -y
|
||||||
|
|
||||||
ENV CGO_LDFLAGS="-ldl"
|
ENV CGO_LDFLAGS="-ldl"
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
)
|
)
|
||||||
|
|
||||||
var tag = "v4.4.64"
|
var tag = "v4.4.66"
|
||||||
|
|
||||||
var commit = func() string {
|
var commit = func() string {
|
||||||
if info, ok := debug.ReadBuildInfo(); ok {
|
if info, ok := debug.ReadBuildInfo(); ok {
|
||||||
|
|||||||
@@ -68,12 +68,22 @@ type RelayerConfig struct {
|
|||||||
FinalizeBundleWithoutProofTimeoutSec uint64 `json:"finalize_bundle_without_proof_timeout_sec"`
|
FinalizeBundleWithoutProofTimeoutSec uint64 `json:"finalize_bundle_without_proof_timeout_sec"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AlternativeGasTokenConfig The configuration for handling token exchange rates when updating the gas price oracle.
|
||||||
|
type AlternativeGasTokenConfig struct {
|
||||||
|
Enabled bool `json:"enabled"`
|
||||||
|
Mode string `json:"mode"`
|
||||||
|
FixedExchangeRate float64 `json:"fixed_exchange_rate"` // fixed exchange rate of L2 gas token / L1 gas token
|
||||||
|
TokenSymbolPair string `json:"token_symbol_pair"` // The pair should be L2 gas token symbol + L1 gas token symbol
|
||||||
|
}
|
||||||
|
|
||||||
// GasOracleConfig The config for updating gas price oracle.
|
// GasOracleConfig The config for updating gas price oracle.
|
||||||
type GasOracleConfig struct {
|
type GasOracleConfig struct {
|
||||||
// MinGasPrice store the minimum gas price to set.
|
// MinGasPrice store the minimum gas price to set.
|
||||||
MinGasPrice uint64 `json:"min_gas_price"`
|
MinGasPrice uint64 `json:"min_gas_price"`
|
||||||
// GasPriceDiff is the minimum percentage of gas price difference to update gas oracle.
|
// GasPriceDiff is the minimum percentage of gas price difference to update gas oracle.
|
||||||
GasPriceDiff uint64 `json:"gas_price_diff"`
|
GasPriceDiff uint64 `json:"gas_price_diff"`
|
||||||
|
// AlternativeGasTokenConfig The configuration for handling token exchange rates when updating the gas price oracle.
|
||||||
|
AlternativeGasTokenConfig *AlternativeGasTokenConfig `json:"alternative_gas_token_config"`
|
||||||
|
|
||||||
// The following configs are only for updating L1 gas price, used for sender in L2.
|
// The following configs are only for updating L1 gas price, used for sender in L2.
|
||||||
// The weight for L1 base fee.
|
// The weight for L1 base fee.
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import (
|
|||||||
"scroll-tech/rollup/internal/config"
|
"scroll-tech/rollup/internal/config"
|
||||||
"scroll-tech/rollup/internal/controller/sender"
|
"scroll-tech/rollup/internal/controller/sender"
|
||||||
"scroll-tech/rollup/internal/orm"
|
"scroll-tech/rollup/internal/orm"
|
||||||
|
rutils "scroll-tech/rollup/internal/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Layer1Relayer is responsible for updating L1 gas price oracle contract on L2.
|
// Layer1Relayer is responsible for updating L1 gas price oracle contract on L2.
|
||||||
@@ -151,6 +152,31 @@ func (r *Layer1Relayer) ProcessGasPriceOracle() {
|
|||||||
baseFee = block.BaseFee
|
baseFee = block.BaseFee
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// include the token exchange rate in the fee data if alternative gas token enabled
|
||||||
|
if r.cfg.GasOracleConfig.AlternativeGasTokenConfig != nil && r.cfg.GasOracleConfig.AlternativeGasTokenConfig.Enabled {
|
||||||
|
// The exchange rate represent the number of native token on L1 required to exchange for 1 native token on L2.
|
||||||
|
var exchangeRate float64
|
||||||
|
switch r.cfg.GasOracleConfig.AlternativeGasTokenConfig.Mode {
|
||||||
|
case "Fixed":
|
||||||
|
exchangeRate = r.cfg.GasOracleConfig.AlternativeGasTokenConfig.FixedExchangeRate
|
||||||
|
case "BinanceApi":
|
||||||
|
exchangeRate, err = rutils.GetExchangeRateFromBinanceApi(r.cfg.GasOracleConfig.AlternativeGasTokenConfig.TokenSymbolPair, 5)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("Failed to get gas token exchange rate from Binance api", "tokenSymbolPair", r.cfg.GasOracleConfig.AlternativeGasTokenConfig.TokenSymbolPair, "err", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
log.Error("Invalid alternative gas token mode", "mode", r.cfg.GasOracleConfig.AlternativeGasTokenConfig.Mode)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if exchangeRate == 0 {
|
||||||
|
log.Error("Invalid exchange rate", "exchangeRate", exchangeRate)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
baseFee = uint64(math.Ceil(float64(baseFee) / exchangeRate))
|
||||||
|
blobBaseFee = uint64(math.Ceil(float64(blobBaseFee) / exchangeRate))
|
||||||
|
}
|
||||||
|
|
||||||
if r.shouldUpdateGasOracle(baseFee, blobBaseFee, isCurie) {
|
if r.shouldUpdateGasOracle(baseFee, blobBaseFee, isCurie) {
|
||||||
// It indicates the committing batch has been stuck for a long time, it's likely that the L1 gas fee spiked.
|
// It indicates the committing batch has been stuck for a long time, it's likely that the L1 gas fee spiked.
|
||||||
// If we are not committing batches due to high fees then we shouldn't update fees to prevent users from paying high l1_data_fee
|
// If we are not committing batches due to high fees then we shouldn't update fees to prevent users from paying high l1_data_fee
|
||||||
@@ -165,6 +191,11 @@ func (r *Layer1Relayer) ProcessGasPriceOracle() {
|
|||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(111)
|
||||||
|
}
|
||||||
|
|
||||||
var data []byte
|
var data []byte
|
||||||
if isCurie {
|
if isCurie {
|
||||||
data, err = r.l1GasOracleABI.Pack("setL1BaseFeeAndBlobBaseFee", new(big.Int).SetUint64(baseFee), new(big.Int).SetUint64(blobBaseFee))
|
data, err = r.l1GasOracleABI.Pack("setL1BaseFeeAndBlobBaseFee", new(big.Int).SetUint64(baseFee), new(big.Int).SetUint64(blobBaseFee))
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math"
|
||||||
"math/big"
|
"math/big"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -324,6 +325,32 @@ func (r *Layer2Relayer) ProcessGasPriceOracle() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
suggestGasPriceUint64 := uint64(suggestGasPrice.Int64())
|
suggestGasPriceUint64 := uint64(suggestGasPrice.Int64())
|
||||||
|
|
||||||
|
// include the token exchange rate in the fee data if alternative gas token enabled
|
||||||
|
if r.cfg.GasOracleConfig.AlternativeGasTokenConfig != nil && r.cfg.GasOracleConfig.AlternativeGasTokenConfig.Enabled {
|
||||||
|
// The exchange rate represent the number of native token on L1 required to exchange for 1 native token on L2.
|
||||||
|
var exchangeRate float64
|
||||||
|
switch r.cfg.GasOracleConfig.AlternativeGasTokenConfig.Mode {
|
||||||
|
case "Fixed":
|
||||||
|
exchangeRate = r.cfg.GasOracleConfig.AlternativeGasTokenConfig.FixedExchangeRate
|
||||||
|
case "BinanceApi":
|
||||||
|
exchangeRate, err = rutils.GetExchangeRateFromBinanceApi(r.cfg.GasOracleConfig.AlternativeGasTokenConfig.TokenSymbolPair, 5)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("Failed to get gas token exchange rate from Binance api", "tokenSymbolPair", r.cfg.GasOracleConfig.AlternativeGasTokenConfig.TokenSymbolPair, "err", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
log.Error("Invalid alternative gas token mode", "mode", r.cfg.GasOracleConfig.AlternativeGasTokenConfig.Mode)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if exchangeRate == 0 {
|
||||||
|
log.Error("Invalid exchange rate", "exchangeRate", exchangeRate)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
suggestGasPriceUint64 = uint64(math.Ceil(float64(suggestGasPriceUint64) * exchangeRate))
|
||||||
|
suggestGasPrice = new(big.Int).SetUint64(suggestGasPriceUint64)
|
||||||
|
}
|
||||||
|
|
||||||
expectedDelta := r.lastGasPrice * r.gasPriceDiff / gasPriceDiffPrecision
|
expectedDelta := r.lastGasPrice * r.gasPriceDiff / gasPriceDiffPrecision
|
||||||
if r.lastGasPrice > 0 && expectedDelta == 0 {
|
if r.lastGasPrice > 0 && expectedDelta == 0 {
|
||||||
expectedDelta = 1
|
expectedDelta = 1
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package watcher
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
@@ -146,6 +147,12 @@ func (p *BundleProposer) proposeBundle() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if firstChunk == nil {
|
||||||
|
log.Error("first chunk not found", "start chunk index", batches[0].StartChunkIndex, "start batch index", batches[0].Index, "firstUnbundledBatchIndex", firstUnbundledBatchIndex)
|
||||||
|
return errors.New("first chunk not found in proposeBundle")
|
||||||
|
}
|
||||||
|
|
||||||
hardforkName := forks.GetHardforkName(p.chainCfg, firstChunk.StartBlockNumber, firstChunk.StartBlockTime)
|
hardforkName := forks.GetHardforkName(p.chainCfg, firstChunk.StartBlockNumber, firstChunk.StartBlockTime)
|
||||||
codecVersion := encoding.CodecVersion(batches[0].CodecVersion)
|
codecVersion := encoding.CodecVersion(batches[0].CodecVersion)
|
||||||
for i := 1; i < len(batches); i++ {
|
for i := 1; i < len(batches); i++ {
|
||||||
|
|||||||
73
rollup/internal/utils/exchange_rate.go
Normal file
73
rollup/internal/utils/exchange_rate.go
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/scroll-tech/go-ethereum/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
var BinanceApiEndpoint string = "https://api.binance.com/api/v3/ticker/price?symbol=%s"
|
||||||
|
|
||||||
|
type BinanceResponse struct {
|
||||||
|
Price string `json:"price"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetExchangeRateFromBinanceApi(tokenSymbolPair string, maxRetries int) (float64, error) {
|
||||||
|
for i := 0; i < maxRetries; i++ {
|
||||||
|
if i > 0 {
|
||||||
|
time.Sleep(5 * time.Second)
|
||||||
|
}
|
||||||
|
|
||||||
|
// make HTTP GET request
|
||||||
|
resp, err := http.Get(fmt.Sprintf(BinanceApiEndpoint, tokenSymbolPair))
|
||||||
|
if err != nil {
|
||||||
|
log.Error("error making HTTP request", "err", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
err = resp.Body.Close()
|
||||||
|
if err != nil {
|
||||||
|
log.Error("error closing response body", "err", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
// check for successful response
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
log.Error("unexpected status code", "code", resp.StatusCode)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// read response body
|
||||||
|
body, err := io.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("error reading response body", "err", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// unmarshal JSON response
|
||||||
|
var data BinanceResponse
|
||||||
|
err = json.Unmarshal(body, &data)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("error unmarshaling JSON", "err", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// convert price string to float64
|
||||||
|
price, err := strconv.ParseFloat(data.Price, 64)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("error parsing price string", "err", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// successful response, return price
|
||||||
|
return price, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// all retries failed, return error
|
||||||
|
return 0, fmt.Errorf("failed to get exchange rate after %d retries", maxRetries)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user