Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(rln-relay): health check should account for window of roots #2664

Merged
merged 4 commits into from
May 8, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions waku/waku_rln_relay/group_manager/on_chain/group_manager.nim
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ proc getNewBlockCallback(g: OnchainGroupManager): proc =
g.retryWrapper(handleBlockRes, "Failed to handle new block"):
await g.getAndHandleEvents(fromBlock, latestBlock)

# cannot use isOkOr here because results in a compile-time error that
# cannot use isOkOr here because results in a compile-time error that
# shows the error is void for some reason
let setMetadataRes = g.setMetadata()
if setMetadataRes.isErr():
Expand Down Expand Up @@ -855,7 +855,8 @@ method isReady*(g: OnchainGroupManager): Future[bool] {.async.} =
g.retryWrapper(currentBlock, "Failed to get the current block number"):
cast[BlockNumber](await g.ethRpc.get().provider.eth_blockNumber())

if g.latestProcessedBlock < currentBlock:
# the node is still able to process messages if it is behind the latest block by a factor of the valid roots
if uint(g.latestProcessedBlock) < uint(currentBlock) - uint(g.validRoots.len):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if is safer to add parenthesis:

Suggested change
if uint(g.latestProcessedBlock) < uint(currentBlock) - uint(g.validRoots.len):
if uint(g.latestProcessedBlock) < ( uint(currentBlock) - uint(g.validRoots.len) ):

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't harm, i would add it as well :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't it better widening rather than narrowing? i mean instead of casting everything to unit and operating with that, using the latestProcessedBlock type which has more bits and then "widening" validRoots to do the -?

wondering also if in the first run we can hit currentBlock-g.validRoots.len where currentBlock=0 and since we are using unit that will lead to a huge value, meaning that we are ready when we are not?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currentBlock will never be 0, since that is fetched from the chain (and we can operate under the assumption that it will always be greater than 0). good point about widening vs narrowing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

casted to u256 - 442ca43

return false

return not (await g.isSyncing())
Loading