@@ -85,6 +85,7 @@ type BlockChainAPI struct {
8585 blocks storage.BlockIndexer
8686 transactions storage.TransactionIndexer
8787 receipts storage.ReceiptIndexer
88+ feeParameters storage.FeeParametersIndexer
8889 indexingResumedHeight uint64
8990 rateLimiter RateLimiter
9091 collector metrics.Collector
@@ -97,6 +98,7 @@ func NewBlockChainAPI(
9798 blocks storage.BlockIndexer ,
9899 transactions storage.TransactionIndexer ,
99100 receipts storage.ReceiptIndexer ,
101+ feeParameters storage.FeeParametersIndexer ,
100102 rateLimiter RateLimiter ,
101103 collector metrics.Collector ,
102104 indexingResumedHeight uint64 ,
@@ -108,6 +110,7 @@ func NewBlockChainAPI(
108110 blocks : blocks ,
109111 transactions : transactions ,
110112 receipts : receipts ,
113+ feeParameters : feeParameters ,
111114 indexingResumedHeight : indexingResumedHeight ,
112115 rateLimiter : rateLimiter ,
113116 collector : collector ,
@@ -179,7 +182,12 @@ func (b *BlockChainAPI) SendRawTransaction(
179182 return common.Hash {}, err
180183 }
181184
182- id , err := b .evm .SendRawTransaction (ctx , input )
185+ feeParams , err := b .feeParameters .Get ()
186+ if err != nil {
187+ return common.Hash {}, err
188+ }
189+
190+ id , err := b .evm .SendRawTransaction (ctx , input , feeParams )
183191 if err != nil {
184192 return handleError [common.Hash ](err , l , b .collector )
185193 }
@@ -805,12 +813,6 @@ func (b *BlockChainAPI) FeeHistory(
805813 )
806814
807815 maxCount := min (uint64 (blockCount ), lastBlockNumber )
808-
809- blockRewards := make ([]* hexutil.Big , len (rewardPercentiles ))
810- for i := range rewardPercentiles {
811- blockRewards [i ] = (* hexutil .Big )(b .config .GasPrice )
812- }
813-
814816 for i := maxCount ; i >= uint64 (1 ); i -- {
815817 // If the requested block count is 5, and the last block number
816818 // is 20, then we need the blocks [16, 17, 18, 19, 20] in this
@@ -827,6 +829,21 @@ func (b *BlockChainAPI) FeeHistory(
827829
828830 baseFees = append (baseFees , (* hexutil .Big )(models .BaseFeePerGas ))
829831
832+ blockRewards := make ([]* hexutil.Big , len (rewardPercentiles ))
833+ feeParams , err := b .feeParameters .Get ()
834+ if err != nil {
835+ b .logger .Warn ().
836+ Uint64 ("height" , blockHeight ).
837+ Err (err ).
838+ Msg ("failed to get fee parameters for block in fee history" )
839+
840+ continue
841+ }
842+ gasPrice := feeParams .CalculateGasPrice (b .config .GasPrice )
843+ for i := range rewardPercentiles {
844+ blockRewards [i ] = (* hexutil .Big )(gasPrice )
845+ }
846+
830847 rewards = append (rewards , blockRewards )
831848
832849 gasUsedRatio := float64 (block .TotalGasUsed ) / float64 (BlockGasLimit )
@@ -1007,7 +1024,13 @@ func (b *BlockChainAPI) Coinbase(ctx context.Context) (common.Address, error) {
10071024
10081025// GasPrice returns a suggestion for a gas price for legacy transactions.
10091026func (b * BlockChainAPI ) GasPrice (ctx context.Context ) (* hexutil.Big , error ) {
1010- return (* hexutil .Big )(b .config .GasPrice ), nil
1027+ feeParams , err := b .feeParameters .Get ()
1028+ if err != nil {
1029+ b .logger .Warn ().Err (err ).Msg ("fee parameters unavailable; falling back to base gas price" )
1030+ return (* hexutil .Big )(b .config .GasPrice ), nil
1031+ }
1032+ gasPrice := feeParams .CalculateGasPrice (b .config .GasPrice )
1033+ return (* hexutil .Big )(gasPrice ), nil
10111034}
10121035
10131036// GetUncleCountByBlockHash returns number of uncles in the block for the given block hash
@@ -1048,7 +1071,13 @@ func (b *BlockChainAPI) GetUncleByBlockNumberAndIndex(
10481071
10491072// MaxPriorityFeePerGas returns a suggestion for a gas tip cap for dynamic fee transactions.
10501073func (b * BlockChainAPI ) MaxPriorityFeePerGas (ctx context.Context ) (* hexutil.Big , error ) {
1051- return (* hexutil .Big )(b .config .GasPrice ), nil
1074+ feeParams , err := b .feeParameters .Get ()
1075+ if err != nil {
1076+ b .logger .Warn ().Err (err ).Msg ("fee parameters unavailable; falling back to base gas price" )
1077+ return (* hexutil .Big )(b .config .GasPrice ), nil
1078+ }
1079+ gasPrice := feeParams .CalculateGasPrice (b .config .GasPrice )
1080+ return (* hexutil .Big )(gasPrice ), nil
10521081}
10531082
10541083// Mining returns true if client is actively mining new blocks.
0 commit comments