This repository has been archived by the owner on Apr 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 569
eth_feeHistory - fix reward calculation from MsgEthereumTx #990
Merged
fedekunze
merged 2 commits into
evmos:main
from
loredanacirstea:loredana/fix-feehistory-reward2
Mar 15, 2022
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
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] | ||
|
@@ -90,29 +91,28 @@ func (e *EVMBackend) processBlock( | |
if reward == nil { | ||
reward = big.NewInt(0) | ||
} | ||
sorter[i] = txGasAndReward{gasUsed: txGasUsed, reward: reward} | ||
break | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why the
But I did not find the answer to it. From what I understand, we should calculate the reward only from
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.