Skip to content

Commit 2a2d634

Browse files
committed
lint and rebase fixes
1 parent 4230cc2 commit 2a2d634

File tree

3 files changed

+41
-20
lines changed

3 files changed

+41
-20
lines changed

nimbus_verified_proxy/rpc/receipts.nim

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,38 @@ proc getReceipts*(
8484

8585
await vp.getReceipts(header, numberTag)
8686

87+
proc verifyFilterBoundaries*(
88+
filter: FilterOptions, logObjs: seq[LogObject]
89+
): Result[bool, string] =
90+
let
91+
fromBlock = filter.fromBlock.get(
92+
BlockTag(kind: BlockIdentifierKind.bidAlias, alias: "latest")
93+
)
94+
toBlock =
95+
filter.toBlock.get(BlockTag(kind: BlockIdentifierKind.bidAlias, alias: "latest"))
96+
97+
bottom =
98+
if fromBlock.kind == BlockIdentifierKind.bidNumber:
99+
fromBlock.number
100+
else:
101+
return err("Cannot verify boundaries for block tags in 'fromBlock' field")
102+
top =
103+
if toBlock.kind == BlockIdentifierKind.bidNumber:
104+
toBlock.number
105+
else:
106+
return err("Cannot verify boundaries for block tags in 'toBlock' field")
107+
108+
for lg in logObjs:
109+
if lg.blockNumber.isSome:
110+
if lg.blockNumber.get < bottom or lg.blockNumber.get > top:
111+
return ok(false)
112+
113+
return ok(true)
114+
87115
proc verifyLogs*(
88116
vp: VerifiedRpcProxy, logObjs: seq[LogObject]
89117
): Future[Result[seq[LogObject], string]] {.async.} =
90-
let
91-
fromBlock = filter.fromBlock.get(BlockTag(kind:BlockIdentifierKind.bidAlias, alias: "latest"))
92-
toBlock = filter.toBlock.get(BlockTag(kind:BlockIdentifierKind.bidAlias, alias: "latest"))
93-
94-
bottom = if fromBlock.kind == BlockIdentifierKind.bidNumber: fromBlock.number
95-
else: return err("Cannot verify boundaries for block tags in 'fromBlock' field")
96-
top = if toBlock.kind == BlockIdentifierKind.bidNumber: toBlock.number
97-
else: return err("Cannot verify boundaries for block tags in 'toBlock' field")
118+
var res = newSeq[LogObject]()
98119
99120
# store block hashes contains the logs so that we can batch receipt requests
100121
var
@@ -103,7 +124,7 @@ proc verifyLogs*(
103124
104125
for lg in logObjs:
105126
# none only for pending logs before block is built
106-
if lg.blockNumber.isSome() and lg.blockHash.isSome() and lg.transactionIndex.isSome() and lg.logIndex.isSome():
127+
if lg.blockHash.isSome() and lg.transactionIndex.isSome() and lg.logIndex.isSome():
107128
# exploit sequentiality of logs
108129
if prevBlockHash != lg.blockHash.get():
109130
# TODO: a cache will solve downloading the same block receipts for multiple logs
@@ -119,7 +140,7 @@ proc verifyLogs*(
119140

120141
if rxLog.address != lg.address or rxLog.data != lg.data or
121142
rxLog.topics != lg.topics or
122-
(not match(toLog(lg), filterOptions.address, filterOptions.topics)) or lg.blockNumber.get < bottom or lg.blockNumber.get > top:
143+
(not match(toLog(lg), filterOptions.address, filterOptions.topics)):
123144
return err("one of the returned logs is invalid")
124145

125146
return ok(logObjs)

nimbus_verified_proxy/rpc/rpc_eth_api.nim

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,8 @@ proc installEthApiHandlers*(vp: VerifiedRpcProxy) =
272272
raise newException(ValueError, "receipt couldn't be verified")
273273

274274
vp.proxy.rpc("eth_getLogs") do(filterOptions: FilterOptions) -> seq[LogObject]:
275-
let
276-
logObjs =
275+
let
276+
logObjs =
277277
try:
278278
await vp.rpcClient.eth_getLogs(filterOptions)
279279
except CatchableError as e:
@@ -291,8 +291,8 @@ proc installEthApiHandlers*(vp: VerifiedRpcProxy) =
291291
return verifiedLogs
292292

293293
vp.proxy.rpc("eth_newFilter") do(filterOptions: FilterOptions) -> int:
294-
let
295-
hexId =
294+
let
295+
hexId =
296296
try:
297297
await vp.rpcClient.eth_newFilter(filterOptions)
298298
except CatchableError as e:
@@ -303,7 +303,7 @@ proc installEthApiHandlers*(vp: VerifiedRpcProxy) =
303303
return id
304304

305305
vp.proxy.rpc("eth_uninstallFilter") do(filterId: int) -> bool:
306-
let status =
306+
let status =
307307
try:
308308
await vp.rpcClient.eth_uninstallFilter("0x" & toHex(filterId))
309309
except CatchableError as e:
@@ -318,8 +318,8 @@ proc installEthApiHandlers*(vp: VerifiedRpcProxy) =
318318
if filterId notin vp.filterStore:
319319
raise newException(ValueError, "Filter doesn't exist")
320320

321-
let
322-
logObjs =
321+
let
322+
logObjs =
323323
try:
324324
# use locally stored filter and get logs
325325
await vp.rpcClient.eth_getLogs(vp.filterStore[filterId])
@@ -341,8 +341,8 @@ proc installEthApiHandlers*(vp: VerifiedRpcProxy) =
341341
if filterId notin vp.filterStore:
342342
raise newException(ValueError, "Filter doesn't exist")
343343

344-
let
345-
logObjs =
344+
let
345+
logObjs =
346346
try:
347347
await vp.rpcClient.eth_getFilterChanges("0x" & toHex(filterId))
348348
except CatchableError as e:

nimbus_verified_proxy/types.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,5 @@ proc init*(
9292
storageCache: StorageCache.init(STORAGE_CACHE_SIZE),
9393
filterStore: initTable[int, FilterOptions](),
9494
chainId: chainId,
95-
maxBlockWalk: maxBlockWalk
95+
maxBlockWalk: maxBlockWalk,
9696
)

0 commit comments

Comments
 (0)