Skip to content

Commit

Permalink
feat(gas-oracle): tweak gas price update logic (#1305)
Browse files Browse the repository at this point in the history
  • Loading branch information
colinlyguo authored Apr 28, 2024
1 parent ca6f856 commit 4cafc93
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion common/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"runtime/debug"
)

var tag = "v4.4.1"
var tag = "v4.4.2"

var commit = func() string {
if info, ok := debug.ReadBuildInfo(); ok {
Expand Down
4 changes: 3 additions & 1 deletion rollup/conf/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
},
"gas_oracle_config": {
"min_gas_price": 0,
"gas_price_diff": 50000
"gas_price_diff": 50000,
"l1_base_fee_weight": 0.132,
"l1_blob_base_fee_weight": 0.145
},
"gas_oracle_sender_private_key": "1313131313131313131313131313131313131313131313131313131313131313"
}
Expand Down
8 changes: 7 additions & 1 deletion rollup/internal/config/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,14 @@ type RelayerConfig struct {
type GasOracleConfig struct {
// MinGasPrice store the minimum gas price to set.
MinGasPrice uint64 `json:"min_gas_price"`
// GasPriceDiff store the percentage of gas price difference.
// GasPriceDiff is the minimum percentage of gas price difference to update gas oracle.
GasPriceDiff uint64 `json:"gas_price_diff"`

// The following configs are only for updating L1 gas price, used for sender in L2.
// The weight for L1 base fee.
L1BaseFeeWeight float64 `json:"l1_base_fee_weight"`
// The weight for L1 blob base fee.
L1BlobBaseFeeWeight float64 `json:"l1_blob_base_fee_weight"`
}

// relayerConfigAlias RelayerConfig alias name
Expand Down
17 changes: 11 additions & 6 deletions rollup/internal/controller/relayer/l1_relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package relayer
import (
"context"
"fmt"
"math"
"math/big"

"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -35,9 +36,11 @@ type Layer1Relayer struct {
gasOracleSender *sender.Sender
l1GasOracleABI *abi.ABI

lastGasPrice uint64
minGasPrice uint64
gasPriceDiff uint64
lastGasPrice uint64
minGasPrice uint64
gasPriceDiff uint64
l1BaseFeeWeight float64
l1BlobBaseFeeWeight float64

l1BlockOrm *orm.L1Block
l2BlockOrm *orm.L2Block
Expand Down Expand Up @@ -86,8 +89,10 @@ func NewLayer1Relayer(ctx context.Context, db *gorm.DB, cfg *config.RelayerConfi
gasOracleSender: gasOracleSender,
l1GasOracleABI: bridgeAbi.L1GasPriceOracleABI,

minGasPrice: minGasPrice,
gasPriceDiff: gasPriceDiff,
minGasPrice: minGasPrice,
gasPriceDiff: gasPriceDiff,
l1BaseFeeWeight: cfg.GasOracleConfig.L1BaseFeeWeight,
l1BlobBaseFeeWeight: cfg.GasOracleConfig.L1BlobBaseFeeWeight,
}

l1Relayer.metrics = initL1RelayerMetrics(reg)
Expand Down Expand Up @@ -140,7 +145,7 @@ func (r *Layer1Relayer) ProcessGasPriceOracle() {

var baseFee uint64
if isBernoulli && block.BlobBaseFee != 0 {
baseFee = block.BlobBaseFee
baseFee = uint64(math.Ceil(r.l1BaseFeeWeight*float64(block.BaseFee) + r.l1BlobBaseFeeWeight*float64(block.BlobBaseFee)))
} else {
baseFee = block.BaseFee
}
Expand Down

0 comments on commit 4cafc93

Please sign in to comment.