diff --git a/hive_integration/nimbus/mapper.jq b/hive_integration/nimbus/mapper.jq index 5526eac1a..ea7f2a0fe 100644 --- a/hive_integration/nimbus/mapper.jq +++ b/hive_integration/nimbus/mapper.jq @@ -64,5 +64,6 @@ def to_bool: "istanbulBlock": env.HIVE_FORK_ISTANBUL|to_int, "muirGlacierBlock": env.HIVE_FORK_MUIR_GLACIER|to_int, "berlinBlock": env.HIVE_FORK_BERLIN|to_int + "londonBlock": env.HIVE_FORK_LONDON|to_int }|remove_empty } diff --git a/hive_integration/nimbus/nimbus.sh b/hive_integration/nimbus/nimbus.sh index 279cdad10..f2acf4e77 100644 --- a/hive_integration/nimbus/nimbus.sh +++ b/hive_integration/nimbus/nimbus.sh @@ -30,6 +30,7 @@ # - [x] HIVE_FORK_ISTANBUL block number for Istanbul transition # - [x] HIVE_FORK_MUIRGLACIER block number for Muir Glacier transition # - [x] HIVE_FORK_BERLIN block number for Berlin transition +# - [x] HIVE_FORK_LONDON block number for London transition # # Clique PoA: # diff --git a/nimbus/chain_config.nim b/nimbus/chain_config.nim index 78d599623..e7ddca78c 100644 --- a/nimbus/chain_config.nim +++ b/nimbus/chain_config.nim @@ -32,6 +32,7 @@ type istanbulBlock : Option[BlockNumber] muirGlacierBlock : Option[BlockNumber] berlinBlock : Option[BlockNumber] + londonBlock : Option[BlockNumber] ChainConfig* = object chainId* : ChainId @@ -52,6 +53,7 @@ type istanbulBlock* : BlockNumber muirGlacierBlock* : BlockNumber berlinBlock* : BlockNumber + londonBlock* : BlockNumber # TODO: this need to be fixed somehow # 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 return false - validateFork(berlinBlock, high(BlockNumber).toBlockNumber) + validateFork(londonBlock, high(BlockNumber).toBlockNumber) + validateFork(berlinBlock, cg.config.londonBlock) validateFork(muirGlacierBlock, cg.config.berlinBlock) validateFork(istanbulBlock, cg.config.muirGlacierBlock) validateFork(petersburgBlock, cg.config.istanbulBlock) diff --git a/nimbus/config.nim b/nimbus/config.nim index dca5eb8d9..b7a698b9a 100644 --- a/nimbus/config.nim +++ b/nimbus/config.nim @@ -159,7 +159,8 @@ proc `$`*(c: ChainId): string = $(c.int) 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.petersburgBlock: FkPetersburg 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 istanbulBlock: 9_069_000.toBlockNumber, # 08/12/2019 12:25:09 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: ChainConfig( @@ -207,7 +209,8 @@ proc chainConfig*(id: NetworkId): ChainConfig = petersburgBlock:4_939_394.toBlockNumber, istanbulBlock: 6_485_846.toBlockNumber, muirGlacierBlock: 7_117_117.toBlockNumber, - berlinBlock: 9_812_189.toBlockNumber + berlinBlock: 9_812_189.toBlockNumber, + londonBlock: high(BlockNumber) ) of RinkebyNet: ChainConfig( @@ -224,7 +227,8 @@ proc chainConfig*(id: NetworkId): ChainConfig = petersburgBlock:4_321_234.toBlockNumber, istanbulBlock: 5_435_345.toBlockNumber, 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: ChainConfig( @@ -241,7 +245,8 @@ proc chainConfig*(id: NetworkId): ChainConfig = petersburgBlock: 0.toBlockNumber, istanbulBlock: 1_561_651.toBlockNumber, muirGlacierBlock: 4_460_644.toBlockNumber, # never occured in goerli network - berlinBlock: 4_460_644.toBlockNumber + berlinBlock: 4_460_644.toBlockNumber, + londonBlock: high(BlockNumber) ) else: # everything else will use CustomNet config diff --git a/nimbus/forks.nim b/nimbus/forks.nim index a49601acc..12ac040f2 100644 --- a/nimbus/forks.nim +++ b/nimbus/forks.nim @@ -17,3 +17,4 @@ type FkPetersburg = "Petersburg" FkIstanbul = "Istanbul" FkBerlin = "Berlin" + FkLondon = "London" diff --git a/nimbus/p2p/chain.nim b/nimbus/p2p/chain.nim index ff1d101e8..e831a08ba 100644 --- a/nimbus/p2p/chain.nim +++ b/nimbus/p2p/chain.nim @@ -30,7 +30,8 @@ type Petersburg, Istanbul, MuirGlacier, - Berlin + Berlin, + London Chain* = ref object of AbstractChainDB db: BaseChainDB @@ -40,7 +41,8 @@ type extraValidation: bool 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.istanbulBlock: Istanbul elif number >= c.petersburgBlock: Petersburg @@ -71,6 +73,7 @@ func getNextFork(c: ChainConfig, fork: ChainFork): uint64 = toNextFork(c.istanbulBlock), toNextFork(c.muirGlacierBlock), toNextFork(c.berlinBlock), + toNextFork(c.londonBlock) ] if fork == high(ChainFork): diff --git a/nimbus/p2p/clique/clique_utils.nim b/nimbus/p2p/clique/clique_utils.nim index c07402f66..d895226e3 100644 --- a/nimbus/p2p/clique/clique_utils.nim +++ b/nimbus/p2p/clique/clique_utils.nim @@ -151,8 +151,7 @@ proc validateGasLimit*(c: var BaseChainDB; header: BlockHeader): CliqueResult {. # params/config.go(450): func (c *ChainConfig) IsLondon(num [..] proc isLondonOrLater*(c: var ChainConfig; number: BlockNumber): bool = - ## FIXME: London is not defined yet, will come after Berlin - FkBerlin < c.toFork(number) + c.toFork(number) >= FkLondon # consensus/misc/eip1559.go(55): func CalcBaseFee(config [..] proc calc1599BaseFee*(c: var ChainConfig; parent: BlockHeader): UInt256 = diff --git a/nimbus/p2p/executor.nim b/nimbus/p2p/executor.nim index 1e34248cd..0d4880ee4 100644 --- a/nimbus/p2p/executor.nim +++ b/nimbus/p2p/executor.nim @@ -90,7 +90,8 @@ const eth2, # FkConstantinople eth2, # FkPetersburg eth2, # FkIstanbul - eth2 # FkBerlin + eth2, # FkBerlin + eth2 # FkLondon ] proc calculateReward(fork: Fork, header: BlockHeader, body: BlockBody, vmState: BaseVMState) = diff --git a/nimbus/vm/evmc_api.nim b/nimbus/vm/evmc_api.nim index 61e2ab687..789af5f84 100644 --- a/nimbus/vm/evmc_api.nim +++ b/nimbus/vm/evmc_api.nim @@ -25,6 +25,7 @@ type block_gas_limit* : int64 # The block gas limit. block_difficulty*: evmc_uint256be # The block difficulty. chain_id* : evmc_uint256be # The blockchain's ChainID. + block_base_fee* : evmc_uint256be # The block base fee. nimbus_message* = object kind*: evmc_call_kind diff --git a/nimbus/vm/evmc_host.nim b/nimbus/vm/evmc_host.nim index e0c315676..65a1f5938 100644 --- a/nimbus/vm/evmc_host.nim +++ b/nimbus/vm/evmc_host.nim @@ -33,7 +33,7 @@ proc hostGetStorageImpl(ctx: Computation, address: EthAddress, key: var evmc_byt ctx.vmState.accountDB.getStorage(address, Uint256.fromEvmc(key)).toEvmc() 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, key, value: var evmc_bytes32): evmc_storage_status {.cdecl.} = diff --git a/nimbus/vm/interpreter/gas_costs.nim b/nimbus/vm/interpreter/gas_costs.nim index ad0126c23..78eb96cec 100644 --- a/nimbus/vm/interpreter/gas_costs.nim +++ b/nimbus/vm/interpreter/gas_costs.nim @@ -738,7 +738,8 @@ const FkConstantinople: SpuriousGasFees, FkPetersburg: SpuriousGasFees, FkIstanbul: IstanbulGasFees, - FkBerlin: BerlinGasFees + FkBerlin: BerlinGasFees, + FkLondon: BerlinGasFees ] @@ -749,6 +750,7 @@ gasCosts(FkSpurious, spurious, SpuriousGasCosts) gasCosts(FkConstantinople, constantinople, ConstantinopleGasCosts) gasCosts(FkIstanbul, istanbul, IstanbulGasCosts) gasCosts(FkBerlin, berlin, BerlinGasCosts) +gasCosts(FkLondon, london, LondonGasCosts) proc forkToSchedule*(fork: Fork): GasCosts = if fork < FkHomestead: @@ -763,8 +765,10 @@ proc forkToSchedule*(fork: Fork): GasCosts = SpuriousGasCosts elif fork < FkBerlin: IstanbulGasCosts - else: + elif fork < FkLondon: BerlinGasCosts + else: + LondonGasCosts const ## Precompile costs diff --git a/nimbus/vm/interpreter_dispatch.nim b/nimbus/vm/interpreter_dispatch.nim index adf6ca0da..7f8ab2312 100644 --- a/nimbus/vm/interpreter_dispatch.nim +++ b/nimbus/vm/interpreter_dispatch.nim @@ -231,7 +231,7 @@ let IstanbulOpDispatch {.compileTime.}: array[Op, NimNode] = genIstanbulJumpTabl proc genBerlinJumpTable(ops: array[Op, NimNode]): array[Op, NimNode] {.compileTime.} = result = ops - # EIP-2315: temporary disabled + # EIP-2315: temporary disabled # Reason : not included in berlin hard fork #result[BeginSub] = newIdentNode "beginSub" @@ -248,6 +248,12 @@ proc genBerlinJumpTable(ops: array[Op, NimNode]): array[Op, NimNode] {.compileTi 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 = let instr = quote do: `c`.instr @@ -336,6 +342,9 @@ macro genIstanbulDispatch(c: Computation): untyped = macro genBerlinDispatch(c: Computation): untyped = result = opTableToCaseStmt(BerlinOpDispatch, c) +macro genLondonDispatch(c: Computation): untyped = + result = opTableToCaseStmt(LondonOpDispatch, c) + proc frontierVM(c: Computation) = genFrontierDispatch(c) @@ -363,6 +372,9 @@ proc istanbulVM(c: Computation) {.gcsafe.} = proc berlinVM(c: Computation) {.gcsafe.} = genBerlinDispatch(c) +proc londonVM(c: Computation) {.gcsafe.} = + genLondonDispatch(c) + proc selectVM(c: Computation, fork: Fork) {.gcsafe.} = # TODO: Optimise getting fork and updating opCodeExec only when necessary case fork @@ -382,8 +394,10 @@ proc selectVM(c: Computation, fork: Fork) {.gcsafe.} = c.petersburgVM() of FkIstanbul: c.istanbulVM() - else: + of FkBerlin: c.berlinVM() + else: + c.londonVM() proc executeOpcodes(c: Computation) = let fork = c.fork diff --git a/nimbus/vm2/interpreter/gas_costs.nim b/nimbus/vm2/interpreter/gas_costs.nim index 415fe375c..70af68bda 100644 --- a/nimbus/vm2/interpreter/gas_costs.nim +++ b/nimbus/vm2/interpreter/gas_costs.nim @@ -708,7 +708,8 @@ const FkConstantinople: SpuriousGasFees, FkPetersburg: SpuriousGasFees, FkIstanbul: IstanbulGasFees, - FkBerlin: BerlinGasFees + FkBerlin: BerlinGasFees, + FkLondon: BerlinGasFees ] @@ -719,6 +720,7 @@ gasCosts(FkSpurious, spurious, SpuriousGasCosts) gasCosts(FkConstantinople, constantinople, ConstantinopleGasCosts) gasCosts(FkIstanbul, istanbul, IstanbulGasCosts) gasCosts(FkBerlin, berlin, BerlinGasCosts) +gasCosts(FkLondon, london, LondonGasCosts) proc forkToSchedule*(fork: Fork): GasCosts = if fork < FkHomestead: @@ -733,8 +735,10 @@ proc forkToSchedule*(fork: Fork): GasCosts = SpuriousGasCosts elif fork < FkBerlin: IstanbulGasCosts - else: + elif fork < FkLondon: BerlinGasCosts + else: + LondonGasCosts const ## Precompile costs diff --git a/nimbus/vm2/interpreter/op_handlers/oph_defs.nim b/nimbus/vm2/interpreter/op_handlers/oph_defs.nim index 26f67cf76..da222cd21 100644 --- a/nimbus/vm2/interpreter/op_handlers/oph_defs.nim +++ b/nimbus/vm2/interpreter/op_handlers/oph_defs.nim @@ -78,6 +78,9 @@ const Vm2OpBerlinAndLater* = Vm2OpIstanbulAndLater - {FkIstanbul} + Vm2OpLondonAndLater* = + Vm2OpBerlinAndLater - {FkBerlin} + # ------------------------------------------------------------------------------ # End # ------------------------------------------------------------------------------