Skip to content

Commit 626cf30

Browse files
aaronbuchwaldmmsqe
authored andcommitted
eth/gasprice: change feehistory input type from int to uint64 (ethereum#26922)
Change input param type from int to uint64
1 parent 15f2d6f commit 626cf30

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
@@ -327,7 +327,7 @@ func (b *EthAPIBackend) SuggestGasTipCap(ctx context.Context) (*big.Int, error)
327327
return b.gpo.SuggestTipCap(ctx)
328328
}
329329

330-
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) {
330+
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) {
331331
return b.gpo.FeeHistory(ctx, blockCount, lastBlock, rewardPercentiles)
332332
}
333333

eth/gasprice/feehistory.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func (oracle *Oracle) processBlock(bf *blockFees, percentiles []float64) {
142142
// also returned if requested and available.
143143
// Note: an error is only returned if retrieving the head header has failed. If there are no
144144
// retrievable blocks in the specified range then zero block count is returned with no error.
145-
func (oracle *Oracle) resolveBlockRange(ctx context.Context, reqEnd rpc.BlockNumber, blocks int) (*types.Block, []*types.Receipt, uint64, int, error) {
145+
func (oracle *Oracle) resolveBlockRange(ctx context.Context, reqEnd rpc.BlockNumber, blocks uint64) (*types.Block, []*types.Receipt, uint64, uint64, error) {
146146
var (
147147
headBlock *types.Header
148148
pendingBlock *types.Block
@@ -200,8 +200,8 @@ func (oracle *Oracle) resolveBlockRange(ctx context.Context, reqEnd rpc.BlockNum
200200
return nil, nil, 0, 0, nil
201201
}
202202
// Ensure not trying to retrieve before genesis.
203-
if int(reqEnd+1) < blocks {
204-
blocks = int(reqEnd + 1)
203+
if uint64(reqEnd+1) < blocks {
204+
blocks = uint64(reqEnd + 1)
205205
}
206206
return pendingBlock, pendingReceipts, uint64(reqEnd), blocks, nil
207207
}
@@ -220,7 +220,7 @@ func (oracle *Oracle) resolveBlockRange(ctx context.Context, reqEnd rpc.BlockNum
220220
//
221221
// Note: baseFee includes the next block after the newest of the returned range, because this
222222
// value can be derived from the newest block.
223-
func (oracle *Oracle) FeeHistory(ctx context.Context, blocks int, unresolvedLastBlock rpc.BlockNumber, rewardPercentiles []float64) (*big.Int, [][]*big.Int, []*big.Int, []float64, error) {
223+
func (oracle *Oracle) FeeHistory(ctx context.Context, blocks uint64, unresolvedLastBlock rpc.BlockNumber, rewardPercentiles []float64) (*big.Int, [][]*big.Int, []*big.Int, []float64, error) {
224224
if blocks < 1 {
225225
return common.Big0, nil, nil, nil, nil // returning with no data and no error means there are no retrievable blocks
226226
}
@@ -249,7 +249,7 @@ func (oracle *Oracle) FeeHistory(ctx context.Context, blocks int, unresolvedLast
249249
if err != nil || blocks == 0 {
250250
return common.Big0, nil, nil, nil, err
251251
}
252-
oldestBlock := lastBlock + 1 - uint64(blocks)
252+
oldestBlock := lastBlock + 1 - blocks
253253

254254
var (
255255
next = oldestBlock
@@ -259,7 +259,7 @@ func (oracle *Oracle) FeeHistory(ctx context.Context, blocks int, unresolvedLast
259259
for i, p := range rewardPercentiles {
260260
binary.LittleEndian.PutUint64(percentileKey[i*8:(i+1)*8], math.Float64bits(p))
261261
}
262-
for i := 0; i < maxBlockFetchers && i < blocks; i++ {
262+
for i := 0; i < maxBlockFetchers && i < int(blocks); i++ {
263263
go func() {
264264
for {
265265
// Retrieve the next block number to fetch with this goroutine
@@ -314,7 +314,7 @@ func (oracle *Oracle) FeeHistory(ctx context.Context, blocks int, unresolvedLast
314314
if fees.err != nil {
315315
return common.Big0, nil, nil, nil, fees.err
316316
}
317-
i := int(fees.blockNumber - oldestBlock)
317+
i := fees.blockNumber - oldestBlock
318318
if fees.results.baseFee != nil {
319319
reward[i], baseFee[i], baseFee[i+1], gasUsedRatio[i] = fees.results.reward, fees.results.baseFee, fees.results.nextBaseFee, fees.results.gasUsedRatio
320320
} 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

7676
historyCache *lru.Cache[cacheKey, processedFees]
7777
}

internal/ethapi/api.go

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

9090
// FeeHistory returns the fee market history.
9191
func (s *EthereumAPI) FeeHistory(ctx context.Context, blockCount math.HexOrDecimal64, lastBlock rpc.BlockNumber, rewardPercentiles []float64) (*feeHistoryResult, error) {
92-
oldest, reward, baseFee, gasUsed, err := s.b.FeeHistory(ctx, int(blockCount), lastBlock, rewardPercentiles)
92+
oldest, reward, baseFee, gasUsed, err := s.b.FeeHistory(ctx, uint64(blockCount), lastBlock, rewardPercentiles)
9393
if err != nil {
9494
return nil, err
9595
}

internal/ethapi/backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ type Backend interface {
4444
SyncProgress() ethereum.SyncProgress
4545

4646
SuggestGasTipCap(ctx context.Context) (*big.Int, error)
47-
FeeHistory(ctx context.Context, blockCount int, lastBlock rpc.BlockNumber, rewardPercentiles []float64) (*big.Int, [][]*big.Int, []*big.Int, []float64, error)
47+
FeeHistory(ctx context.Context, blockCount uint64, lastBlock rpc.BlockNumber, rewardPercentiles []float64) (*big.Int, [][]*big.Int, []*big.Int, []float64, error)
4848
ChainDb() ethdb.Database
4949
AccountManager() *accounts.Manager
5050
ExtRPCEnabled() bool

internal/ethapi/transaction_args_test.go

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

259259
// Other methods needed to implement Backend interface.
260260
func (b *backendMock) SyncProgress() ethereum.SyncProgress { return ethereum.SyncProgress{} }
261-
func (b *backendMock) FeeHistory(ctx context.Context, blockCount int, lastBlock rpc.BlockNumber, rewardPercentiles []float64) (*big.Int, [][]*big.Int, []*big.Int, []float64, error) {
261+
func (b *backendMock) FeeHistory(ctx context.Context, blockCount uint64, lastBlock rpc.BlockNumber, rewardPercentiles []float64) (*big.Int, [][]*big.Int, []*big.Int, []float64, error) {
262262
return nil, nil, nil, nil, nil
263263
}
264264
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
@@ -272,7 +272,7 @@ func (b *LesApiBackend) SuggestGasTipCap(ctx context.Context) (*big.Int, error)
272272
return b.gpo.SuggestTipCap(ctx)
273273
}
274274

275-
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) {
275+
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) {
276276
return b.gpo.FeeHistory(ctx, blockCount, lastBlock, rewardPercentiles)
277277
}
278278

0 commit comments

Comments
 (0)