mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-12 13:24:21 +00:00
parent
112a6f7d76
commit
1ab5c29530
@ -17,22 +17,12 @@ import
|
|||||||
../../../constants,
|
../../../constants,
|
||||||
../../../forks,
|
../../../forks,
|
||||||
../tx_item,
|
../tx_item,
|
||||||
eth/[common]
|
eth/[common, eip1559]
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
const
|
const
|
||||||
EIP1559_BASE_FEE_CHANGE_DENOMINATOR = ##\
|
INITIAL_BASE_FEE = EIP1559_INITIAL_BASE_FEE.truncate(uint64)
|
||||||
## Bounds the amount the base fee can change between blocks.
|
|
||||||
8
|
|
||||||
|
|
||||||
EIP1559_ELASTICITY_MULTIPLIER = ##\
|
|
||||||
## Bounds the maximum gas limit an EIP-1559 block may have.
|
|
||||||
2
|
|
||||||
|
|
||||||
EIP1559_INITIAL_BASE_FEE = ##\
|
|
||||||
## Initial base fee for Eip1559 blocks.
|
|
||||||
1_000_000_000
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Public functions
|
# Public functions
|
||||||
@ -46,9 +36,6 @@ proc baseFeeGet*(config: ChainConfig; parent: BlockHeader): GasPrice =
|
|||||||
|
|
||||||
# Note that the baseFee is calculated for the next header
|
# Note that the baseFee is calculated for the next header
|
||||||
let
|
let
|
||||||
parentGasUsed = parent.gasUsed
|
|
||||||
parentGasLimit = parent.gasLimit
|
|
||||||
parentBaseFee = parent.baseFee.truncate(uint64)
|
|
||||||
parentFork = config.toFork(parent.blockNumber)
|
parentFork = config.toFork(parent.blockNumber)
|
||||||
nextFork = config.toFork(parent.blockNumber + 1)
|
nextFork = config.toFork(parent.blockNumber + 1)
|
||||||
|
|
||||||
@ -57,35 +44,14 @@ proc baseFeeGet*(config: ChainConfig; parent: BlockHeader): GasPrice =
|
|||||||
|
|
||||||
# If the new block is the first EIP-1559 block, return initial base fee.
|
# If the new block is the first EIP-1559 block, return initial base fee.
|
||||||
if parentFork < FkLondon:
|
if parentFork < FkLondon:
|
||||||
return EIP1559_INITIAL_BASE_FEE.GasPrice
|
return INITIAL_BASE_FEE.GasPrice
|
||||||
|
|
||||||
let
|
# TODO: which one is better?
|
||||||
parGasTrg = parentGasLimit div EIP1559_ELASTICITY_MULTIPLIER
|
# truncate parent.baseFee to uint64 first and do the operation in uint64
|
||||||
parGasDenom = (parGasTrg * EIP1559_BASE_FEE_CHANGE_DENOMINATOR).uint64
|
# or truncate the result?
|
||||||
|
calcEip1599BaseFee(parent.gasLimit,
|
||||||
# If parent gasUsed is the same as the target, the baseFee remains unchanged.
|
parent.gasUsed,
|
||||||
if parentGasUsed == parGasTrg:
|
parent.baseFee).truncate(uint64).GasPrice
|
||||||
return parentBaseFee.GasPrice
|
|
||||||
|
|
||||||
if parGasTrg < parentGasUsed:
|
|
||||||
# If the parent block used more gas than its target, the baseFee should
|
|
||||||
# increase.
|
|
||||||
let
|
|
||||||
gasUsedDelta = (parentGasUsed - parGasTrg).uint64
|
|
||||||
baseFeeDelta = (parentBaseFee * gasUsedDelta) div parGasDenom
|
|
||||||
|
|
||||||
return (parentBaseFee + max(1u64, baseFeeDelta)).GasPrice
|
|
||||||
|
|
||||||
# Otherwise if the parent block used less gas than its target, the
|
|
||||||
# baseFee should decrease.
|
|
||||||
let
|
|
||||||
gasUsedDelta = (parGasTrg - parentGasUsed).uint64
|
|
||||||
baseFeeDelta = (parentBaseFee * gasUsedDelta) div parGasDenom
|
|
||||||
|
|
||||||
if baseFeeDelta < parentBaseFee:
|
|
||||||
return (parentBaseFee - baseFeeDelta).GasPrice
|
|
||||||
|
|
||||||
0.GasPrice
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# End
|
# End
|
||||||
|
Loading…
x
Reference in New Issue
Block a user