mirror of https://github.com/waku-org/nwaku.git
chore: handle errors w.r.t. configured cluster-id and pubsub topics (#2368)
This commit is contained in:
parent
573788739b
commit
e04e35e229
|
@ -49,7 +49,7 @@ import
|
|||
../../waku/waku_api/jsonrpc/store/handlers as rpc_store_api,
|
||||
../../waku/waku_archive,
|
||||
../../waku/waku_dnsdisc,
|
||||
../../waku/waku_enr,
|
||||
../../waku/waku_enr/sharding,
|
||||
../../waku/waku_discv5,
|
||||
../../waku/waku_peer_exchange,
|
||||
../../waku/waku_rln_relay,
|
||||
|
@ -128,20 +128,9 @@ proc init*(T: type App, rng: ref HmacDrbgContext, conf: WakuNodeConf): T =
|
|||
quit(QuitFailure)
|
||||
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 isClusterMismatched(record, conf.clusterId):
|
||||
error "cluster id mismatch configured shards"
|
||||
quit(QuitFailure)
|
||||
|
||||
App(
|
||||
version: git_version,
|
||||
|
@ -368,15 +357,8 @@ 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 isClusterMismatched(record, app.conf.clusterId):
|
||||
return err("cluster id mismatch configured shards")
|
||||
|
||||
app.record = record
|
||||
app.node.enr = record
|
||||
|
|
|
@ -254,3 +254,11 @@ proc containsShard*(r: Record, topic: PubsubTopic|string): bool =
|
|||
return false
|
||||
|
||||
containsShard(r, parseRes.value)
|
||||
|
||||
proc isClusterMismatched*(record: Record, clusterId: uint32): bool =
|
||||
## Check the ENR sharding info for matching cluster id
|
||||
if (let typedRecord = record.toTyped(); typedRecord.isOk()):
|
||||
if (let relayShard = typedRecord.get().relaySharding(); relayShard.isSome()):
|
||||
return relayShard.get().clusterId != clusterId
|
||||
|
||||
return false
|
Loading…
Reference in New Issue