From 04c7ed8ec9347164010239b512de732288d06948 Mon Sep 17 00:00:00 2001 From: andri lim Date: Wed, 18 Oct 2023 09:16:11 +0700 Subject: [PATCH] Change EthTime from std.Time to distinct uint64 (#1820) * Change EthTime from std.Time to distinct uint64 * Bump nimbus-eth2 --- fluffy/network/history/history_network.nim | 6 ++-- fluffy/rpc/rpc_eth_api.nim | 2 +- .../beacon_lc_bridge/beacon_lc_bridge.nim | 4 +-- hive_integration/nodocker/engine/clmock.nim | 16 ++++----- .../nodocker/engine/engine_client.nim | 2 +- .../nodocker/engine/exchange_cap_tests.nim | 10 +++--- hive_integration/nodocker/engine/helper.nim | 4 +-- .../engine/withdrawals/wd_base_spec.nim | 7 ++-- .../nodocker/pyspec/pyspec_sim.nim | 3 +- nimbus/beacon/api_handler/api_newpayload.nim | 1 - nimbus/beacon/web3_eth_conv.nim | 8 ++--- nimbus/common/chain_config.nim | 28 +++++++++------ nimbus/common/common.nim | 10 +++--- nimbus/common/hardforks.nim | 6 ++-- nimbus/core/clique.nim | 5 ++- nimbus/core/clique/clique_cfg.nim | 8 ++--- nimbus/core/clique/clique_defs.nim | 2 +- nimbus/core/clique/clique_genvote.nim | 8 ++--- nimbus/core/clique/clique_sealer.nim | 35 ++++++++++--------- nimbus/core/clique/clique_verify.nim | 2 +- nimbus/core/pow/difficulty.nim | 17 +++++---- nimbus/core/pow/header.nim | 2 +- nimbus/core/sealer.nim | 3 +- nimbus/core/tx_pool/tx_chain.nim | 6 ++-- nimbus/core/validate.nim | 4 +-- .../data_sources/json_rpc_data_source.nim | 2 +- nimbus/evm/computation.nim | 6 ++-- nimbus/evm/stack.nim | 4 +-- nimbus/graphql/ethapi.nim | 4 +-- nimbus/rpc/rpc_utils.nim | 4 +-- nimbus/sync/legacy.nim | 2 +- nimbus/transaction/call_evm.nim | 4 +-- nimbus/transaction/host_services.nim | 2 +- nimbus/utils/debug.nim | 6 ++-- nimbus_verified_proxy/rpc/rpc_utils.nim | 2 +- premix/parser.nim | 6 ++-- tests/macro_assembler.nim | 18 +++++----- tests/replay/pp.nim | 6 ++-- tests/test_beacon/setup_env.nim | 2 +- tests/test_blockchain_json.nim | 4 +-- tests/test_clique/pool.nim | 4 +-- tests/test_difficulty.nim | 6 ++-- tests/test_rpc.nim | 2 +- tests/test_txpool.nim | 2 +- tests/test_txpool2.nim | 14 ++++---- tools/common/helpers.nim | 7 ++-- tools/evmstate/helpers.nim | 2 +- tools/t8n/helpers.nim | 2 +- tools/t8n/transition.nim | 2 +- vendor/nim-bearssl | 2 +- vendor/nim-chronicles | 2 +- vendor/nim-eth | 2 +- vendor/nim-http-utils | 2 +- vendor/nim-kzg4844 | 2 +- vendor/nim-libp2p | 2 +- vendor/nim-presto | 2 +- vendor/nim-stint | 2 +- vendor/nim-toml-serialization | 2 +- vendor/nim-web3 | 2 +- vendor/nimbus-eth2 | 2 +- 60 files changed, 169 insertions(+), 165 deletions(-) diff --git a/fluffy/network/history/history_network.nim b/fluffy/network/history/history_network.nim index ddc6bac99..bd379f368 100644 --- a/fluffy/network/history/history_network.nim +++ b/fluffy/network/history/history_network.nim @@ -18,8 +18,6 @@ import ../wire/[portal_protocol, portal_stream, portal_protocol_config], "."/[history_content, accumulator] -from std/times import toUnix - logScope: topics = "portal_hist" @@ -278,7 +276,7 @@ proc validateBlockBodyBytes*( ## header. ## TODO: improve this decoding in combination with the block body validation ## calls. - let timestamp = Moment.init(header.timestamp.toUnix(), Second) + let timestamp = Moment.init(header.timestamp.int64, Second) # TODO: The additional header checks are not needed as header is implicitly # verified by means of the accumulator? Except that we don't use this yet # post merge, so the checks are still useful, for now. @@ -352,7 +350,7 @@ proc get(db: ContentDB, T: type BlockBody, contentId: ContentId, return Opt.none(T) let - timestamp = Moment.init(header.timestamp.toUnix(), Second) + timestamp = Moment.init(header.timestamp.int64, Second) body = if isShanghai(chainConfig, timestamp): BlockBody.fromPortalBlockBodyOrRaise( diff --git a/fluffy/rpc/rpc_eth_api.nim b/fluffy/rpc/rpc_eth_api.nim index cad144bd5..8dc0cff2c 100644 --- a/fluffy/rpc/rpc_eth_api.nim +++ b/fluffy/rpc/rpc_eth_api.nim @@ -93,7 +93,7 @@ func init*( totalDifficulty: encodeQuantity(UInt256.low()), gasLimit: encodeQuantity(header.gasLimit.uint64), gasUsed: encodeQuantity(header.gasUsed.uint64), - timestamp: encodeQuantity(header.timestamp.toUnix.uint64) + timestamp: encodeQuantity(header.timestamp.uint64) ) let size = sizeof(BlockHeader) - sizeof(Blob) + header.extraData.len diff --git a/fluffy/tools/beacon_lc_bridge/beacon_lc_bridge.nim b/fluffy/tools/beacon_lc_bridge/beacon_lc_bridge.nim index e5f20ede6..424e7d216 100644 --- a/fluffy/tools/beacon_lc_bridge/beacon_lc_bridge.nim +++ b/fluffy/tools/beacon_lc_bridge/beacon_lc_bridge.nim @@ -241,7 +241,7 @@ proc asPortalBlockData*( blockNumber: payload.blockNumber.distinctBase.u256, gasLimit: payload.gasLimit.unsafeQuantityToInt64, gasUsed: payload.gasUsed.unsafeQuantityToInt64, - timestamp: fromUnix payload.timestamp.unsafeQuantityToInt64, + timestamp: payload.timestamp.EthTime, extraData: bytes payload.extraData, mixDigest: payload.prevRandao.asEthHash, nonce: default(BlockNonce), @@ -286,7 +286,7 @@ proc asPortalBlockData*( blockNumber: payload.blockNumber.distinctBase.u256, gasLimit: payload.gasLimit.unsafeQuantityToInt64, gasUsed: payload.gasUsed.unsafeQuantityToInt64, - timestamp: fromUnix payload.timestamp.unsafeQuantityToInt64, + timestamp: payload.timestamp.EthTime, extraData: bytes payload.extraData, mixDigest: payload.prevRandao.asEthHash, nonce: default(BlockNonce), diff --git a/hive_integration/nodocker/engine/clmock.nim b/hive_integration/nodocker/engine/clmock.nim index 9a3927648..39dd54aec 100644 --- a/hive_integration/nodocker/engine/clmock.nim +++ b/hive_integration/nodocker/engine/clmock.nim @@ -1,5 +1,5 @@ import - std/[times, tables], + std/[tables], chronicles, nimcrypto/sysrand, stew/[byteutils, endians2], @@ -165,16 +165,16 @@ proc isBlockPoS*(cl: CLMocker, bn: common.BlockNumber): bool = return true # Return the per-block timestamp value increment -func getTimestampIncrement(cl: CLMocker): int = - cl.blockTimestampIncrement.get(1) +func getTimestampIncrement(cl: CLMocker): EthTime = + EthTime cl.blockTimestampIncrement.get(1) # Returns the timestamp value to be included in the next payload attributes -func getNextBlockTimestamp(cl: CLMocker): int64 = +func getNextBlockTimestamp(cl: CLMocker): EthTime = if cl.firstPoSBlockNumber.isNone and cl.transitionPayloadTimestamp.isSome: # We are producing the transition payload and there's a value specified # for this specific payload - return cl.transitionPayloadTimestamp.get - return cl.latestHeader.timestamp.toUnix + cl.getTimestampIncrement().int64 + return EthTime cl.transitionPayloadTimestamp.get + return cl.latestHeader.timestamp + cl.getTimestampIncrement() func setNextWithdrawals(cl: CLMocker, nextWithdrawals: Option[seq[WithdrawalV1]]) = cl.nextWithdrawals = nextWithdrawals @@ -185,11 +185,11 @@ func timestampToBeaconRoot(timestamp: Quantity): FixedBytes[32] = FixedBytes[32](h.data) func isShanghai(cl: CLMocker, timestamp: Quantity): bool = - let ts = fromUnix(timestamp.int64) + let ts = EthTime(timestamp.uint64) cl.com.isShanghaiOrLater(ts) func isCancun(cl: CLMocker, timestamp: Quantity): bool = - let ts = fromUnix(timestamp.int64) + let ts = EthTime(timestamp.uint64) cl.com.isCancunOrLater(ts) # Picks the next payload producer from the set of clients registered diff --git a/hive_integration/nodocker/engine/engine_client.nim b/hive_integration/nodocker/engine/engine_client.nim index d2ab5d280..042ee3de3 100644 --- a/hive_integration/nodocker/engine/engine_client.nim +++ b/hive_integration/nodocker/engine/engine_client.nim @@ -226,7 +226,7 @@ proc toBlockHeader(bc: eth_api.BlockObject): common.BlockHeader = mixDigest : bc.mixHash, gasLimit : hexToInt(string bc.gasLimit, GasInt), gasUsed : hexToInt(string bc.gasUsed, GasInt), - timestamp : initTime(hexToInt(string bc.timestamp, int64), 0), + timestamp : EthTime hexToInt(string bc.timestamp, uint64), fee : maybeU256(bc.baseFeePerGas), withdrawalsRoot: bc.withdrawalsRoot, blobGasUsed : maybeU64(bc.blobGasUsed), diff --git a/hive_integration/nodocker/engine/exchange_cap_tests.nim b/hive_integration/nodocker/engine/exchange_cap_tests.nim index 7f5307c9c..4348919b0 100644 --- a/hive_integration/nodocker/engine/exchange_cap_tests.nim +++ b/hive_integration/nodocker/engine/exchange_cap_tests.nim @@ -1,11 +1,13 @@ import - std/[options, times], + std/[options], + eth/common/eth_types, ./test_env, ./types, chronicles, - ../../tools/common/helpers, ../../nimbus/common/hardforks +import ../../tools/common/helpers except LogLevel + type ECSpec* = ref object of BaseSpec exec*: proc(env: TestEnv): bool @@ -50,11 +52,11 @@ proc ecCancun(env: TestEnv): bool = proc getCCShanghai(timestamp: int): ChainConfig = result = getChainConfig("Shanghai") - result.shanghaiTime = some(fromUnix(timestamp)) + result.shanghaiTime = some(EthTime(timestamp)) proc getCCCancun(timestamp: int): ChainConfig = result = getChainConfig("Cancun") - result.cancunTime = some(fromUnix(timestamp)) + result.cancunTime = some(EthTime(timestamp)) proc specExecute(ws: BaseSpec): bool = let ws = ECSpec(ws) diff --git a/hive_integration/nodocker/engine/helper.nim b/hive_integration/nodocker/engine/helper.nim index 33c1e52a8..0906282ce 100644 --- a/hive_integration/nodocker/engine/helper.nim +++ b/hive_integration/nodocker/engine/helper.nim @@ -1,5 +1,5 @@ import - std/[typetraits, times], + std/[typetraits], nimcrypto/sysrand, eth/[common, rlp, keys], json_rpc/[rpcclient], @@ -283,7 +283,7 @@ proc generateInvalidPayload*(basePayload: ExecutableData, of InvalidGasUsed: customPayload.gasUsed = some(basePayload.gasUsed - 1) of InvalidTimestamp: - customPayload.timestamp = some(basePayload.timestamp - 1.seconds) + customPayload.timestamp = some(basePayload.timestamp - 1) of InvalidPrevRandao: # This option potentially requires a transaction that uses the PREVRANDAO opcode. # Otherwise the payload will still be valid. diff --git a/hive_integration/nodocker/engine/withdrawals/wd_base_spec.nim b/hive_integration/nodocker/engine/withdrawals/wd_base_spec.nim index b2458e784..ec2dab572 100644 --- a/hive_integration/nodocker/engine/withdrawals/wd_base_spec.nim +++ b/hive_integration/nodocker/engine/withdrawals/wd_base_spec.nim @@ -1,5 +1,5 @@ import - std/[times, options], + std/[options], stint, chronicles, chronos, @@ -11,13 +11,14 @@ import ../test_env, ../engine_client, ../types, - ../../../tools/common/helpers, ../../../nimbus/common/common, ../../../nimbus/utils/utils, ../../../nimbus/common/chain_config, ../../../nimbus/beacon/execution_types, ../../../nimbus/beacon/web3_eth_conv +import ../../../tools/common/helpers except LogLevel + type WDBaseSpec* = ref object of BaseSpec timeIncrements*: int # Timestamp increments per block throughout the test @@ -63,7 +64,7 @@ func getWithdrawalsForkTime(ws: WDBaseSpec): int = # Generates the fork config, including withdrawals fork timestamp. func getForkConfig*(ws: WDBaseSpec): ChainConfig = result = getChainConfig("Shanghai") - result.shanghaiTime = some(ws.getWithdrawalsForkTime().fromUnix) + result.shanghaiTime = some(ws.getWithdrawalsForkTime().EthTime) # Get the start account for all withdrawals. func getWithdrawalsStartAccount*(ws: WDBaseSpec): UInt256 = diff --git a/hive_integration/nodocker/pyspec/pyspec_sim.nim b/hive_integration/nodocker/pyspec/pyspec_sim.nim index ca4644873..7a0dcc7a4 100644 --- a/hive_integration/nodocker/pyspec/pyspec_sim.nim +++ b/hive_integration/nodocker/pyspec/pyspec_sim.nim @@ -183,8 +183,7 @@ proc runTest(node: JsonNode, network: string): TestStatus = const skipName = [ - "beacon_root_contract_timestamps.json", - "beacon_root_equal_to_timestamp.json", + "nothing skipped", ] caseFolderCancun = "tests/fixtures/eth_tests/EIPTests/Pyspecs/cancun" diff --git a/nimbus/beacon/api_handler/api_newpayload.nim b/nimbus/beacon/api_handler/api_newpayload.nim index f4f6af277..5f0351ab5 100644 --- a/nimbus/beacon/api_handler/api_newpayload.nim +++ b/nimbus/beacon/api_handler/api_newpayload.nim @@ -8,7 +8,6 @@ # those terms. import - std/[times], eth/common, stew/results, ../web3_eth_conv, diff --git a/nimbus/beacon/web3_eth_conv.nim b/nimbus/beacon/web3_eth_conv.nim index ba32c255e..944d42fbc 100644 --- a/nimbus/beacon/web3_eth_conv.nim +++ b/nimbus/beacon/web3_eth_conv.nim @@ -8,7 +8,7 @@ # those terms. import - std/[options, times, typetraits], + std/[options, typetraits], web3/ethtypes, web3/engine_api_types, eth/common/eth_types_rlp, @@ -86,7 +86,7 @@ func u256*(x: Web3Quantity): UInt256 = u256(x.uint64) func ethTime*(x: Web3Quantity): common.EthTime = - fromUnix(x.unsafeQuantityToInt64) + common.EthTime(x.unsafeQuantityToInt64) func ethHash*(x: Web3PrevRandao): common.Hash256 = common.Hash256(data: distinctBase x) @@ -163,10 +163,10 @@ func w3Qty*(x: common.GasInt): Web3Quantity = Web3Quantity x.uint64 func w3Qty*(x: common.EthTime): Web3Quantity = - Web3Quantity x.toUnix + Web3Quantity x.uint64 func w3Qty*(x: common.EthTime, y: int): Web3Quantity = - Web3Quantity(x.toUnix + y.int64) + Web3Quantity(x + y.EthTime) func w3Qty*(x: Web3Quantity, y: int): Web3Quantity = Web3Quantity(x.uint64 + y.uint64) diff --git a/nimbus/common/chain_config.nim b/nimbus/common/chain_config.nim index 9cfed81ed..4f99f20d0 100644 --- a/nimbus/common/chain_config.nim +++ b/nimbus/common/chain_config.nim @@ -86,6 +86,14 @@ const # ------------------------------------------------------------------------------ # Private helper functions # ------------------------------------------------------------------------------ +proc writeValue(writer: var JsonWriter, value: Option[EthTime]) + {.gcsafe, raises: [IOError].} = + mixin writeValue + + if value.isSome: + writer.writeValue value.get.uint64 + else: + writer.writeValue JsonString("null") proc read(rlp: var Rlp, x: var AddressBalance, _: type EthAddress): EthAddress {.gcsafe, raises: [RlpError].} = @@ -172,13 +180,13 @@ proc readValue(reader: var JsonReader, value: var BlockNonce) proc readValue(reader: var JsonReader, value: var EthTime) {.gcsafe, raises: [SerializationError, IOError].} = try: - value = fromHex[int64](reader.readValue(string)).fromUnix + value = fromHex[int64](reader.readValue(string)).EthTime except ValueError as ex: reader.raiseUnexpectedValue(ex.msg) # but shanghaiTime and cancunTime in config is in int literal proc readValue(reader: var JsonReader, value: var Option[EthTime]) - {.gcsafe, raises: [SerializationError, IOError].} = + {.gcsafe, raises: [IOError].} = let tok = reader.lexer.lazyTok if tok == tkNull: reset value @@ -187,8 +195,8 @@ proc readValue(reader: var JsonReader, value: var Option[EthTime]) # both readValue(GasInt/AccountNonce) will be called if # we use readValue(int64/uint64) let tok {.used.} = reader.lexer.tok # resove lazy token - let val = reader.lexer.absIntVal.int64 - value = some val.fromUnix + let val = EthTime reader.lexer.absIntVal + value = some val reader.lexer.next() proc readValue(reader: var JsonReader, value: var seq[byte]) @@ -401,7 +409,7 @@ proc chainConfigForNetwork*(id: NetworkId): ChainConfig = arrowGlacierBlock: some(13_773_000.toBlockNumber), # 2021-12-09 19:55:23 UTC grayGlacierBlock: some(15_050_000.toBlockNumber), # 2022-06-30 10:54:04 UTC terminalTotalDifficulty: some(mainNetTTD), - shanghaiTime: some(1_681_338_455.fromUnix) + shanghaiTime: some(1_681_338_455.EthTime) ) of RopstenNet: ChainConfig( @@ -462,7 +470,7 @@ proc chainConfigForNetwork*(id: NetworkId): ChainConfig = berlinBlock: some(4_460_644.toBlockNumber), # 2021-03-18 05:29:51 UTC londonBlock: some(5_062_605.toBlockNumber), # 2021-07-01 03:19:39 UTC terminalTotalDifficulty: some(10790000.u256), - shanghaiTime: some(1_678_832_736.fromUnix) + shanghaiTime: some(1_678_832_736.EthTime) ) of SepoliaNet: const sepoliaTTD = parse("17000000000000000",UInt256) @@ -483,7 +491,7 @@ proc chainConfigForNetwork*(id: NetworkId): ChainConfig = berlinBlock: some(0.toBlockNumber), londonBlock: some(0.toBlockNumber), terminalTotalDifficulty: some(sepoliaTTD), - shanghaiTime: some(1_677_557_088.fromUnix) + shanghaiTime: some(1_677_557_088.EthTime) ) else: ChainConfig() @@ -510,7 +518,7 @@ proc genesisBlockForNetwork*(id: NetworkId): Genesis of RinkebyNet: Genesis( nonce: 0.toBlockNonce, - timestamp: initTime(0x58ee40ba, 0), + timestamp: EthTime(0x58ee40ba), extraData: hexToSeqByte("0x52657370656374206d7920617574686f7269746168207e452e436172746d616e42eb768f2244c8811c63729a21a3569731535f067ffc57839b00206d1ad20c69a1981b489f772031b279182d99e65703f0076e4812653aab85fca0f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"), gasLimit: 4700000, difficulty: 1.u256, @@ -519,7 +527,7 @@ proc genesisBlockForNetwork*(id: NetworkId): Genesis of GoerliNet: Genesis( nonce: 0.toBlockNonce, - timestamp: initTime(0x5c51a607, 0), + timestamp: EthTime(0x5c51a607), extraData: hexToSeqByte("0x22466c6578692069732061207468696e6722202d204166726900000000000000e0a2bd4258d2768837baa26a28fe71dc079f84c70000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"), gasLimit: 0xa00000, difficulty: 1.u256, @@ -528,7 +536,7 @@ proc genesisBlockForNetwork*(id: NetworkId): Genesis of SepoliaNet: Genesis( nonce: 0.toBlockNonce, - timestamp: initTime(0x6159af19, 0), + timestamp: EthTime(0x6159af19), extraData: hexToSeqByte("0x5365706f6c69612c20417468656e732c204174746963612c2047726565636521"), gasLimit: 0x1c9c380, difficulty: 0x20000.u256, diff --git a/nimbus/common/common.nim b/nimbus/common/common.nim index 6ecfada63..7bc86bf51 100644 --- a/nimbus/common/common.nim +++ b/nimbus/common/common.nim @@ -10,7 +10,7 @@ {.push raises: [].} import - std/[options, times], + std/[options], chronicles, eth/trie/trie_defs, ../core/[pow, clique, casper], @@ -101,7 +101,7 @@ proc hardForkTransition*( com: CommonRef, forkDeterminer: ForkDeterminationInfo) {.gcsafe, raises: [].} -func cliquePeriod*(com: CommonRef): int +func cliquePeriod*(com: CommonRef): EthTime func cliqueEpoch*(com: CommonRef): int @@ -158,7 +158,7 @@ proc init(com : CommonRef, # set it before creating genesis block # TD need to be some(0.u256) because it can be the genesis # already at the MergeFork - const TimeZero = fromUnix(0) + const TimeZero = EthTime(0) # com.forkIds and com.blockZeroHash is set # by setForkId @@ -432,9 +432,9 @@ func ttd*(com: CommonRef): Option[DifficultyInt] = # if you messing with clique period and # and epoch, it likely will fail clique verification # at epoch * blocknumber -func cliquePeriod*(com: CommonRef): int = +func cliquePeriod*(com: CommonRef): EthTime = if com.config.clique.period.isSome: - return com.config.clique.period.get() + return EthTime com.config.clique.period.get() func cliqueEpoch*(com: CommonRef): int = if com.config.clique.epoch.isSome: diff --git a/nimbus/common/hardforks.nim b/nimbus/common/hardforks.nim index 337774ad5..0eca9cd34 100644 --- a/nimbus/common/hardforks.nim +++ b/nimbus/common/hardforks.nim @@ -8,7 +8,7 @@ # those terms. import - std/[options, times], + std/[options], eth/common, stew/endians2, json_serialization, @@ -114,7 +114,7 @@ func adjustForNextBlock*(t: EthTime): EthTime = # # If this makes no sense, what should the callers # do instead? - fromUnix(t.toUnix + 12) + t + 12 func adjustForNextBlock*(f: ForkDeterminationInfo): ForkDeterminationInfo = ForkDeterminationInfo( @@ -343,7 +343,7 @@ func toNextFork(n: Option[BlockNumber]): uint64 = # EIP-6122: ForkID now works with timestamps too. func toNextFork(t: Option[EthTime]): uint64 = if t.isSome: - t.get.toUnix.uint64 + t.get.uint64 else: 0'u64 diff --git a/nimbus/core/clique.nim b/nimbus/core/clique.nim index 091b9097c..31ef3a42a 100644 --- a/nimbus/core/clique.nim +++ b/nimbus/core/clique.nim @@ -19,7 +19,6 @@ ## import - std/[times], ./clique/[clique_cfg, clique_defs, clique_desc], ./clique/snapshot/[ballot, snapshot_desc], stew/results @@ -44,7 +43,7 @@ type # Public # ------------------------------------------------------------------------------ -proc newClique*(db: CoreDbRef, cliquePeriod, cliqueEpoch: int): Clique = +proc newClique*(db: CoreDbRef, cliquePeriod: EthTime, cliqueEpoch: int): Clique = ## Constructor for a new Clique proof-of-authority consensus engine. The ## initial state of the engine is `empty`, there are no authorised signers. ## @@ -54,7 +53,7 @@ proc newClique*(db: CoreDbRef, cliquePeriod, cliqueEpoch: int): Clique = let cfg = db.newCliqueCfg if cliquePeriod > 0: - cfg.period = initDuration(seconds = cliquePeriod) + cfg.period = cliquePeriod if cliqueEpoch > 0: cfg.epoch = cliqueEpoch cfg.newClique diff --git a/nimbus/core/clique/clique_cfg.nim b/nimbus/core/clique/clique_cfg.nim index 6928a030e..5e5c310a9 100644 --- a/nimbus/core/clique/clique_cfg.nim +++ b/nimbus/core/clique/clique_cfg.nim @@ -43,7 +43,7 @@ type snapsData*: uint64 ## Raw payload stored on disk (for logging troublesshoting) - period: Duration + period: EthTime ## Time between blocks to enforce. ckpInterval: int @@ -108,9 +108,9 @@ proc `epoch=`*(cfg: CliqueCfg; epoch: SomeInteger) = cfg.epoch = if 0 < epoch: epoch else: EPOCH_LENGTH -proc `period=`*(cfg: CliqueCfg; period: Duration) = +proc `period=`*(cfg: CliqueCfg; period: EthTime) = ## Setter - cfg.period = if period != Duration(): period + cfg.period = if period != EthTime(0): period else: BLOCK_PERIOD proc `ckpInterval=`*(cfg: CliqueCfg; numBlocks: SomeInteger) = @@ -147,7 +147,7 @@ proc epoch*(cfg: CliqueCfg): BlockNumber = ## Getter cfg.epoch.u256 -proc period*(cfg: CliqueCfg): Duration = +proc period*(cfg: CliqueCfg): EthTime = ## Getter cfg.period diff --git a/nimbus/core/clique/clique_defs.nim b/nimbus/core/clique/clique_defs.nim index cc9c33ed6..5d7ec4db8 100644 --- a/nimbus/core/clique/clique_defs.nim +++ b/nimbus/core/clique/clique_defs.nim @@ -51,7 +51,7 @@ const ## Minimum difference in seconds between two consecutive block timestamps. ## Suggested time is 15s for the `testnet` to remain analogous to the ## `mainnet` ethash target. - initDuration(seconds = 15) + EthTime 15 EXTRA_VANITY* = ##\ ## Fixed number of extra-data prefix bytes reserved for signer vanity. diff --git a/nimbus/core/clique/clique_genvote.nim b/nimbus/core/clique/clique_genvote.nim index e49268c4e..fc3d8a6df 100644 --- a/nimbus/core/clique/clique_genvote.nim +++ b/nimbus/core/clique/clique_genvote.nim @@ -19,7 +19,7 @@ ## import - std/[sequtils, times], + std/[sequtils], eth/[common, keys], ../../constants, ./clique_cfg, @@ -64,7 +64,7 @@ proc cliqueGenvote*( voter: EthAddress; # new voter account/identity seal: PrivateKey; # signature key parent: BlockHeader; - elapsed = initDuration(); + elapsed = EthTime(0); voteInOk = false; # vote in the new voter if `true` outOfTurn = false; checkPoint: seq[EthAddress] = @[]): BlockHeader = @@ -124,7 +124,7 @@ proc cliqueGenvote*( ## block is a block where the block number is a multiple of `c.cfg.epoch`. ## Typically, `c.cfg.epoch` is initialised as `30'000`. ## - let timeElapsed = if elapsed == initDuration(): c.cfg.period else: elapsed + let timeElapsed = if elapsed == EthTime(0): c.cfg.period else: elapsed result = BlockHeader( parentHash: parent.blockHash, @@ -157,7 +157,7 @@ proc cliqueGenvote*( proc cliqueGenvote*( c: Clique; voter: EthAddress; seal: PrivateKey; - elapsed = initDuration(); + elapsed = EthTime(0); voteInOk = false; outOfTurn = false; checkPoint: seq[EthAddress] = @[]): BlockHeader diff --git a/nimbus/core/clique/clique_sealer.nim b/nimbus/core/clique/clique_sealer.nim index 625d8aa7d..ab9923ba8 100644 --- a/nimbus/core/clique/clique_sealer.nim +++ b/nimbus/core/clique/clique_sealer.nim @@ -129,8 +129,8 @@ proc prepare*(c: Clique; parent: BlockHeader, header: var BlockHeader): CliqueOk # Ensure the timestamp has the correct delay header.timestamp = parent.timestamp + c.cfg.period - if header.timestamp < getTime(): - header.timestamp = getTime() + if header.timestamp < EthTime.now(): + header.timestamp = EthTime.now() ok() @@ -182,7 +182,7 @@ proc seal*(c: Clique; ethBlock: var EthBlock): # For 0-period chains, refuse to seal empty blocks (no reward but would spin # sealing) - if c.cfg.period.isZero and ethBlock.txs.len == 0: + if c.cfg.period == 0 and ethBlock.txs.len == 0: info $nilCliqueSealNoBlockYet return err((nilCliqueSealNoBlockYet, "")) @@ -207,21 +207,22 @@ proc seal*(c: Clique; ethBlock: var EthBlock): info $nilCliqueSealSignedRecently return err((nilCliqueSealSignedRecently, "")) - # Sweet, the protocol permits us to sign the block, wait for our time - var delay = header.timestamp - getTime() - if header.difficulty == DIFF_NOTURN: - # It's not our turn explicitly to sign, delay it a bit - let wiggle = c.snapshot.signersThreshold.int64 * WIGGLE_TIME - # Kludge for limited rand() argument range - if wiggle.inSeconds < (int.high div 1000).int64: - let rndWiggleMs = c.cfg.rand(wiggle.inMilliseconds.int) - delay += initDuration(milliseconds = rndWiggleMs) - else: - let rndWiggleSec = c.cfg.rand((wiggle.inSeconds and int.high).int) - delay += initDuration(seconds = rndWiggleSec) + when false: + # Sweet, the protocol permits us to sign the block, wait for our time + var delay = header.timestamp - EthTime.now() + if header.difficulty == DIFF_NOTURN: + # It's not our turn explicitly to sign, delay it a bit + let wiggle = c.snapshot.signersThreshold.int64 * WIGGLE_TIME + # Kludge for limited rand() argument range + if wiggle.inSeconds < (int.high div 1000).int64: + let rndWiggleMs = c.cfg.rand(wiggle.inMilliseconds.int) + delay += initDuration(milliseconds = rndWiggleMs) + else: + let rndWiggleSec = c.cfg.rand((wiggle.inSeconds and int.high).int) + delay += initDuration(seconds = rndWiggleSec) - trace "Out-of-turn signing requested", - wiggle = $wiggle + trace "Out-of-turn signing requested", + wiggle = $wiggle # Sign all the things! try: diff --git a/nimbus/core/clique/clique_verify.nim b/nimbus/core/clique/clique_verify.nim index 0d5c16c40..99ed77a38 100644 --- a/nimbus/core/clique/clique_verify.nim +++ b/nimbus/core/clique/clique_verify.nim @@ -205,7 +205,7 @@ proc verifyHeaderFields(c: Clique; header: BlockHeader): CliqueOkResult = # clique/clique.go(250): number := header.Number.Uint64() # Don't waste time checking blocks from the future - if getTime() < header.timestamp: + if EthTime.now() < header.timestamp: return err((errFutureBlock,"")) # Checkpoint blocks need to enforce zero beneficiary diff --git a/nimbus/core/pow/difficulty.nim b/nimbus/core/pow/difficulty.nim index d0df6ab28..bb902e66b 100644 --- a/nimbus/core/pow/difficulty.nim +++ b/nimbus/core/pow/difficulty.nim @@ -1,5 +1,4 @@ import - times, ../../common/common export @@ -37,8 +36,8 @@ template difficultyBomb(periodCount: UInt256) = func calcDifficultyFrontier*(timeStamp: EthTime, parent: BlockHeader): DifficultyInt = var diff: DifficultyInt let adjust = parent.difficulty div DifficultyBoundDivisorU - let time = timeStamp.toUnix() - let parentTime = parent.timestamp.toUnix() + let time = timeStamp + let parentTime = parent.timestamp if time - parentTime < DurationLimit: diff = parent.difficulty + adjust @@ -61,12 +60,12 @@ func calcDifficultyHomestead*(timeStamp: EthTime, parent: BlockHeader): Difficul # (parent_diff / 2048 * max(1 - (block_timestamp - parent_timestamp) # 10, -99)) # ) + 2^(periodCount - 2) - let time = timeStamp.toUnix() - let parentTime = parent.timestamp.toUnix() + let time = timeStamp + let parentTime = parent.timestamp let parentDifficulty = cast[Int256](parent.difficulty) # 1 - (block_timestamp - parent_timestamp) # 10 - var x = (time - parentTime).i256 + var x = (time - parentTime).uint64.i256 x = x div bigTenI x = bigOneI - x @@ -102,12 +101,12 @@ func makeDifficultyCalculator(bombDelay: static[int], timeStamp: EthTime, parent # (parent_diff / 2048 * max((2 if len(parent.uncles) else 1) - ((timestamp - parent.timestamp) # 9), -99)) # ) + 2^(periodCount - 2) - let time = timeStamp.toUnix() - let parentTime = parent.timestamp.toUnix() + let time = timeStamp + let parentTime = parent.timestamp let parentDifficulty = cast[Int256](parent.difficulty) # (2 if len(parent_uncles) else 1) - (block_timestamp - parent_timestamp) # 9 - var x = (time - parentTime).i256 + var x = (time - parentTime).uint64.i256 x = x div bigNine if parent.ommersHash == EMPTY_UNCLE_HASH: diff --git a/nimbus/core/pow/header.nim b/nimbus/core/pow/header.nim index 06ea9ec8a..c8f4ecbe4 100644 --- a/nimbus/core/pow/header.nim +++ b/nimbus/core/pow/header.nim @@ -7,7 +7,7 @@ import - std/[strformat, times], + std/[strformat], ./difficulty export BlockHeader diff --git a/nimbus/core/sealer.nim b/nimbus/core/sealer.nim index 6e387357a..93015453d 100644 --- a/nimbus/core/sealer.nim +++ b/nimbus/core/sealer.nim @@ -8,7 +8,6 @@ # those terms. import - std/[times], pkg/[chronos, stew/results, chronicles, @@ -95,7 +94,7 @@ proc sealingLoop(engine: SealingEngineRef): Future[void] {.async.} = clique.authorize(engine.signer, signerFunc) # convert times.Duration to chronos.Duration - let period = chronos.seconds(clique.cfg.period.inSeconds) + let period = chronos.seconds(clique.cfg.period.int64) while engine.state == EngineRunning: # the sealing engine will tick every `cliquePeriod` seconds diff --git a/nimbus/core/tx_pool/tx_chain.nim b/nimbus/core/tx_pool/tx_chain.nim index a32b494bb..a4ef2fbe2 100644 --- a/nimbus/core/tx_pool/tx_chain.nim +++ b/nimbus/core/tx_pool/tx_chain.nim @@ -107,11 +107,11 @@ proc prepareForSeal(dh: TxChainRef; header: var BlockHeader) {.gcsafe, raises: [ proc getTimestamp(dh: TxChainRef, parent: BlockHeader): EthTime = case dh.com.consensus of ConsensusType.POW: - getTime().utc.toTime + EthTime.now() of ConsensusType.POA: let timestamp = parent.timestamp + dh.com.poa.cfg.period - if timestamp < getTime(): - getTime() + if timestamp < EthTime.now(): + EthTime.now() else: timestamp of ConsensusType.POS: diff --git a/nimbus/core/validate.nim b/nimbus/core/validate.nim index b8636a443..741343300 100644 --- a/nimbus/core/validate.nim +++ b/nimbus/core/validate.nim @@ -9,7 +9,7 @@ # according to those terms. import - std/[sequtils, sets, times, strutils], + std/[sequtils, sets, strutils], ../db/accounts_cache, ".."/[transaction, common/common], ".."/[errors], @@ -92,7 +92,7 @@ proc validateHeader( if header.blockNumber != parentHeader.blockNumber + 1: return err("Blocks must be numbered consecutively") - if header.timestamp.toUnix <= parentHeader.timestamp.toUnix: + if header.timestamp <= parentHeader.timestamp: return err("timestamp must be strictly later than parent") if com.daoForkSupport and inDAOExtraRange(header.blockNumber): diff --git a/nimbus/evm/async/data_sources/json_rpc_data_source.nim b/nimbus/evm/async/data_sources/json_rpc_data_source.nim index 7f5db6c90..4530f0090 100644 --- a/nimbus/evm/async/data_sources/json_rpc_data_source.nim +++ b/nimbus/evm/async/data_sources/json_rpc_data_source.nim @@ -101,7 +101,7 @@ func blockHeaderFromBlockObject(o: BlockObject): BlockHeader = blockNumber: distinctBase(o.number).u256, gasLimit: int64(distinctBase(o.gasLimit)), gasUsed: int64(distinctBase(o.gasUsed)), - timestamp: initTime(int64(distinctBase(o.timestamp)), 0), + timestamp: EthTime(distinctBase(o.timestamp)), extraData: distinctBase(o.extraData), #mixDigest: o.mixHash.toHash, # AARDVARK what's this? nonce: nonce, diff --git a/nimbus/evm/computation.nim b/nimbus/evm/computation.nim index 3cbff129d..2a6d0f1f0 100644 --- a/nimbus/evm/computation.nim +++ b/nimbus/evm/computation.nim @@ -67,11 +67,11 @@ template getCoinbase*(c: Computation): EthAddress = else: c.vmState.coinbase -template getTimestamp*(c: Computation): int64 = +template getTimestamp*(c: Computation): uint64 = when evmc_enabled: - c.host.getTxContext().block_timestamp + cast[uint64](c.host.getTxContext().block_timestamp) else: - c.vmState.blockCtx.timestamp.toUnix + c.vmState.blockCtx.timestamp.uint64 template getBlockNumber*(c: Computation): UInt256 = when evmc_enabled: diff --git a/nimbus/evm/stack.nim b/nimbus/evm/stack.nim index 30409a7c8..ff99d3f4d 100644 --- a/nimbus/evm/stack.nim +++ b/nimbus/evm/stack.nim @@ -27,7 +27,7 @@ proc len*(stack: Stack): int {.inline.} = len(stack.values) proc toStackElement(v: UInt256, elem: var StackElement) {.inline.} = elem = v -proc toStackElement(v: uint | int | GasInt, elem: var StackElement) {.inline.} = elem = v.u256 +proc toStackElement(v: uint64 | uint | int | GasInt, elem: var StackElement) {.inline.} = elem = v.u256 proc toStackElement(v: EthAddress, elem: var StackElement) {.inline.} = elem.initFromBytesBE(v) proc toStackElement(v: MDigest, elem: var StackElement) {.inline.} = elem.initFromBytesBE(v.data) @@ -46,7 +46,7 @@ proc pushAux[T](stack: var Stack, value: T) = stack.values.setLen(stack.values.len + 1) toStackElement(value, stack.values[^1]) -proc push*(stack: var Stack, value: uint | int | GasInt | UInt256 | EthAddress | Hash256) {.inline.} = +proc push*(stack: var Stack, value: uint64 | uint | int | GasInt | UInt256 | EthAddress | Hash256) {.inline.} = pushAux(stack, value) proc push*(stack: var Stack, value: openArray[byte]) {.inline.} = diff --git a/nimbus/graphql/ethapi.nim b/nimbus/graphql/ethapi.nim index 00c00250a..82a4bf640 100644 --- a/nimbus/graphql/ethapi.nim +++ b/nimbus/graphql/ethapi.nim @@ -8,7 +8,7 @@ # those terms. import - std/[strutils, times], + std/[strutils], stew/[results, byteutils], stint, eth/common/eth_types_rlp, chronos, stew/shims/net, @@ -967,7 +967,7 @@ proc blockGasUsed(ud: RootRef, params: Args, parent: Node): RespResult {.apiPrag proc blockTimestamp(ud: RootRef, params: Args, parent: Node): RespResult {.apiPragma.} = let ctx = GraphqlContextRef(ud) let h = HeaderNode(parent) - bigIntNode(h.header.timestamp.toUnix.uint64) + bigIntNode(h.header.timestamp.uint64) proc blockLogsBloom(ud: RootRef, params: Args, parent: Node): RespResult {.apiPragma.} = let ctx = GraphqlContextRef(ud) diff --git a/nimbus/rpc/rpc_utils.nim b/nimbus/rpc/rpc_utils.nim index 8f0e52918..bcf7d5e78 100644 --- a/nimbus/rpc/rpc_utils.nim +++ b/nimbus/rpc/rpc_utils.nim @@ -10,7 +10,7 @@ {.push raises: [].} import hexstrings, eth/[common, keys], stew/byteutils, - ../db/core_db, strutils, algorithm, options, times, json, + ../db/core_db, strutils, algorithm, options, json, ../constants, stint, rpc_types, ../utils/utils, ../transaction, ../transaction/call_evm @@ -216,7 +216,7 @@ proc populateBlockObject*(header: BlockHeader, chain: CoreDbRef, fullTx: bool, i result.gasLimit = encodeQuantity(header.gasLimit.uint64) result.gasUsed = encodeQuantity(header.gasUsed.uint64) - result.timestamp = encodeQuantity(header.timestamp.toUnix.uint64) + result.timestamp = encodeQuantity(header.timestamp.uint64) result.baseFeePerGas = if header.fee.isSome: some(encodeQuantity(header.baseFee)) else: diff --git a/nimbus/sync/legacy.nim b/nimbus/sync/legacy.nim index 0b98e1358..c7b0b8b0f 100644 --- a/nimbus/sync/legacy.nim +++ b/nimbus/sync/legacy.nim @@ -213,7 +213,7 @@ proc validateHeader(ctx: LegacySyncRef, header: BlockHeader, return false if consensusType == ConsensusType.POA: - let period = initDuration(seconds = com.cliquePeriod) + let period = com.cliquePeriod # Timestamp diff between blocks is lower than PERIOD (clique) if parentHeader.timestamp + period > header.timestamp: trace "invalid timestamp diff (lower than period)", diff --git a/nimbus/transaction/call_evm.nim b/nimbus/transaction/call_evm.nim index 361b547b4..60efa60bf 100644 --- a/nimbus/transaction/call_evm.nim +++ b/nimbus/transaction/call_evm.nim @@ -83,7 +83,7 @@ proc rpcCallEvm*(call: RpcCallData, header: BlockHeader, com: CommonRef): CallRe const globalGasCap = 0 # TODO: globalGasCap should configurable by user let topHeader = BlockHeader( parentHash: header.blockHash, - timestamp: getTime().utc.toTime, + timestamp: EthTime.now(), gasLimit: 0.GasInt, ## ??? fee: UInt256.none()) ## ??? let vmState = BaseVMState.new(topHeader, com) @@ -99,7 +99,7 @@ proc rpcEstimateGas*(cd: RpcCallData, header: BlockHeader, com: CommonRef, gasCa # Binary search the gas requirement, as it may be higher than the amount used let topHeader = BlockHeader( parentHash: header.blockHash, - timestamp: getTime().utc.toTime, + timestamp: EthTime.now(), gasLimit: 0.GasInt, ## ??? fee: UInt256.none()) ## ??? let vmState = BaseVMState.new(topHeader, com) diff --git a/nimbus/transaction/host_services.nim b/nimbus/transaction/host_services.nim index 28c315d7d..f14db977e 100644 --- a/nimbus/transaction/host_services.nim +++ b/nimbus/transaction/host_services.nim @@ -58,7 +58,7 @@ proc setupTxContext(host: TransactionHost) = host.txContext.block_number = (vmState.blockNumber .truncate(typeof(host.txContext.block_number))) # vmState.timestamp now unused - host.txContext.block_timestamp = vmState.blockCtx.timestamp.toUnix + host.txContext.block_timestamp = cast[int64](vmState.blockCtx.timestamp) # vmState.gasLimit now unused host.txContext.block_gas_limit = vmState.blockCtx.gasLimit # vmState.difficulty now unused diff --git a/nimbus/utils/debug.nim b/nimbus/utils/debug.nim index ba8d9820a..a433388ed 100644 --- a/nimbus/utils/debug.nim +++ b/nimbus/utils/debug.nim @@ -9,7 +9,7 @@ # according to those terms. import - std/[options, times, json, strutils], + std/[options, json, strutils], ../common/common, stew/byteutils, ../vm_state, @@ -43,7 +43,7 @@ proc debug*(h: BlockHeader): string = result.add "blockNumber : " & $h.blockNumber & "\n" result.add "gasLimit : " & $h.gasLimit & "\n" result.add "gasUsed : " & $h.gasUsed & "\n" - result.add "timestamp : " & $h.timestamp.toUnix & "\n" + result.add "timestamp : " & $h.timestamp & "\n" result.add "extraData : " & $h.extraData & "\n" result.add "mixDigest : " & $h.mixDigest & "\n" result.add "nonce : " & $h.nonce & "\n" @@ -97,7 +97,7 @@ proc debugAccounts*(vmState: BaseVMState): string = proc debug*(vms: BaseVMState): string = result.add "com.consensus : " & $vms.com.consensus & "\n" result.add "parent : " & $vms.parent.blockHash & "\n" - result.add "timestamp : " & $vms.blockCtx.timestamp.toUnix & "\n" + result.add "timestamp : " & $vms.blockCtx.timestamp & "\n" result.add "gasLimit : " & $vms.blockCtx.gasLimit & "\n" result.add "fee : " & $vms.blockCtx.fee & "\n" result.add "prevRandao : " & $vms.blockCtx.prevRandao & "\n" diff --git a/nimbus_verified_proxy/rpc/rpc_utils.nim b/nimbus_verified_proxy/rpc/rpc_utils.nim index a97f23302..fa620771a 100644 --- a/nimbus_verified_proxy/rpc/rpc_utils.nim +++ b/nimbus_verified_proxy/rpc/rpc_utils.nim @@ -113,7 +113,7 @@ func blockHeaderSize( blockNumber : payload.blockNumber.distinctBase.u256, gasLimit : payload.gasLimit.unsafeQuantityToInt64, gasUsed : payload.gasUsed.unsafeQuantityToInt64, - timestamp : fromUnix payload.timestamp.unsafeQuantityToInt64, + timestamp : payload.timestamp.EthTime, extraData : bytes payload.extraData, mixDigest : payload.prevRandao.asEthHash, nonce : default(etypes.BlockNonce), diff --git a/premix/parser.nim b/premix/parser.nim index bc146a9dd..1dc6b613d 100644 --- a/premix/parser.nim +++ b/premix/parser.nim @@ -1,5 +1,5 @@ import - json, strutils, times, options, os, + json, strutils, options, os, eth/common, httputils, nimcrypto/utils, stint, stew/byteutils @@ -75,8 +75,8 @@ proc fromJson*(n: JsonNode, name: string, x: var SomeInteger) = doAssert($x == $node.getInt, name) proc fromJson*(n: JsonNode, name: string, x: var EthTime) = - x = initTime(hexToInt(n[name].getStr(), int64), 0) - doAssert(x.toUnix.prefixHex == toLowerAscii(n[name].getStr()), name) + x = EthTime(hexToInt(n[name].getStr(), uint64)) + doAssert(x.uint64.prefixHex == toLowerAscii(n[name].getStr()), name) proc fromJson*[T](n: JsonNode, name: string, x: var Option[T]) = if name in n: diff --git a/tests/macro_assembler.nim b/tests/macro_assembler.nim index 9adc18a75..96eab20fa 100644 --- a/tests/macro_assembler.nim +++ b/tests/macro_assembler.nim @@ -1,5 +1,5 @@ import - std/[macrocache, strutils, times], + std/[macrocache, strutils], eth/keys, unittest2, chronicles, @@ -12,22 +12,22 @@ import ../nimbus/vm_internals, ../nimbus/transaction/[call_common, call_evm], ../nimbus/[vm_types, vm_state], - ../nimbus/core/pow/difficulty, - ../tools/common/helpers + ../nimbus/core/pow/difficulty # Ditto, for GasPrice. import ../nimbus/transaction except GasPrice +import ../tools/common/helpers except LogLevel export byteutils {.experimental: "dynamicBindSym".} # backported from Nim 0.19.9 # remove this when we use newer Nim -proc newLitFixed*(arg: enum): NimNode {.compileTime.} = - result = newCall( - arg.type.getTypeInst[1], - newLit(int(arg)) - ) +#proc newLitFixed*(arg: enum): NimNode {.compileTime.} = +# result = newCall( +# arg.type.getTypeInst[1], +# newLit(int(arg)) +# ) type VMWord* = array[32, byte] @@ -271,7 +271,7 @@ proc initVMEnv*(network: string): BaseVMState = stateRoot: EMPTY_ROOT_HASH, parentHash: parentHash, coinbase: coinbase, - timestamp: fromUnix(0x1234), + timestamp: EthTime(0x1234), difficulty: 1003.u256, gasLimit: 100_000 ) diff --git a/tests/replay/pp.nim b/tests/replay/pp.nim index 7fe6486bf..7cd8d92d5 100644 --- a/tests/replay/pp.nim +++ b/tests/replay/pp.nim @@ -13,7 +13,7 @@ ## ---------------------------------------------------- import - std/[tables, times], + std/[tables], ./pp_light, ../../nimbus/common/chain_config, eth/common @@ -45,7 +45,7 @@ proc pp*(h: BlockHeader; sep = " "): string = &"coinbase={h.coinbase.pp}{sep}" & &"gasLimit={h.gasLimit}{sep}" & &"gasUsed={h.gasUsed}{sep}" & - &"timestamp={h.timestamp.toUnix}{sep}" & + &"timestamp={h.timestamp}{sep}" & &"extraData={h.extraData.pp}{sep}" & &"difficulty={h.difficulty}{sep}" & &"mixDigest={h.mixDigest.pp}{sep}" & @@ -62,7 +62,7 @@ proc pp*(h: BlockHeader; sep = " "): string = proc pp*(g: Genesis; sep = " "): string = "" & &"nonce={g.nonce.pp}{sep}" & - &"timestamp={g.timestamp.toUnix}{sep}" & + &"timestamp={g.timestamp}{sep}" & &"extraData={g.extraData.pp}{sep}" & &"gasLimit={g.gasLimit}{sep}" & &"difficulty={g.difficulty}{sep}" & diff --git a/tests/test_beacon/setup_env.nim b/tests/test_beacon/setup_env.nim index 00f5a69f8..8f7e18573 100644 --- a/tests/test_beacon/setup_env.nim +++ b/tests/test_beacon/setup_env.nim @@ -84,7 +84,7 @@ func header*(bn: uint64, temp, parent: BlockHeader, diff: uint64): BlockHeader = blockNumber: bn.toBlockNumber, parentHash : parent.blockHash, difficulty : diff.u256, - timestamp : fromUnix(parent.timestamp.toUnix + 1), + timestamp : parent.timestamp + 1, gasLimit : temp.gasLimit, stateRoot : temp.stateRoot, txRoot : temp.txRoot, diff --git a/tests/test_blockchain_json.nim b/tests/test_blockchain_json.nim index 96dc0507a..717546348 100644 --- a/tests/test_blockchain_json.nim +++ b/tests/test_blockchain_json.nim @@ -387,9 +387,9 @@ proc testFixture(node: JsonNode, testStatusIMPL: var TestStatus, debugMode = fal proc blockchainJsonMain*(debugMode = false) = const legacyFolder = "eth_tests/LegacyTests/Constantinople/BlockchainTests" - newFolder = "eth_tests/BlockchainTests" + #newFolder = "eth_tests/BlockchainTests" #newFolder = "eth_tests/EIPTests/BlockchainTests" - #newFolder = "eth_tests/EIPTests/Pyspecs/cancun" + newFolder = "eth_tests/EIPTests/Pyspecs/cancun" let res = loadKzgTrustedSetup() if res.isErr: diff --git a/tests/test_clique/pool.nim b/tests/test_clique/pool.nim index 87fde52bd..d7843e5df 100644 --- a/tests/test_clique/pool.nim +++ b/tests/test_clique/pool.nim @@ -9,7 +9,7 @@ # according to those terms. import - std/[algorithm, sequtils, strformat, strutils, tables, times], + std/[algorithm, sequtils, strformat, strutils, tables], eth/keys, ethash, secp256k1/abi, @@ -404,7 +404,7 @@ proc appendVoter*(ap: TesterPool; voter = ap.address(voter.voted), seal = ap.privateKey(voter.signer), parent = parent, - elapsed = initDuration(seconds = 100), + elapsed = EthTime(100), voteInOk = voter.auth, outOfTurn = voter.noTurn, checkPoint = voter.checkpoint.mapIt(ap.address(it)).sorted(EthAscending)) diff --git a/tests/test_difficulty.nim b/tests/test_difficulty.nim index 7578c173d..90f8e927e 100644 --- a/tests/test_difficulty.nim +++ b/tests/test_difficulty.nim @@ -1,5 +1,5 @@ import - std/[strutils, tables, os, json, times], + std/[strutils, tables, os, json], unittest2, stew/byteutils, ../nimbus/core/pow/difficulty, @@ -84,12 +84,12 @@ proc testFixture(fixtures: JsonNode, testStatusIMPL: var TestStatus) = for title, t in tests: let p = BlockHeader( difficulty : t.parentDifficulty, - timestamp : times.fromUnix(t.parentTimestamp), + timestamp : EthTime(t.parentTimestamp), blockNumber: t.currentBlockNumber - 1, ommersHash : t.parentUncles ) - let timestamp = times.fromUnix(t.currentTimeStamp) + let timestamp = EthTime(t.currentTimeStamp) let diff = calculator(revision, timestamp, p) check diff == t.currentDifficulty diff --git a/tests/test_rpc.nim b/tests/test_rpc.nim index 8acca0ad9..31eaa8d92 100644 --- a/tests/test_rpc.nim +++ b/tests/test_rpc.nim @@ -98,7 +98,7 @@ proc setupEnv(com: CommonRef, signer, ks2: EthAddress, ctx: EthContext): TestEnv let receiptRoot = com.db.persistReceipts(vmState.receipts) date = dateTime(2017, mMar, 30) - timeStamp = date.toTime + timeStamp = date.toTime.toUnix.EthTime difficulty = com.calcDifficulty(timeStamp, parent) # call persist() before we get the rootHash diff --git a/tests/test_txpool.nim b/tests/test_txpool.nim index f875c3ea3..130c1d656 100644 --- a/tests/test_txpool.nim +++ b/tests/test_txpool.nim @@ -638,7 +638,7 @@ proc runTxPackerTests(noisy = true) = test &"Clear and re-pack bucket": # prepare for POS transition in txpool - xq.chain.com.pos.timestamp = getTime() + xq.chain.com.pos.timestamp = EthTime.now() let items0 = xq.toItems(txItemPacked) diff --git a/tests/test_txpool2.nim b/tests/test_txpool2.nim index 6a603a486..a2dfedab3 100644 --- a/tests/test_txpool2.nim +++ b/tests/test_txpool2.nim @@ -1,5 +1,5 @@ import - std/[tables, times, os], + std/[tables, os], eth/[keys], stew/[byteutils, results], unittest2, ../nimbus/db/state_db, @@ -89,10 +89,10 @@ proc initEnv(envFork: HardFork): TestEnv = conf.networkParams.config.terminalTotalDifficulty = some(100.u256) if envFork >= Shanghai: - conf.networkParams.config.shanghaiTime = some(0.fromUnix) + conf.networkParams.config.shanghaiTime = some(0.EthTime) if envFork >= Cancun: - conf.networkParams.config.cancunTime = some(0.fromUnix) + conf.networkParams.config.cancunTime = some(0.EthTime) let com = CommonRef.new( @@ -207,7 +207,7 @@ proc runTxPoolCliqueTest*() = return # prevent block from future detected in persistBlocks - os.sleep(com.cliquePeriod * 1000) + os.sleep(com.cliquePeriod.int * 1000) xp.chain.clearAccounts check xp.chain.vmState.processBlock(blk.header, body).isOK @@ -240,7 +240,7 @@ proc runTxPoolPosTest*() = test "TxPool ethBlock": com.pos.prevRandao = prevRandao com.pos.feeRecipient = feeRecipient - com.pos.timestamp = getTime() + com.pos.timestamp = EthTime.now() blk = xp.ethBlock() @@ -303,7 +303,7 @@ proc runTxPoolBlobhashTest*() = test "TxPool ethBlock": com.pos.prevRandao = prevRandao com.pos.feeRecipient = feeRecipient - com.pos.timestamp = getTime() + com.pos.timestamp = EthTime.now() blk = xp.ethBlock() @@ -381,7 +381,7 @@ proc runTxHeadDelta*(noisy = true) = # pending/staged/packed : total/disposed &" stats={xp.nItems.pp}" - timestamp = timestamp + 1.seconds + timestamp = timestamp + 1 com.pos.prevRandao = prevRandao com.pos.timestamp = timestamp com.pos.feeRecipient = feeRecipient diff --git a/tools/common/helpers.nim b/tools/common/helpers.nim index b6f7c3dd2..5273b191f 100644 --- a/tools/common/helpers.nim +++ b/tools/common/helpers.nim @@ -9,7 +9,6 @@ # according to those terms. import - std/times, ../../nimbus/common/common, ./types @@ -19,7 +18,7 @@ export const BlockNumberZero: BlockNumber = 0.toBlockNumber BlockNumberFive: BlockNumber = 5.toBlockNumber - TimeZero: EthTime = fromUnix(0) + TimeZero = EthTime(0) proc createForkTransitionTable(transitionFork: HardFork, b: Option[BlockNumber], t: Option[EthTime], ttd: Option[DifficultyInt]): ForkTransitionTable = @@ -112,11 +111,11 @@ func getChainConfig*(network: string, c: ChainConfig) = of $TestFork.Shanghai: c.assignTime(HardFork.Shanghai, TimeZero) of $TestFork.MergeToShanghaiAtTime15k: - c.assignTime(HardFork.Shanghai, fromUnix(15000)) + c.assignTime(HardFork.Shanghai, EthTime(15000)) of $TestFork.Cancun: c.assignTime(HardFork.Cancun, TimeZero) of $TestFork.ShanghaiToCancunAtTime15k: - c.assignTime(HardFork.Cancun, fromUnix(15000)) + c.assignTime(HardFork.Cancun, EthTime(15000)) else: raise newException(ValueError, "unsupported network " & network) diff --git a/tools/evmstate/helpers.nim b/tools/evmstate/helpers.nim index 715b08092..ec73841a9 100644 --- a/tools/evmstate/helpers.nim +++ b/tools/evmstate/helpers.nim @@ -47,7 +47,7 @@ template fromJson(T: type AccountNonce, n: JsonNode): AccountNonce = fromHex[AccountNonce](n.getStr) template fromJson(T: type EthTime, n: JsonNode): EthTime = - fromUnix(fromHex[int64](n.getStr)) + EthTime(fromHex[uint64](n.getStr)) proc fromJson(T: type PrivateKey, n: JsonNode): PrivateKey = var secretKey = n.getStr diff --git a/tools/t8n/helpers.nim b/tools/t8n/helpers.nim index 37e9cd618..4b2c5de10 100644 --- a/tools/t8n/helpers.nim +++ b/tools/t8n/helpers.nim @@ -72,7 +72,7 @@ proc fromJson(T: type Hash256, n: JsonNode, field: string): Hash256 = fromJson(T, n[field]) template fromJson(T: type EthTime, n: JsonNode, field: string): EthTime = - fromUnix(parseHexOrInt[int64](n[field].getStr())) + EthTime(parseHexOrInt[uint64](n[field].getStr())) proc fromJson(T: type AccessList, n: JsonNode, field: string): AccessList = let z = n[field] diff --git a/tools/t8n/transition.nim b/tools/t8n/transition.nim index ada060495..876ac841e 100644 --- a/tools/t8n/transition.nim +++ b/tools/t8n/transition.nim @@ -9,7 +9,7 @@ # according to those terms. import - std/[json, strutils, times, tables, os, streams], + std/[json, strutils, tables, os, streams], eth/[rlp, trie, eip1559], stint, stew/results, "."/[config, types, helpers], diff --git a/vendor/nim-bearssl b/vendor/nim-bearssl index acf9645e3..d55d3a86d 160000 --- a/vendor/nim-bearssl +++ b/vendor/nim-bearssl @@ -1 +1 @@ -Subproject commit acf9645e328bdcab481cfda1c158e07ecd46bd7b +Subproject commit d55d3a86d7ec3ad11b244e17b3bad490bfbd076d diff --git a/vendor/nim-chronicles b/vendor/nim-chronicles index af31ca215..d1d34b949 160000 --- a/vendor/nim-chronicles +++ b/vendor/nim-chronicles @@ -1 +1 @@ -Subproject commit af31ca2157ed5c65ed339a0bbe5bed6faa033502 +Subproject commit d1d34b9490f99fa2052ffcff2bcf0edaf42d1bdd diff --git a/vendor/nim-eth b/vendor/nim-eth index fe88d9e6b..e34a9c4e5 160000 --- a/vendor/nim-eth +++ b/vendor/nim-eth @@ -1 +1 @@ -Subproject commit fe88d9e6b73f97d92cefa861add6f069ef70abf2 +Subproject commit e34a9c4e5daee654d6ea16f6c4595253548ffb17 diff --git a/vendor/nim-http-utils b/vendor/nim-http-utils index aad684d37..87b7cbf03 160000 --- a/vendor/nim-http-utils +++ b/vendor/nim-http-utils @@ -1 +1 @@ -Subproject commit aad684d3758a74c1b327df93da2e956458410b48 +Subproject commit 87b7cbf032c90b9e6b446081f4a647e950362cec diff --git a/vendor/nim-kzg4844 b/vendor/nim-kzg4844 index f8b78edcc..6c406c70a 160000 --- a/vendor/nim-kzg4844 +++ b/vendor/nim-kzg4844 @@ -1 +1 @@ -Subproject commit f8b78edcc8296f412c2593e6d60f47c77aa421c5 +Subproject commit 6c406c70ad8cde6ab56320158dd969beb45322ef diff --git a/vendor/nim-libp2p b/vendor/nim-libp2p index 20b0e40f7..60f953629 160000 --- a/vendor/nim-libp2p +++ b/vendor/nim-libp2p @@ -1 +1 @@ -Subproject commit 20b0e40f7d89da3f9f1a0a7e823112e938365337 +Subproject commit 60f953629d725c061f4c0c7ffe79f506efaad7be diff --git a/vendor/nim-presto b/vendor/nim-presto index 35652ed19..2ae448ff5 160000 --- a/vendor/nim-presto +++ b/vendor/nim-presto @@ -1 +1 @@ -Subproject commit 35652ed19ccbbf042e95941bc2f8bab39e3f6030 +Subproject commit 2ae448ff5b0808c8f562c6f0a70bbd7a05407a37 diff --git a/vendor/nim-stint b/vendor/nim-stint index 54e24cae4..711cda445 160000 --- a/vendor/nim-stint +++ b/vendor/nim-stint @@ -1 +1 @@ -Subproject commit 54e24cae415b1bed39a987ecd08c19a34f740972 +Subproject commit 711cda4456c32d3ba3c6c4524135b3453dffeb9c diff --git a/vendor/nim-toml-serialization b/vendor/nim-toml-serialization index bad61aa6d..43c546c36 160000 --- a/vendor/nim-toml-serialization +++ b/vendor/nim-toml-serialization @@ -1 +1 @@ -Subproject commit bad61aa6db4fd7aa0007c99b07276da55cc097da +Subproject commit 43c546c365af4d291c33b7d94b5b730300165aaf diff --git a/vendor/nim-web3 b/vendor/nim-web3 index b52a53e7a..ebf4a12cb 160000 --- a/vendor/nim-web3 +++ b/vendor/nim-web3 @@ -1 +1 @@ -Subproject commit b52a53e7a544850569002224f7bada07fb757ded +Subproject commit ebf4a12cbaf8d07c2a6c315adf6278a67c1fdc54 diff --git a/vendor/nimbus-eth2 b/vendor/nimbus-eth2 index 35bf03a3f..0f9b52933 160000 --- a/vendor/nimbus-eth2 +++ b/vendor/nimbus-eth2 @@ -1 +1 @@ -Subproject commit 35bf03a3fbb6a55c52911479760c9bbb69e7c2cc +Subproject commit 0f9b52933eed5035e497ca3dd7d580536ad98e9a