From 0c411dec21a698253c92a4ba88bd97c57a489f7c Mon Sep 17 00:00:00 2001 From: jm-clius Date: Mon, 17 Jan 2022 19:02:48 +0000 Subject: [PATCH] deploy: 95d2e8bf71fde85fc5e8c77aa1b6bb2e88913641 --- CHANGELOG.md | 1 + .../vendor/libbacktrace-upstream/libtool | 2 +- waku/v2/protocol/waku_store/waku_store.nim | 13 ++++++++----- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 087683a84..4b12034f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/vendor/nim-libbacktrace/vendor/libbacktrace-upstream/libtool b/vendor/nim-libbacktrace/vendor/libbacktrace-upstream/libtool index 1d424fb96..cedf0a579 100755 --- a/vendor/nim-libbacktrace/vendor/libbacktrace-upstream/libtool +++ b/vendor/nim-libbacktrace/vendor/libbacktrace-upstream/libtool @@ -2,7 +2,7 @@ # libtool - Provide generalized library-building support services. # Generated automatically by config.status (libbacktrace) version-unused -# Libtool was configured on host fv-az272-614: +# Libtool was configured on host fv-az199-574: # NOTE: Changes made to this file will be lost: look at ltmain.sh. # # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, diff --git a/waku/v2/protocol/waku_store/waku_store.nim b/waku/v2/protocol/waku_store/waku_store.nim index ecbab596c..c9294085c 100644 --- a/waku/v2/protocol/waku_store/waku_store.nim +++ b/waku/v2/protocol/waku_store/waku_store.nim @@ -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"