Remove all integrations with signal wakuv2.peerstats (#20501)

Removes code integrating with the signal wakuv2.peerstats. The response from
this signal is rather large and it can sometimes happen in short bursts.

- Fixes https://github.com/status-im/status-mobile/issues/20176

We were using it to keep track of the number of peers in real-time. We now only
fetch the peer count in two instances (synchronously inside rn/use-mount):

- When the user opens the legacy screen Settings > Advanced > Peers stats.
- When the user opens the visibility status dropdown in Settings, because the
  peers count will be used when the user chooses "Offline" (status inactive).

Note: we don't send anymore the peers count when the user shakes the phone. We
assume this value is already available in :peers-summary (which will be shared
by the user).

status-go still publishes the signal, we just ignore it to remove the
performance overhead of transforming to cljs and mutating the app-db (thus
interrupting the queue from more important stuff).

Steps to test:

- Verify user can see peers count in Settings > Advanced > Peers stats
- Verify changing the visibility status of user Alice in the Settings screen
  leads to the desired effect to the other party seeing Alice's visibility
  status.
This commit is contained in:
Icaro Motta 2024-07-02 19:48:15 -03:00 committed by GitHub
parent e221e23255
commit 91c22df498
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 42 additions and 209 deletions

View File

@ -17,7 +17,7 @@
(reg-root-key-sub :ui/search :ui/search)
(reg-root-key-sub :network/type :network/type)
(reg-root-key-sub :network-status :network-status)
(reg-root-key-sub :peers-count :peers-count)
(reg-root-key-sub :peer-stats/count :peer-stats/count)
(reg-root-key-sub :peers-summary :peers-summary)
(reg-root-key-sub :web3-node-version :web3-node-version)

View File

@ -1,14 +1,9 @@
(ns legacy.status-im.ui.components.connectivity.view
(:require
[clojure.string :as string]
[legacy.status-im.ui.components.animation :as animation]
[legacy.status-im.ui.components.colors :as colors]
[legacy.status-im.ui.components.core :as quo]
[legacy.status-im.ui.components.list.item :as list.item]
[legacy.status-im.ui.components.react :as react]
[re-frame.core :as re-frame]
[utils.i18n :as i18n])
(:require-macros [legacy.status-im.utils.views :as views :refer [defview letsubs]]))
[legacy.status-im.ui.components.react :as react])
(:require-macros [legacy.status-im.utils.views :as views]))
(defn easing
[direction n]
@ -72,112 +67,3 @@
colors/white)
:left
(* 0.15 parent-width))}]]]))
(defview loading-indicator
[]
(letsubs [fetching? [:mailserver/fetching?]
window-width [:dimensions/window-width]]
(when fetching?
[loading-indicator-anim window-width])))
(defn hide-sheet-and-dispatch
[event]
(re-frame/dispatch [:bottom-sheet/hide-old])
(re-frame/dispatch event))
(defview connectivity-sheet
[]
(letsubs [{:keys [peers node mobile sync]} [:connectivity/state]
current-mailserver-name [:mailserver/current-name]
peers-count [:peers-count]
{:keys [syncing-on-mobile-network?]} [:profile/profile]]
[:<>
[quo/header {:title (i18n/label :t/connection-status) :border-bottom false}]
[quo/list-header (i18n/label :t/peer-to-peer)]
(if (= peers :offline)
[list.item/list-item
{:title (i18n/label :t/not-connected-to-peers)
:accessibility-label "not-connected-to-peers"
:subtitle (i18n/label :t/unable-to-send-messages)
:subtitle-max-lines 2
:theme :negative
:icon :main-icons/network}]
[list.item/list-item
{:title (str (i18n/label :t/connected-to)
" " peers-count
" " (string/lower-case (i18n/label :t/peers)))
:accessibility-label "connected-to-n-peers"
:subtitle (i18n/label :t/can-send-messages)
:subtitle-max-lines 2
:theme :positive
:icon :main-icons/network}])
[quo/list-header (i18n/label :t/history-nodes)]
(cond
(#{:error :offline} node)
[list.item/list-item
{:title (i18n/label :t/not-connected-nodes)
:accessibility-label "not-connected-nodes"
:subtitle (i18n/label :t/unable-to-fetch)
:theme :negative
:icon :main-icons/mailserver}]
(= node :disabled)
[list.item/list-item
{:title (i18n/label :t/nodes-disabled)
:accessibility-label "nodes-disabled"
:subtitle (i18n/label :t/unable-to-fetch)
:disabled true
:icon :main-icons/mailserver}]
(and mobile (not sync))
[list.item/list-item
{:title (i18n/label :t/waiting-wi-fi)
:accessibility-label "waiting-wi-fi"
:subtitle (i18n/label :t/unable-to-fetch)
:disabled true
:icon :main-icons/mailserver}]
(= node :connecting)
[list.item/list-item
{:title (i18n/label :t/connecting)
:accessibility-label "connecting"
:subtitle (i18n/label :t/unable-to-fetch)
:icon :main-icons/mailserver}]
(= node :online)
[list.item/list-item
{:title (str (i18n/label :t/connected-to) " " current-mailserver-name)
:accessibility-label "connected-to-mailserver"
:subtitle (i18n/label :t/you-can-fetch)
:theme :positive
:icon :main-icons/mailserver}])
[list.item/list-item
{:title (i18n/label :t/settings)
:accessibility-label "settings"
:theme :accent
:on-press #(hide-sheet-and-dispatch [:navigate-to :legacy-sync-settings])
:icon :main-icons/settings}]
(when mobile
[:<>
[react/view
{:margin-vertical 8
:background-color colors/gray-lighter
:height 36
:align-items :center
:justify-content :center}
[react/text {:style {:color colors/gray}} (i18n/label :t/youre-on-mobile-network)]]
[list.item/list-item
{:title (i18n/label :t/mobile-network-use-mobile)
:accessibility-label "mobile-network-use-mobile"
:accessory :switch
:on-press #(re-frame/dispatch [:mobile-network/set-syncing
(not syncing-on-mobile-network?)])
:active syncing-on-mobile-network?}]
[react/text {:style {:margin-horizontal 16 :margin-bottom 12 :color colors/gray}}
(i18n/label :t/status-mobile-descr)]])]))
(defn get-icon
[{:keys [peers node mobile sync]}]
(if (or (= peers :offline)
(= node :offline)
(= node :connecting))
:main-icons/offline
(if mobile
(if sync :main-icons/mobile-sync :main-icons/mobile-sync-off)
(when (#{:error :disabled} node) :main-icons/node-offline))))

View File

@ -1,17 +1,21 @@
(ns legacy.status-im.ui.screens.peers-stats
(:require
[react-native.core :as react-native.core]
[react-native.core :as rn]
[utils.i18n :as i18n]
[utils.re-frame :as re-frame]))
[utils.re-frame :as rf]))
(defn peers-stats
[]
(let [peers-count (re-frame/sub [:peers-count])]
[react-native.core/view
{:flex 1
:margin-horizontal 8}
[react-native.core/view
(let [peers-count (rf/sub [:peer-stats/count])]
(rn/use-mount
(fn []
(rf/dispatch [:peer-stats/get-count])))
[rn/view
{:style {:flex 1
:margin-horizontal 8}}
[rn/view
{:style {:flex-direction :row
:margin-vertical 8
:justify-content :space-between}}
[react-native.core/text (str (i18n/label :t/peers-count) ": " peers-count)]]]))
[rn/text (str (i18n/label :t/peers-count) ": " peers-count)]]]))

View File

@ -128,7 +128,6 @@
:current-chat-id
:network
:network-status
:peers-count
:peers-summary
:sync-state
:view-id

View File

@ -130,7 +130,7 @@
status-type]}]
(and
(= status-type constants/visibility-status-inactive)
(> (:peers-count db) 0))
(pos? (:peer-stats/count db)))
;; Disable broadcasting further updates
(conj {:ms 1000
:dispatch

View File

@ -0,0 +1,17 @@
(ns status-im.common.peer-stats.events
(:require
[taoensso.timbre :as log]
[utils.re-frame :as rf]))
(rf/reg-event-fx :peer-stats/get-count
(fn []
{:fx [[:json-rpc/call
[{:method :wakuext_peers
:on-success [:peer-stats/get-count-success]
:on-error (fn [error]
(log/error "failed to fetch wakuv2 peer count"
{:error error}))}]]]}))
(rf/reg-event-fx :peer-stats/get-count-success
(fn [{:keys [db]} [response]]
{:db (assoc db :peer-stats/count (count response))}))

View File

@ -10,7 +10,6 @@
[status-im.contexts.communities.discover.events]
[status-im.contexts.profile.push-notifications.local.events :as local-notifications]
[taoensso.timbre :as log]
[utils.debounce :as debounce]
[utils.re-frame :as rf]
[utils.transforms :as transforms]))
@ -20,17 +19,10 @@
peers-count (count peers-summary)]
(rf/merge cofx
{:db (assoc db
:peers-summary peers-summary
:peers-count peers-count)}
:peers-summary peers-summary
:peer-stats/count peers-count)}
(visibility-status-updates/peers-summary-change peers-count))))
(rf/reg-event-fx :wakuv2-peer-stats
(fn [{:keys [db]} [^js peer-stats-js]]
(let [peer-stats (transforms/js->clj peer-stats-js)]
{:db (assoc db
:peer-stats peer-stats
:peers-count (count (:peers peer-stats)))})))
(rf/defn process
{:events [:signals/signal-received]}
[{:keys [db] :as cofx} event-str]
@ -46,9 +38,6 @@
"wallet"
{:fx [[:dispatch [:wallet/signal-received event-js]]]}
"wakuv2.peerstats"
(debounce/debounce-and-dispatch [:wakuv2-peer-stats event-js] 1000)
"envelope.sent"
(messages.transport/update-envelopes-status
cofx

View File

@ -1,5 +1,6 @@
(ns status-im.contexts.profile.settings.visibility-sheet.view
(:require [quo.core :as quo]
[react-native.core :as rn]
[status-im.constants :as constants]
[utils.i18n :as i18n]
[utils.re-frame :as rf]))
@ -17,6 +18,10 @@
[:visibility-status-updates/visibility-status-update
public-key])
customization-color (rf/sub [:profile/customization-color])]
(rn/use-mount
(fn []
(rf/dispatch [:peer-stats/get-count])))
[quo/action-drawer
[[{:icon :i/online
:no-icon-color? true

View File

@ -20,7 +20,7 @@
:link-previews-whitelist []
:app-state "active"
:wallet wallet/defaults
:peers-count 0
:peer-stats/count 0
:node-info {}
:peers-summary []
:transport/message-envelopes {}

View File

@ -9,6 +9,7 @@
[status-im.common.json-rpc.events]
status-im.common.log
status-im.common.password-authentication.events
status-im.common.peer-stats.events
status-im.common.shared-urls.events
status-im.common.signals.events
status-im.common.theme.events

View File

@ -3,7 +3,6 @@
[clojure.string :as string]
[legacy.status-im.multiaccounts.model :as multiaccounts.model]
[legacy.status-im.utils.build :as build]
[legacy.status-im.utils.mobile-sync :as mobile-network-utils]
[re-frame.core :as re-frame]
[status-im.subs.chat.utils :as chat.utils]
[utils.ethereum.chain :as chain]))
@ -76,17 +75,6 @@
(fn [network]
(:name network)))
(re-frame/reg-sub
:disconnected?
:<- [:peers-count]
:<- [:waku/v2-flag]
:<- [:waku/v2-peer-stats]
(fn [[peers-count wakuv2-flag peer-stats]]
;; If wakuv2 is enabled, then fetch connectivity status from
;; peer-stats (populated from "wakuv2.peerstats" status-go signal)
;; Otherwise use peers-count fetched from "discovery.summary" signal
(if wakuv2-flag (not (:isOnline peer-stats)) (zero? peers-count))))
(re-frame/reg-sub
:syncing?
:<- [:sync-state]
@ -146,55 +134,6 @@
(-> selected-contacts
(contains? element))))
(re-frame/reg-sub
:is-participant-selected?
:<- [:group-chat/selected-participants]
(fn [selected-participants [_ element]]
(-> selected-participants
(contains? element))))
(re-frame/reg-sub
:ethereum/chain-keyword
:<- [:current-network]
(fn [network]
(chain/network->chain-keyword network)))
(re-frame/reg-sub
:connectivity/state
:<- [:network-status]
:<- [:disconnected?]
:<- [:mailserver/connecting?]
:<- [:mailserver/connection-error?]
:<- [:mailserver/request-error?]
:<- [:network/type]
:<- [:profile/profile]
(fn [[network-status disconnected? mailserver-connecting? mailserver-connection-error?
mailserver-request-error? network-type {:keys [syncing-on-mobile-network? use-mailservers?]}]]
(merge {:mobile (mobile-network-utils/cellular? network-type)
:sync syncing-on-mobile-network?
:peers :online}
(cond
(= network-status :offline)
{:peers :offline
:node :offline}
(not use-mailservers?)
{:node :disabled}
(or mailserver-connection-error? mailserver-connecting?)
{:node :connecting}
mailserver-request-error?
{:node :error}
disconnected?
{:peers :offline
:node :offline}
:else
{:peers :online
:node :online}))))
(re-frame/reg-sub
:mnemonic
:<- [:profile/profile]

View File

@ -166,12 +166,6 @@
(fn [multiaccount]
(get multiaccount :log-level)))
(re-frame/reg-sub
:waku/v2-flag
:<- [:fleets/current-fleet]
(fn [fleet]
(string/starts-with? (name fleet) "wakuv2")))
(re-frame/reg-sub
:dapps-address
:<- [:profile/profile]

View File

@ -64,7 +64,6 @@
(reg-root-key-sub :tooltips :tooltips)
(reg-root-key-sub :app-state :app-state)
(reg-root-key-sub :home-items-show-number :home-items-show-number)
(reg-root-key-sub :waku/v2-peer-stats :peer-stats)
(reg-root-key-sub :password-authentication :password-authentication)
(reg-root-key-sub :initials-avatar-font-file :initials-avatar-font-file)
(reg-root-key-sub :alert-banners :alert-banners)