Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor_:remove part of node config for local pair sync #19826

Merged
merged 1 commit into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
158 changes: 0 additions & 158 deletions src/legacy/status_im/node/core.cljs
Original file line number Diff line number Diff line change
@@ -1,86 +1,8 @@
(ns legacy.status-im.node.core
(:require
[clojure.string :as string]
[legacy.status-im.utils.deprecated-types :as types]
[react-native.platform :as platform]
[status-im.config :as config]))

(defn- add-log-level
[config log-level]
(if (empty? log-level)
(assoc config
:MaxPeers 20
:MaxPendingPeers 20
:LogLevel "ERROR"
:LogEnabled false)
(assoc config
:MaxPeers 20
:MaxPendingPeers 20
:LogLevel log-level
:LogEnabled true)))

(defn get-network-genesis-hash-prefix
"returns the hex representation of the first 8 bytes of
a network's genesis hash"
[network]
(case network
1 "d4e56740f876aef8"
3 "41941023680923e0"
4 "6341fd3daf94b748"
nil))

(defn get-les-topic
"returns discovery v5 topic derived from genesis of the provided network"
[network]
(let [les-discovery-identifier "LES2@"
hash-prefix (get-network-genesis-hash-prefix network)]
(when hash-prefix
(str les-discovery-identifier hash-prefix))))

(defn get-topics
[network]
(let [les-topic (get-les-topic network)]
(cond-> {"whisper" {:Min 2 :Max 2}}
les-topic (assoc les-topic {:Min 2 :Max 2}))))

(defn- get-base-node-config
[config]
(cond-> (assoc config
:Name
"StatusIM")
config/dev-build?
(assoc :ListenAddr ":0"
:DataDir (str (:DataDir config) "_dev"))))

(def wakuv2-default-config
{:DiscoveryLimit 20
:EnableDiscV5 true
:Host "0.0.0.0"
:AutoUpdate true
;; Temporary fix until https://github.com/status-im/status-go/issues/3024 is resolved
:Nameserver "8.8.8.8"
:PeerExchange true
:Port 0
:UDPPort 0
:LightClient false})

(def login-node-config
{:WalletConfig (cond-> {:Enabled true}
(not= config/opensea-api-key "")
(assoc :OpenseaAPIKey config/opensea-api-key))
:WakuV2Config wakuv2-default-config})

(defn- get-login-node-config
[config]
(merge config login-node-config))

(defn- pick-nodes
"Picks `limit` different nodes randomly from the list of nodes
if there is more than `limit` nodes in the list, otherwise return the list
of nodes"
[limit nodes]
(take limit (shuffle nodes)))

(defn fleets
[{:keys [custom-fleets]}]
(as-> [(js/require "./fleets.js")] $
Expand All @@ -93,83 +15,3 @@
(keyword (get-in db
[:profile/profile :fleet]
config/fleet)))

(defn get-current-fleet
[db]
(get (fleets db)
(current-fleet-key db)))

(defn- wakuv2-enabled?
[fleet]
(let [ks (keys fleet)]
(some #(string/includes? (str %) "waku") ks)))

(defn get-multiaccount-node-config
[{:keys [profile/profile :networks/current-network]
:as db}]
(let [wakuv2-config (get profile :wakuv2-config {})
fleet-key (current-fleet-key db)
current-fleet (get-current-fleet db)
wakuv2-enabled (wakuv2-enabled? current-fleet)
waku-nodes (get config/waku-nodes-config fleet-key)
rendezvous-nodes (pick-nodes 3 (vals (:rendezvous current-fleet)))
{:keys [installation-id log-level
waku-bloom-filter-mode]}
profile]
(cond-> {}
:always
(get-base-node-config)

:always
(get-login-node-config)

current-fleet
(assoc :NoDiscovery wakuv2-enabled
:Rendezvous (if wakuv2-enabled false (boolean (seq rendezvous-nodes)))
:ClusterConfig {:Enabled true
:Fleet (name fleet-key)
:DiscV5BootstrapNodes
(if wakuv2-enabled
waku-nodes
[])
:TrustedMailServers
(if wakuv2-enabled [] (pick-nodes 6 (vals (:mail current-fleet))))
:StaticNodes
(if wakuv2-enabled
[]
(into (pick-nodes 2
(vals (:whisper current-fleet)))
(vals (:static current-fleet))))
:RendezvousNodes (if wakuv2-enabled [] rendezvous-nodes)
:WakuNodes (or waku-nodes [])})

:always
(assoc :LocalNotificationsConfig {:Enabled true}
:KeycardPairingDataFile "/ethereum/mainnet_rpc/keycard/pairings.json"
:BrowsersConfig {:Enabled true}
:PermissionsConfig {:Enabled true}
:MailserversConfig {:Enabled true}
:EnableNTPSync true
:WakuConfig
{:Enabled (not wakuv2-enabled)
:BloomFilterMode waku-bloom-filter-mode
:LightClient true
:MinimumPoW 0.000001}
:WakuV2Config (merge (assoc wakuv2-config :Enabled wakuv2-enabled)
wakuv2-default-config)
:ShhextConfig
{:BackupDisabledDataDir (if platform/android? "/../no_backup" "/")
:InstallationID installation-id
:MaxMessageDeliveryAttempts config/max-message-delivery-attempts
:MailServerConfirmations config/mailserver-confirmations-enabled?
:VerifyTransactionURL config/verify-transaction-url
:VerifyENSURL config/verify-ens-url
:VerifyENSContractAddress config/verify-ens-contract-address
:VerifyTransactionChainID config/verify-transaction-chain-id
:DataSyncEnabled true
:PFSEnabled true}
:RequireTopics (get-topics current-network)
:StatusAccountsConfig {:Enabled true})

:always
(add-log-level log-level))))
36 changes: 20 additions & 16 deletions src/status_im/contexts/syncing/events.cljs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
(ns status-im.contexts.syncing.events
(:require
[clojure.string :as string]
[legacy.status-im.node.core :as node]
[native-module.core :as native-module]
[re-frame.core :as re-frame]
[react-native.platform :as platform]
[status-im.config :as config]
[status-im.constants :as constants]
Expand All @@ -25,14 +23,23 @@
{:db (dissoc db :syncing)})

(defn- get-default-node-config
[installation-id]
(let [db {:profile/profile {:installation-id installation-id
:device-name (native-module/get-installation-name)
:log-level config/log-level
:waku-bloom-filter-mode false
:custom-bootnodes nil
:custom-bootnodes-enabled? false}}]
(node/get-multiaccount-node-config db)))
[]
(let [log-level config/log-level
log-config (if (empty? log-level)
{:LogLevel "ERROR" :LogEnabled false}
{:LogLevel log-level :LogEnabled true})]
(merge {:WalletConfig (cond-> {:Enabled true}
(not= config/opensea-api-key "")
(assoc :OpenseaAPIKey config/opensea-api-key))
:WakuV2Config {;; Temporary fix until https://github.com/status-im/status-go/issues/3024
;; is resolved
:Nameserver "8.8.8.8"
:LightClient false}
:ShhextConfig {:VerifyTransactionURL config/verify-transaction-url
:VerifyENSURL config/verify-ens-url
:VerifyENSContractAddress config/verify-ens-contract-address
:VerifyTransactionChainID config/verify-transaction-chain-id}}
log-config)))

(defn- extract-error
[json-str]
Expand Down Expand Up @@ -67,12 +74,9 @@
(native-module/local-pairing-preflight-outbound-check callback)))

(rf/defn initiate-local-pairing-with-connection-string
{:events [:syncing/input-connection-string-for-bootstrapping]
:interceptors [(re-frame/inject-cofx :random-guid-generator)]}
[{:keys [random-guid-generator db]} connection-string]
(let [installation-id (random-guid-generator)
default-node-config (get-default-node-config installation-id)
default-node-config-string (.stringify js/JSON (clj->js default-node-config))
{:events [:syncing/input-connection-string-for-bootstrapping]}
[{:keys [db]} connection-string]
(let [default-node-config-string (.stringify js/JSON (clj->js (get-default-node-config)))
callback
(fn [final-node-config]
(let [config-map (.stringify js/JSON
Expand Down
6 changes: 3 additions & 3 deletions status-go-version.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"_comment": "Instead use: scripts/update-status-go.sh <rev>",
"owner": "status-im",
"repo": "status-go",
"version": "v0.179.12",
"commit-sha1": "22bea87bb2102aaffe7bb19ba07893a223f0f3d9",
"src-sha256": "0nh2nr5lg8f7lsqqqxpxz045ymrry787qvyn5hzvsqazda1ii1hb"
"version": "v0.179.13",
"commit-sha1": "f3f48654f54aebbb4949129f930fef648d8da8f9",
"src-sha256": "09gcr6fgx6v4qdp83w0n2ynnlvwjqid477jgpqjk57l5wfrv2raq"
}