Skip to content

Commit

Permalink
Problem: nextBaseFee is not aligned max with minGasPrice in eth_feeHi…
Browse files Browse the repository at this point in the history
…story (#401)

* Problem: nextBaseFee is not aligned max with minGasPrice in eth_feeHistory

* Update CHANGELOG.md

Signed-off-by: mmsqe <[email protected]>

* fix lint

---------

Signed-off-by: mmsqe <[email protected]>
  • Loading branch information
mmsqe authored Jan 22, 2024
1 parent e2b1d5e commit 2f3643b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (rpc) [#388](https://github.com/crypto-org-chain/ethermint/pull/388) Avoid out of bound panic when error message.
* (rpc) [#391](https://github.com/crypto-org-chain/ethermint/pull/391) Align block param with go-ethereum in debug_traceCall.
- (evm) [#396](https://github.com/crypto-org-chain/ethermint/pull/396) Align evm tx type with go-ethereum.
- (rpc) [#401](https://github.com/crypto-org-chain/ethermint/pull/401) Align max nextBaseFee with minGasPrice in eth_feeHistory.

### Improvements

Expand Down
14 changes: 7 additions & 7 deletions rpc/backend/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,13 @@ func (b *Backend) getAccountNonce(accAddr common.Address, pending bool, height i
}

// CalcBaseFee calculates the basefee of the header.
func CalcBaseFee(config *params.ChainConfig, parent *ethtypes.Header, baseFeeChangeDenominator, elasticityMultiplier uint32) *big.Int {
func CalcBaseFee(config *params.ChainConfig, parent *ethtypes.Header, p feemarkettypes.Params) *big.Int {
// If the current block is the first EIP-1559 block, return the InitialBaseFee.
if !config.IsLondon(parent.Number) {
return new(big.Int).SetUint64(params.InitialBaseFee)
}

parentGasTarget := parent.GasLimit / uint64(elasticityMultiplier)
parentGasTarget := parent.GasLimit / uint64(p.ElasticityMultiplier)
// If the parent gasUsed is the same as the target, the baseFee remains unchanged.
if parent.GasUsed == parentGasTarget {
return new(big.Int).Set(parent.BaseFee)
Expand All @@ -141,7 +141,7 @@ func CalcBaseFee(config *params.ChainConfig, parent *ethtypes.Header, baseFeeCha
num.SetUint64(parent.GasUsed - parentGasTarget)
num.Mul(num, parent.BaseFee)
num.Div(num, denom.SetUint64(parentGasTarget))
num.Div(num, denom.SetUint64(uint64(baseFeeChangeDenominator)))
num.Div(num, denom.SetUint64(uint64(p.BaseFeeChangeDenominator)))
baseFeeDelta := math.BigMax(num, common.Big1)

return num.Add(parent.BaseFee, baseFeeDelta)
Expand All @@ -152,10 +152,10 @@ func CalcBaseFee(config *params.ChainConfig, parent *ethtypes.Header, baseFeeCha
num.SetUint64(parentGasTarget - parent.GasUsed)
num.Mul(num, parent.BaseFee)
num.Div(num, denom.SetUint64(parentGasTarget))
num.Div(num, denom.SetUint64(uint64(baseFeeChangeDenominator)))
num.Div(num, denom.SetUint64(uint64(p.BaseFeeChangeDenominator)))
baseFee := num.Sub(parent.BaseFee, num)

return math.BigMax(baseFee, common.Big0)
minGasPrice := p.MinGasPrice.TruncateInt().BigInt()
return math.BigMax(baseFee, minGasPrice)
}

// output: targetOneFeeHistory
Expand Down Expand Up @@ -201,7 +201,7 @@ func (b *Backend) processBlock(
if err != nil {
return err
}
targetOneFeeHistory.NextBaseFee = CalcBaseFee(cfg, &header, params.Params.BaseFeeChangeDenominator, params.Params.ElasticityMultiplier)
targetOneFeeHistory.NextBaseFee = CalcBaseFee(cfg, &header, params.Params)
} else {
targetOneFeeHistory.NextBaseFee = new(big.Int)
}
Expand Down

0 comments on commit 2f3643b

Please sign in to comment.