From ce331b4de8149f055cba1df682eccf95330ba83f Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Thu, 3 Oct 2024 13:42:24 +0200 Subject: [PATCH] post-merge nrpc fix (#2685) * post-merge nrpc fix * bump * bump * bump * bump * bump * bump * bump * bump * bump * bump * bump --- hive_integration/nodocker/rpc/client.nim | 2 +- nimbus/beacon/web3_eth_conv.nim | 6 ++--- nimbus/nimbus_import.nim | 33 +++--------------------- nrpc/nrpc.nim | 8 +++--- tests/replay/pp.nim | 2 +- tests/test_filters.nim | 22 ++++++++-------- tests/test_ledger.nim | 2 +- tests/test_op_env.nim | 2 +- tests/test_txpool2.nim | 6 ++--- tools/evmstate/helpers.nim | 5 +++- tools/t8n/helpers.nim | 12 ++++++++- tools/t8n/t8n_debug.nim | 4 +-- tools/t8n/transition.nim | 2 +- tools/t8n/types.nim | 2 +- vendor/nim-eth | 2 +- vendor/nim-web3 | 2 +- 16 files changed, 49 insertions(+), 63 deletions(-) diff --git a/hive_integration/nodocker/rpc/client.nim b/hive_integration/nodocker/rpc/client.nim index 410971490..942ee458b 100644 --- a/hive_integration/nodocker/rpc/client.nim +++ b/hive_integration/nodocker/rpc/client.nim @@ -53,7 +53,7 @@ func toLogs(list: openArray[LogObject]): seq[Log] = result.add Log( address: ethAddr x.address, data: x.data, - topics: toTopics(x.topics) + topics: x.topics ) proc txReceipt*(client: RpcClient, txHash: common.Hash256): Future[Option[Receipt]] {.async.} = diff --git a/nimbus/beacon/web3_eth_conv.nim b/nimbus/beacon/web3_eth_conv.nim index fa5f8a313..b25047051 100644 --- a/nimbus/beacon/web3_eth_conv.nim +++ b/nimbus/beacon/web3_eth_conv.nim @@ -9,6 +9,7 @@ import std/[typetraits], + chronicles, web3/primitives as web3types, web3/eth_api_types, web3/engine_api_types, @@ -51,9 +52,6 @@ proc `$`*(x: Opt[PayloadID]): string = if x.isNone: "none" else: x.get().toHex -proc `$`*(x: Web3Quantity): string = - $distinctBase(x) - # ------------------------------------------------------------------------------ # Web3 defaults # ------------------------------------------------------------------------------ @@ -403,3 +401,5 @@ func ethRequests*(p: ExecutionPayload): Opt[seq[Request]] = res.add ethRequest(x) ok(res) + +chronicles.formatIt(Quantity): $(distinctBase it) \ No newline at end of file diff --git a/nimbus/nimbus_import.nim b/nimbus/nimbus_import.nim index bf626c888..b49b1b36c 100644 --- a/nimbus/nimbus_import.nim +++ b/nimbus/nimbus_import.nim @@ -13,7 +13,7 @@ import chronicles, metrics, chronos/timer, - std/[os, strformat, strutils], + std/[strformat, strutils], stew/io2, beacon_chain/era_db, beacon_chain/networking/network_metadata, @@ -33,33 +33,6 @@ declareCounter nec_imported_gas, "Gas processed during import" var running {.volatile.} = true -func shortLog(a: timer.Duration, parts = int.high): string {.inline.} = - ## Returns string representation of Duration ``a`` as nanoseconds value. - var - res = "" - v = a.nanoseconds() - parts = parts - - template f(n: string, T: Duration) = - if v >= T.nanoseconds(): - res.add($(uint64(v div T.nanoseconds()))) - res.add(n) - v = v mod T.nanoseconds() - dec parts - if v == 0 or parts <= 0: - return res - - f("w", Week) - f("d", Day) - f("h", Hour) - f("m", Minute) - f("s", Second) - f("ms", Millisecond) - f("us", Microsecond) - f("ns", Nanosecond) - - res - proc importBlocks*(conf: NimbusConf, com: CommonRef) = proc controlCHandler() {.noconv.} = when defined(windows): @@ -191,7 +164,7 @@ proc importBlocks*(conf: NimbusConf, com: CommonRef) = avgBps = f(imported.float / diff0), avgTps = f(txs.float / diff0), avgMGps = f(gas.float / 1000000 / diff0), - elapsed = shortLog(time2 - time0, 3) + elapsed = toString(time2 - time0, 3) metrics.set(nec_import_block_number, int64(blockNumber)) nec_imported_blocks.inc(blocks.len) @@ -231,7 +204,7 @@ proc importBlocks*(conf: NimbusConf, com: CommonRef) = endSlot: Slot, ): bool = # Checks if the Nimbus block number is ahead the era block number - # First we load the last era number, and get the fist slot number + # First we load the last era number, and get the fist slot number # Since the slot emptiness cannot be predicted, we iterate over to find the block and check # if the block number is greater than the current block number var diff --git a/nrpc/nrpc.nim b/nrpc/nrpc.nim index 7542c91c9..054f6ce72 100644 --- a/nrpc/nrpc.nim +++ b/nrpc/nrpc.nim @@ -218,14 +218,14 @@ proc syncToEngineApi(conf: NRpcConf) {.async.} = payloadResponse = await rpcClient.newPayload( payload, versioned_hashes, - primitives.FixedBytes[32] forkyBlck.message.parent_root.data, + forkyBlck.message.parent_root.to(Hash32), ) notice "Payload status", response = payloadResponse # Load the head hash from the execution payload, for forkchoice headHash = forkyBlck.message.body.execution_payload.block_hash - # Make the forkchoicestate based on the the last + # Make the forkchoicestate based on the the last # `new_payload` call and the state received from the EL rest api # And generate the PayloadAttributes based on the consensus fork let @@ -248,13 +248,13 @@ proc syncToEngineApi(conf: NRpcConf) {.async.} = # Update the finalized hash # This is updated after the fcu call is made - # So that head - head mod 32 is maintained + # So that head - head mod 32 is maintained # i.e finalized have to be mod slots per epoch == 0 let blknum = forkyBlck.message.body.execution_payload.block_number if blknum < finalizedBlck.header.number and blknum mod 32 == 0: finalizedHash = headHash elif blknum >= finalizedBlck.header.number: - # If the real finalized block is crossed, then upate the finalized hash to the real one + # If the real finalized block is crossed, then upate the finalized hash to the real one (finalizedBlck, _) = client.getELBlockFromBeaconChain( BlockIdent.init(BlockIdentType.Finalized), clConfig ) diff --git a/tests/replay/pp.nim b/tests/replay/pp.nim index f69b34f87..caaa3486d 100644 --- a/tests/replay/pp.nim +++ b/tests/replay/pp.nim @@ -37,7 +37,7 @@ func pp*(a: Opt[EthAddress]): string = func pp*(a: openArray[EthAddress]): string = "[" & a.mapIt(it.pp).join(" ") & "]" -func pp*(a: Bytes8): string = +func pp*(a: Bytes8|Bytes32): string = a.toHex func pp*(a: NetworkPayload): string = diff --git a/tests/test_filters.nim b/tests/test_filters.nim index 4cb68b940..a5e8a14b8 100644 --- a/tests/test_filters.nim +++ b/tests/test_filters.nim @@ -90,7 +90,7 @@ proc filtersMain*() = len(filteredLogs) == 0 test "Filter topics, specific topic at first position": - let topic = w3Hash("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef") + let topic = bytes32("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef") let filteredLogs = filterLogs( @@ -108,8 +108,8 @@ proc filtersMain*() = log.topics[0] == topic test "Filter topics, specific topic at first position and second position": - let topic = w3Hash("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef") - let topic1 = w3Hash("0x000000000000000000000000919040a01a0adcef25ed6ecbc6ab2a86ca6d77df") + let topic = bytes32("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef") + let topic1 = bytes32("0x000000000000000000000000919040a01a0adcef25ed6ecbc6ab2a86ca6d77df") let filteredLogs = filterLogs( @@ -128,8 +128,8 @@ proc filtersMain*() = log.topics[1] == topic1 test "Filter topics, specific topic at first position and third position": - let topic = w3Hash("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef") - let topic1 = w3Hash("0x000000000000000000000000fdc183d01a793613736cd40a5a578f49add1772b") + let topic = bytes32("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef") + let topic1 = bytes32("0x000000000000000000000000fdc183d01a793613736cd40a5a578f49add1772b") let filteredLogs = filterLogs( @@ -151,8 +151,8 @@ proc filtersMain*() = log.topics[2] == topic1 test "Filter topics, or query at first position": - let topic = w3Hash("0x4a504a94899432a9846e1aa406dceb1bcfd538bb839071d49d1e5e23f5be30ef") - let topic1 = w3Hash("0x526441bb6c1aba3c9a4a6ca1d6545da9c2333c8c48343ef398eb858d72b79236") + let topic = bytes32("0x4a504a94899432a9846e1aa406dceb1bcfd538bb839071d49d1e5e23f5be30ef") + let topic1 = bytes32("0x526441bb6c1aba3c9a4a6ca1d6545da9c2333c8c48343ef398eb858d72b79236") let filteredLogs = filterLogs( @@ -171,11 +171,11 @@ proc filtersMain*() = log.topics[0] == topic or log.topics[0] == topic1 test "Filter topics, or query at first position and or query at second position": - let topic = w3Hash("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef") - let topic1 = w3Hash("0xa64da754fccf55aa65a1f0128a648633fade3884b236e879ee9f64c78df5d5d7") + let topic = bytes32("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef") + let topic1 = bytes32("0xa64da754fccf55aa65a1f0128a648633fade3884b236e879ee9f64c78df5d5d7") - let topic2 = w3Hash("0x000000000000000000000000e16c02eac87920033ac72fc55ee1df3151c75786") - let topic3 = w3Hash("0x000000000000000000000000b626a5facc4de1c813f5293ec3be31979f1d1c78") + let topic2 = bytes32("0x000000000000000000000000e16c02eac87920033ac72fc55ee1df3151c75786") + let topic3 = bytes32("0x000000000000000000000000b626a5facc4de1c813f5293ec3be31979f1d1c78") let filteredLogs = filterLogs( diff --git a/tests/test_ledger.nim b/tests/test_ledger.nim index 3aca68b0c..574d04b18 100644 --- a/tests/test_ledger.nim +++ b/tests/test_ledger.nim @@ -295,7 +295,7 @@ const NumTransactions = 17 NumBlocks = 13 feeRecipient = initAddr(401) - prevRandao = EMPTY_UNCLE_HASH # it can be any valid hash + prevRandao = Bytes32 EMPTY_UNCLE_HASH # it can be any valid hash proc runLedgerTransactionTests(noisy = true) = suite "Ledger nesting scenarios": diff --git a/tests/test_op_env.nim b/tests/test_op_env.nim index 304223643..5f6abffba 100644 --- a/tests/test_op_env.nim +++ b/tests/test_op_env.nim @@ -378,7 +378,7 @@ proc opEnvMain*() = assembler: title: "EIP-4399 PrevRandao: EMPTY_UNCLE_HASH" setup: - vmState.blockCtx.prevRandao = EMPTY_UNCLE_HASH + vmState.blockCtx.prevRandao = Bytes32 EMPTY_UNCLE_HASH code: PrevRandao Stop diff --git a/tests/test_txpool2.nim b/tests/test_txpool2.nim index 319f52626..48c92b997 100644 --- a/tests/test_txpool2.nim +++ b/tests/test_txpool2.nim @@ -125,7 +125,7 @@ proc initEnv(envFork: HardFork): TestEnv = const amount = 1000.u256 slot = 0x11.u256 - prevRandao = EMPTY_UNCLE_HASH # it can be any valid hash + prevRandao = Bytes32 EMPTY_UNCLE_HASH # it can be any valid hash proc runTxPoolPosTest() = var @@ -173,7 +173,7 @@ proc runTxPoolPosTest() = test "validate TxPool prevRandao setter": var sdb = LedgerRef.init(com.db, blk.header.stateRoot) let val = sdb.getStorage(recipient, slot) - let randao = Hash32(val.toBytesBE) + let randao = Bytes32(val.toBytesBE) check randao == prevRandao test "feeRecipient rewarded": @@ -238,7 +238,7 @@ proc runTxPoolBlobhashTest() = test "validate TxPool prevRandao setter": var sdb = LedgerRef.init(com.db, blk.header.stateRoot) let val = sdb.getStorage(recipient, slot) - let randao = Hash32(val.toBytesBE) + let randao = Bytes32(val.toBytesBE) check randao == prevRandao test "feeRecipient rewarded": diff --git a/tools/evmstate/helpers.nim b/tools/evmstate/helpers.nim index 840e15cf3..92192fc2c 100644 --- a/tools/evmstate/helpers.nim +++ b/tools/evmstate/helpers.nim @@ -30,6 +30,9 @@ proc fromJson(T: type UInt256, n: JsonNode): UInt256 = else: UInt256.fromHex(hex) +template fromJson*(T: type Bytes32, n: JsonNode): Bytes32 = + Bytes32(hexToByteArray(n.getStr, 32)) + template fromJson*(T: type Hash256, n: JsonNode): Hash256 = Hash32(hexToByteArray(n.getStr, 32)) @@ -109,7 +112,7 @@ proc parseHeader*(n: JsonNode): BlockHeader = gasLimit : required(GasInt, "currentGasLimit"), timestamp : required(EthTime, "currentTimestamp"), stateRoot : emptyRlpHash, - mixHash : omitZero(Hash256, "currentRandom"), + mixHash : omitZero(Bytes32, "currentRandom"), baseFeePerGas : optional(UInt256, "currentBaseFee"), withdrawalsRoot: optional(Hash256, "currentWithdrawalsRoot"), excessBlobGas : optional(uint64, "currentExcessBlobGas"), diff --git a/tools/t8n/helpers.nim b/tools/t8n/helpers.nim index 3f2ea2344..1251ce04d 100644 --- a/tools/t8n/helpers.nim +++ b/tools/t8n/helpers.nim @@ -55,6 +55,16 @@ template fromJson(T: type UInt256, n: JsonNode, field: string): UInt256 = template fromJson(T: type ChainId, n: JsonNode, field: string): ChainId = parseHexOrInt[uint64](n[field].getStr()).ChainId +proc fromJson(T: type Bytes32, n: JsonNode): Bytes32 = + var num = n.getStr() + num.removePrefix("0x") + if num.len < 64: + num = repeat('0', 64 - num.len) & num + Bytes32(hexToByteArray(num, 32)) + +proc fromJson(T: type Bytes32, n: JsonNode, field: string): Bytes32 = + fromJson(T, n[field]) + proc fromJson(T: type Hash256, n: JsonNode): Hash256 = var num = n.getStr() num.removePrefix("0x") @@ -174,7 +184,7 @@ proc parseEnv*(ctx: var TransContext, n: JsonNode) = required(ctx.env, BlockNumber, currentNumber) required(ctx.env, EthTime, currentTimestamp) optional(ctx.env, DifficultyInt, currentDifficulty) - optional(ctx.env, Hash256, currentRandom) + optional(ctx.env, Bytes32, currentRandom) optional(ctx.env, DifficultyInt, parentDifficulty) omitZero(ctx.env, EthTime, parentTimestamp) optional(ctx.env, UInt256, currentBaseFee) diff --git a/tools/t8n/t8n_debug.nim b/tools/t8n/t8n_debug.nim index 5f39198f1..a5de9aa05 100644 --- a/tools/t8n/t8n_debug.nim +++ b/tools/t8n/t8n_debug.nim @@ -52,7 +52,7 @@ type BCTEnv* = object currentCoinbase*: primitives.Address currentDifficulty*: UInt256 - currentRandom*: Opt[BlockHash] + currentRandom*: Opt[Bytes32] parentDifficulty*: Opt[UInt256] currentGasLimit*: Quantity currentNumber*: Quantity @@ -121,7 +121,7 @@ proc toBctEnv(parentBlock, currentBlock: EthBlock, hashes: BCTHashes): BCTEnv = result.currentNumber = w3Qty(current.number) result.currentTimestamp = Opt.some w3Qty(current.timestamp) result.currentDifficulty = current.difficulty - result.currentRandom = Opt.some w3Hash(current.mixHash) + result.currentRandom = Opt.some current.mixHash # t8n should able to calculate these values itself if not supplied #result.currentBaseFee = current.baseFeePerGas diff --git a/tools/t8n/transition.nim b/tools/t8n/transition.nim index 5afd5f6fa..c74ef6651 100644 --- a/tools/t8n/transition.nim +++ b/tools/t8n/transition.nim @@ -93,7 +93,7 @@ proc envToHeader(env: EnvStruct): BlockHeader = BlockHeader( coinbase : env.currentCoinbase, difficulty : env.currentDifficulty.get(0.u256), - mixHash : env.currentRandom.get(default(Hash256)), + mixHash : env.currentRandom.get(default(Bytes32)), number : env.currentNumber, gasLimit : env.currentGasLimit, timestamp : env.currentTimestamp, diff --git a/tools/t8n/types.nim b/tools/t8n/types.nim index f955be8f3..b93c435b6 100644 --- a/tools/t8n/types.nim +++ b/tools/t8n/types.nim @@ -30,7 +30,7 @@ type EnvStruct* = object currentCoinbase*: EthAddress currentDifficulty*: Opt[DifficultyInt] - currentRandom*: Opt[Hash256] + currentRandom*: Opt[Bytes32] parentDifficulty*: Opt[DifficultyInt] currentGasLimit*: GasInt currentNumber*: BlockNumber diff --git a/vendor/nim-eth b/vendor/nim-eth index 5ce3c4557..792b8b9bf 160000 --- a/vendor/nim-eth +++ b/vendor/nim-eth @@ -1 +1 @@ -Subproject commit 5ce3c4557fc78ee425fcb8f30f80cb336bbe0b7c +Subproject commit 792b8b9bff09a5ed7cc98bc12b0c3d991e019b6f diff --git a/vendor/nim-web3 b/vendor/nim-web3 index b41316b25..62a0005b0 160000 --- a/vendor/nim-web3 +++ b/vendor/nim-web3 @@ -1 +1 @@ -Subproject commit b41316b25c77c525a2d33192a52958a6972b839d +Subproject commit 62a0005b0907a64090827d4e5d691682587f5b2a