Skip to content

Commit 4df6ee5

Browse files
committed
Improve eth_feeHistory block reward calculation
1 parent 16e67bd commit 4df6ee5

3 files changed

Lines changed: 17 additions & 19 deletions

File tree

api/api.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,21 @@ func (b *BlockChainAPI) FeeHistory(
856856
)
857857

858858
maxCount := min(uint64(blockCount), lastBlockNumber)
859+
860+
blockRewards := make([]*hexutil.Big, len(rewardPercentiles))
861+
gasPrice := b.config.GasPrice
862+
863+
feeParams, err := b.feeParameters.Get()
864+
if err != nil {
865+
b.logger.Warn().Err(err).Msg("fee parameters unavailable; falling back to base gas price")
866+
} else {
867+
gasPrice = feeParams.CalculateGasPrice(b.config.GasPrice)
868+
}
869+
870+
for i := range rewardPercentiles {
871+
blockRewards[i] = (*hexutil.Big)(gasPrice)
872+
}
873+
859874
for i := maxCount; i >= uint64(1); i-- {
860875
// If the requested block count is 5, and the last block number
861876
// is 20, then we need the blocks [16, 17, 18, 19, 20] in this
@@ -872,21 +887,6 @@ func (b *BlockChainAPI) FeeHistory(
872887

873888
baseFees = append(baseFees, (*hexutil.Big)(models.BaseFeePerGas))
874889

875-
blockRewards := make([]*hexutil.Big, len(rewardPercentiles))
876-
feeParams, err := b.feeParameters.Get()
877-
if err != nil {
878-
b.logger.Warn().
879-
Uint64("height", blockHeight).
880-
Err(err).
881-
Msg("failed to get fee parameters for block in fee history")
882-
883-
continue
884-
}
885-
gasPrice := feeParams.CalculateGasPrice(b.config.GasPrice)
886-
for i := range rewardPercentiles {
887-
blockRewards[i] = (*hexutil.Big)(gasPrice)
888-
}
889-
890890
rewards = append(rewards, blockRewards)
891891

892892
gasUsedRatio := float64(block.TotalGasUsed) / float64(BlockGasLimit)

bootstrap/bootstrap.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -819,12 +819,11 @@ func getNetworkFeeParams(
819819
}
820820

821821
// sanity check, should never occur
822-
if _, ok := val.(cadence.UFix64); !ok {
822+
surgeFactor, ok := val.(cadence.UFix64)
823+
if !ok {
823824
return nil, fmt.Errorf("failed to convert surgeFactor %v to UFix64, got type: %T", val, val)
824825
}
825826

826-
surgeFactor := val.(cadence.UFix64)
827-
828827
logger.Debug().
829828
Uint64("surge-factor", uint64(surgeFactor)).
830829
Msg("get current surge factor executed")

tests/web3js/eth_gas_price_surge_test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ it('should accept transactions with the updated gas price', async () => {
8383

8484
it('should update gas price for eth_feeFistory', async () => {
8585
let response = await web3.eth.getFeeHistory(10, 'latest', [20])
86-
console.log('Response: ', response)
8786

8887
assert.deepEqual(
8988
response,

0 commit comments

Comments
 (0)