Skip to content

Commit b3f4e62

Browse files
yiweichi0g-wh
authored andcommitted
eth/gasprice: fix eth_feeHistory blobGasUsedRatio divide zero (ethereum#31663)
The API `eth_feeHistory` returns `{"jsonrpc":"2.0","id":1,"error":{"code":-32603,"message":"json: unsupported value: NaN"}}`, when we query `eth_feeHistory` with a old block that without a blob, or when the field `config.blobSchedule.cancun.max` in genesis.config is 0 (that happens for some projects fork geth but they don't have blob). So here we specially handle the case when maxBlobGas == 0 to prevent this issue from happening.
1 parent 06a1823 commit b3f4e62

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

eth/gasprice/feehistory.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ func (oracle *Oracle) processBlock(bf *blockFees, percentiles []float64) {
108108
bf.results.gasUsedRatio = float64(bf.header.GasUsed) / float64(bf.header.GasLimit)
109109
if blobGasUsed := bf.header.BlobGasUsed; blobGasUsed != nil {
110110
maxBlobGas := eip4844.MaxBlobGasPerBlock(config, bf.header.Time)
111-
bf.results.blobGasUsedRatio = float64(*blobGasUsed) / float64(maxBlobGas)
111+
if maxBlobGas != 0 {
112+
bf.results.blobGasUsedRatio = float64(*blobGasUsed) / float64(maxBlobGas)
113+
}
112114
}
113115

114116
if len(percentiles) == 0 {

0 commit comments

Comments
 (0)