Skip to content

Commit

Permalink
fix: add more logs, stagger intervals & set prune offset to 10% for w…
Browse files Browse the repository at this point in the history
…aku sync (#3142)
  • Loading branch information
SionoiS authored Oct 23, 2024
1 parent 80c7581 commit a386880
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
14 changes: 1 addition & 13 deletions waku/waku_core/time.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]#

15 changes: 12 additions & 3 deletions waku/waku_sync/protocol.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -364,7 +370,7 @@ proc new*(
syncInterval: syncInterval,
syncRange: syncRange,
relayJitter: relayJitter,
pruneOffset: syncInterval div 100,
pruneOffset: syncInterval div 10, # 10% offset
)

sync.initProtocolHandler()
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit a386880

Please sign in to comment.