Skip to content

Commit

Permalink
feat: ENR can now be updated
Browse files Browse the repository at this point in the history
  • Loading branch information
SionoiS committed Aug 17, 2023
1 parent cf30139 commit 7793ebf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 11 additions & 0 deletions waku/waku_discv5.nim
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,17 @@ proc new*(T: type WakuDiscoveryV5,

WakuDiscoveryV5.new(rng, conf, some(record))

proc updateENRShards*(wd: WakuDiscoveryV5, shards: RelayShards): Result[void, cstring] =
let (field, value) =
if shards.indices.len >= 64:
(ShardingBitVectorEnrField, shards.toBitVector())
else:
(ShardingIndicesListEnrField, ?shards.toIndicesList())

?wd.protocol.updateRecord([(field, value)])

ok()

proc shardingPredicate*(record: Record): Option[WakuDiscv5Predicate] =
## Filter peers based on relay sharding information

Expand Down
4 changes: 2 additions & 2 deletions waku/waku_enr/sharding.nim
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func contains*(rs: RelayShards, topic: PubsubTopic|string): bool =

# ENR builder extension

func toIndicesList(rs: RelayShards): EnrResult[seq[byte]] =
func toIndicesList*(rs: RelayShards): EnrResult[seq[byte]] =
if rs.indices.len > high(uint8).int:
return err("indices list too long")

Expand Down Expand Up @@ -137,7 +137,7 @@ func fromIndicesList(buf: seq[byte]): Result[RelayShards, string] =

ok(RelayShards(cluster: cluster, indices: indices))

func toBitVector(rs: RelayShards): seq[byte] =
func toBitVector*(rs: RelayShards): seq[byte] =
## The value is comprised of a two-byte shard cluster index in network byte
## order concatenated with a 128-byte wide bit vector. The bit vector
## indicates which shards of the respective shard cluster the node is part
Expand Down

0 comments on commit 7793ebf

Please sign in to comment.