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: improved error handling when config uses cluster-id and pubsub topics #2368

Merged
merged 2 commits into from
Jan 30, 2024
Merged
Changes from 1 commit
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
31 changes: 9 additions & 22 deletions apps/wakunode2/app.nim
Original file line number Diff line number Diff line change
Expand Up @@ -129,19 +129,11 @@ proc init*(T: type App, rng: ref HmacDrbgContext, conf: WakuNodeConf): T =
else: recordRes.get()

# Check the ENR sharding info for matching config cluster id
if conf.clusterId != 0:
let res = record.toTyped()
if res.isErr():
error "ENR setup failed", error = $res.get()
quit(QuitFailure)

let relayShard = res.get().relaySharding().valueOr:
error "no sharding info"
quit(QuitFailure)

if conf.clusterId != relayShard.clusterId:
error "cluster id mismatch"
quit(QuitFailure)
if (let typedRecord = record.toTyped(); typedRecord.isOk):
if (let relayShard = typedRecord.get().relaySharding(); relayShard.isSome):
SionoiS marked this conversation as resolved.
Show resolved Hide resolved
if relayShard.get().clusterId != conf.clusterId:
error "cluster id mismatch configured shards"
quit(QuitFailure)

App(
version: git_version,
Expand Down Expand Up @@ -368,15 +360,10 @@ proc updateEnr(app: var App): AppResult[void] =
let record = enrConfiguration(app.conf, app.netConf, app.key).valueOr:
return err("ENR setup failed: " & error)

if app.conf.clusterId != 0:
let tRecord = record.toTyped().valueOr:
return err("ENR setup failed: " & $error)

let relayShard = tRecord.relaySharding().valueOr:
return err("ENR setup failed: no sharding info")

if app.conf.clusterId != relayShard.clusterId:
return err("ENR setup failed: cluster id mismatch")
if (let typedRecord = record.toTyped(); typedRecord.isOk):
if (let relayShard = typedRecord.get().relaySharding(); relayShard.isSome):
if relayShard.get().clusterId != app.conf.clusterId:
SionoiS marked this conversation as resolved.
Show resolved Hide resolved
return err("cluster id mismatch configured shards")

app.record = record
app.node.enr = record
Expand Down
Loading