Skip to content

Commit 7b2b59a

Browse files
authored
Add missing fields to RPC object conversion (#2863)
* Add missing fields to RPC object conversion * Fix populateBlockObject call * Remove server_api_helpers.nim * Add metric defined conditional compilation * link with rocksdb
1 parent a241050 commit 7b2b59a

File tree

7 files changed

+138
-237
lines changed

7 files changed

+138
-237
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,17 +322,17 @@ utp-test: | build deps
322322
# Nimbus Verified Proxy related targets
323323

324324
# Builds the nimbus_verified_proxy
325-
nimbus_verified_proxy: | build deps
325+
nimbus_verified_proxy: | build deps rocksdb
326326
echo -e $(BUILD_MSG) "build/$@" && \
327327
$(ENV_SCRIPT) nim nimbus_verified_proxy $(NIM_PARAMS) nimbus.nims
328328

329329
# builds and runs the nimbus_verified_proxy test suite
330-
nimbus-verified-proxy-test: | build deps
330+
nimbus-verified-proxy-test: | build deps rocksdb
331331
$(ENV_SCRIPT) nim nimbus_verified_proxy_test $(NIM_PARAMS) nimbus.nims
332332

333333
# Shared library for verified proxy
334334

335-
libverifproxy: | build deps
335+
libverifproxy: | build deps rocksdb
336336
+ echo -e $(BUILD_MSG) "build/$@" && \
337337
$(ENV_SCRIPT) nim --version && \
338338
$(ENV_SCRIPT) nim c --app:lib -d:"libp2p_pki_schemes=secp256k1" --noMain:on --threads:on --nimcache:nimcache/libverifproxy -o:$(VERIF_PROXY_OUT_PATH)/$@.$(VERIF_PROXY_SHAREDLIBEXT) $(NIM_PARAMS) nimbus_verified_proxy/libverifproxy/verifproxy.nim

nimbus/db/aristo/aristo_init/rocks_db/rdb_get.nim

Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import
2020
../../[aristo_blobify, aristo_desc],
2121
../init_common,
2222
./rdb_desc,
23-
metrics,
2423
std/concurrency/atomics
2524

2625
const
@@ -34,49 +33,53 @@ when extraTraceMessages:
3433
logScope:
3534
topics = "aristo-rocksdb"
3635

37-
type
38-
RdbVtxLruCounter = ref object of Counter
39-
RdbKeyLruCounter = ref object of Counter
40-
41-
var
42-
rdbVtxLruStatsMetric {.used.} = RdbVtxLruCounter.newCollector(
43-
"aristo_rdb_vtx_lru_total",
44-
"Vertex LRU lookup (hit/miss, world/account, branch/leaf)",
45-
labels = ["state", "vtype", "hit"],
46-
)
47-
rdbKeyLruStatsMetric {.used.} = RdbKeyLruCounter.newCollector(
48-
"aristo_rdb_key_lru_total", "HashKey LRU lookup", labels = ["state", "hit"]
49-
)
50-
51-
method collect*(collector: RdbVtxLruCounter, output: MetricHandler) =
52-
let timestamp = collector.now()
53-
54-
# We don't care about synchronization between each type of metric or between
55-
# the metrics thread and others since small differences like this don't matter
56-
for state in RdbStateType:
57-
for vtype in VertexType:
36+
when defined(metrics):
37+
import
38+
metrics
39+
40+
type
41+
RdbVtxLruCounter = ref object of Counter
42+
RdbKeyLruCounter = ref object of Counter
43+
44+
var
45+
rdbVtxLruStatsMetric {.used.} = RdbVtxLruCounter.newCollector(
46+
"aristo_rdb_vtx_lru_total",
47+
"Vertex LRU lookup (hit/miss, world/account, branch/leaf)",
48+
labels = ["state", "vtype", "hit"],
49+
)
50+
rdbKeyLruStatsMetric {.used.} = RdbKeyLruCounter.newCollector(
51+
"aristo_rdb_key_lru_total", "HashKey LRU lookup", labels = ["state", "hit"]
52+
)
53+
54+
method collect*(collector: RdbVtxLruCounter, output: MetricHandler) =
55+
let timestamp = collector.now()
56+
57+
# We don't care about synchronization between each type of metric or between
58+
# the metrics thread and others since small differences like this don't matter
59+
for state in RdbStateType:
60+
for vtype in VertexType:
61+
for hit in [false, true]:
62+
output(
63+
name = "aristo_rdb_vtx_lru_total",
64+
value = float64(rdbVtxLruStats[state][vtype].get(hit)),
65+
labels = ["state", "vtype", "hit"],
66+
labelValues = [$state, $vtype, $ord(hit)],
67+
timestamp = timestamp,
68+
)
69+
70+
method collect*(collector: RdbKeyLruCounter, output: MetricHandler) =
71+
let timestamp = collector.now()
72+
73+
for state in RdbStateType:
5874
for hit in [false, true]:
5975
output(
60-
name = "aristo_rdb_vtx_lru_total",
61-
value = float64(rdbVtxLruStats[state][vtype].get(hit)),
62-
labels = ["state", "vtype", "hit"],
63-
labelValues = [$state, $vtype, $ord(hit)],
76+
name = "aristo_rdb_key_lru_total",
77+
value = float64(rdbKeyLruStats[state].get(hit)),
78+
labels = ["state", "hit"],
79+
labelValues = [$state, $ord(hit)],
6480
timestamp = timestamp,
6581
)
6682

67-
method collect*(collector: RdbKeyLruCounter, output: MetricHandler) =
68-
let timestamp = collector.now()
69-
70-
for state in RdbStateType:
71-
for hit in [false, true]:
72-
output(
73-
name = "aristo_rdb_key_lru_total",
74-
value = float64(rdbKeyLruStats[state].get(hit)),
75-
labels = ["state", "hit"],
76-
labelValues = [$state, $ord(hit)],
77-
timestamp = timestamp,
78-
)
79-
8083
# ------------------------------------------------------------------------------
8184
# Public functions
8285
# ------------------------------------------------------------------------------

nimbus/rpc/rpc_utils.nim

Lines changed: 89 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ proc calculateMedianGasPrice*(chain: CoreDbRef): GasInt {.raises: [RlpError].} =
5454
# For compatibility with `ethpandaops/ethereum-package`, set this to a
5555
# sane minimum for compatibility to unblock testing.
5656
# Note: When this is fixed, update `tests/graphql/queries.toml` and
57-
# re-enable the "query.gasPrice" test case (remove `skip = true`).
57+
# re-enable the "query.gasPrice" test case (remove `skip = true`).
5858
result = max(result, minGasPrice)
5959

6060
proc unsignedTx*(tx: TransactionArgs, chain: CoreDbRef, defaultNonce: AccountNonce, chainId: ChainId): Transaction
@@ -92,112 +92,126 @@ proc unsignedTx*(tx: TransactionArgs, chain: CoreDbRef, defaultNonce: AccountNon
9292

9393
proc toWd(wd: Withdrawal): WithdrawalObject =
9494
WithdrawalObject(
95-
index: Quantity wd.index,
95+
index: Quantity(wd.index),
9696
validatorIndex: Quantity wd.validatorIndex,
9797
address: wd.address,
9898
amount: Quantity wd.amount,
9999
)
100100

101101
proc toWdList(list: openArray[Withdrawal]): seq[WithdrawalObject] =
102-
var res = newSeqOfCap[WithdrawalObject](list.len)
102+
result = newSeqOfCap[WithdrawalObject](list.len)
103103
for x in list:
104-
res.add toWd(x)
105-
return res
104+
result.add toWd(x)
106105

107-
func toWdList(x: Opt[seq[eth_types.Withdrawal]]):
106+
func toWdList(x: Opt[seq[Withdrawal]]):
108107
Opt[seq[WithdrawalObject]] =
109108
if x.isNone: Opt.none(seq[WithdrawalObject])
110109
else: Opt.some(toWdList x.get)
111110

111+
func toAuth*(x: Authorization): AuthorizationObject =
112+
AuthorizationObject(
113+
chainId: Quantity(x.chainId),
114+
address: x.address,
115+
nonce: Quantity(x.nonce),
116+
v: Quantity(x.v),
117+
r: x.r,
118+
s: x.s,
119+
)
120+
121+
proc toAuthList(list: openArray[Authorization]): seq[AuthorizationObject] =
122+
result = newSeqOfCap[AuthorizationObject](list.len)
123+
for x in list:
124+
result.add toAuth(x)
125+
112126
proc populateTransactionObject*(tx: Transaction,
113127
optionalHash: Opt[eth_types.Hash32] = Opt.none(eth_types.Hash32),
114128
optionalNumber: Opt[eth_types.BlockNumber] = Opt.none(eth_types.BlockNumber),
115129
txIndex: Opt[uint64] = Opt.none(uint64)): TransactionObject =
116-
var res = TransactionObject()
117-
res.`type` = Opt.some Quantity(tx.txType)
118-
res.blockHash = optionalHash
119-
res.blockNumber = w3Qty(optionalNumber)
130+
result = TransactionObject()
131+
result.`type` = Opt.some Quantity(tx.txType)
132+
result.blockHash = optionalHash
133+
result.blockNumber = w3Qty(optionalNumber)
120134

121135
if (let sender = tx.recoverSender(); sender.isOk):
122-
res.`from` = sender[]
123-
res.gas = Quantity(tx.gasLimit)
124-
res.gasPrice = Quantity(tx.gasPrice)
125-
res.hash = tx.rlpHash
126-
res.input = tx.payload
127-
res.nonce = Quantity(tx.nonce)
128-
res.to = Opt.some(tx.destination)
136+
result.`from` = sender[]
137+
result.gas = Quantity(tx.gasLimit)
138+
result.gasPrice = Quantity(tx.gasPrice)
139+
result.hash = tx.rlpHash
140+
result.input = tx.payload
141+
result.nonce = Quantity(tx.nonce)
142+
result.to = Opt.some(tx.destination)
129143
if txIndex.isSome:
130-
res.transactionIndex = Opt.some(Quantity(txIndex.get))
131-
res.value = tx.value
132-
res.v = Quantity(tx.V)
133-
res.r = tx.R
134-
res.s = tx.S
135-
res.maxFeePerGas = Opt.some Quantity(tx.maxFeePerGas)
136-
res.maxPriorityFeePerGas = Opt.some Quantity(tx.maxPriorityFeePerGas)
144+
result.transactionIndex = Opt.some(Quantity(txIndex.get))
145+
result.value = tx.value
146+
result.v = Quantity(tx.V)
147+
result.r = tx.R
148+
result.s = tx.S
149+
result.maxFeePerGas = Opt.some Quantity(tx.maxFeePerGas)
150+
result.maxPriorityFeePerGas = Opt.some Quantity(tx.maxPriorityFeePerGas)
137151

138152
if tx.txType >= TxEip2930:
139-
res.chainId = Opt.some(Quantity(tx.chainId))
140-
res.accessList = Opt.some(tx.accessList)
153+
result.chainId = Opt.some(Quantity(tx.chainId))
154+
result.accessList = Opt.some(tx.accessList)
141155

142156
if tx.txType >= TxEip4844:
143-
res.maxFeePerBlobGas = Opt.some(tx.maxFeePerBlobGas)
144-
res.blobVersionedHashes = Opt.some(tx.versionedHashes)
157+
result.maxFeePerBlobGas = Opt.some(tx.maxFeePerBlobGas)
158+
result.blobVersionedHashes = Opt.some(tx.versionedHashes)
145159

146-
return res
160+
if tx.txType >= TxEip7702:
161+
result.authorizationList = Opt.some(toAuthList(tx.authorizationList))
147162

148-
proc populateBlockObject*(blockHash: Hash32,
163+
proc populateBlockObject*(blockHash: eth_types.Hash32,
149164
blk: Block,
150165
totalDifficulty: UInt256,
151166
fullTx: bool,
152-
isUncle = false): BlockObject =
167+
withUncles: bool = false): BlockObject =
153168
template header: auto = blk.header
154169

155-
var res = BlockObject()
156-
res.number = Quantity(header.number)
157-
res.hash = blockHash
158-
res.parentHash = header.parentHash
159-
res.nonce = Opt.some(header.nonce)
160-
res.sha3Uncles = header.ommersHash
161-
res.logsBloom = header.logsBloom
162-
res.transactionsRoot = header.txRoot
163-
res.stateRoot = header.stateRoot
164-
res.receiptsRoot = header.receiptsRoot
165-
res.miner = header.coinbase
166-
res.difficulty = header.difficulty
167-
res.extraData = HistoricExtraData header.extraData
168-
res.mixHash = Hash32 header.mixHash
170+
result = BlockObject()
171+
result.number = Quantity(header.number)
172+
result.hash = blockHash
173+
result.parentHash = header.parentHash
174+
result.nonce = Opt.some(header.nonce)
175+
result.sha3Uncles = header.ommersHash
176+
result.logsBloom = header.logsBloom
177+
result.transactionsRoot = header.txRoot
178+
result.stateRoot = header.stateRoot
179+
result.receiptsRoot = header.receiptsRoot
180+
result.miner = header.coinbase
181+
result.difficulty = header.difficulty
182+
result.extraData = HistoricExtraData header.extraData
183+
result.mixHash = Hash32 header.mixHash
169184

170185
# discard sizeof(seq[byte]) of extraData and use actual length
171-
let size = sizeof(Header) - sizeof(seq[byte]) + header.extraData.len
172-
res.size = Quantity(size)
173-
174-
res.gasLimit = Quantity(header.gasLimit)
175-
res.gasUsed = Quantity(header.gasUsed)
176-
res.timestamp = Quantity(header.timestamp)
177-
res.baseFeePerGas = header.baseFeePerGas
178-
res.totalDifficulty = totalDifficulty
179-
180-
if not isUncle:
181-
res.uncles = blk.uncles.mapIt(it.blockHash)
182-
183-
if fullTx:
184-
for i, tx in blk.transactions:
185-
let txObj = populateTransactionObject(tx,
186-
Opt.some(blockHash),
187-
Opt.some(header.number), Opt.some(i.uint64))
188-
res.transactions.add txOrHash(txObj)
189-
else:
190-
for i, tx in blk.transactions:
191-
let txHash = rlpHash(tx)
192-
res.transactions.add txOrHash(txHash)
193-
194-
res.withdrawalsRoot = header.withdrawalsRoot
195-
res.withdrawals = toWdList blk.withdrawals
196-
res.parentBeaconBlockRoot = header.parentBeaconBlockRoot
197-
res.blobGasUsed = w3Qty(header.blobGasUsed)
198-
res.excessBlobGas = w3Qty(header.excessBlobGas)
199-
200-
return res
186+
let size = sizeof(eth_types.Header) - sizeof(eth_api_types.Blob) + header.extraData.len
187+
result.size = Quantity(size)
188+
189+
result.gasLimit = Quantity(header.gasLimit)
190+
result.gasUsed = Quantity(header.gasUsed)
191+
result.timestamp = Quantity(header.timestamp)
192+
result.baseFeePerGas = header.baseFeePerGas
193+
result.totalDifficulty = totalDifficulty
194+
195+
if not withUncles:
196+
result.uncles = blk.uncles.mapIt(it.blockHash)
197+
198+
if fullTx:
199+
for i, tx in blk.transactions:
200+
let txObj = populateTransactionObject(tx,
201+
Opt.some(blockHash),
202+
Opt.some(header.number), Opt.some(i.uint64))
203+
result.transactions.add txOrHash(txObj)
204+
else:
205+
for i, tx in blk.transactions:
206+
let txHash = rlpHash(tx)
207+
result.transactions.add txOrHash(txHash)
208+
209+
result.withdrawalsRoot = header.withdrawalsRoot
210+
result.withdrawals = toWdList blk.withdrawals
211+
result.parentBeaconBlockRoot = header.parentBeaconBlockRoot
212+
result.blobGasUsed = w3Qty(header.blobGasUsed)
213+
result.excessBlobGas = w3Qty(header.excessBlobGas)
214+
result.requestsHash = header.requestsHash
201215

202216
proc populateReceipt*(receipt: Receipt, gasUsed: GasInt, tx: Transaction,
203217
txIndex: uint64, header: Header): ReceiptObject =

0 commit comments

Comments
 (0)