Always try to assert that saved network is the one which node was actually started

This commit is contained in:
janherich 2018-06-21 10:55:12 +02:00
parent 08932c4e2b
commit 73dab568ff
No known key found for this signature in database
GPG Key ID: C23B473AFBE94D13
2 changed files with 20 additions and 3 deletions

View File

@ -3,8 +3,9 @@
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.constants :as constants] [status-im.constants :as constants]
[status-im.native-module.core :as status] [status-im.native-module.core :as status]
[status-im.utils.utils :as utils]
[status-im.utils.datetime :as datetime] [status-im.utils.datetime :as datetime]
[status-im.utils.ethereum.core :as utils] [status-im.utils.ethereum.core :as ethereum-utils]
[status-im.utils.handlers :as handlers] [status-im.utils.handlers :as handlers]
[status-im.utils.handlers-macro :as handlers-macro] [status-im.utils.handlers-macro :as handlers-macro]
[status-im.utils.web3-provider :as web3-provider] [status-im.utils.web3-provider :as web3-provider]
@ -36,6 +37,21 @@
(fn [] (fn []
(status/init-jail))) (status/init-jail)))
(defn- assert-correct-network
[{:keys [db]}]
;; Assure that node was started correctly
(let [{:keys [network web3]} db]
(when-let [network-id (str (get-in db [:account/account :networks network :config :NetworkId]))]
(when web3 ; necessary because of the unit tests
(.getNetwork (.-version web3)
(fn [error fetched-network-id]
(when (and (not error) ; error most probably means we are offline
(not= network-id fetched-network-id))
(utils/show-popup
"Ethereum node started incorrectly"
"Ethereum node was started with incorrect configuration, application will be stopped to recover from that condition."
#(re-frame/dispatch [:close-application])))))))))
(defn initialize-protocol (defn initialize-protocol
[{:data-store/keys [transport mailservers] :keys [db web3] :as cofx} [current-account-id ethereum-rpc-url]] [{:data-store/keys [transport mailservers] :keys [db web3] :as cofx} [current-account-id ethereum-rpc-url]]
(handlers-macro/merge-fx cofx (handlers-macro/merge-fx cofx
@ -43,6 +59,7 @@
:web3 web3 :web3 web3
:rpc-url (or ethereum-rpc-url constants/ethereum-rpc-url) :rpc-url (or ethereum-rpc-url constants/ethereum-rpc-url)
:transport/chats transport)} :transport/chats transport)}
(assert-correct-network)
(transport.inbox/initialize-offline-inbox mailservers) (transport.inbox/initialize-offline-inbox mailservers)
(transport/init-whisper current-account-id))) (transport/init-whisper current-account-id)))
;;; INITIALIZE PROTOCOL ;;; INITIALIZE PROTOCOL
@ -87,6 +104,6 @@
:initialize-sync-listener :initialize-sync-listener
(fn [{{:keys [sync-listening-started network account/account] :as db} :db} _] (fn [{{:keys [sync-listening-started network account/account] :as db} :db} _]
(when (and (not sync-listening-started) (when (and (not sync-listening-started)
(not (utils/network-with-upstream-rpc? (get-in account [:networks network])))) (not (ethereum-utils/network-with-upstream-rpc? (get-in account [:networks network]))))
{:db (assoc db :sync-listening-started true) {:db (assoc db :sync-listening-started true)
:dispatch [:check-sync]}))) :dispatch [:check-sync]})))

View File

@ -14,7 +14,7 @@
;; handlers ;; handlers
(handlers/register-handler-fx (handlers/register-handler-fx
::close-application :close-application
(fn [_ _] (fn [_ _]
{:close-application nil})) {:close-application nil}))