From a386880be99ebb55f09dabc3bad4b27ce7703790 Mon Sep 17 00:00:00 2001 From: Simon-Pierre Vivier Date: Wed, 23 Oct 2024 17:56:19 -0400 Subject: [PATCH] fix: add more logs, stagger intervals & set prune offset to 10% for waku sync (#3142) --- waku/waku_core/time.nim | 14 +------------- waku/waku_sync/protocol.nim | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/waku/waku_core/time.nim b/waku/waku_core/time.nim index bee5522bd..6f9e5eace 100644 --- a/waku/waku_core/time.nim +++ b/waku/waku_core/time.nim @@ -35,16 +35,4 @@ template nanosecondTime*(collector: Gauge, body: untyped) = metrics.set(collector, nowInUnixFloat() - start) else: body - -# Unused yet. Kept for future use in Waku Sync. -#[ proc timestampInSeconds*(time: Timestamp): Timestamp = - let timeStr = $time - var timestamp: Timestamp = time - - if timeStr.len() > 16: - timestamp = Timestamp(time div Timestamp(1_000_000_000)) - elif timeStr.len() < 16 and timeStr.len() > 13: - timestamp = Timestamp(time div Timestamp(1_000_000)) - elif timeStr.len() > 10: - timestamp = Timestamp(time div Timestamp(1000)) - return timestamp ]# + diff --git a/waku/waku_sync/protocol.nim b/waku/waku_sync/protocol.nim index 620ff1fa6..a76a6f173 100644 --- a/waku/waku_sync/protocol.nim +++ b/waku/waku_sync/protocol.nim @@ -69,8 +69,8 @@ proc messageIngress*( trace "inserting message into waku sync storage ", msg_hash = msgHash.to0xHex(), timestamp = msg.timestamp - if self.storage.insert(msg.timestamp, msgHash).isErr(): - error "failed to insert message ", msg_hash = msgHash.to0xHex() + self.storage.insert(msg.timestamp, msgHash).isOkOr: + error "failed to insert message ", msg_hash = msgHash.to0xHex(), error = error proc calculateRange( jitter: Duration = 20.seconds, syncRange: Duration = 1.hours @@ -130,6 +130,9 @@ proc request( debug "sync session ended gracefully", client = self.peerManager.switch.peerInfo.peerId, server = conn.peerId + trace "hashes to sync", + client = self.peerManager.switch.peerInfo.peerId, msg_hashes = $hashes + return ok(hashes) continue @@ -177,6 +180,9 @@ proc handleSyncSession( let hashes = await completed.serverTerminate() + trace "hashes to sync", + server = self.peerManager.switch.peerInfo.peerId, msg_hashes = $hashes + return ok(hashes) sent = ?await reconciled.send() @@ -364,7 +370,7 @@ proc new*( syncInterval: syncInterval, syncRange: syncRange, relayJitter: relayJitter, - pruneOffset: syncInterval div 100, + pruneOffset: syncInterval div 10, # 10% offset ) sync.initProtocolHandler() @@ -400,6 +406,9 @@ proc new*( proc periodicSync(self: WakuSync, callback: TransferCallback) {.async.} = debug "periodic sync initialized", interval = $self.syncInterval + # to stagger the intervals + await sleepAsync((self.syncInterval div 2)) + while true: # infinite loop await sleepAsync(self.syncInterval)