Skip to content

Commit e3cf2cb

Browse files
authored
refactor(gas-oracle): remove outdated logic (#1560)
Co-authored-by: colinlyguo <[email protected]>
1 parent b602542 commit e3cf2cb

File tree

12 files changed

+29
-155
lines changed

12 files changed

+29
-155
lines changed

common/version/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"runtime/debug"
66
)
77

8-
var tag = "v4.4.73"
8+
var tag = "v4.4.74"
99

1010
var commit = func() string {
1111
if info, ok := debug.ReadBuildInfo(); ok {

rollup/abi/bridge_abi.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ var L2GasPriceOracleMetaData = &bind.MetaData{
3434

3535
// L1GasPriceOracleMetaData contains all meta data concerning the L1GasPriceOracle contract.
3636
var L1GasPriceOracleMetaData = &bind.MetaData{
37-
ABI: "[{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"scalar\",\"type\":\"uint256\"}],\"name\":\"BlobScalarUpdated\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"scalar\",\"type\":\"uint256\"}],\"name\":\"CommitScalarUpdated\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"l1BaseFee\",\"type\":\"uint256\"}],\"name\":\"L1BaseFeeUpdated\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"l1BlobBaseFee\",\"type\":\"uint256\"}],\"name\":\"L1BlobBaseFeeUpdated\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"overhead\",\"type\":\"uint256\"}],\"name\":\"OverheadUpdated\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"scalar\",\"type\":\"uint256\"}],\"name\":\"ScalarUpdated\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"blobScalar\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"commitScalar\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"getL1Fee\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"getL1GasUsed\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"l1BaseFee\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"l1BlobBaseFee\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"overhead\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"scalar\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"_l1BaseFee\",\"type\":\"uint256\"}],\"name\":\"setL1BaseFee\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"_l1BaseFee\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"_l1BlobBaseFee\",\"type\":\"uint256\"}],\"name\":\"setL1BaseFeeAndBlobBaseFee\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]",
37+
ABI: "[{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"scalar\",\"type\":\"uint256\"}],\"name\":\"BlobScalarUpdated\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"scalar\",\"type\":\"uint256\"}],\"name\":\"CommitScalarUpdated\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"l1BaseFee\",\"type\":\"uint256\"}],\"name\":\"L1BaseFeeUpdated\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"l1BlobBaseFee\",\"type\":\"uint256\"}],\"name\":\"L1BlobBaseFeeUpdated\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"overhead\",\"type\":\"uint256\"}],\"name\":\"OverheadUpdated\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"scalar\",\"type\":\"uint256\"}],\"name\":\"ScalarUpdated\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"blobScalar\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"commitScalar\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"getL1Fee\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"getL1GasUsed\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"l1BaseFee\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"l1BlobBaseFee\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"overhead\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"scalar\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"_l1BaseFee\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"_l1BlobBaseFee\",\"type\":\"uint256\"}],\"name\":\"setL1BaseFeeAndBlobBaseFee\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]",
3838
}

rollup/abi/bridge_abi_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,15 @@ func TestPackImportGenesisBatch(t *testing.T) {
5252
assert.NoError(err)
5353
}
5454

55-
func TestPackSetL1BaseFee(t *testing.T) {
55+
func TestPackSetL1BaseFeeAndBlobBaseFee(t *testing.T) {
5656
assert := assert.New(t)
5757

5858
l1GasOracleABI, err := L1GasPriceOracleMetaData.GetAbi()
5959
assert.NoError(err)
6060

6161
baseFee := big.NewInt(2333)
62-
_, err = l1GasOracleABI.Pack("setL1BaseFee", baseFee)
62+
blobBaseFee := big.NewInt(1)
63+
_, err = l1GasOracleABI.Pack("setL1BaseFeeAndBlobBaseFee", baseFee, blobBaseFee)
6364
assert.NoError(err)
6465
}
6566

rollup/cmd/gas_oracle/app/app.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"scroll-tech/rollup/internal/config"
2323
"scroll-tech/rollup/internal/controller/relayer"
2424
"scroll-tech/rollup/internal/controller/watcher"
25-
butils "scroll-tech/rollup/internal/utils"
25+
rutils "scroll-tech/rollup/internal/utils"
2626
)
2727

2828
var app *cli.App
@@ -98,7 +98,7 @@ func action(ctx *cli.Context) error {
9898
go utils.LoopWithContext(subCtx, 10*time.Second, func(ctx context.Context) {
9999
// Fetch the latest block number to decrease the delay when fetching gas prices
100100
// Use latest block number - 1 to prevent frequent reorg
101-
number, loopErr := butils.GetLatestConfirmedBlockNumber(ctx, l1client, rpc.LatestBlockNumber)
101+
number, loopErr := rutils.GetLatestConfirmedBlockNumber(ctx, l1client, rpc.LatestBlockNumber)
102102
if loopErr != nil {
103103
log.Error("failed to get block number", "err", loopErr)
104104
return

rollup/cmd/rollup_relayer/app/app.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"scroll-tech/rollup/internal/config"
2121
"scroll-tech/rollup/internal/controller/relayer"
2222
"scroll-tech/rollup/internal/controller/watcher"
23-
butils "scroll-tech/rollup/internal/utils"
23+
rutils "scroll-tech/rollup/internal/utils"
2424
)
2525

2626
var app *cli.App
@@ -92,7 +92,7 @@ func action(ctx *cli.Context) error {
9292

9393
// Watcher loop to fetch missing blocks
9494
go utils.LoopWithContext(subCtx, 2*time.Second, func(ctx context.Context) {
95-
number, loopErr := butils.GetLatestConfirmedBlockNumber(ctx, l2client, cfg.L2Config.Confirmations)
95+
number, loopErr := rutils.GetLatestConfirmedBlockNumber(ctx, l2client, cfg.L2Config.Confirmations)
9696
if loopErr != nil {
9797
log.Error("failed to get block number", "err", loopErr)
9898
return

rollup/conf/config.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
"gas_oracle_config": {
1919
"min_gas_price": 0,
2020
"gas_price_diff": 50000,
21-
"l1_base_fee_weight": 0.132,
22-
"l1_blob_base_fee_weight": 0.145,
2321
"check_committed_batches_window_minutes": 5,
2422
"l1_base_fee_default": 15000000000,
2523
"l1_blob_base_fee_default": 1

rollup/internal/config/relayer.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,6 @@ type GasOracleConfig struct {
8585
// AlternativeGasTokenConfig The configuration for handling token exchange rates when updating the gas price oracle.
8686
AlternativeGasTokenConfig *AlternativeGasTokenConfig `json:"alternative_gas_token_config"`
8787

88-
// The following configs are only for updating L1 gas price, used for sender in L2.
89-
// The weight for L1 base fee.
90-
L1BaseFeeWeight float64 `json:"l1_base_fee_weight"`
91-
// The weight for L1 blob base fee.
92-
L1BlobBaseFeeWeight float64 `json:"l1_blob_base_fee_weight"`
9388
// CheckCommittedBatchesWindowMinutes the time frame to check if we committed batches to decide to update gas oracle or not in minutes
9489
CheckCommittedBatchesWindowMinutes int `json:"check_committed_batches_window_minutes"`
9590
L1BaseFeeDefault uint64 `json:"l1_base_fee_default"`

rollup/internal/controller/relayer/l1_relayer.go

Lines changed: 19 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,10 @@ type Layer1Relayer struct {
3636
gasOracleSender *sender.Sender
3737
l1GasOracleABI *abi.ABI
3838

39-
lastBaseFee uint64
40-
lastBlobBaseFee uint64
41-
minGasPrice uint64
42-
gasPriceDiff uint64
43-
l1BaseFeeWeight float64
44-
l1BlobBaseFeeWeight float64
39+
lastBaseFee uint64
40+
lastBlobBaseFee uint64
41+
minGasPrice uint64
42+
gasPriceDiff uint64
4543

4644
l1BlockOrm *orm.L1Block
4745
l2BlockOrm *orm.L2Block
@@ -91,10 +89,8 @@ func NewLayer1Relayer(ctx context.Context, db *gorm.DB, cfg *config.RelayerConfi
9189
gasOracleSender: gasOracleSender,
9290
l1GasOracleABI: bridgeAbi.L1GasPriceOracleABI,
9391

94-
minGasPrice: minGasPrice,
95-
gasPriceDiff: gasPriceDiff,
96-
l1BaseFeeWeight: cfg.GasOracleConfig.L1BaseFeeWeight,
97-
l1BlobBaseFeeWeight: cfg.GasOracleConfig.L1BlobBaseFeeWeight,
92+
minGasPrice: minGasPrice,
93+
gasPriceDiff: gasPriceDiff,
9894
}
9995

10096
l1Relayer.metrics = initL1RelayerMetrics(reg)
@@ -132,25 +128,13 @@ func (r *Layer1Relayer) ProcessGasPriceOracle() {
132128
block := blocks[0]
133129

134130
if types.GasOracleStatus(block.GasOracleStatus) == types.GasOraclePending {
135-
latestL2Height, err := r.l2BlockOrm.GetL2BlocksLatestHeight(r.ctx)
136-
if err != nil {
137-
log.Warn("Failed to fetch latest L2 block height from db", "err", err)
131+
if block.BaseFee == 0 || block.BlobBaseFee == 0 {
132+
log.Error("Invalid base fee or blob base fee", "block.Hash", block.Hash, "block.Height", block.Number, "block.BaseFee", block.BaseFee, "block.BlobBaseFee", block.BlobBaseFee)
138133
return
139134
}
140135

141-
var isBernoulli = block.BlobBaseFee > 0 && r.chainCfg.IsBernoulli(new(big.Int).SetUint64(latestL2Height))
142-
var isCurie = block.BlobBaseFee > 0 && r.chainCfg.IsCurie(new(big.Int).SetUint64(latestL2Height))
143-
144-
var baseFee uint64
145-
var blobBaseFee uint64
146-
if isCurie {
147-
baseFee = block.BaseFee
148-
blobBaseFee = block.BlobBaseFee
149-
} else if isBernoulli {
150-
baseFee = uint64(math.Ceil(r.l1BaseFeeWeight*float64(block.BaseFee) + r.l1BlobBaseFeeWeight*float64(block.BlobBaseFee)))
151-
} else {
152-
baseFee = block.BaseFee
153-
}
136+
baseFee := block.BaseFee
137+
blobBaseFee := block.BlobBaseFee
154138

155139
// include the token exchange rate in the fee data if alternative gas token enabled
156140
if r.cfg.GasOracleConfig.AlternativeGasTokenConfig != nil && r.cfg.GasOracleConfig.AlternativeGasTokenConfig.Enabled {
@@ -177,7 +161,7 @@ func (r *Layer1Relayer) ProcessGasPriceOracle() {
177161
blobBaseFee = uint64(math.Ceil(float64(blobBaseFee) / exchangeRate))
178162
}
179163

180-
if r.shouldUpdateGasOracle(baseFee, blobBaseFee, isCurie) {
164+
if r.shouldUpdateGasOracle(baseFee, blobBaseFee) {
181165
// It indicates the committing batch has been stuck for a long time, it's likely that the L1 gas fee spiked.
182166
// 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
183167
// Also, set fees to some default value, because we have already updated fees to some high values, probably
@@ -191,24 +175,15 @@ func (r *Layer1Relayer) ProcessGasPriceOracle() {
191175
} else if err != nil {
192176
return
193177
}
194-
var data []byte
195-
if isCurie {
196-
data, err = r.l1GasOracleABI.Pack("setL1BaseFeeAndBlobBaseFee", new(big.Int).SetUint64(baseFee), new(big.Int).SetUint64(blobBaseFee))
197-
if err != nil {
198-
log.Error("Failed to pack setL1BaseFeeAndBlobBaseFee", "block.Hash", block.Hash, "block.Height", block.Number, "block.BaseFee", baseFee, "block.BlobBaseFee", blobBaseFee, "isBernoulli", isBernoulli, "isCurie", isCurie, "err", err)
199-
return
200-
}
201-
} else {
202-
data, err = r.l1GasOracleABI.Pack("setL1BaseFee", new(big.Int).SetUint64(baseFee))
203-
if err != nil {
204-
log.Error("Failed to pack setL1BaseFee", "block.Hash", block.Hash, "block.Height", block.Number, "block.BaseFee", baseFee, "block.BlobBaseFee", blobBaseFee, "isBernoulli", isBernoulli, "isCurie", isCurie, "err", err)
205-
return
206-
}
178+
data, err := r.l1GasOracleABI.Pack("setL1BaseFeeAndBlobBaseFee", new(big.Int).SetUint64(baseFee), new(big.Int).SetUint64(blobBaseFee))
179+
if err != nil {
180+
log.Error("Failed to pack setL1BaseFeeAndBlobBaseFee", "block.Hash", block.Hash, "block.Height", block.Number, "block.BaseFee", baseFee, "block.BlobBaseFee", blobBaseFee, "err", err)
181+
return
207182
}
208183

209184
hash, err := r.gasOracleSender.SendTransaction(block.Hash, &r.cfg.GasPriceOracleContractAddress, data, nil, 0)
210185
if err != nil {
211-
log.Error("Failed to send gas oracle update tx to layer2", "block.Hash", block.Hash, "block.Height", block.Number, "block.BaseFee", baseFee, "block.BlobBaseFee", blobBaseFee, "isBernoulli", isBernoulli, "isCurie", isCurie, "err", err)
186+
log.Error("Failed to send gas oracle update tx to layer2", "block.Hash", block.Hash, "block.Height", block.Number, "block.BaseFee", baseFee, "block.BlobBaseFee", blobBaseFee, "err", err)
212187
return
213188
}
214189

@@ -222,7 +197,7 @@ func (r *Layer1Relayer) ProcessGasPriceOracle() {
222197
r.lastBlobBaseFee = blobBaseFee
223198
r.metrics.rollupL1RelayerLatestBaseFee.Set(float64(r.lastBaseFee))
224199
r.metrics.rollupL1RelayerLatestBlobBaseFee.Set(float64(r.lastBlobBaseFee))
225-
log.Info("Update l1 base fee", "txHash", hash.String(), "baseFee", baseFee, "blobBaseFee", blobBaseFee, "isBernoulli", isBernoulli, "isCurie", isCurie)
200+
log.Info("Update l1 base fee", "txHash", hash.String(), "baseFee", baseFee, "blobBaseFee", blobBaseFee)
226201
}
227202
}
228203
}
@@ -271,9 +246,10 @@ func (r *Layer1Relayer) StopSenders() {
271246
}
272247
}
273248

274-
func (r *Layer1Relayer) shouldUpdateGasOracle(baseFee uint64, blobBaseFee uint64, isCurie bool) bool {
249+
func (r *Layer1Relayer) shouldUpdateGasOracle(baseFee uint64, blobBaseFee uint64) bool {
275250
// Right after restarting.
276251
if r.lastBaseFee == 0 {
252+
log.Info("First time to update gas oracle after restarting", "baseFee", baseFee, "blobBaseFee", blobBaseFee)
277253
return true
278254
}
279255

@@ -282,16 +258,6 @@ func (r *Layer1Relayer) shouldUpdateGasOracle(baseFee uint64, blobBaseFee uint64
282258
return true
283259
}
284260

285-
// Omitting blob base fee checks before Curie.
286-
if !isCurie {
287-
return false
288-
}
289-
290-
// Right after enabling Curie.
291-
if r.lastBlobBaseFee == 0 {
292-
return true
293-
}
294-
295261
expectedBlobBaseFeeDelta := r.lastBlobBaseFee * r.gasPriceDiff / gasPriceDiffPrecision
296262
// Plus a minimum of 0.01 gwei, since the blob base fee is usually low, preventing short-time flunctuation.
297263
expectedBlobBaseFeeDelta += 10000000

rollup/internal/controller/relayer/l1_relayer_test.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,6 @@ func testL1RelayerProcessGasPriceOracle(t *testing.T) {
141141
return tmpInfo, nil
142142
})
143143

144-
convey.Convey("setL1BaseFee failure", t, func() {
145-
targetErr := errors.New("pack setL1BaseFee error")
146-
patchGuard.ApplyMethodFunc(l1Relayer.l1GasOracleABI, "Pack", func(name string, args ...interface{}) ([]byte, error) {
147-
return nil, targetErr
148-
})
149-
l1Relayer.ProcessGasPriceOracle()
150-
})
151-
152144
patchGuard.ApplyMethodFunc(l1Relayer.l1GasOracleABI, "Pack", func(name string, args ...interface{}) ([]byte, error) {
153145
return []byte("for test"), nil
154146
})

rollup/mock_bridge/MockBridge.sol

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,6 @@ contract MockBridge {
102102

103103
mapping(uint256 => bytes32) public withdrawRoots;
104104

105-
function setL1BaseFee(uint256 _l1BaseFee) external {
106-
l1BaseFee = _l1BaseFee;
107-
}
108-
109105
function setL1BaseFeeAndBlobBaseFee(uint256 _l1BaseFee, uint256 _l1BlobBaseFee) external {
110106
l1BaseFee = _l1BaseFee;
111107
l1BlobBaseFee = _l1BlobBaseFee;

0 commit comments

Comments
 (0)