Round receiver time (#815)

This commit is contained in:
Hanno Cornelius 2022-01-17 19:37:06 +01:00 committed by GitHub
parent 3e9ca25abc
commit 95d2e8bf71
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 5 deletions

View File

@ -17,6 +17,7 @@ which is a sequence of string.
- Increased maximum length for reading from a libp2p input stream to allow largest possible protocol messages, including `HistoryResponse` messages at max size.
- Significantly improved store node query performance
- Added GossipSub `MessageIdProvider` for `11/WAKU2-RELAY` messages.
- Store: timestamps of message reception, used for indexing, now have consistent millisecond resolution.
## 2021-11-05 v0.6

View File

@ -7,7 +7,7 @@
# Group by std, external then internal imports
import
# std imports
std/[tables, times, sequtils, algorithm, options],
std/[tables, times, sequtils, algorithm, options, math],
# external imports
bearssl,
chronicles,
@ -55,15 +55,18 @@ const
# TODO Move serialization function to separate file, too noisy
# TODO Move pagination to separate file, self-contained logic
proc computeIndex*(msg: WakuMessage): Index =
## Takes a WakuMessage and returns its Index
proc computeIndex*(msg: WakuMessage, receivedTime = getTime().toUnixFloat()): Index =
## Takes a WakuMessage with received timestamp and returns its Index.
## Received timestamp will default to system time if not provided.
var ctx: sha256
ctx.init()
ctx.update(msg.contentTopic.toBytes()) # converts the contentTopic to bytes
ctx.update(msg.payload)
let digest = ctx.finish() # computes the hash
ctx.clear()
var index = Index(digest:digest, receiverTime: epochTime(), senderTime: msg.timestamp)
let receiverTime = receivedTime.round(3) # Ensure timestamp has (only) millisecond resolution
var index = Index(digest:digest, receiverTime: receiverTime, senderTime: msg.timestamp)
return index
proc encode*(index: Index): ProtoBuffer =
@ -466,7 +469,7 @@ proc init*(ws: WakuStore, capacity = DefaultStoreCapacity) =
proc onData(receiverTime: float64, msg: WakuMessage, pubsubTopic: string) =
# TODO index should not be recalculated
ws.messages.add(IndexedWakuMessage(msg: msg, index: msg.computeIndex(), pubsubTopic: pubsubTopic))
ws.messages.add(IndexedWakuMessage(msg: msg, index: msg.computeIndex(receiverTime), pubsubTopic: pubsubTopic))
info "attempting to load messages from persistent storage"