Skip to content

Commit

Permalink
[EVM-739]: Fix eth_feeHistory parsing of hex arguments (#1725)
Browse files Browse the repository at this point in the history
* Fix

* GasUsedRatio fix

* Comments fix
  • Loading branch information
goran-ethernal committed Jul 17, 2023
1 parent da7ad74 commit 5ea0540
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
14 changes: 10 additions & 4 deletions jsonrpc/eth_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -803,16 +803,22 @@ func (e *Eth) MaxPriorityFeePerGas() (interface{}, error) {
return argBigPtr(priorityFee), nil
}

func (e *Eth) FeeHistory(blockCount uint64, newestBlock uint64, rewardPercentiles []float64) (interface{}, error) {
func (e *Eth) FeeHistory(blockCount argUint64, newestBlock BlockNumber,
rewardPercentiles []float64) (interface{}, error) {
block, err := GetNumericBlockNumber(newestBlock, e.store)
if err != nil {
return nil, fmt.Errorf("could not parse newest block argument. Error: %w", err)
}

// Retrieve oldestBlock, baseFeePerGas, gasUsedRatio, and reward synchronously
history, err := e.store.FeeHistory(blockCount, newestBlock, rewardPercentiles)
history, err := e.store.FeeHistory(uint64(blockCount), block, rewardPercentiles)
if err != nil {
return nil, err
}

// Create channels to receive the processed slices asynchronously
baseFeePerGasCh := make(chan []argUint64)
gasUsedRatioCh := make(chan []argUint64)
gasUsedRatioCh := make(chan []float64)
rewardCh := make(chan [][]argUint64)

// Process baseFeePerGas asynchronously
Expand All @@ -822,7 +828,7 @@ func (e *Eth) FeeHistory(blockCount uint64, newestBlock uint64, rewardPercentile

// Process gasUsedRatio asynchronously
go func() {
gasUsedRatioCh <- convertFloat64SliceToArgUint64Slice(history.GasUsedRatio)
gasUsedRatioCh <- history.GasUsedRatio
}()

// Process reward asynchronously
Expand Down
17 changes: 4 additions & 13 deletions jsonrpc/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,10 @@ type progression struct {
}

type feeHistoryResult struct {
OldestBlock argUint64
BaseFeePerGas []argUint64
GasUsedRatio []argUint64
Reward [][]argUint64
OldestBlock argUint64 `json:"oldestBlock"`
BaseFeePerGas []argUint64 `json:"baseFeePerGas,omitempty"`
GasUsedRatio []float64 `json:"gasUsedRatio"`
Reward [][]argUint64 `json:"reward,omitempty"`
}

func convertToArgUint64Slice(slice []uint64) []argUint64 {
Expand All @@ -373,12 +373,3 @@ func convertToArgUint64SliceSlice(slice [][]uint64) [][]argUint64 {

return argSlice
}

func convertFloat64SliceToArgUint64Slice(slice []float64) []argUint64 {
argSlice := make([]argUint64, len(slice))
for i, value := range slice {
argSlice[i] = argUint64(value)
}

return argSlice
}

0 comments on commit 5ea0540

Please sign in to comment.