Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Problem: missing json rpc of eth_feeHistory #685 #734

Merged
merged 4 commits into from
Nov 17, 2021

Conversation

leejw51crypto
Copy link
Contributor

Solution: add feehistory api

@leejw51crypto
Copy link
Contributor Author

leejw51crypto commented Nov 12, 2021

will add unit test
and will limit count up to 100

because it's heavy task, can be used maliciously

@fedekunze
Copy link
Contributor

@leejw51crypto let me know if you need support with this PR, I'd like to add it for the next release

@leejw51crypto
Copy link
Contributor Author

ok

@leejw51crypto leejw51crypto force-pushed the feature/685 branch 3 times, most recently from 8f3cb1c to 0e48645 Compare November 15, 2021 23:40
@leejw51crypto
Copy link
Contributor Author

add unit test
rebased

@leejw51crypto leejw51crypto marked this pull request as ready for review November 15, 2021 23:44
@leejw51crypto leejw51crypto force-pushed the feature/685 branch 3 times, most recently from dc25728 to 720fbaa Compare November 16, 2021 06:31
@leejw51crypto
Copy link
Contributor Author

fix golangci-lint

Copy link
Contributor

@fedekunze fedekunze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @leejw51crypto, please add more comments and clean up the logic based on the comments. Also if you could add a changelog entry

rpc/ethereum/backend/feebackend.go Outdated Show resolved Hide resolved
Comment on lines 48 to 49
gasUsedString := gasUsedBig.ToInt().String()
gasusedfloat, _ := strconv.ParseFloat(gasUsedString, 64)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you convert to float64 directly without parsing the string?

Comment on lines 51 to 57
if gasLimitUint64 > 0 {
gasUsedRatio = gasusedfloat / float64(gasLimitUint64)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs a comment

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we error if gasLimitUint64 is 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, i'll return error if gaslimit is 0

Comment on lines 114 to 118
type OneFeeHistory struct {
BaseFee *big.Int
Reward []*big.Int
GasUsed float64
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to types? also add a comment to describe what it is and what it does

GasUsed float64
}

func (e *EVMBackend) FeeHistory(userBlockCount rpc.DecimalOrHex, lastBlock rpc.BlockNumber, rewardPercentiles []float64) (*rpctypes.FeeHistoryResult, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add comment and split arguments

Comment on lines 158 to 160
if ethBlock == nil || err != nil {
return nil, err
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

technically this can return nil, nil if both ethBlock and err are nil. is this expected?

Copy link
Contributor Author

@leejw51crypto leejw51crypto Nov 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with err==nil, ethBlock is also nil

rpc/ethereum/backend/feebackend.go Outdated Show resolved Hide resolved
rpc/ethereum/backend/feebackend.go Outdated Show resolved Hide resolved
rpc/ethereum/backend/feebackend.go Outdated Show resolved Hide resolved
rpc/ethereum/backend/feebackend.go Outdated Show resolved Hide resolved
@leejw51crypto
Copy link
Contributor Author

leejw51crypto commented Nov 17, 2021

done

@leejw51crypto leejw51crypto force-pushed the feature/685 branch 2 times, most recently from 3daab0e to d6692e6 Compare November 17, 2021 06:46
add oracle backend

space ready

structure ok

refactoring

return feehistory

data flow ok

basefee

set gas used ratio

computing reward

add testing

add gas used

prepare data

fill reward

increase coin

fixing api

add mac

add launch

gas used ratio ok

print element

reward workes

reward working

fix panic

value correct

remove debugging log

tidy up

tidy up

remove oracle

tidy up

fix handler crash

add unit test

tidy up

add limit check

reformat

fix lint

fix lint

fix lint

fix lint

Update rpc/ethereum/backend/feebackend.go

thanks

Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>

Update rpc/ethereum/backend/feebackend.go

Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>

Update rpc/ethereum/backend/feebackend.go

thanks

Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>

Update rpc/ethereum/backend/feebackend.go

Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>

fix compile error

split lines

remove temporary string conversion

return error if gaslimit is 0

move OneFeeHistory to types

add comment

only err check

Update rpc/ethereum/backend/feebackend.go

Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>

Update rpc/ethereum/backend/feebackend.go

Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>

tidy up

add feehistory-cap
@codecov
Copy link

codecov bot commented Nov 17, 2021

Codecov Report

Merging #734 (6c260a6) into main (b7e8dd8) will decrease coverage by 0.03%.
The diff coverage is 42.85%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #734      +/-   ##
==========================================
- Coverage   55.86%   55.83%   -0.04%     
==========================================
  Files          64       64              
  Lines        5859     5864       +5     
==========================================
+ Hits         3273     3274       +1     
- Misses       2386     2390       +4     
  Partials      200      200              
Impacted Files Coverage Δ
server/config/config.go 21.42% <42.85%> (-0.06%) ⬇️

@leejw51crypto
Copy link
Contributor Author

default history cap is 100 to prevent ddos attack,
can configured with app.toml

# FeeHistoryCap sets the global cap for total number of blocks that can be fetched
feehistory-cap = 100

Copy link
Contributor

@fedekunze fedekunze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM minor comments

rpc/ethereum/backend/backend.go Outdated Show resolved Hide resolved
rpc/ethereum/backend/feebackend.go Outdated Show resolved Hide resolved
tx := ethMsg.AsTransaction()
reward := tx.EffectiveGasTipValue(blockBaseFee)
sorter[i] = txGasAndReward{gasUsed: txGasUsed, reward: reward}
break
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the purpose of this break here, are we only supporting 1 MsgEthereumTx message?

rpc/ethereum/backend/feebackend.go Outdated Show resolved Hide resolved
rpc/ethereum/backend/feebackend.go Outdated Show resolved Hide resolved
rpc/ethereum/types/types.go Outdated Show resolved Hide resolved
@fedekunze fedekunze enabled auto-merge (squash) November 17, 2021 11:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants