mirror of
https://github.com/status-im/status-react.git
synced 2025-02-18 13:58:24 +00:00
Don't start a node while the node is already being started.
Restart it instead, so that we are sure which config is there. Signed-off-by: yenda <eric@status.im>
This commit is contained in:
parent
b8fa4f5cbd
commit
1c4cca1004
@ -8,6 +8,7 @@
|
|||||||
[status-im.accounts.update.core :as accounts.update]
|
[status-im.accounts.update.core :as accounts.update]
|
||||||
[status-im.bootnodes.core :as bootnodes]
|
[status-im.bootnodes.core :as bootnodes]
|
||||||
[status-im.browser.core :as browser]
|
[status-im.browser.core :as browser]
|
||||||
|
[status-im.node.core :as node]
|
||||||
[status-im.browser.permissions :as browser.permissions]
|
[status-im.browser.permissions :as browser.permissions]
|
||||||
[status-im.chat.commands.input :as commands.input]
|
[status-im.chat.commands.input :as commands.input]
|
||||||
[status-im.chat.models :as chat]
|
[status-im.chat.models :as chat]
|
||||||
|
@ -61,8 +61,9 @@
|
|||||||
|
|
||||||
(fx/defn initialize-app-db
|
(fx/defn initialize-app-db
|
||||||
"Initialize db to initial state"
|
"Initialize db to initial state"
|
||||||
[{{:keys [status-module-initialized? status-node-started? view-id
|
[{{:keys [status-module-initialized? view-id
|
||||||
network-status network peers-count peers-summary device-UUID]
|
network-status network peers-count peers-summary device-UUID]
|
||||||
|
:node/keys [status]
|
||||||
:or {network (get app-db :network)}} :db}]
|
:or {network (get app-db :network)}} :db}]
|
||||||
{:db (assoc app-db
|
{:db (assoc app-db
|
||||||
:contacts/contacts {}
|
:contacts/contacts {}
|
||||||
@ -70,7 +71,7 @@
|
|||||||
:peers-count (or peers-count 0)
|
:peers-count (or peers-count 0)
|
||||||
:peers-summary (or peers-summary [])
|
:peers-summary (or peers-summary [])
|
||||||
:status-module-initialized? (or platform/ios? js/goog.DEBUG status-module-initialized?)
|
:status-module-initialized? (or platform/ios? js/goog.DEBUG status-module-initialized?)
|
||||||
:status-node-started? status-node-started?
|
:node/status status
|
||||||
:network network
|
:network network
|
||||||
:device-UUID device-UUID
|
:device-UUID device-UUID
|
||||||
:view-id view-id)})
|
:view-id view-id)})
|
||||||
@ -88,7 +89,7 @@
|
|||||||
:hardwallet/check-nfc-support nil
|
:hardwallet/check-nfc-support nil
|
||||||
:hardwallet/check-nfc-enabled nil}
|
:hardwallet/check-nfc-enabled nil}
|
||||||
(initialize-app-db)
|
(initialize-app-db)
|
||||||
(node/start nil)))
|
(node/initialize nil)))
|
||||||
|
|
||||||
(fx/defn set-device-uuid
|
(fx/defn set-device-uuid
|
||||||
[{:keys [db]} device-uuid]
|
[{:keys [db]} device-uuid]
|
||||||
@ -142,7 +143,8 @@
|
|||||||
(let [{:universal-links/keys [url]
|
(let [{:universal-links/keys [url]
|
||||||
:keys [accounts/accounts accounts/create contacts/contacts networks/networks
|
:keys [accounts/accounts accounts/create contacts/contacts networks/networks
|
||||||
network network-status peers-count peers-summary view-id navigation-stack
|
network network-status peers-count peers-summary view-id navigation-stack
|
||||||
status-module-initialized? status-node-started? device-UUID semaphores]
|
status-module-initialized? device-UUID semaphores]
|
||||||
|
:node/keys [status]
|
||||||
:or {network (get app-db :network)}} db
|
:or {network (get app-db :network)}} db
|
||||||
current-account (get accounts address)
|
current-account (get accounts address)
|
||||||
account-network-id (get current-account :network network)
|
account-network-id (get current-account :network network)
|
||||||
@ -152,7 +154,7 @@
|
|||||||
:view-id view-id
|
:view-id view-id
|
||||||
:navigation-stack navigation-stack
|
:navigation-stack navigation-stack
|
||||||
:status-module-initialized? (or platform/ios? js/goog.DEBUG status-module-initialized?)
|
:status-module-initialized? (or platform/ios? js/goog.DEBUG status-module-initialized?)
|
||||||
:status-node-started? status-node-started?
|
:node/status status
|
||||||
:accounts/create create
|
:accounts/create create
|
||||||
:networks/networks networks
|
:networks/networks networks
|
||||||
:account/account current-account
|
:account/account current-account
|
||||||
|
@ -127,18 +127,24 @@
|
|||||||
(get-node-config db network))
|
(get-node-config db network))
|
||||||
node-config-json (types/clj->json node-config)]
|
node-config-json (types/clj->json node-config)]
|
||||||
(log/info "Node config: " node-config-json)
|
(log/info "Node config: " node-config-json)
|
||||||
{:db (assoc db :network network)
|
{:db (assoc db
|
||||||
|
:network network
|
||||||
|
:node/status :starting)
|
||||||
:node/start node-config-json}))
|
:node/start node-config-json}))
|
||||||
|
|
||||||
(defn restart
|
(defn stop
|
||||||
[]
|
[{:keys [db]}]
|
||||||
{:node/stop nil})
|
{:db (assoc db :node/status :stopping)
|
||||||
|
:node/stop nil})
|
||||||
|
|
||||||
(fx/defn initialize
|
(fx/defn initialize
|
||||||
[{{:keys [status-node-started?] :as db} :db :as cofx} address]
|
[{{:node/keys [status] :as db} :db :as cofx} address]
|
||||||
(if (not status-node-started?)
|
(let [restart {:db (assoc db :node/restart? true :node/address address)}]
|
||||||
(start cofx address)
|
(case status
|
||||||
(restart)))
|
:started (stop cofx)
|
||||||
|
:starting restart
|
||||||
|
:stopping restart
|
||||||
|
(start cofx address))))
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
:node/start
|
:node/start
|
||||||
|
@ -11,15 +11,25 @@
|
|||||||
|
|
||||||
(fx/defn status-node-started
|
(fx/defn status-node-started
|
||||||
[{db :db :as cofx}]
|
[{db :db :as cofx}]
|
||||||
(fx/merge cofx
|
(let [{:node/keys [restart? address]} db
|
||||||
{:db (assoc db :status-node-started? true)}
|
can-login? (and (not restart?)
|
||||||
#(when (:password (accounts.db/credentials cofx))
|
(:password (accounts.db/credentials cofx)))]
|
||||||
(accounts.login/login %))))
|
(fx/merge cofx
|
||||||
|
{:db (-> db
|
||||||
|
(assoc :node/status :started)
|
||||||
|
(dissoc :node/restart? :node/address))}
|
||||||
|
|
||||||
|
(when restart?
|
||||||
|
(node/initialize address))
|
||||||
|
(when can-login?
|
||||||
|
(accounts.login/login)))))
|
||||||
|
|
||||||
(fx/defn status-node-stopped
|
(fx/defn status-node-stopped
|
||||||
[cofx]
|
[{db :db :as cofx}]
|
||||||
(let [{:keys [address]} (accounts.db/credentials cofx)]
|
(let [{:keys [address]} (accounts.db/credentials cofx)]
|
||||||
(node/start cofx address)))
|
(fx/merge cofx
|
||||||
|
{:db (assoc db :node/status :stopped)}
|
||||||
|
(node/start address))))
|
||||||
|
|
||||||
(fx/defn status-module-initialized [{:keys [db]}]
|
(fx/defn status-module-initialized [{:keys [db]}]
|
||||||
{:db (assoc db :status-module-initialized? true)
|
{:db (assoc db :status-module-initialized? true)
|
||||||
|
@ -81,7 +81,10 @@
|
|||||||
;;object?
|
;;object?
|
||||||
(spec/def ::webview-bridge (spec/nilable any?))
|
(spec/def ::webview-bridge (spec/nilable any?))
|
||||||
(spec/def ::status-module-initialized? (spec/nilable boolean?))
|
(spec/def ::status-module-initialized? (spec/nilable boolean?))
|
||||||
(spec/def ::status-node-started? (spec/nilable boolean?))
|
(spec/def :node/status (spec/nilable #{:stopped :starting :started :stopping}))
|
||||||
|
(spec/def :node/node-restart? (spec/nilable boolean?))
|
||||||
|
(spec/def :node/address (spec/nilable string?))
|
||||||
|
|
||||||
;;height of native keyboard if shown
|
;;height of native keyboard if shown
|
||||||
(spec/def ::keyboard-height (spec/nilable number?))
|
(spec/def ::keyboard-height (spec/nilable number?))
|
||||||
(spec/def ::keyboard-max-height (spec/nilable number?))
|
(spec/def ::keyboard-max-height (spec/nilable number?))
|
||||||
@ -218,6 +221,9 @@
|
|||||||
:inbox/wnodes
|
:inbox/wnodes
|
||||||
:inbox/current-id
|
:inbox/current-id
|
||||||
:inbox/fetching?
|
:inbox/fetching?
|
||||||
|
:node/status
|
||||||
|
:node/restart?
|
||||||
|
:node/address
|
||||||
:universal-links/url
|
:universal-links/url
|
||||||
:push-notifications/stored
|
:push-notifications/stored
|
||||||
:browser/browsers
|
:browser/browsers
|
||||||
@ -247,7 +253,6 @@
|
|||||||
::web3-node-version
|
::web3-node-version
|
||||||
::webview-bridge
|
::webview-bridge
|
||||||
::status-module-initialized?
|
::status-module-initialized?
|
||||||
::status-node-started?
|
|
||||||
::keyboard-height
|
::keyboard-height
|
||||||
::keyboard-max-height
|
::keyboard-max-height
|
||||||
::tab-bar-visible?
|
::tab-bar-visible?
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
(is (= [:login-account-internal "testnet" "password"] (get-in actual [:db :node/after-start]))))))
|
(is (= [:login-account-internal "testnet" "password"] (get-in actual [:db :node/after-start]))))))
|
||||||
|
|
||||||
(testing "status-go has started & the user is on mainnet"
|
(testing "status-go has started & the user is on mainnet"
|
||||||
(let [db (assoc-in initial-db [:db :status-node-started?] true)
|
(let [db (assoc-in initial-db [:db :node/status] :started)
|
||||||
actual (models/user-login "mainnet" "password" db)]
|
actual (models/user-login "mainnet" "password" db)]
|
||||||
(testing "it does not start status-node if it has already started"
|
(testing "it does not start status-node if it has already started"
|
||||||
(is (not (:init/initialize-geth actual))))
|
(is (not (:init/initialize-geth actual))))
|
||||||
@ -32,7 +32,7 @@
|
|||||||
|
|
||||||
(testing "the user has selected a different network"
|
(testing "the user has selected a different network"
|
||||||
(testing "status-go has started"
|
(testing "status-go has started"
|
||||||
(let [db (assoc-in initial-db [:db :status-node-started?] true)
|
(let [db (assoc-in initial-db [:db :node/status] :started)
|
||||||
actual (models/user-login "testnet" "password" db)]
|
actual (models/user-login "testnet" "password" db)]
|
||||||
(testing "it dispatches start-node"
|
(testing "it dispatches start-node"
|
||||||
(is (get-in actual [:db :node/after-stop] [:start-node "testnet" "password"])))
|
(is (get-in actual [:db :node/after-stop] [:start-node "testnet" "password"])))
|
||||||
@ -65,7 +65,7 @@
|
|||||||
{:bootnodes {"mainnet_rpc" true}})
|
{:bootnodes {"mainnet_rpc" true}})
|
||||||
actual (models/user-login "mainnet" "password" bootnodes-enabled-db)]
|
actual (models/user-login "mainnet" "password" bootnodes-enabled-db)]
|
||||||
(testing "status-node has started"
|
(testing "status-node has started"
|
||||||
(let [db (assoc-in bootnodes-enabled-db [:db :status-node-started?] true)
|
(let [db (assoc-in bootnodes-enabled-db [:db :node/status] :started)
|
||||||
actual (models/user-login "mainnet" "password" db)]
|
actual (models/user-login "mainnet" "password" db)]
|
||||||
(testing "it dispatches start-node"
|
(testing "it dispatches start-node"
|
||||||
(is (get-in actual [:db :node/after-stop] [:start-node "testnet" "password"])))
|
(is (get-in actual [:db :node/after-stop] [:start-node "testnet" "password"])))
|
||||||
@ -82,7 +82,7 @@
|
|||||||
|
|
||||||
(testing "custom bootnodes not enabled"
|
(testing "custom bootnodes not enabled"
|
||||||
(testing "status-node has started"
|
(testing "status-node has started"
|
||||||
(let [db (assoc-in bootnodes-db [:db :status-node-started?] true)
|
(let [db (assoc-in bootnodes-db [:db :node/status] :started)
|
||||||
actual (models/user-login "mainnet" "password" db)]
|
actual (models/user-login "mainnet" "password" db)]
|
||||||
(testing "it does not start status-node if it has already started"
|
(testing "it does not start status-node if it has already started"
|
||||||
(is (not (:init/initialize-geth actual))))
|
(is (not (:init/initialize-geth actual))))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user