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

eth_feeHistory - fix reward calculation from MsgEthereumTx #990

Merged
merged 2 commits into from
Mar 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ Ref: https://keepachangelog.com/en/1.0.0/

## Unreleased

### Bug Fixes

* (rpc) [tharsis#990](https://github.com/tharsis/ethermint/pull/990) Calculate reward values from all `MsgEthereumTx` from a block in `eth_feeHistory`.

## [v0.11.0] - 2022-03-06

### State Machine Breaking

* (ante) [tharsis#964](https://github.com/tharsis/ethermint/pull/964) add NewInfiniteGasMeterWithLimit for storing the user provided gas limit. Fixes block's consumed gas calculation in the block creation phase.
Expand Down
30 changes: 15 additions & 15 deletions rpc/ethereum/backend/feebackend.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,15 @@ func (e *EVMBackend) processBlock(
rewardCount := len(rewardPercentiles)
targetOneFeeHistory.Reward = make([]*big.Int, rewardCount)
for i := 0; i < rewardCount; i++ {
targetOneFeeHistory.Reward[i] = big.NewInt(2000)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

2000 was chosen as default in https://github.com/tharsis/ethermint/pull/734/files#diff-4d996264fd51e2936260254650a034814a870ddfa9f7df7398d53feba7c39ef6R64.
Standard default value is 0 and it was usually rewritten anyway by the code below this line.

targetOneFeeHistory.Reward[i] = big.NewInt(0)
}

// check tendermintTxs
tendermintTxs := tendermintBlock.Block.Txs
tendermintTxResults := tendermintBlockResult.TxsResults
tendermintTxCount := len(tendermintTxs)
sorter := make(sortGasAndReward, tendermintTxCount)

var sorter sortGasAndReward

for i := 0; i < tendermintTxCount; i++ {
eachTendermintTx := tendermintTxs[i]
Expand All @@ -90,29 +91,28 @@ func (e *EVMBackend) processBlock(
if reward == nil {
reward = big.NewInt(0)
}
sorter[i] = txGasAndReward{gasUsed: txGasUsed, reward: reward}
break
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why the break? I see this same question was asked by @fedekunze :

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

But I did not find the answer to it.

From what I understand, we should calculate the reward only from MsgEthereumTx and not from tendermintTx. But I have some questions:

  • can we find multiple MsgEthereumTx in a tendermint Tx? (tx.GetMsgs())
  • if yes, on what rules are the MsgEthereumTx batched in a Tx?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, we can find MsgEthereumTx in a Tendermint Tx. There are no filters, we can only iterate over the msgs

sorter = append(sorter, txGasAndReward{gasUsed: txGasUsed, reward: reward})
}
}

// return an all zero row if there are no transactions to gather data from
ethTxCount := len(sorter)
if ethTxCount == 0 {
return nil
}

sort.Sort(sorter)

var txIndex int
sumGasUsed := uint64(0)
if len(sorter) > 0 {
sumGasUsed = sorter[0].gasUsed
}
sumGasUsed := sorter[0].gasUsed

for i, p := range rewardPercentiles {
thresholdGasUsed := uint64(blockGasUsed * p / 100)
for sumGasUsed < thresholdGasUsed && txIndex < tendermintTxCount-1 {
for sumGasUsed < thresholdGasUsed && txIndex < ethTxCount-1 {
txIndex++
sumGasUsed += sorter[txIndex].gasUsed
}

chosenReward := big.NewInt(0)
if 0 <= txIndex && txIndex < len(sorter) {
chosenReward = sorter[txIndex].reward
}
targetOneFeeHistory.Reward[i] = chosenReward
targetOneFeeHistory.Reward[i] = sorter[txIndex].reward
}

return nil
Expand Down