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.bootnodes.core :as bootnodes]
|
||||
[status-im.browser.core :as browser]
|
||||
[status-im.node.core :as node]
|
||||
[status-im.browser.permissions :as browser.permissions]
|
||||
[status-im.chat.commands.input :as commands.input]
|
||||
[status-im.chat.models :as chat]
|
||||
|
|
|
@ -61,8 +61,9 @@
|
|||
|
||||
(fx/defn initialize-app-db
|
||||
"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]
|
||||
:node/keys [status]
|
||||
:or {network (get app-db :network)}} :db}]
|
||||
{:db (assoc app-db
|
||||
:contacts/contacts {}
|
||||
|
@ -70,7 +71,7 @@
|
|||
:peers-count (or peers-count 0)
|
||||
:peers-summary (or peers-summary [])
|
||||
:status-module-initialized? (or platform/ios? js/goog.DEBUG status-module-initialized?)
|
||||
:status-node-started? status-node-started?
|
||||
:node/status status
|
||||
:network network
|
||||
:device-UUID device-UUID
|
||||
:view-id view-id)})
|
||||
|
@ -88,7 +89,7 @@
|
|||
:hardwallet/check-nfc-support nil
|
||||
:hardwallet/check-nfc-enabled nil}
|
||||
(initialize-app-db)
|
||||
(node/start nil)))
|
||||
(node/initialize nil)))
|
||||
|
||||
(fx/defn set-device-uuid
|
||||
[{:keys [db]} device-uuid]
|
||||
|
@ -142,7 +143,8 @@
|
|||
(let [{:universal-links/keys [url]
|
||||
:keys [accounts/accounts accounts/create contacts/contacts networks/networks
|
||||
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
|
||||
current-account (get accounts address)
|
||||
account-network-id (get current-account :network network)
|
||||
|
@ -152,7 +154,7 @@
|
|||
:view-id view-id
|
||||
:navigation-stack navigation-stack
|
||||
:status-module-initialized? (or platform/ios? js/goog.DEBUG status-module-initialized?)
|
||||
:status-node-started? status-node-started?
|
||||
:node/status status
|
||||
:accounts/create create
|
||||
:networks/networks networks
|
||||
:account/account current-account
|
||||
|
|
|
@ -127,18 +127,24 @@
|
|||
(get-node-config db network))
|
||||
node-config-json (types/clj->json node-config)]
|
||||
(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}))
|
||||
|
||||
(defn restart
|
||||
[]
|
||||
{:node/stop nil})
|
||||
(defn stop
|
||||
[{:keys [db]}]
|
||||
{:db (assoc db :node/status :stopping)
|
||||
:node/stop nil})
|
||||
|
||||
(fx/defn initialize
|
||||
[{{:keys [status-node-started?] :as db} :db :as cofx} address]
|
||||
(if (not status-node-started?)
|
||||
(start cofx address)
|
||||
(restart)))
|
||||
[{{:node/keys [status] :as db} :db :as cofx} address]
|
||||
(let [restart {:db (assoc db :node/restart? true :node/address address)}]
|
||||
(case status
|
||||
:started (stop cofx)
|
||||
:starting restart
|
||||
:stopping restart
|
||||
(start cofx address))))
|
||||
|
||||
(re-frame/reg-fx
|
||||
:node/start
|
||||
|
|
|
@ -11,15 +11,25 @@
|
|||
|
||||
(fx/defn status-node-started
|
||||
[{db :db :as cofx}]
|
||||
(fx/merge cofx
|
||||
{:db (assoc db :status-node-started? true)}
|
||||
#(when (:password (accounts.db/credentials cofx))
|
||||
(accounts.login/login %))))
|
||||
(let [{:node/keys [restart? address]} db
|
||||
can-login? (and (not restart?)
|
||||
(:password (accounts.db/credentials cofx)))]
|
||||
(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
|
||||
[cofx]
|
||||
[{db :db :as 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]}]
|
||||
{:db (assoc db :status-module-initialized? true)
|
||||
|
|
|
@ -81,7 +81,10 @@
|
|||
;;object?
|
||||
(spec/def ::webview-bridge (spec/nilable any?))
|
||||
(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
|
||||
(spec/def ::keyboard-height (spec/nilable number?))
|
||||
(spec/def ::keyboard-max-height (spec/nilable number?))
|
||||
|
@ -218,6 +221,9 @@
|
|||
:inbox/wnodes
|
||||
:inbox/current-id
|
||||
:inbox/fetching?
|
||||
:node/status
|
||||
:node/restart?
|
||||
:node/address
|
||||
:universal-links/url
|
||||
:push-notifications/stored
|
||||
:browser/browsers
|
||||
|
@ -247,7 +253,6 @@
|
|||
::web3-node-version
|
||||
::webview-bridge
|
||||
::status-module-initialized?
|
||||
::status-node-started?
|
||||
::keyboard-height
|
||||
::keyboard-max-height
|
||||
::tab-bar-visible?
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
(is (= [:login-account-internal "testnet" "password"] (get-in actual [:db :node/after-start]))))))
|
||||
|
||||
(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)]
|
||||
(testing "it does not start status-node if it has already started"
|
||||
(is (not (:init/initialize-geth actual))))
|
||||
|
@ -32,7 +32,7 @@
|
|||
|
||||
(testing "the user has selected a different network"
|
||||
(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)]
|
||||
(testing "it dispatches start-node"
|
||||
(is (get-in actual [:db :node/after-stop] [:start-node "testnet" "password"])))
|
||||
|
@ -65,7 +65,7 @@
|
|||
{:bootnodes {"mainnet_rpc" true}})
|
||||
actual (models/user-login "mainnet" "password" bootnodes-enabled-db)]
|
||||
(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)]
|
||||
(testing "it dispatches start-node"
|
||||
(is (get-in actual [:db :node/after-stop] [:start-node "testnet" "password"])))
|
||||
|
@ -82,7 +82,7 @@
|
|||
|
||||
(testing "custom bootnodes not enabled"
|
||||
(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)]
|
||||
(testing "it does not start status-node if it has already started"
|
||||
(is (not (:init/initialize-geth actual))))
|
||||
|
|
Loading…
Reference in New Issue