Skip to content

Commit bc24ddb

Browse files
committed
review
1 parent 7116edf commit bc24ddb

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

nimbus_verified_proxy/rpc/rpc_eth_api.nim

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,27 @@ proc installEthApiHandlers*(vp: VerifiedRpcProxy) =
277277
raise newException(ValueError, error)
278278

279279
vp.proxy.rpc("eth_newFilter") do(filterOptions: FilterOptions) -> string:
280-
var id: array[8, byte] # 64bits
280+
if vp.filterStore.len >= MAX_FILTERS:
281+
raise newException(ValueError, "FilterStore already full")
281282

282-
if randomBytes(id) != len(id):
283-
raise newException(ValueError, "Couldn't assign a identifier for the filter")
283+
var
284+
id: array[8, byte] # 64bits
285+
strId: string
284286

285-
let strId = toHex(id)
287+
for i in 0 .. (MAX_ID_TRIES + 1):
288+
if randomBytes(id) != len(id):
289+
raise newException(
290+
ValueError, "Couldn't generate a random identifier for the filter"
291+
)
292+
293+
strId = toHex(id)
294+
295+
if not vp.filterStore.contains(strId):
296+
break
297+
298+
if i >= MAX_ID_TRIES:
299+
raise
300+
newException(ValueError, "Couldn't create a unique identifier for the filter")
286301

287302
vp.filterStore[strId] =
288303
FilterStoreItem(filter: filterOptions, blockMarker: Opt.none(Quantity))

nimbus_verified_proxy/types.nim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ const
2222
ACCOUNTS_CACHE_SIZE = 128
2323
CODE_CACHE_SIZE = 64
2424
STORAGE_CACHE_SIZE = 256
25+
MAX_ID_TRIES* = 10
26+
MAX_FILTERS* = 256
2527

2628
type
2729
AccountsCacheKey* = (Root, Address)

0 commit comments

Comments
 (0)