move isLondon to chain_config.nim

This commit is contained in:
jangko 2022-10-20 09:44:16 +07:00
parent 306143f3d1
commit 93a05ad513
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
3 changed files with 9 additions and 14 deletions

View File

@ -549,3 +549,6 @@ proc `==`*(a, b: ChainConfig): bool =
if a.isNil and not b.isNil: return false if a.isNil and not b.isNil: return false
if not a.isNil and b.isNil: return false if not a.isNil and b.isNil: return false
a[] == b[] a[] == b[]
proc isLondon*(c: ChainConfig, number: BlockNumber): bool {.inline.} =
number >= c.londonBlock

View File

@ -14,8 +14,7 @@ import
eth/[common, eip1559], eth/[common, eip1559],
../db/db_chain, ../db/db_chain,
../constants, ../constants,
../chain_config, ../chain_config
../forks
export export
eip1559 eip1559
@ -55,17 +54,13 @@ proc validateGasLimit(c: BaseChainDB; header: BlockHeader): Result[void, string]
# Eip 1559 support # Eip 1559 support
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# params/config.go(450): func (c *ChainConfig) IsLondon(num [..]
proc isLondonOrLater*(c: ChainConfig; number: BlockNumber): bool =
c.toFork(number) >= FkLondon
# consensus/misc/eip1559.go(55): func CalcBaseFee(config [..] # consensus/misc/eip1559.go(55): func CalcBaseFee(config [..]
proc calcEip1599BaseFee*(c: ChainConfig; parent: BlockHeader): UInt256 = proc calcEip1599BaseFee*(c: ChainConfig; parent: BlockHeader): UInt256 =
## calculates the basefee of the header. ## calculates the basefee of the header.
# If the current block is the first EIP-1559 block, return the # If the current block is the first EIP-1559 block, return the
# initial base fee. # initial base fee.
if c.isLondonOrLater(parent.blockNumber): if c.isLondon(parent.blockNumber):
eip1559.calcEip1599BaseFee(parent.gasLimit, parent.gasUsed, parent.baseFee) eip1559.calcEip1599BaseFee(parent.gasLimit, parent.gasUsed, parent.baseFee)
else: else:
EIP1559_INITIAL_BASE_FEE EIP1559_INITIAL_BASE_FEE
@ -75,7 +70,7 @@ proc verifyEip1559Header(c: ChainConfig;
parent, header: BlockHeader): Result[void, string] parent, header: BlockHeader): Result[void, string]
{.raises: [Defect].} = {.raises: [Defect].} =
## Verify that the gas limit remains within allowed bounds ## Verify that the gas limit remains within allowed bounds
let limit = if c.isLondonOrLater(parent.blockNumber): let limit = if c.isLondon(parent.blockNumber):
parent.gasLimit parent.gasLimit
else: else:
parent.gasLimit * EIP1559_ELASTICITY_MULTIPLIER parent.gasLimit * EIP1559_ELASTICITY_MULTIPLIER
@ -106,7 +101,7 @@ proc validateGasLimitOrBaseFee*(c: BaseChainDB;
header, parent: BlockHeader): Result[void, string] header, parent: BlockHeader): Result[void, string]
{.gcsafe, raises: [Defect].} = {.gcsafe, raises: [Defect].} =
if not c.config.isLondonOrLater(header.blockNumber): if not c.config.isLondon(header.blockNumber):
# Verify BaseFee not present before EIP-1559 fork. # Verify BaseFee not present before EIP-1559 fork.
if not header.baseFee.isZero: if not header.baseFee.isZero:
return err("invalid baseFee before London fork: have " & $header.baseFee & ", want <0>") return err("invalid baseFee before London fork: have " & $header.baseFee & ", want <0>")

View File

@ -87,9 +87,6 @@ proc setPreLondonLimits(gl: var TxChainGasLimits) =
gl.minLimit = gl.gasLimit - delta gl.minLimit = gl.gasLimit - delta
gl.trgLimit = gl.gasLimit gl.trgLimit = gl.gasLimit
proc isLondon(c: ChainConfig, number: BlockNumber): bool {.inline.} =
number >= c.londonBlock
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Public functions # Public functions
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------