chore: Refactor of FilterV2 subscription management with Time-to-live maintenance (#2341)

* Refactor of FilterV2 subscription handling and maintenance with addition subscription time-to-live support.
Fixed all tests and reworked where subscription handling changes needed it.
Adapted REST API /admin filter subscription retrieve to new filter subscription structure.

* Fix tests and PR comments

* Added filter v2 subscription timeout tests and fixed

* Fix review comments and suggestions. No functional change.

* Remove leftover echoes from test_rest_admin

* Fix failed legacy filter tests due to separation of mounting the filters.

* Small fixes, fix naming typo, removed duplicated checks in test
This commit is contained in:
NagyZoltanPeter
2024-01-16 17:27:40 +01:00
committed by GitHub
parent 3d816c0814
commit c3358409bb
23 changed files with 1122 additions and 544 deletions
+2 -1
View File
@@ -468,6 +468,7 @@ proc processInput(rfd: AsyncFD, rng: ref HmacDrbgContext) {.async.} =
let peerInfo = parsePeerInfo(conf.filternode)
if peerInfo.isOk():
await node.mountFilter()
await node.mountLegacyFilter()
await node.mountFilterClient()
node.peerManager.addServicePeer(peerInfo.value, WakuLegacyFilterCodec)
@@ -507,7 +508,7 @@ proc processInput(rfd: AsyncFD, rng: ref HmacDrbgContext) {.async.} =
echo "A spam message is found and discarded"
chat.prompt = false
showChatPrompt(chat)
echo "rln-relay preparation is in progress..."
let rlnConf = WakuRlnConfig(
+1
View File
@@ -288,6 +288,7 @@ when isMainModule:
if conf.filter:
waitFor mountFilter(bridge.nodev2)
waitFor mountLegacyFilter(bridge.nodev2)
if conf.staticnodes.len > 0:
waitFor connectToNodes(bridge.nodev2, conf.staticnodes)
+14 -6
View File
@@ -254,7 +254,7 @@ proc setupDiscoveryV5*(app: App): WakuDiscoveryV5 =
)
WakuDiscoveryV5.new(
app.rng,
app.rng,
discv5Conf,
some(app.record),
some(app.node.peerManager),
@@ -326,7 +326,7 @@ proc setupWakuApp*(app: var App): AppResult[void] =
ok()
proc getPorts(listenAddrs: seq[MultiAddress]):
AppResult[tuple[tcpPort, websocketPort: Option[Port]]] =
AppResult[tuple[tcpPort, websocketPort: Option[Port]]] =
var tcpPort, websocketPort = none(Port)
@@ -548,7 +548,15 @@ proc setupProtocols(node: WakuNode,
# Filter setup. NOTE Must be mounted after relay
if conf.filter:
try:
await mountFilter(node, filterTimeout = chronos.seconds(conf.filterTimeout))
await mountLegacyFilter(node, filterTimeout = chronos.seconds(conf.filterTimeout))
except CatchableError:
return err("failed to mount waku legacy filter protocol: " & getCurrentExceptionMsg())
try:
await mountFilter(node,
subscriptionTimeout = chronos.seconds(conf.filterSubscriptionTimeout),
maxFilterPeers = conf.filterMaxPeersToServe,
maxFilterCriteriaPerPeer = conf.filterMaxCriteria)
except CatchableError:
return err("failed to mount waku filter protocol: " & getCurrentExceptionMsg())
@@ -724,7 +732,7 @@ proc startRestServer(app: App, address: IpAddress, port: Port, conf: WakuNodeCon
let filterCache = MessageCache.init()
let filterDiscoHandler =
let filterDiscoHandler =
if app.wakuDiscv5.isSome():
some(defaultDiscoveryHandler(app.wakuDiscv5.get(), Filter))
else: none(DiscoveryHandler)
@@ -739,7 +747,7 @@ proc startRestServer(app: App, address: IpAddress, port: Port, conf: WakuNodeCon
notInstalledTab["filter"] = "/filter endpoints are not available. Please check your configuration: --filternode"
## Store REST API
let storeDiscoHandler =
let storeDiscoHandler =
if app.wakuDiscv5.isSome():
some(defaultDiscoveryHandler(app.wakuDiscv5.get(), Store))
else: none(DiscoveryHandler)
@@ -749,7 +757,7 @@ proc startRestServer(app: App, address: IpAddress, port: Port, conf: WakuNodeCon
## Light push API
if conf.lightpushnode != "" and
app.node.wakuLightpushClient != nil:
let lightDiscoHandler =
let lightDiscoHandler =
if app.wakuDiscv5.isSome():
some(defaultDiscoveryHandler(app.wakuDiscv5.get(), Lightpush))
else: none(DiscoveryHandler)
+18 -2
View File
@@ -95,6 +95,7 @@ type
defaultValue: false,
name: "execute" .}: bool
of noCommand:
## Application-level configuration
protectedTopics* {.
@@ -221,7 +222,7 @@ type
desc: "Rln relay identity commitment key as a Hex string",
defaultValue: ""
name: "rln-relay-id-commitment-key" }: string
rlnRelayTreePath* {.
desc: "Path to the RLN merkle tree sled db (https://github.com/spacejam/sled)",
defaultValue: ""
@@ -304,10 +305,25 @@ type
name: "filternode" }: string
filterTimeout* {.
desc: "Timeout for filter node in seconds.",
desc: "Filter clients will be wiped out if not able to receive push messages within this timeout. In seconds.",
defaultValue: 14400 # 4 hours
name: "filter-timeout" }: int64
filterSubscriptionTimeout* {.
desc: "Timeout for filter subscription without ping or refresh it, in seconds. Only for v2 filter protocol.",
defaultValue: 300 # 5 minutes
name: "filter-subscription-timeout" }: int64
filterMaxPeersToServe* {.
desc: "Maximum number of peers to serve at a time. Only for v2 filter protocol.",
defaultValue: 1000
name: "filter-max-peers-to-serve" }: uint32
filterMaxCriteria* {.
desc: "Maximum number of pubsub- and content topic combination per peers at a time. Only for v2 filter protocol.",
defaultValue: 1000
name: "filter-max-criteria" }: uint32
## Lightpush config
lightpush* {.