Skip to content

Commit 95c59a3

Browse files
committed
address comments
1 parent 22505e9 commit 95c59a3

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

eth/gasprice/feehistory.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,9 @@ func (oracle *Oracle) FeeHistory(ctx context.Context, blocks int, unresolvedLast
250250
// tip cap. This is to prevent users from overpaying for gas when the network is not congested and a few high-priced
251251
// transactions are causing the suggested tip cap to be high.
252252
var nonCongestedPrice *big.Int
253-
suggestedGasPrice := oracle.CalculateSuggestPriorityFee(ctx, headHeader)
254-
// Before Curie (EIP-1559), we need to return the total suggested gas price. After Curie we return defaultGasTipCap wei as the tip cap,
255-
// as the base fee is set separately or added manually for legacy transactions.
256-
if oracle.backend.ChainConfig().IsCurie(headHeader.Number) && suggestedGasPrice.Cmp(oracle.defaultBasePrice) == 0 {
257-
nonCongestedPrice = oracle.defaultGasTipCap
258-
} else if !oracle.backend.ChainConfig().IsCurie(headHeader.Number) && suggestedGasPrice.Cmp(oracle.defaultGasTipCap) == 0 {
259-
nonCongestedPrice = oracle.defaultBasePrice
253+
suggestedGasPrice, isCongested := oracle.calculateSuggestPriorityFee(ctx, headHeader)
254+
if !isCongested {
255+
nonCongestedPrice = suggestedGasPrice
260256
}
261257

262258
var (

eth/gasprice/scroll_gasprice.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import (
1111
"github.com/scroll-tech/go-ethereum/rpc"
1212
)
1313

14-
func (oracle *Oracle) CalculateSuggestPriorityFee(ctx context.Context, header *types.Header) *big.Int {
14+
func (oracle *Oracle) calculateSuggestPriorityFee(ctx context.Context, header *types.Header) (*big.Int, bool) {
15+
var isCongested bool
1516
// Before Curie (EIP-1559), we need to return the total suggested gas price. After Curie we return defaultGasTipCap wei as the tip cap,
1617
// as the base fee is set separately or added manually for legacy transactions.
1718
suggestion := oracle.defaultGasTipCap
@@ -24,7 +25,7 @@ func (oracle *Oracle) CalculateSuggestPriorityFee(ctx context.Context, header *t
2425
receipts, err := oracle.backend.GetReceipts(ctx, header.Hash())
2526
if receipts == nil || err != nil {
2627
log.Error("failed to get block receipts", "block number", header.Number, "err", err)
27-
return suggestion
28+
return suggestion, isCongested
2829
}
2930
var maxTxGasUsed uint64
3031

@@ -44,7 +45,7 @@ func (oracle *Oracle) CalculateSuggestPriorityFee(ctx context.Context, header *t
4445
block, err := oracle.backend.BlockByNumber(ctx, rpc.BlockNumber(header.Number.Int64()))
4546
if block == nil || err != nil {
4647
log.Error("failed to get last block", "err", err)
47-
return suggestion
48+
return suggestion, isCongested
4849
}
4950
txs := block.Transactions()
5051

@@ -59,11 +60,11 @@ func (oracle *Oracle) CalculateSuggestPriorityFee(ctx context.Context, header *t
5960
// sanity check the max gas used and transaction size value
6061
if maxTxGasUsed > header.GasLimit {
6162
log.Error("found tx consuming more gas than the block limit", "gas", maxTxGasUsed)
62-
return suggestion
63+
return suggestion, isCongested
6364
}
6465
if !oracle.backend.ChainConfig().Scroll.IsValidBlockSize(maxTxSizeUsed) {
6566
log.Error("found tx consuming more size than the block size limit", "size", maxTxSizeUsed)
66-
return suggestion
67+
return suggestion, isCongested
6768
}
6869

6970
if header.GasUsed+maxTxGasUsed > header.GasLimit ||
@@ -91,7 +92,7 @@ func (oracle *Oracle) CalculateSuggestPriorityFee(ctx context.Context, header *t
9192
baseFee := block.BaseFee()
9293
if len(txs) == 0 {
9394
log.Error("block was at capacity but doesn't have transactions")
94-
return suggestion
95+
return suggestion, isCongested
9596
}
9697
tips := bigIntArray(make([]*big.Int, len(txs)))
9798
for i := range txs {
@@ -100,6 +101,7 @@ func (oracle *Oracle) CalculateSuggestPriorityFee(ctx context.Context, header *t
100101
sort.Sort(tips)
101102
median := tips[len(tips)/2]
102103
newSuggestion := new(big.Int).Add(median, new(big.Int).Div(median, big.NewInt(10)))
104+
isCongested = true
103105
// use the new suggestion only if it's bigger than the minimum
104106
if newSuggestion.Cmp(suggestion) > 0 {
105107
suggestion = newSuggestion
@@ -111,7 +113,7 @@ func (oracle *Oracle) CalculateSuggestPriorityFee(ctx context.Context, header *t
111113
suggestion.Set(oracle.maxPrice)
112114
}
113115

114-
return suggestion
116+
return suggestion, isCongested
115117
}
116118

117119
// SuggestScrollPriorityFee returns a max priority fee value that can be used such that newly
@@ -139,7 +141,7 @@ func (oracle *Oracle) CalculateSuggestPriorityFee(ctx context.Context, header *t
139141
// returning a suggestion that is a significant amount (10%) higher than the median effective
140142
// priority fee from the previous block.
141143
func (oracle *Oracle) SuggestScrollPriorityFee(ctx context.Context, header *types.Header) *big.Int {
142-
suggestion := oracle.CalculateSuggestPriorityFee(ctx, header)
144+
suggestion, _ := oracle.calculateSuggestPriorityFee(ctx, header)
143145

144146
oracle.cacheLock.Lock()
145147
oracle.lastHead = header.Hash()

0 commit comments

Comments
 (0)