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

fix(rpc): align nextBaseFee and invalid check for fee history #1720

Closed
wants to merge 12 commits into from

Conversation

mmsqe
Copy link
Contributor

@mmsqe mmsqe commented Mar 22, 2023

  • next block fee for historical block should not change based on latest block
  • handle request beyond head block
  • invalid reward percentile

For contributor use:

  • Targeted PR against correct branch (see CONTRIBUTING.md)
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/)
  • Added relevant godoc comments.
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer

For admin use:

  • Added appropriate labels to PR (ex. WIP, R4R, docs, etc)
  • Reviewers assigned
  • Squashed all commits, uses message "Merge pull request #XYZ: [title]" (coding standards)

@mmsqe mmsqe marked this pull request as ready for review March 22, 2023 13:12
@mmsqe mmsqe requested a review from a team as a code owner March 22, 2023 13:12
@mmsqe mmsqe requested review from 0a1c and GAtom22 and removed request for a team March 22, 2023 13:12
@mmsqe mmsqe force-pushed the fix_fee_history branch 2 times, most recently from fceb6ac to 7d2b87b Compare March 23, 2023 11:13
}
}
}(int32(blockID - blockStart + int64(i)))

Check failure

Code scanning / gosec

Potential integer overflow by integer type conversion

Potential integer overflow by integer type conversion
Comment on lines +208 to +267
go func(index int32) {
defer wg.Done()
// fetch block
// tendermint block
blockNum := rpctypes.BlockNumber(blockStart + int64(index))
tendermintblock, err := b.TendermintBlockByNumber(blockNum)
if tendermintblock == nil {
chanErr <- err
return
}

// fetch block
for blockID := blockStart; blockID <= blockEnd; blockID++ {
index := int32(blockID - blockStart)
// tendermint block
tendermintblock, err := b.TendermintBlockByNumber(rpctypes.BlockNumber(blockID))
if tendermintblock == nil {
return nil, err
}

// eth block
ethBlock, err := b.GetBlockByNumber(rpctypes.BlockNumber(blockID), true)
if ethBlock == nil {
return nil, err
}
// eth block
ethBlock, err := b.GetBlockByNumber(blockNum, true)
if ethBlock == nil {
chanErr <- err
return
}

// tendermint block result
tendermintBlockResult, err := b.TendermintBlockResultByNumber(&tendermintblock.Block.Height)
if tendermintBlockResult == nil {
b.logger.Debug("block result not found", "height", tendermintblock.Block.Height, "error", err.Error())
return nil, err
}
// tendermint block result
tendermintBlockResult, err := b.TendermintBlockResultByNumber(&tendermintblock.Block.Height)
if tendermintBlockResult == nil {
b.logger.Debug("block result not found", "height", tendermintblock.Block.Height, "error", err.Error())
chanErr <- err
return
}

oneFeeHistory := rpctypes.OneFeeHistory{}
err = b.processBlock(tendermintblock, &ethBlock, rewardPercentiles, tendermintBlockResult, &oneFeeHistory)
if err != nil {
return nil, err
}
oneFeeHistory := rpctypes.OneFeeHistory{}
err = b.processBlock(tendermintblock, &ethBlock, rewardPercentiles, tendermintBlockResult, &oneFeeHistory)
if err != nil {
chanErr <- err
return
}

// copy
thisBaseFee[index] = (*hexutil.Big)(oneFeeHistory.BaseFee)
thisBaseFee[index+1] = (*hexutil.Big)(oneFeeHistory.NextBaseFee)
thisGasUsedRatio[index] = oneFeeHistory.GasUsedRatio
if calculateRewards {
for j := 0; j < rewardCount; j++ {
reward[index][j] = (*hexutil.Big)(oneFeeHistory.Reward[j])
if reward[index][j] == nil {
reward[index][j] = (*hexutil.Big)(big.NewInt(0))
// copy
thisBaseFee[index] = (*hexutil.Big)(oneFeeHistory.BaseFee)
thisBaseFee[index+1] = (*hexutil.Big)(oneFeeHistory.NextBaseFee)
thisGasUsedRatio[index] = oneFeeHistory.GasUsedRatio
if calculateRewards {
for j := 0; j < rewardCount; j++ {
reward[index][j] = (*hexutil.Big)(oneFeeHistory.Reward[j])
if reward[index][j] == nil {
reward[index][j] = (*hexutil.Big)(big.NewInt(0))
}
}
}
}
}(int32(blockID - blockStart + int64(i)))

Check notice

Code scanning / CodeQL

Spawning a Go routine

Spawning a Go routine may be a possible source of non-determinism
Comment on lines +255 to +272
go func() {
wg.Wait()
close(wgDone)
}()

Check notice

Code scanning / CodeQL

Spawning a Go routine

Spawning a Go routine may be a possible source of non-determinism
@codecov
Copy link

codecov bot commented Mar 25, 2023

Codecov Report

Merging #1720 (9e06e1f) into main (10d9579) will decrease coverage by 0.98%.
The diff coverage is 68.22%.

❗ Current head 9e06e1f differs from pull request most recent head 4348828. Consider uploading reports for the commit 4348828 to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1720      +/-   ##
==========================================
- Coverage   68.89%   67.92%   -0.98%     
==========================================
  Files         117      112       -5     
  Lines       10681    10280     -401     
==========================================
- Hits         7359     6983     -376     
+ Misses       2900     2884      -16     
+ Partials      422      413       -9     
Impacted Files Coverage Δ
rpc/backend/utils.go 45.81% <51.85%> (+2.31%) ⬆️
rpc/backend/chain_info.go 84.12% <84.90%> (+1.38%) ⬆️

... and 13 files with indirect coverage changes

yihuang added a commit to crypto-org-chain/ethermint that referenced this pull request Apr 3, 2023
* fix blk number for next base fee

* add test

* add change doc

* cross check next fee

* calc base fee based on params

elasticity_multiplier & base_fee_change_denominator

* concurrent call with maxBlockFetchers

* test with get feemarket params

* Update CHANGELOG.md

---------

Signed-off-by: yihuang <huang@crypto.com>
Co-authored-by: yihuang <huang@crypto.com>
blockEnd = int64(blockNumber)
} else if int64(blockNumber) < blockEnd {
return nil, fmt.Errorf("%w: requested %d, head %d", errRequestBeyondHead, blockEnd, int64(blockNumber))

Check failure

Code scanning / gosec

Potential integer overflow by integer type conversion

Potential integer overflow by integer type conversion
blockEnd = int64(blockNumber)
} else if int64(blockNumber) < blockEnd {

Check failure

Code scanning / gosec

Potential integer overflow by integer type conversion

Potential integer overflow by integer type conversion
@mmsqe mmsqe changed the title fix(rpc): nextBaseFee for fee history fix(rpc): align nextBaseFee and invalid check for fee history May 10, 2023
mmsqe added a commit to crypto-org-chain/ethermint that referenced this pull request May 15, 2023
… (#241)

* align request beyond head block

* align invalid reward percentile
mmsqe added a commit to mmsqe/ethermint that referenced this pull request Jun 14, 2023
* fix blk number for next base fee

* add test

* add change doc

* cross check next fee

* calc base fee based on params

elasticity_multiplier & base_fee_change_denominator

* concurrent call with maxBlockFetchers

* test with get feemarket params

* Update CHANGELOG.md

---------

Signed-off-by: yihuang <huang@crypto.com>
Co-authored-by: yihuang <huang@crypto.com>
mmsqe added a commit to mmsqe/ethermint that referenced this pull request Jun 14, 2023
… (#241)

* align request beyond head block

* align invalid reward percentile
mmsqe added a commit to crypto-org-chain/ethermint that referenced this pull request Jun 14, 2023
* fix(rpc): nextBaseFee for fee history (backport: evmos#1720) (#234)

* fix blk number for next base fee

* add test

* add change doc

* cross check next fee

* calc base fee based on params

elasticity_multiplier & base_fee_change_denominator

* concurrent call with maxBlockFetchers

* test with get feemarket params

* Update CHANGELOG.md

---------

Signed-off-by: yihuang <huang@crypto.com>
Co-authored-by: yihuang <huang@crypto.com>

* fix(rpc): add more invalid check for fee history (backport: evmos#1720)  (#241)

* align request beyond head block

* align invalid reward percentile

---------

Signed-off-by: yihuang <huang@crypto.com>
Co-authored-by: yihuang <huang@crypto.com>
@github-actions
Copy link

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days-before-close if no further activity occurs.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant