Skip to content

Commit 419f81f

Browse files
committed
eth/gasprice: change feehistory input type from int to uint64 (ethereum#26922)
1 parent b823688 commit 419f81f

File tree

8 files changed

+17
-17
lines changed

8 files changed

+17
-17
lines changed

eth/api_backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ func (b *EthApiBackend) SuggestGasTipCap(ctx context.Context) (*big.Int, error)
349349
return b.gpo.SuggestTipCap(ctx)
350350
}
351351

352-
func (b *EthApiBackend) FeeHistory(ctx context.Context, blockCount int, lastBlock rpc.BlockNumber, rewardPercentiles []float64) (firstBlock *big.Int, reward [][]*big.Int, baseFee []*big.Int, gasUsedRatio []float64, err error) {
352+
func (b *EthApiBackend) FeeHistory(ctx context.Context, blockCount uint64, lastBlock rpc.BlockNumber, rewardPercentiles []float64) (firstBlock *big.Int, reward [][]*big.Int, baseFee []*big.Int, gasUsedRatio []float64, err error) {
353353
return b.gpo.FeeHistory(ctx, blockCount, lastBlock, rewardPercentiles)
354354
}
355355

eth/gasprice/feehistory.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func (oracle *Oracle) processBlock(bf *blockFees, percentiles []float64) {
137137
// also returned if requested and available.
138138
// Note: an error is only returned if retrieving the head header has failed. If there are no
139139
// retrievable blocks in the specified range then zero block count is returned with no error.
140-
func (oracle *Oracle) resolveBlockRange(ctx context.Context, reqEnd rpc.BlockNumber, blocks int) (*types.Block, []*types.Receipt, uint64, int, error) {
140+
func (oracle *Oracle) resolveBlockRange(ctx context.Context, reqEnd rpc.BlockNumber, blocks uint64) (*types.Block, []*types.Receipt, uint64, uint64, error) {
141141
var (
142142
headBlock *types.Header
143143
pendingBlock *types.Block
@@ -193,8 +193,8 @@ func (oracle *Oracle) resolveBlockRange(ctx context.Context, reqEnd rpc.BlockNum
193193
return nil, nil, 0, 0, nil
194194
}
195195
// Ensure not trying to retrieve before genesis.
196-
if int(reqEnd+1) < blocks {
197-
blocks = int(reqEnd + 1)
196+
if uint64(reqEnd+1) < blocks {
197+
blocks = uint64(reqEnd + 1)
198198
}
199199
return pendingBlock, pendingReceipts, uint64(reqEnd), blocks, nil
200200
}
@@ -213,7 +213,7 @@ func (oracle *Oracle) resolveBlockRange(ctx context.Context, reqEnd rpc.BlockNum
213213
//
214214
// Note: baseFee includes the next block after the newest of the returned range, because this
215215
// value can be derived from the newest block.
216-
func (oracle *Oracle) FeeHistory(ctx context.Context, blocks int, unresolvedLastBlock rpc.BlockNumber, rewardPercentiles []float64) (*big.Int, [][]*big.Int, []*big.Int, []float64, error) {
216+
func (oracle *Oracle) FeeHistory(ctx context.Context, blocks uint64, unresolvedLastBlock rpc.BlockNumber, rewardPercentiles []float64) (*big.Int, [][]*big.Int, []*big.Int, []float64, error) {
217217
if blocks < 1 {
218218
return common.Big0, nil, nil, nil, nil // returning with no data and no error means there are no retrievable blocks
219219
}
@@ -242,7 +242,7 @@ func (oracle *Oracle) FeeHistory(ctx context.Context, blocks int, unresolvedLast
242242
if err != nil || blocks == 0 {
243243
return common.Big0, nil, nil, nil, err
244244
}
245-
oldestBlock := lastBlock + 1 - uint64(blocks)
245+
oldestBlock := lastBlock + 1 - blocks
246246

247247
var (
248248
next = oldestBlock
@@ -252,7 +252,7 @@ func (oracle *Oracle) FeeHistory(ctx context.Context, blocks int, unresolvedLast
252252
for i, p := range rewardPercentiles {
253253
binary.LittleEndian.PutUint64(percentileKey[i*8:(i+1)*8], math.Float64bits(p))
254254
}
255-
for i := 0; i < maxBlockFetchers && i < blocks; i++ {
255+
for i := 0; i < maxBlockFetchers && i < int(blocks); i++ {
256256
go func() {
257257
for {
258258
// Retrieve the next block number to fetch with this goroutine
@@ -310,7 +310,7 @@ func (oracle *Oracle) FeeHistory(ctx context.Context, blocks int, unresolvedLast
310310
if fees.err != nil {
311311
return common.Big0, nil, nil, nil, fees.err
312312
}
313-
i := int(fees.blockNumber - oldestBlock)
313+
i := fees.blockNumber - oldestBlock
314314
if fees.results.baseFee != nil {
315315
reward[i], baseFee[i], baseFee[i+1], gasUsedRatio[i] = fees.results.reward, fees.results.baseFee, fees.results.nextBaseFee, fees.results.gasUsedRatio
316316
} else {

eth/gasprice/feehistory_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ import (
2828
func TestFeeHistory(t *testing.T) {
2929
var cases = []struct {
3030
pending bool
31-
maxHeader, maxBlock int
32-
count int
31+
maxHeader, maxBlock uint64
32+
count uint64
3333
last rpc.BlockNumber
3434
percent []float64
3535
expFirst uint64

eth/gasprice/gasprice.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ var (
4242
type Config struct {
4343
Blocks int
4444
Percentile int
45-
MaxHeaderHistory int
46-
MaxBlockHistory int
45+
MaxHeaderHistory uint64
46+
MaxBlockHistory uint64
4747
Default *big.Int `toml:",omitempty"`
4848
MaxPrice *big.Int `toml:",omitempty"`
4949
IgnorePrice *big.Int `toml:",omitempty"`
@@ -71,7 +71,7 @@ type Oracle struct {
7171
fetchLock sync.Mutex
7272

7373
checkBlocks, percentile int
74-
maxHeaderHistory, maxBlockHistory int
74+
maxHeaderHistory, maxBlockHistory uint64
7575
historyCache *lru.Cache
7676
}
7777

internal/ethapi/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ type feeHistoryResult struct {
111111

112112
// FeeHistory returns the fee market history.
113113
func (s *PublicEthereumAPI) FeeHistory(ctx context.Context, blockCount hexutil.Uint, lastBlock rpc.BlockNumber, rewardPercentiles []float64) (*feeHistoryResult, error) {
114-
oldest, reward, baseFee, gasUsed, err := s.b.FeeHistory(ctx, int(blockCount), lastBlock, rewardPercentiles)
114+
oldest, reward, baseFee, gasUsed, err := s.b.FeeHistory(ctx, uint64(blockCount), lastBlock, rewardPercentiles)
115115
if err != nil {
116116
return nil, err
117117
}

internal/ethapi/backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ type Backend interface {
4949
Downloader() *downloader.Downloader
5050
ProtocolVersion() int
5151
SuggestGasTipCap(ctx context.Context) (*big.Int, error)
52-
FeeHistory(ctx context.Context, blockCount int, lastBlock rpc.BlockNumber, rewardPercentiles []float64) (*big.Int, [][]*big.Int, []*big.Int, []float64, error)
52+
FeeHistory(ctx context.Context, blockCount uint64, lastBlock rpc.BlockNumber, rewardPercentiles []float64) (*big.Int, [][]*big.Int, []*big.Int, []float64, error)
5353
ChainDb() ethdb.Database
5454
AccountManager() *accounts.Manager
5555
RPCGasCap() uint64 // global gas cap for eth_call over rpc: DoS protection

internal/ethapi/transaction_args_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ func (b *backendMock) ChainConfig() *params.ChainConfig { return b.config }
265265

266266
// Other methods needed to implement Backend interface.
267267
func (b *backendMock) SyncProgress() ethereum.SyncProgress { return ethereum.SyncProgress{} }
268-
func (b *backendMock) FeeHistory(ctx context.Context, blockCount int, lastBlock rpc.BlockNumber, rewardPercentiles []float64) (*big.Int, [][]*big.Int, []*big.Int, []float64, error) {
268+
func (b *backendMock) FeeHistory(context.Context, uint64, rpc.BlockNumber, []float64) (*big.Int, [][]*big.Int, []*big.Int, []float64, error) {
269269
return nil, nil, nil, nil, nil
270270
}
271271
func (b *backendMock) ChainDb() ethdb.Database { return nil }

les/api_backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ func (b *LesApiBackend) SuggestGasTipCap(ctx context.Context) (*big.Int, error)
282282
return b.gpo.SuggestTipCap(ctx)
283283
}
284284

285-
func (b *LesApiBackend) FeeHistory(ctx context.Context, blockCount int, lastBlock rpc.BlockNumber, rewardPercentiles []float64) (firstBlock *big.Int, reward [][]*big.Int, baseFee []*big.Int, gasUsedRatio []float64, err error) {
285+
func (b *LesApiBackend) FeeHistory(ctx context.Context, blockCount uint64, lastBlock rpc.BlockNumber, rewardPercentiles []float64) (firstBlock *big.Int, reward [][]*big.Int, baseFee []*big.Int, gasUsedRatio []float64, err error) {
286286
return b.gpo.FeeHistory(ctx, blockCount, lastBlock, rewardPercentiles)
287287
}
288288

0 commit comments

Comments
 (0)