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

cba3ac57...f3f48654
This commit is contained in:
frank 2024-05-07 19:33:46 +08:00 committed by GitHub
parent 7ec77db666
commit 0c6bb61ebe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 23 additions and 177 deletions

View File

@ -1,86 +1,8 @@
(ns legacy.status-im.node.core (ns legacy.status-im.node.core
(:require (:require
[clojure.string :as string]
[legacy.status-im.utils.deprecated-types :as types] [legacy.status-im.utils.deprecated-types :as types]
[react-native.platform :as platform]
[status-im.config :as config])) [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 (defn fleets
[{:keys [custom-fleets]}] [{:keys [custom-fleets]}]
(as-> [(js/require "./fleets.js")] $ (as-> [(js/require "./fleets.js")] $
@ -93,83 +15,3 @@
(keyword (get-in db (keyword (get-in db
[:profile/profile :fleet] [:profile/profile :fleet]
config/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))))

View File

@ -1,9 +1,7 @@
(ns status-im.contexts.syncing.events (ns status-im.contexts.syncing.events
(:require (:require
[clojure.string :as string] [clojure.string :as string]
[legacy.status-im.node.core :as node]
[native-module.core :as native-module] [native-module.core :as native-module]
[re-frame.core :as re-frame]
[react-native.platform :as platform] [react-native.platform :as platform]
[status-im.config :as config] [status-im.config :as config]
[status-im.constants :as constants] [status-im.constants :as constants]
@ -25,14 +23,23 @@
{:db (dissoc db :syncing)}) {:db (dissoc db :syncing)})
(defn- get-default-node-config (defn- get-default-node-config
[installation-id] []
(let [db {:profile/profile {:installation-id installation-id (let [log-level config/log-level
:device-name (native-module/get-installation-name) log-config (if (empty? log-level)
:log-level config/log-level {:LogLevel "ERROR" :LogEnabled false}
:waku-bloom-filter-mode false {:LogLevel log-level :LogEnabled true})]
:custom-bootnodes nil (merge {:WalletConfig (cond-> {:Enabled true}
:custom-bootnodes-enabled? false}}] (not= config/opensea-api-key "")
(node/get-multiaccount-node-config db))) (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 (defn- extract-error
[json-str] [json-str]
@ -67,12 +74,9 @@
(native-module/local-pairing-preflight-outbound-check callback))) (native-module/local-pairing-preflight-outbound-check callback)))
(rf/defn initiate-local-pairing-with-connection-string (rf/defn initiate-local-pairing-with-connection-string
{:events [:syncing/input-connection-string-for-bootstrapping] {:events [:syncing/input-connection-string-for-bootstrapping]}
:interceptors [(re-frame/inject-cofx :random-guid-generator)]} [{:keys [db]} connection-string]
[{:keys [random-guid-generator db]} connection-string] (let [default-node-config-string (.stringify js/JSON (clj->js (get-default-node-config)))
(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))
callback callback
(fn [final-node-config] (fn [final-node-config]
(let [config-map (.stringify js/JSON (let [config-map (.stringify js/JSON

View File

@ -3,7 +3,7 @@
"_comment": "Instead use: scripts/update-status-go.sh <rev>", "_comment": "Instead use: scripts/update-status-go.sh <rev>",
"owner": "status-im", "owner": "status-im",
"repo": "status-go", "repo": "status-go",
"version": "v0.179.12", "version": "v0.179.13",
"commit-sha1": "22bea87bb2102aaffe7bb19ba07893a223f0f3d9", "commit-sha1": "f3f48654f54aebbb4949129f930fef648d8da8f9",
"src-sha256": "0nh2nr5lg8f7lsqqqxpxz045ymrry787qvyn5hzvsqazda1ii1hb" "src-sha256": "09gcr6fgx6v4qdp83w0n2ynnlvwjqid477jgpqjk57l5wfrv2raq"
} }