Skip to content

Commit 2de4a31

Browse files
committed
Improve eth_feeHistory block reward calculation
1 parent 405470c commit 2de4a31

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
@@ -820,6 +820,21 @@ func (b *BlockChainAPI) FeeHistory(
820820
)
821821

822822
maxCount := min(uint64(blockCount), lastBlockNumber)
823+
824+
blockRewards := make([]*hexutil.Big, len(rewardPercentiles))
825+
gasPrice := b.config.GasPrice
826+
827+
feeParams, err := b.feeParameters.Get()
828+
if err != nil {
829+
b.logger.Warn().Err(err).Msg("fee parameters unavailable; falling back to base gas price")
830+
} else {
831+
gasPrice = feeParams.CalculateGasPrice(b.config.GasPrice)
832+
}
833+
834+
for i := range rewardPercentiles {
835+
blockRewards[i] = (*hexutil.Big)(gasPrice)
836+
}
837+
823838
for i := maxCount; i >= uint64(1); i-- {
824839
// If the requested block count is 5, and the last block number
825840
// is 20, then we need the blocks [16, 17, 18, 19, 20] in this
@@ -836,21 +851,6 @@ func (b *BlockChainAPI) FeeHistory(
836851

837852
baseFees = append(baseFees, (*hexutil.Big)(models.BaseFeePerGas))
838853

839-
blockRewards := make([]*hexutil.Big, len(rewardPercentiles))
840-
feeParams, err := b.feeParameters.Get()
841-
if err != nil {
842-
b.logger.Warn().
843-
Uint64("height", blockHeight).
844-
Err(err).
845-
Msg("failed to get fee parameters for block in fee history")
846-
847-
continue
848-
}
849-
gasPrice := feeParams.CalculateGasPrice(b.config.GasPrice)
850-
for i := range rewardPercentiles {
851-
blockRewards[i] = (*hexutil.Big)(gasPrice)
852-
}
853-
854854
rewards = append(rewards, blockRewards)
855855

856856
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)