post-merge nrpc fix (#2685)

* post-merge nrpc fix

* bump

* bump

* bump

* bump

* bump

* bump

* bump

* bump

* bump

* bump

* bump
This commit is contained in:
Jacek Sieka 2024-10-03 13:42:24 +02:00 committed by GitHub
parent 9192aa13ed
commit ce331b4de8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
16 changed files with 49 additions and 63 deletions

View File

@ -53,7 +53,7 @@ func toLogs(list: openArray[LogObject]): seq[Log] =
result.add Log( result.add Log(
address: ethAddr x.address, address: ethAddr x.address,
data: x.data, data: x.data,
topics: toTopics(x.topics) topics: x.topics
) )
proc txReceipt*(client: RpcClient, txHash: common.Hash256): Future[Option[Receipt]] {.async.} = proc txReceipt*(client: RpcClient, txHash: common.Hash256): Future[Option[Receipt]] {.async.} =

View File

@ -9,6 +9,7 @@
import import
std/[typetraits], std/[typetraits],
chronicles,
web3/primitives as web3types, web3/primitives as web3types,
web3/eth_api_types, web3/eth_api_types,
web3/engine_api_types, web3/engine_api_types,
@ -51,9 +52,6 @@ proc `$`*(x: Opt[PayloadID]): string =
if x.isNone: "none" if x.isNone: "none"
else: x.get().toHex else: x.get().toHex
proc `$`*(x: Web3Quantity): string =
$distinctBase(x)
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Web3 defaults # Web3 defaults
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
@ -403,3 +401,5 @@ func ethRequests*(p: ExecutionPayload): Opt[seq[Request]] =
res.add ethRequest(x) res.add ethRequest(x)
ok(res) ok(res)
chronicles.formatIt(Quantity): $(distinctBase it)

View File

@ -13,7 +13,7 @@ import
chronicles, chronicles,
metrics, metrics,
chronos/timer, chronos/timer,
std/[os, strformat, strutils], std/[strformat, strutils],
stew/io2, stew/io2,
beacon_chain/era_db, beacon_chain/era_db,
beacon_chain/networking/network_metadata, beacon_chain/networking/network_metadata,
@ -33,33 +33,6 @@ declareCounter nec_imported_gas, "Gas processed during import"
var running {.volatile.} = true 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 importBlocks*(conf: NimbusConf, com: CommonRef) =
proc controlCHandler() {.noconv.} = proc controlCHandler() {.noconv.} =
when defined(windows): when defined(windows):
@ -191,7 +164,7 @@ proc importBlocks*(conf: NimbusConf, com: CommonRef) =
avgBps = f(imported.float / diff0), avgBps = f(imported.float / diff0),
avgTps = f(txs.float / diff0), avgTps = f(txs.float / diff0),
avgMGps = f(gas.float / 1000000 / 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)) metrics.set(nec_import_block_number, int64(blockNumber))
nec_imported_blocks.inc(blocks.len) nec_imported_blocks.inc(blocks.len)

View File

@ -218,7 +218,7 @@ proc syncToEngineApi(conf: NRpcConf) {.async.} =
payloadResponse = await rpcClient.newPayload( payloadResponse = await rpcClient.newPayload(
payload, payload,
versioned_hashes, versioned_hashes,
primitives.FixedBytes[32] forkyBlck.message.parent_root.data, forkyBlck.message.parent_root.to(Hash32),
) )
notice "Payload status", response = payloadResponse notice "Payload status", response = payloadResponse

View File

@ -37,7 +37,7 @@ func pp*(a: Opt[EthAddress]): string =
func pp*(a: openArray[EthAddress]): string = func pp*(a: openArray[EthAddress]): string =
"[" & a.mapIt(it.pp).join(" ") & "]" "[" & a.mapIt(it.pp).join(" ") & "]"
func pp*(a: Bytes8): string = func pp*(a: Bytes8|Bytes32): string =
a.toHex a.toHex
func pp*(a: NetworkPayload): string = func pp*(a: NetworkPayload): string =

View File

@ -90,7 +90,7 @@ proc filtersMain*() =
len(filteredLogs) == 0 len(filteredLogs) == 0
test "Filter topics, specific topic at first position": test "Filter topics, specific topic at first position":
let topic = w3Hash("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef") let topic = bytes32("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef")
let filteredLogs = let filteredLogs =
filterLogs( filterLogs(
@ -108,8 +108,8 @@ proc filtersMain*() =
log.topics[0] == topic log.topics[0] == topic
test "Filter topics, specific topic at first position and second position": test "Filter topics, specific topic at first position and second position":
let topic = w3Hash("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef") let topic = bytes32("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef")
let topic1 = w3Hash("0x000000000000000000000000919040a01a0adcef25ed6ecbc6ab2a86ca6d77df") let topic1 = bytes32("0x000000000000000000000000919040a01a0adcef25ed6ecbc6ab2a86ca6d77df")
let filteredLogs = let filteredLogs =
filterLogs( filterLogs(
@ -128,8 +128,8 @@ proc filtersMain*() =
log.topics[1] == topic1 log.topics[1] == topic1
test "Filter topics, specific topic at first position and third position": test "Filter topics, specific topic at first position and third position":
let topic = w3Hash("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef") let topic = bytes32("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef")
let topic1 = w3Hash("0x000000000000000000000000fdc183d01a793613736cd40a5a578f49add1772b") let topic1 = bytes32("0x000000000000000000000000fdc183d01a793613736cd40a5a578f49add1772b")
let filteredLogs = let filteredLogs =
filterLogs( filterLogs(
@ -151,8 +151,8 @@ proc filtersMain*() =
log.topics[2] == topic1 log.topics[2] == topic1
test "Filter topics, or query at first position": test "Filter topics, or query at first position":
let topic = w3Hash("0x4a504a94899432a9846e1aa406dceb1bcfd538bb839071d49d1e5e23f5be30ef") let topic = bytes32("0x4a504a94899432a9846e1aa406dceb1bcfd538bb839071d49d1e5e23f5be30ef")
let topic1 = w3Hash("0x526441bb6c1aba3c9a4a6ca1d6545da9c2333c8c48343ef398eb858d72b79236") let topic1 = bytes32("0x526441bb6c1aba3c9a4a6ca1d6545da9c2333c8c48343ef398eb858d72b79236")
let filteredLogs = let filteredLogs =
filterLogs( filterLogs(
@ -171,11 +171,11 @@ proc filtersMain*() =
log.topics[0] == topic or log.topics[0] == topic1 log.topics[0] == topic or log.topics[0] == topic1
test "Filter topics, or query at first position and or query at second position": test "Filter topics, or query at first position and or query at second position":
let topic = w3Hash("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef") let topic = bytes32("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef")
let topic1 = w3Hash("0xa64da754fccf55aa65a1f0128a648633fade3884b236e879ee9f64c78df5d5d7") let topic1 = bytes32("0xa64da754fccf55aa65a1f0128a648633fade3884b236e879ee9f64c78df5d5d7")
let topic2 = w3Hash("0x000000000000000000000000e16c02eac87920033ac72fc55ee1df3151c75786") let topic2 = bytes32("0x000000000000000000000000e16c02eac87920033ac72fc55ee1df3151c75786")
let topic3 = w3Hash("0x000000000000000000000000b626a5facc4de1c813f5293ec3be31979f1d1c78") let topic3 = bytes32("0x000000000000000000000000b626a5facc4de1c813f5293ec3be31979f1d1c78")
let filteredLogs = let filteredLogs =
filterLogs( filterLogs(

View File

@ -295,7 +295,7 @@ const
NumTransactions = 17 NumTransactions = 17
NumBlocks = 13 NumBlocks = 13
feeRecipient = initAddr(401) 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) = proc runLedgerTransactionTests(noisy = true) =
suite "Ledger nesting scenarios": suite "Ledger nesting scenarios":

View File

@ -378,7 +378,7 @@ proc opEnvMain*() =
assembler: assembler:
title: "EIP-4399 PrevRandao: EMPTY_UNCLE_HASH" title: "EIP-4399 PrevRandao: EMPTY_UNCLE_HASH"
setup: setup:
vmState.blockCtx.prevRandao = EMPTY_UNCLE_HASH vmState.blockCtx.prevRandao = Bytes32 EMPTY_UNCLE_HASH
code: code:
PrevRandao PrevRandao
Stop Stop

View File

@ -125,7 +125,7 @@ proc initEnv(envFork: HardFork): TestEnv =
const const
amount = 1000.u256 amount = 1000.u256
slot = 0x11.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() = proc runTxPoolPosTest() =
var var
@ -173,7 +173,7 @@ proc runTxPoolPosTest() =
test "validate TxPool prevRandao setter": test "validate TxPool prevRandao setter":
var sdb = LedgerRef.init(com.db, blk.header.stateRoot) var sdb = LedgerRef.init(com.db, blk.header.stateRoot)
let val = sdb.getStorage(recipient, slot) let val = sdb.getStorage(recipient, slot)
let randao = Hash32(val.toBytesBE) let randao = Bytes32(val.toBytesBE)
check randao == prevRandao check randao == prevRandao
test "feeRecipient rewarded": test "feeRecipient rewarded":
@ -238,7 +238,7 @@ proc runTxPoolBlobhashTest() =
test "validate TxPool prevRandao setter": test "validate TxPool prevRandao setter":
var sdb = LedgerRef.init(com.db, blk.header.stateRoot) var sdb = LedgerRef.init(com.db, blk.header.stateRoot)
let val = sdb.getStorage(recipient, slot) let val = sdb.getStorage(recipient, slot)
let randao = Hash32(val.toBytesBE) let randao = Bytes32(val.toBytesBE)
check randao == prevRandao check randao == prevRandao
test "feeRecipient rewarded": test "feeRecipient rewarded":

View File

@ -30,6 +30,9 @@ proc fromJson(T: type UInt256, n: JsonNode): UInt256 =
else: else:
UInt256.fromHex(hex) UInt256.fromHex(hex)
template fromJson*(T: type Bytes32, n: JsonNode): Bytes32 =
Bytes32(hexToByteArray(n.getStr, 32))
template fromJson*(T: type Hash256, n: JsonNode): Hash256 = template fromJson*(T: type Hash256, n: JsonNode): Hash256 =
Hash32(hexToByteArray(n.getStr, 32)) Hash32(hexToByteArray(n.getStr, 32))
@ -109,7 +112,7 @@ proc parseHeader*(n: JsonNode): BlockHeader =
gasLimit : required(GasInt, "currentGasLimit"), gasLimit : required(GasInt, "currentGasLimit"),
timestamp : required(EthTime, "currentTimestamp"), timestamp : required(EthTime, "currentTimestamp"),
stateRoot : emptyRlpHash, stateRoot : emptyRlpHash,
mixHash : omitZero(Hash256, "currentRandom"), mixHash : omitZero(Bytes32, "currentRandom"),
baseFeePerGas : optional(UInt256, "currentBaseFee"), baseFeePerGas : optional(UInt256, "currentBaseFee"),
withdrawalsRoot: optional(Hash256, "currentWithdrawalsRoot"), withdrawalsRoot: optional(Hash256, "currentWithdrawalsRoot"),
excessBlobGas : optional(uint64, "currentExcessBlobGas"), excessBlobGas : optional(uint64, "currentExcessBlobGas"),

View File

@ -55,6 +55,16 @@ template fromJson(T: type UInt256, n: JsonNode, field: string): UInt256 =
template fromJson(T: type ChainId, n: JsonNode, field: string): ChainId = template fromJson(T: type ChainId, n: JsonNode, field: string): ChainId =
parseHexOrInt[uint64](n[field].getStr()).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 = proc fromJson(T: type Hash256, n: JsonNode): Hash256 =
var num = n.getStr() var num = n.getStr()
num.removePrefix("0x") num.removePrefix("0x")
@ -174,7 +184,7 @@ proc parseEnv*(ctx: var TransContext, n: JsonNode) =
required(ctx.env, BlockNumber, currentNumber) required(ctx.env, BlockNumber, currentNumber)
required(ctx.env, EthTime, currentTimestamp) required(ctx.env, EthTime, currentTimestamp)
optional(ctx.env, DifficultyInt, currentDifficulty) optional(ctx.env, DifficultyInt, currentDifficulty)
optional(ctx.env, Hash256, currentRandom) optional(ctx.env, Bytes32, currentRandom)
optional(ctx.env, DifficultyInt, parentDifficulty) optional(ctx.env, DifficultyInt, parentDifficulty)
omitZero(ctx.env, EthTime, parentTimestamp) omitZero(ctx.env, EthTime, parentTimestamp)
optional(ctx.env, UInt256, currentBaseFee) optional(ctx.env, UInt256, currentBaseFee)

View File

@ -52,7 +52,7 @@ type
BCTEnv* = object BCTEnv* = object
currentCoinbase*: primitives.Address currentCoinbase*: primitives.Address
currentDifficulty*: UInt256 currentDifficulty*: UInt256
currentRandom*: Opt[BlockHash] currentRandom*: Opt[Bytes32]
parentDifficulty*: Opt[UInt256] parentDifficulty*: Opt[UInt256]
currentGasLimit*: Quantity currentGasLimit*: Quantity
currentNumber*: Quantity currentNumber*: Quantity
@ -121,7 +121,7 @@ proc toBctEnv(parentBlock, currentBlock: EthBlock, hashes: BCTHashes): BCTEnv =
result.currentNumber = w3Qty(current.number) result.currentNumber = w3Qty(current.number)
result.currentTimestamp = Opt.some w3Qty(current.timestamp) result.currentTimestamp = Opt.some w3Qty(current.timestamp)
result.currentDifficulty = current.difficulty 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 # t8n should able to calculate these values itself if not supplied
#result.currentBaseFee = current.baseFeePerGas #result.currentBaseFee = current.baseFeePerGas

View File

@ -93,7 +93,7 @@ proc envToHeader(env: EnvStruct): BlockHeader =
BlockHeader( BlockHeader(
coinbase : env.currentCoinbase, coinbase : env.currentCoinbase,
difficulty : env.currentDifficulty.get(0.u256), difficulty : env.currentDifficulty.get(0.u256),
mixHash : env.currentRandom.get(default(Hash256)), mixHash : env.currentRandom.get(default(Bytes32)),
number : env.currentNumber, number : env.currentNumber,
gasLimit : env.currentGasLimit, gasLimit : env.currentGasLimit,
timestamp : env.currentTimestamp, timestamp : env.currentTimestamp,

View File

@ -30,7 +30,7 @@ type
EnvStruct* = object EnvStruct* = object
currentCoinbase*: EthAddress currentCoinbase*: EthAddress
currentDifficulty*: Opt[DifficultyInt] currentDifficulty*: Opt[DifficultyInt]
currentRandom*: Opt[Hash256] currentRandom*: Opt[Bytes32]
parentDifficulty*: Opt[DifficultyInt] parentDifficulty*: Opt[DifficultyInt]
currentGasLimit*: GasInt currentGasLimit*: GasInt
currentNumber*: BlockNumber currentNumber*: BlockNumber

2
vendor/nim-eth vendored

@ -1 +1 @@
Subproject commit 5ce3c4557fc78ee425fcb8f30f80cb336bbe0b7c Subproject commit 792b8b9bff09a5ed7cc98bc12b0c3d991e019b6f

2
vendor/nim-web3 vendored

@ -1 +1 @@
Subproject commit b41316b25c77c525a2d33192a52958a6972b839d Subproject commit 62a0005b0907a64090827d4e5d691682587f5b2a