@@ -11,7 +11,8 @@ import (
11
11
"github.com/scroll-tech/go-ethereum/rpc"
12
12
)
13
13
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
15
16
// Before Curie (EIP-1559), we need to return the total suggested gas price. After Curie we return defaultGasTipCap wei as the tip cap,
16
17
// as the base fee is set separately or added manually for legacy transactions.
17
18
suggestion := oracle .defaultGasTipCap
@@ -24,7 +25,7 @@ func (oracle *Oracle) CalculateSuggestPriorityFee(ctx context.Context, header *t
24
25
receipts , err := oracle .backend .GetReceipts (ctx , header .Hash ())
25
26
if receipts == nil || err != nil {
26
27
log .Error ("failed to get block receipts" , "block number" , header .Number , "err" , err )
27
- return suggestion
28
+ return suggestion , isCongested
28
29
}
29
30
var maxTxGasUsed uint64
30
31
@@ -44,7 +45,7 @@ func (oracle *Oracle) CalculateSuggestPriorityFee(ctx context.Context, header *t
44
45
block , err := oracle .backend .BlockByNumber (ctx , rpc .BlockNumber (header .Number .Int64 ()))
45
46
if block == nil || err != nil {
46
47
log .Error ("failed to get last block" , "err" , err )
47
- return suggestion
48
+ return suggestion , isCongested
48
49
}
49
50
txs := block .Transactions ()
50
51
@@ -59,11 +60,11 @@ func (oracle *Oracle) CalculateSuggestPriorityFee(ctx context.Context, header *t
59
60
// sanity check the max gas used and transaction size value
60
61
if maxTxGasUsed > header .GasLimit {
61
62
log .Error ("found tx consuming more gas than the block limit" , "gas" , maxTxGasUsed )
62
- return suggestion
63
+ return suggestion , isCongested
63
64
}
64
65
if ! oracle .backend .ChainConfig ().Scroll .IsValidBlockSize (maxTxSizeUsed ) {
65
66
log .Error ("found tx consuming more size than the block size limit" , "size" , maxTxSizeUsed )
66
- return suggestion
67
+ return suggestion , isCongested
67
68
}
68
69
69
70
if header .GasUsed + maxTxGasUsed > header .GasLimit ||
@@ -91,7 +92,7 @@ func (oracle *Oracle) CalculateSuggestPriorityFee(ctx context.Context, header *t
91
92
baseFee := block .BaseFee ()
92
93
if len (txs ) == 0 {
93
94
log .Error ("block was at capacity but doesn't have transactions" )
94
- return suggestion
95
+ return suggestion , isCongested
95
96
}
96
97
tips := bigIntArray (make ([]* big.Int , len (txs )))
97
98
for i := range txs {
@@ -100,6 +101,7 @@ func (oracle *Oracle) CalculateSuggestPriorityFee(ctx context.Context, header *t
100
101
sort .Sort (tips )
101
102
median := tips [len (tips )/ 2 ]
102
103
newSuggestion := new (big.Int ).Add (median , new (big.Int ).Div (median , big .NewInt (10 )))
104
+ isCongested = true
103
105
// use the new suggestion only if it's bigger than the minimum
104
106
if newSuggestion .Cmp (suggestion ) > 0 {
105
107
suggestion = newSuggestion
@@ -111,7 +113,7 @@ func (oracle *Oracle) CalculateSuggestPriorityFee(ctx context.Context, header *t
111
113
suggestion .Set (oracle .maxPrice )
112
114
}
113
115
114
- return suggestion
116
+ return suggestion , isCongested
115
117
}
116
118
117
119
// 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
139
141
// returning a suggestion that is a significant amount (10%) higher than the median effective
140
142
// priority fee from the previous block.
141
143
func (oracle * Oracle ) SuggestScrollPriorityFee (ctx context.Context , header * types.Header ) * big.Int {
142
- suggestion := oracle .CalculateSuggestPriorityFee (ctx , header )
144
+ suggestion , _ := oracle .calculateSuggestPriorityFee (ctx , header )
143
145
144
146
oracle .cacheLock .Lock ()
145
147
oracle .lastHead = header .Hash ()
0 commit comments