mirror of https://github.com/waku-org/nwaku.git
fix: filter discv5 bootstrap nodes by shards (#2073)
This commit is contained in:
parent
7a376f59c8
commit
d178105d9f
|
@ -4,7 +4,7 @@ else:
|
||||||
{.push raises: [].}
|
{.push raises: [].}
|
||||||
|
|
||||||
import
|
import
|
||||||
std/[sequtils, strutils, options, sugar, sets],
|
std/[sequtils, strutils, options, sets],
|
||||||
stew/results,
|
stew/results,
|
||||||
stew/shims/net,
|
stew/shims/net,
|
||||||
chronos,
|
chronos,
|
||||||
|
@ -42,7 +42,7 @@ type WakuDiscoveryV5Config* = object
|
||||||
|
|
||||||
## Protocol
|
## Protocol
|
||||||
|
|
||||||
type WakuDiscv5Predicate* = proc(record: waku_enr.Record): bool {.closure, gcsafe.}
|
type WakuDiscv5Predicate* = proc(record: waku_enr.Record): bool {.closure, gcsafe, raises: [].}
|
||||||
|
|
||||||
type WakuDiscoveryV5* = ref object
|
type WakuDiscoveryV5* = ref object
|
||||||
conf: WakuDiscoveryV5Config
|
conf: WakuDiscoveryV5Config
|
||||||
|
@ -74,14 +74,32 @@ proc shardingPredicate*(record: Record): Option[WakuDiscv5Predicate] =
|
||||||
|
|
||||||
return some(predicate)
|
return some(predicate)
|
||||||
|
|
||||||
proc new*(T: type WakuDiscoveryV5, rng: ref HmacDrbgContext, conf: WakuDiscoveryV5Config, record: Option[waku_enr.Record]): T =
|
proc new*(
|
||||||
|
T: type WakuDiscoveryV5,
|
||||||
|
rng: ref HmacDrbgContext,
|
||||||
|
conf: WakuDiscoveryV5Config,
|
||||||
|
record: Option[waku_enr.Record]
|
||||||
|
): T =
|
||||||
|
let shardPredOp =
|
||||||
|
if record.isSome(): shardingPredicate(record.get())
|
||||||
|
else: none(WakuDiscv5Predicate)
|
||||||
|
|
||||||
|
var bootstrapRecords = conf.bootstrapRecords
|
||||||
|
|
||||||
|
# Remove bootstrap nodes with which we don't share shards.
|
||||||
|
if shardPredOp.isSome():
|
||||||
|
bootstrapRecords.keepIf(shardPredOp.get())
|
||||||
|
|
||||||
|
if conf.bootstrapRecords.len > 0 and bootstrapRecords.len == 0:
|
||||||
|
warn "No discv5 bootstrap nodes share this node configured shards"
|
||||||
|
|
||||||
let protocol = newProtocol(
|
let protocol = newProtocol(
|
||||||
rng = rng,
|
rng = rng,
|
||||||
config = conf.discv5Config.get(protocol.defaultDiscoveryConfig),
|
config = conf.discv5Config.get(protocol.defaultDiscoveryConfig),
|
||||||
bindPort = conf.port,
|
bindPort = conf.port,
|
||||||
bindIp = conf.address,
|
bindIp = conf.address,
|
||||||
privKey = conf.privateKey,
|
privKey = conf.privateKey,
|
||||||
bootstrapRecords = conf.bootstrapRecords,
|
bootstrapRecords = bootstrapRecords,
|
||||||
enrAutoUpdate = conf.autoupdateRecord,
|
enrAutoUpdate = conf.autoupdateRecord,
|
||||||
previousRecord = record,
|
previousRecord = record,
|
||||||
enrIp = none(ValidIpAddress),
|
enrIp = none(ValidIpAddress),
|
||||||
|
@ -89,12 +107,6 @@ proc new*(T: type WakuDiscoveryV5, rng: ref HmacDrbgContext, conf: WakuDiscovery
|
||||||
enrUdpPort = none(Port),
|
enrUdpPort = none(Port),
|
||||||
)
|
)
|
||||||
|
|
||||||
let shardPredOp =
|
|
||||||
if record.isSome():
|
|
||||||
shardingPredicate(record.get())
|
|
||||||
else:
|
|
||||||
none(WakuDiscv5Predicate)
|
|
||||||
|
|
||||||
WakuDiscoveryV5(conf: conf, protocol: protocol, listening: false, predicate: shardPredOp)
|
WakuDiscoveryV5(conf: conf, protocol: protocol, listening: false, predicate: shardPredOp)
|
||||||
|
|
||||||
proc new*(T: type WakuDiscoveryV5,
|
proc new*(T: type WakuDiscoveryV5,
|
||||||
|
|
Loading…
Reference in New Issue