eth_feeHistory - fix reward calculation from MsgEthereumTx (#990)
* eth_feeHistory - fix reward calculation from MsgEthereumTx Problem: - rewards calculation based on percentiles took into consideration the tendermint tx count instead of `MsgEthereumTx` count. - `sorter := make(sortGasAndReward, tendermintTxCount)` creates an array of `{0 <nil>}` values. The `nil` value from the `reward` attribute was never rewritten for tendermint Tx without any `MsgEthereumTx` Fixes: - return early if there are 0 `MsgEthereumTx` - use the `MsgEthereumTx` count to calculate rewards * Add change log
This commit is contained in:
parent
50e093a6d2
commit
d04787e97f
@ -38,6 +38,12 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
|||||||
|
|
||||||
## Unreleased
|
## 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
|
### 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.
|
* (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.
|
||||||
|
@ -61,14 +61,15 @@ func (e *EVMBackend) processBlock(
|
|||||||
rewardCount := len(rewardPercentiles)
|
rewardCount := len(rewardPercentiles)
|
||||||
targetOneFeeHistory.Reward = make([]*big.Int, rewardCount)
|
targetOneFeeHistory.Reward = make([]*big.Int, rewardCount)
|
||||||
for i := 0; i < rewardCount; i++ {
|
for i := 0; i < rewardCount; i++ {
|
||||||
targetOneFeeHistory.Reward[i] = big.NewInt(2000)
|
targetOneFeeHistory.Reward[i] = big.NewInt(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// check tendermintTxs
|
// check tendermintTxs
|
||||||
tendermintTxs := tendermintBlock.Block.Txs
|
tendermintTxs := tendermintBlock.Block.Txs
|
||||||
tendermintTxResults := tendermintBlockResult.TxsResults
|
tendermintTxResults := tendermintBlockResult.TxsResults
|
||||||
tendermintTxCount := len(tendermintTxs)
|
tendermintTxCount := len(tendermintTxs)
|
||||||
sorter := make(sortGasAndReward, tendermintTxCount)
|
|
||||||
|
var sorter sortGasAndReward
|
||||||
|
|
||||||
for i := 0; i < tendermintTxCount; i++ {
|
for i := 0; i < tendermintTxCount; i++ {
|
||||||
eachTendermintTx := tendermintTxs[i]
|
eachTendermintTx := tendermintTxs[i]
|
||||||
@ -90,29 +91,28 @@ func (e *EVMBackend) processBlock(
|
|||||||
if reward == nil {
|
if reward == nil {
|
||||||
reward = big.NewInt(0)
|
reward = big.NewInt(0)
|
||||||
}
|
}
|
||||||
sorter[i] = txGasAndReward{gasUsed: txGasUsed, reward: reward}
|
sorter = append(sorter, txGasAndReward{gasUsed: txGasUsed, reward: reward})
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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)
|
sort.Sort(sorter)
|
||||||
|
|
||||||
var txIndex int
|
var txIndex int
|
||||||
sumGasUsed := uint64(0)
|
sumGasUsed := sorter[0].gasUsed
|
||||||
if len(sorter) > 0 {
|
|
||||||
sumGasUsed = sorter[0].gasUsed
|
|
||||||
}
|
|
||||||
for i, p := range rewardPercentiles {
|
for i, p := range rewardPercentiles {
|
||||||
thresholdGasUsed := uint64(blockGasUsed * p / 100)
|
thresholdGasUsed := uint64(blockGasUsed * p / 100)
|
||||||
for sumGasUsed < thresholdGasUsed && txIndex < tendermintTxCount-1 {
|
for sumGasUsed < thresholdGasUsed && txIndex < ethTxCount-1 {
|
||||||
txIndex++
|
txIndex++
|
||||||
sumGasUsed += sorter[txIndex].gasUsed
|
sumGasUsed += sorter[txIndex].gasUsed
|
||||||
}
|
}
|
||||||
|
targetOneFeeHistory.Reward[i] = sorter[txIndex].reward
|
||||||
chosenReward := big.NewInt(0)
|
|
||||||
if 0 <= txIndex && txIndex < len(sorter) {
|
|
||||||
chosenReward = sorter[txIndex].reward
|
|
||||||
}
|
|
||||||
targetOneFeeHistory.Reward[i] = chosenReward
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user