Skip to content

Commit ba80db8

Browse files
committed
Multiple eth_gasPrice with the latest surge factor
1 parent fabb97f commit ba80db8

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

api/api.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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,
@@ -1007,7 +1010,16 @@ func (b *BlockChainAPI) Coinbase(ctx context.Context) (common.Address, error) {
10071010

10081011
// GasPrice returns a suggestion for a gas price for legacy transactions.
10091012
func (b *BlockChainAPI) GasPrice(ctx context.Context) (*hexutil.Big, error) {
1010-
return (*hexutil.Big)(b.config.GasPrice), nil
1013+
feeParams, err := b.feeParameters.Get()
1014+
if err != nil {
1015+
return nil, err
1016+
}
1017+
1018+
surgeFactor := uint64(feeParams.SurgeFactor)
1019+
multiplier := new(big.Int).Exp(big.NewInt(10), big.NewInt(int64(8)), nil)
1020+
gp := b.config.GasPrice.Uint64()
1021+
gasPrice := new(big.Int).SetUint64(uint64(gp * surgeFactor))
1022+
return (*hexutil.Big)(new(big.Int).Div(gasPrice, multiplier)), nil
10111023
}
10121024

10131025
// GetUncleCountByBlockHash returns number of uncles in the block for the given block hash

bootstrap/bootstrap.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ func (b *Bootstrap) StartAPIServer(ctx context.Context) error {
316316
b.storages.Blocks,
317317
b.storages.Transactions,
318318
b.storages.Receipts,
319+
b.storages.FeeParameters,
319320
rateLimiter,
320321
b.collector,
321322
indexingResumedHeight,

0 commit comments

Comments
 (0)