From 6ff878c83615029895cbd4cfce537fb0a8ca3515 Mon Sep 17 00:00:00 2001 From: Andrea Maria Piana Date: Wed, 29 Jan 2020 16:57:12 +0100 Subject: [PATCH] Explicitly start messenger We should only start receiving messages/processing topics once all the initializiation is completed, so an endpoint that start the messenger has been added. Before we would initialize the topics/receiving messages at the same time, which resulted in a race condition where a topic was signaled from status-go and was considered new just because was not loaded yet. Signed-off-by: Andrea Maria Piana --- src/status_im/ethereum/json_rpc.cljs | 1 + src/status_im/mailserver/core.cljs | 2 +- src/status_im/mailserver/topics.cljs | 8 +++++--- src/status_im/protocol/core.cljs | 2 +- src/status_im/transport/core.cljs | 14 ++++++++++++++ status-go-version.json | 6 +++--- 6 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/status_im/ethereum/json_rpc.cljs b/src/status_im/ethereum/json_rpc.cljs index cbd04d5d33..261a2c2d13 100644 --- a/src/status_im/ethereum/json_rpc.cljs +++ b/src/status_im/ethereum/json_rpc.cljs @@ -31,6 +31,7 @@ "shh_generateSymKeyFromPassword" {} "shh_getSymKey" {} "shh_markTrustedPeer" {} + "shhext_startMessenger" {} "shhext_sendPairInstallation" {} "shhext_syncDevices" {} "shhext_requestMessages" {} diff --git a/src/status_im/mailserver/core.cljs b/src/status_im/mailserver/core.cljs index 13231eda90..6c10cb8183 100644 --- a/src/status_im/mailserver/core.cljs +++ b/src/status_im/mailserver/core.cljs @@ -808,7 +808,7 @@ :on-success #(log/debug "added mailserver-topic successfully") :on-failure - #(log/error "failed to delete mailserver topic" %)}) + #(log/error "failed to add mailserver topic" %)}) mailserver-topics)} (process-next-messages-request)))))))) diff --git a/src/status_im/mailserver/topics.cljs b/src/status_im/mailserver/topics.cljs index d02e116954..5786f4b36e 100644 --- a/src/status_im/mailserver/topics.cljs +++ b/src/status_im/mailserver/topics.cljs @@ -5,12 +5,14 @@ [status-im.utils.fx :as fx] [taoensso.timbre :as log])) -(defn calculate-last-request [{:keys [discovery?]} +(defn calculate-last-request [{:keys [negotiated? + discovery?]} {:keys [previous-last-request now-s]}] ;; New topic, if discovery we don't fetch history (if (and (nil? previous-last-request) - discovery?) + (or discovery? + negotiated?)) (- now-s 10) (max previous-last-request (- now-s constants/max-request-range)))) @@ -34,7 +36,7 @@ {::json-rpc/call [{:method "mailservers_addMailserverTopic" :params [mailserver-topic] :on-success #(log/debug "added mailserver-topic successfully") - :on-failure #(log/error "failed to delete mailserver topic" %)}]})) + :on-failure #(log/error "failed to add mailserver topic" %)}]})) (defn new-chat-ids? [previous-mailserver-topic new-mailserver-topic] (seq (clojure.set/difference (:chat-ids new-mailserver-topic) diff --git a/src/status_im/protocol/core.cljs b/src/status_im/protocol/core.cljs index 0cba94d138..2b8cbd1af3 100644 --- a/src/status_im/protocol/core.cljs +++ b/src/status_im/protocol/core.cljs @@ -68,4 +68,4 @@ (not initialization-complete?) (assoc :initialization-protocol initialization-protocol))} (when initialization-complete? - (transport/init-whisper))))) + (transport/init-messenger))))) diff --git a/src/status_im/transport/core.cljs b/src/status_im/transport/core.cljs index 064b0120de..6d4f2f19a3 100644 --- a/src/status_im/transport/core.cljs +++ b/src/status_im/transport/core.cljs @@ -2,6 +2,7 @@ status-im.transport.core (:require [re-frame.core :as re-frame] + [status-im.ethereum.json-rpc :as json-rpc] [status-im.native-module.core :as status] [status-im.mailserver.core :as mailserver] [status-im.transport.message.core :as message] @@ -34,10 +35,23 @@ (fx/defn fetch-node-info-fx [cofx] {::fetch-node-info []}) +(fx/defn init-messenger + "We should only start receiving messages/processing topics once all the + initializiation is completed, otherwise we might receive messages/topics + when the state has not been properly initialized." + [cofx] + {::json-rpc/call [{:method "shhext_startMessenger" + :on-success #(do + (log/debug "messenger initialized") + (re-frame/dispatch [::init-whisper])) + :on-failure #(log/error "failed to init messenger")}]}) + (fx/defn init-whisper "Initialises whisper protocol by: - (optionally) initializing mailserver" + {:events [::init-whisper]} [cofx] + (log/debug "Initializing whisper") (fx/merge cofx (fetch-node-info-fx) (pairing/init) diff --git a/status-go-version.json b/status-go-version.json index dc01035a7e..3db8129eda 100644 --- a/status-go-version.json +++ b/status-go-version.json @@ -2,7 +2,7 @@ "_comment": "DO NOT EDIT THIS FILE BY HAND. USE 'scripts/update-status-go.sh ' instead", "owner": "status-im", "repo": "status-go", - "version": "v0.40.0", - "commit-sha1": "dc31c818fce6dbff6cfd76da09d901b0df742e2e", - "src-sha256": "1f0fp5c4lqnh244wcvbnl5i4p9fb0f3i0rjjvbiqwkz9zwwp3xlv" + "version": "v0.41.0", + "commit-sha1": "8931b14c4e40261e6161a3c776bf16cc0fdd1f3a", + "src-sha256": "16r3xbzhh3fljpx11yahm1r5xh4cyvggy5avg6smkpw9m93cb6f7" }