mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-12 21:34:33 +00:00
preparation for London hard fork
This preparation is needed for subsequent EIPs included in London. - Add London to Fork enum - Block number to fork - Parsing London fork in chain config - Prepare gas costs table for London - Prepare EVM opcode dispatcher for London - Block rewards for London - Prepare hive script for London
This commit is contained in:
parent
b5de442d33
commit
5159ad7aac
@ -64,5 +64,6 @@ def to_bool:
|
|||||||
"istanbulBlock": env.HIVE_FORK_ISTANBUL|to_int,
|
"istanbulBlock": env.HIVE_FORK_ISTANBUL|to_int,
|
||||||
"muirGlacierBlock": env.HIVE_FORK_MUIR_GLACIER|to_int,
|
"muirGlacierBlock": env.HIVE_FORK_MUIR_GLACIER|to_int,
|
||||||
"berlinBlock": env.HIVE_FORK_BERLIN|to_int
|
"berlinBlock": env.HIVE_FORK_BERLIN|to_int
|
||||||
|
"londonBlock": env.HIVE_FORK_LONDON|to_int
|
||||||
}|remove_empty
|
}|remove_empty
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
# - [x] HIVE_FORK_ISTANBUL block number for Istanbul transition
|
# - [x] HIVE_FORK_ISTANBUL block number for Istanbul transition
|
||||||
# - [x] HIVE_FORK_MUIRGLACIER block number for Muir Glacier transition
|
# - [x] HIVE_FORK_MUIRGLACIER block number for Muir Glacier transition
|
||||||
# - [x] HIVE_FORK_BERLIN block number for Berlin transition
|
# - [x] HIVE_FORK_BERLIN block number for Berlin transition
|
||||||
|
# - [x] HIVE_FORK_LONDON block number for London transition
|
||||||
#
|
#
|
||||||
# Clique PoA:
|
# Clique PoA:
|
||||||
#
|
#
|
||||||
|
@ -32,6 +32,7 @@ type
|
|||||||
istanbulBlock : Option[BlockNumber]
|
istanbulBlock : Option[BlockNumber]
|
||||||
muirGlacierBlock : Option[BlockNumber]
|
muirGlacierBlock : Option[BlockNumber]
|
||||||
berlinBlock : Option[BlockNumber]
|
berlinBlock : Option[BlockNumber]
|
||||||
|
londonBlock : Option[BlockNumber]
|
||||||
|
|
||||||
ChainConfig* = object
|
ChainConfig* = object
|
||||||
chainId* : ChainId
|
chainId* : ChainId
|
||||||
@ -52,6 +53,7 @@ type
|
|||||||
istanbulBlock* : BlockNumber
|
istanbulBlock* : BlockNumber
|
||||||
muirGlacierBlock* : BlockNumber
|
muirGlacierBlock* : BlockNumber
|
||||||
berlinBlock* : BlockNumber
|
berlinBlock* : BlockNumber
|
||||||
|
londonBlock* : BlockNumber
|
||||||
|
|
||||||
# TODO: this need to be fixed somehow
|
# TODO: this need to be fixed somehow
|
||||||
# using `real` engine configuration
|
# using `real` engine configuration
|
||||||
@ -174,7 +176,8 @@ proc loadCustomGenesis*(fileName: string, cg: var CustomGenesis): bool =
|
|||||||
error "Forks can't be assigned out of order", fork=fork
|
error "Forks can't be assigned out of order", fork=fork
|
||||||
return false
|
return false
|
||||||
|
|
||||||
validateFork(berlinBlock, high(BlockNumber).toBlockNumber)
|
validateFork(londonBlock, high(BlockNumber).toBlockNumber)
|
||||||
|
validateFork(berlinBlock, cg.config.londonBlock)
|
||||||
validateFork(muirGlacierBlock, cg.config.berlinBlock)
|
validateFork(muirGlacierBlock, cg.config.berlinBlock)
|
||||||
validateFork(istanbulBlock, cg.config.muirGlacierBlock)
|
validateFork(istanbulBlock, cg.config.muirGlacierBlock)
|
||||||
validateFork(petersburgBlock, cg.config.istanbulBlock)
|
validateFork(petersburgBlock, cg.config.istanbulBlock)
|
||||||
|
@ -159,7 +159,8 @@ proc `$`*(c: ChainId): string =
|
|||||||
$(c.int)
|
$(c.int)
|
||||||
|
|
||||||
proc toFork*(c: ChainConfig, number: BlockNumber): Fork =
|
proc toFork*(c: ChainConfig, number: BlockNumber): Fork =
|
||||||
if number >= c.berlinBlock: FkBerlin
|
if number >= c.londonBlock: FkLondon
|
||||||
|
elif number >= c.berlinBlock: FkBerlin
|
||||||
elif number >= c.istanbulBlock: FkIstanbul
|
elif number >= c.istanbulBlock: FkIstanbul
|
||||||
elif number >= c.petersburgBlock: FkPetersburg
|
elif number >= c.petersburgBlock: FkPetersburg
|
||||||
elif number >= c.constantinopleBlock: FkConstantinople
|
elif number >= c.constantinopleBlock: FkConstantinople
|
||||||
@ -190,7 +191,8 @@ proc chainConfig*(id: NetworkId): ChainConfig =
|
|||||||
petersburgBlock:7_280_000.toBlockNumber, # 28/02/2019 07:52:04
|
petersburgBlock:7_280_000.toBlockNumber, # 28/02/2019 07:52:04
|
||||||
istanbulBlock: 9_069_000.toBlockNumber, # 08/12/2019 12:25:09
|
istanbulBlock: 9_069_000.toBlockNumber, # 08/12/2019 12:25:09
|
||||||
muirGlacierBlock: 9_200_000.toBlockNumber, # 02/01/2020 08:30:49
|
muirGlacierBlock: 9_200_000.toBlockNumber, # 02/01/2020 08:30:49
|
||||||
berlinBlock: 12_244_000.toBlockNumber # 15/04/2021 10:07:03
|
berlinBlock: 12_244_000.toBlockNumber, # 15/04/2021 10:07:03
|
||||||
|
londonBlock: high(BlockNumber)
|
||||||
)
|
)
|
||||||
of RopstenNet:
|
of RopstenNet:
|
||||||
ChainConfig(
|
ChainConfig(
|
||||||
@ -207,7 +209,8 @@ proc chainConfig*(id: NetworkId): ChainConfig =
|
|||||||
petersburgBlock:4_939_394.toBlockNumber,
|
petersburgBlock:4_939_394.toBlockNumber,
|
||||||
istanbulBlock: 6_485_846.toBlockNumber,
|
istanbulBlock: 6_485_846.toBlockNumber,
|
||||||
muirGlacierBlock: 7_117_117.toBlockNumber,
|
muirGlacierBlock: 7_117_117.toBlockNumber,
|
||||||
berlinBlock: 9_812_189.toBlockNumber
|
berlinBlock: 9_812_189.toBlockNumber,
|
||||||
|
londonBlock: high(BlockNumber)
|
||||||
)
|
)
|
||||||
of RinkebyNet:
|
of RinkebyNet:
|
||||||
ChainConfig(
|
ChainConfig(
|
||||||
@ -224,7 +227,8 @@ proc chainConfig*(id: NetworkId): ChainConfig =
|
|||||||
petersburgBlock:4_321_234.toBlockNumber,
|
petersburgBlock:4_321_234.toBlockNumber,
|
||||||
istanbulBlock: 5_435_345.toBlockNumber,
|
istanbulBlock: 5_435_345.toBlockNumber,
|
||||||
muirGlacierBlock: 8_290_928.toBlockNumber, # never occured in rinkeby network
|
muirGlacierBlock: 8_290_928.toBlockNumber, # never occured in rinkeby network
|
||||||
berlinBlock: 8_290_928.toBlockNumber
|
berlinBlock: 8_290_928.toBlockNumber,
|
||||||
|
londonBlock: high(BlockNumber)
|
||||||
)
|
)
|
||||||
of GoerliNet:
|
of GoerliNet:
|
||||||
ChainConfig(
|
ChainConfig(
|
||||||
@ -241,7 +245,8 @@ proc chainConfig*(id: NetworkId): ChainConfig =
|
|||||||
petersburgBlock: 0.toBlockNumber,
|
petersburgBlock: 0.toBlockNumber,
|
||||||
istanbulBlock: 1_561_651.toBlockNumber,
|
istanbulBlock: 1_561_651.toBlockNumber,
|
||||||
muirGlacierBlock: 4_460_644.toBlockNumber, # never occured in goerli network
|
muirGlacierBlock: 4_460_644.toBlockNumber, # never occured in goerli network
|
||||||
berlinBlock: 4_460_644.toBlockNumber
|
berlinBlock: 4_460_644.toBlockNumber,
|
||||||
|
londonBlock: high(BlockNumber)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
# everything else will use CustomNet config
|
# everything else will use CustomNet config
|
||||||
|
@ -17,3 +17,4 @@ type
|
|||||||
FkPetersburg = "Petersburg"
|
FkPetersburg = "Petersburg"
|
||||||
FkIstanbul = "Istanbul"
|
FkIstanbul = "Istanbul"
|
||||||
FkBerlin = "Berlin"
|
FkBerlin = "Berlin"
|
||||||
|
FkLondon = "London"
|
||||||
|
@ -30,7 +30,8 @@ type
|
|||||||
Petersburg,
|
Petersburg,
|
||||||
Istanbul,
|
Istanbul,
|
||||||
MuirGlacier,
|
MuirGlacier,
|
||||||
Berlin
|
Berlin,
|
||||||
|
London
|
||||||
|
|
||||||
Chain* = ref object of AbstractChainDB
|
Chain* = ref object of AbstractChainDB
|
||||||
db: BaseChainDB
|
db: BaseChainDB
|
||||||
@ -40,7 +41,8 @@ type
|
|||||||
extraValidation: bool
|
extraValidation: bool
|
||||||
|
|
||||||
func toChainFork(c: ChainConfig, number: BlockNumber): ChainFork =
|
func toChainFork(c: ChainConfig, number: BlockNumber): ChainFork =
|
||||||
if number >= c.berlinBlock: Berlin
|
if number >= c.londonBlock: London
|
||||||
|
elif number >= c.berlinBlock: Berlin
|
||||||
elif number >= c.muirGlacierBlock: MuirGlacier
|
elif number >= c.muirGlacierBlock: MuirGlacier
|
||||||
elif number >= c.istanbulBlock: Istanbul
|
elif number >= c.istanbulBlock: Istanbul
|
||||||
elif number >= c.petersburgBlock: Petersburg
|
elif number >= c.petersburgBlock: Petersburg
|
||||||
@ -71,6 +73,7 @@ func getNextFork(c: ChainConfig, fork: ChainFork): uint64 =
|
|||||||
toNextFork(c.istanbulBlock),
|
toNextFork(c.istanbulBlock),
|
||||||
toNextFork(c.muirGlacierBlock),
|
toNextFork(c.muirGlacierBlock),
|
||||||
toNextFork(c.berlinBlock),
|
toNextFork(c.berlinBlock),
|
||||||
|
toNextFork(c.londonBlock)
|
||||||
]
|
]
|
||||||
|
|
||||||
if fork == high(ChainFork):
|
if fork == high(ChainFork):
|
||||||
|
@ -151,8 +151,7 @@ proc validateGasLimit*(c: var BaseChainDB; header: BlockHeader): CliqueResult {.
|
|||||||
|
|
||||||
# params/config.go(450): func (c *ChainConfig) IsLondon(num [..]
|
# params/config.go(450): func (c *ChainConfig) IsLondon(num [..]
|
||||||
proc isLondonOrLater*(c: var ChainConfig; number: BlockNumber): bool =
|
proc isLondonOrLater*(c: var ChainConfig; number: BlockNumber): bool =
|
||||||
## FIXME: London is not defined yet, will come after Berlin
|
c.toFork(number) >= FkLondon
|
||||||
FkBerlin < c.toFork(number)
|
|
||||||
|
|
||||||
# consensus/misc/eip1559.go(55): func CalcBaseFee(config [..]
|
# consensus/misc/eip1559.go(55): func CalcBaseFee(config [..]
|
||||||
proc calc1599BaseFee*(c: var ChainConfig; parent: BlockHeader): UInt256 =
|
proc calc1599BaseFee*(c: var ChainConfig; parent: BlockHeader): UInt256 =
|
||||||
|
@ -90,7 +90,8 @@ const
|
|||||||
eth2, # FkConstantinople
|
eth2, # FkConstantinople
|
||||||
eth2, # FkPetersburg
|
eth2, # FkPetersburg
|
||||||
eth2, # FkIstanbul
|
eth2, # FkIstanbul
|
||||||
eth2 # FkBerlin
|
eth2, # FkBerlin
|
||||||
|
eth2 # FkLondon
|
||||||
]
|
]
|
||||||
|
|
||||||
proc calculateReward(fork: Fork, header: BlockHeader, body: BlockBody, vmState: BaseVMState) =
|
proc calculateReward(fork: Fork, header: BlockHeader, body: BlockBody, vmState: BaseVMState) =
|
||||||
|
@ -25,6 +25,7 @@ type
|
|||||||
block_gas_limit* : int64 # The block gas limit.
|
block_gas_limit* : int64 # The block gas limit.
|
||||||
block_difficulty*: evmc_uint256be # The block difficulty.
|
block_difficulty*: evmc_uint256be # The block difficulty.
|
||||||
chain_id* : evmc_uint256be # The blockchain's ChainID.
|
chain_id* : evmc_uint256be # The blockchain's ChainID.
|
||||||
|
block_base_fee* : evmc_uint256be # The block base fee.
|
||||||
|
|
||||||
nimbus_message* = object
|
nimbus_message* = object
|
||||||
kind*: evmc_call_kind
|
kind*: evmc_call_kind
|
||||||
|
@ -33,7 +33,7 @@ proc hostGetStorageImpl(ctx: Computation, address: EthAddress, key: var evmc_byt
|
|||||||
ctx.vmState.accountDB.getStorage(address, Uint256.fromEvmc(key)).toEvmc()
|
ctx.vmState.accountDB.getStorage(address, Uint256.fromEvmc(key)).toEvmc()
|
||||||
|
|
||||||
proc sstoreNetGasMetering(ctx: Computation): bool {.inline.} =
|
proc sstoreNetGasMetering(ctx: Computation): bool {.inline.} =
|
||||||
ctx.fork in {FkConstantinople, FkIstanbul, FkBerlin}
|
ctx.fork in {FkConstantinople, FkIstanbul, FkBerlin, FkLondon}
|
||||||
|
|
||||||
proc hostSetStorageImpl(ctx: Computation, address: EthAddress,
|
proc hostSetStorageImpl(ctx: Computation, address: EthAddress,
|
||||||
key, value: var evmc_bytes32): evmc_storage_status {.cdecl.} =
|
key, value: var evmc_bytes32): evmc_storage_status {.cdecl.} =
|
||||||
|
@ -738,7 +738,8 @@ const
|
|||||||
FkConstantinople: SpuriousGasFees,
|
FkConstantinople: SpuriousGasFees,
|
||||||
FkPetersburg: SpuriousGasFees,
|
FkPetersburg: SpuriousGasFees,
|
||||||
FkIstanbul: IstanbulGasFees,
|
FkIstanbul: IstanbulGasFees,
|
||||||
FkBerlin: BerlinGasFees
|
FkBerlin: BerlinGasFees,
|
||||||
|
FkLondon: BerlinGasFees
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@ -749,6 +750,7 @@ gasCosts(FkSpurious, spurious, SpuriousGasCosts)
|
|||||||
gasCosts(FkConstantinople, constantinople, ConstantinopleGasCosts)
|
gasCosts(FkConstantinople, constantinople, ConstantinopleGasCosts)
|
||||||
gasCosts(FkIstanbul, istanbul, IstanbulGasCosts)
|
gasCosts(FkIstanbul, istanbul, IstanbulGasCosts)
|
||||||
gasCosts(FkBerlin, berlin, BerlinGasCosts)
|
gasCosts(FkBerlin, berlin, BerlinGasCosts)
|
||||||
|
gasCosts(FkLondon, london, LondonGasCosts)
|
||||||
|
|
||||||
proc forkToSchedule*(fork: Fork): GasCosts =
|
proc forkToSchedule*(fork: Fork): GasCosts =
|
||||||
if fork < FkHomestead:
|
if fork < FkHomestead:
|
||||||
@ -763,8 +765,10 @@ proc forkToSchedule*(fork: Fork): GasCosts =
|
|||||||
SpuriousGasCosts
|
SpuriousGasCosts
|
||||||
elif fork < FkBerlin:
|
elif fork < FkBerlin:
|
||||||
IstanbulGasCosts
|
IstanbulGasCosts
|
||||||
else:
|
elif fork < FkLondon:
|
||||||
BerlinGasCosts
|
BerlinGasCosts
|
||||||
|
else:
|
||||||
|
LondonGasCosts
|
||||||
|
|
||||||
const
|
const
|
||||||
## Precompile costs
|
## Precompile costs
|
||||||
|
@ -248,6 +248,12 @@ proc genBerlinJumpTable(ops: array[Op, NimNode]): array[Op, NimNode] {.compileTi
|
|||||||
|
|
||||||
let BerlinOpDispatch {.compileTime.}: array[Op, NimNode] = genBerlinJumpTable(IstanbulOpDispatch)
|
let BerlinOpDispatch {.compileTime.}: array[Op, NimNode] = genBerlinJumpTable(IstanbulOpDispatch)
|
||||||
|
|
||||||
|
proc genLondonJumpTable(ops: array[Op, NimNode]): array[Op, NimNode] {.compileTime.} =
|
||||||
|
result = ops
|
||||||
|
# incoming EIP-3198 and EIP-3529
|
||||||
|
|
||||||
|
let LondonOpDispatch {.compileTime.}: array[Op, NimNode] = genLondonJumpTable(BerlinOpDispatch)
|
||||||
|
|
||||||
proc opTableToCaseStmt(opTable: array[Op, NimNode], c: NimNode): NimNode =
|
proc opTableToCaseStmt(opTable: array[Op, NimNode], c: NimNode): NimNode =
|
||||||
|
|
||||||
let instr = quote do: `c`.instr
|
let instr = quote do: `c`.instr
|
||||||
@ -336,6 +342,9 @@ macro genIstanbulDispatch(c: Computation): untyped =
|
|||||||
macro genBerlinDispatch(c: Computation): untyped =
|
macro genBerlinDispatch(c: Computation): untyped =
|
||||||
result = opTableToCaseStmt(BerlinOpDispatch, c)
|
result = opTableToCaseStmt(BerlinOpDispatch, c)
|
||||||
|
|
||||||
|
macro genLondonDispatch(c: Computation): untyped =
|
||||||
|
result = opTableToCaseStmt(LondonOpDispatch, c)
|
||||||
|
|
||||||
proc frontierVM(c: Computation) =
|
proc frontierVM(c: Computation) =
|
||||||
genFrontierDispatch(c)
|
genFrontierDispatch(c)
|
||||||
|
|
||||||
@ -363,6 +372,9 @@ proc istanbulVM(c: Computation) {.gcsafe.} =
|
|||||||
proc berlinVM(c: Computation) {.gcsafe.} =
|
proc berlinVM(c: Computation) {.gcsafe.} =
|
||||||
genBerlinDispatch(c)
|
genBerlinDispatch(c)
|
||||||
|
|
||||||
|
proc londonVM(c: Computation) {.gcsafe.} =
|
||||||
|
genLondonDispatch(c)
|
||||||
|
|
||||||
proc selectVM(c: Computation, fork: Fork) {.gcsafe.} =
|
proc selectVM(c: Computation, fork: Fork) {.gcsafe.} =
|
||||||
# TODO: Optimise getting fork and updating opCodeExec only when necessary
|
# TODO: Optimise getting fork and updating opCodeExec only when necessary
|
||||||
case fork
|
case fork
|
||||||
@ -382,8 +394,10 @@ proc selectVM(c: Computation, fork: Fork) {.gcsafe.} =
|
|||||||
c.petersburgVM()
|
c.petersburgVM()
|
||||||
of FkIstanbul:
|
of FkIstanbul:
|
||||||
c.istanbulVM()
|
c.istanbulVM()
|
||||||
else:
|
of FkBerlin:
|
||||||
c.berlinVM()
|
c.berlinVM()
|
||||||
|
else:
|
||||||
|
c.londonVM()
|
||||||
|
|
||||||
proc executeOpcodes(c: Computation) =
|
proc executeOpcodes(c: Computation) =
|
||||||
let fork = c.fork
|
let fork = c.fork
|
||||||
|
@ -708,7 +708,8 @@ const
|
|||||||
FkConstantinople: SpuriousGasFees,
|
FkConstantinople: SpuriousGasFees,
|
||||||
FkPetersburg: SpuriousGasFees,
|
FkPetersburg: SpuriousGasFees,
|
||||||
FkIstanbul: IstanbulGasFees,
|
FkIstanbul: IstanbulGasFees,
|
||||||
FkBerlin: BerlinGasFees
|
FkBerlin: BerlinGasFees,
|
||||||
|
FkLondon: BerlinGasFees
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@ -719,6 +720,7 @@ gasCosts(FkSpurious, spurious, SpuriousGasCosts)
|
|||||||
gasCosts(FkConstantinople, constantinople, ConstantinopleGasCosts)
|
gasCosts(FkConstantinople, constantinople, ConstantinopleGasCosts)
|
||||||
gasCosts(FkIstanbul, istanbul, IstanbulGasCosts)
|
gasCosts(FkIstanbul, istanbul, IstanbulGasCosts)
|
||||||
gasCosts(FkBerlin, berlin, BerlinGasCosts)
|
gasCosts(FkBerlin, berlin, BerlinGasCosts)
|
||||||
|
gasCosts(FkLondon, london, LondonGasCosts)
|
||||||
|
|
||||||
proc forkToSchedule*(fork: Fork): GasCosts =
|
proc forkToSchedule*(fork: Fork): GasCosts =
|
||||||
if fork < FkHomestead:
|
if fork < FkHomestead:
|
||||||
@ -733,8 +735,10 @@ proc forkToSchedule*(fork: Fork): GasCosts =
|
|||||||
SpuriousGasCosts
|
SpuriousGasCosts
|
||||||
elif fork < FkBerlin:
|
elif fork < FkBerlin:
|
||||||
IstanbulGasCosts
|
IstanbulGasCosts
|
||||||
else:
|
elif fork < FkLondon:
|
||||||
BerlinGasCosts
|
BerlinGasCosts
|
||||||
|
else:
|
||||||
|
LondonGasCosts
|
||||||
|
|
||||||
const
|
const
|
||||||
## Precompile costs
|
## Precompile costs
|
||||||
|
@ -78,6 +78,9 @@ const
|
|||||||
Vm2OpBerlinAndLater* =
|
Vm2OpBerlinAndLater* =
|
||||||
Vm2OpIstanbulAndLater - {FkIstanbul}
|
Vm2OpIstanbulAndLater - {FkIstanbul}
|
||||||
|
|
||||||
|
Vm2OpLondonAndLater* =
|
||||||
|
Vm2OpBerlinAndLater - {FkBerlin}
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# End
|
# End
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
Loading…
x
Reference in New Issue
Block a user