From 9cf640842b4d0266bcc1b30f6d776c250fdb5c04 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Mon, 3 Feb 2020 11:20:04 +0200 Subject: [PATCH] [status-im/status-react#9942] Upgradable paths in configs Storing absolute path for different configs breaks compatibility on iOS as app's dir is changed after upgrade. The solution is to store relative paths and to concatenate it with `backend.rootDataDir`. The only exception is `LogFile` as it is stored outside `backend.rootDataDir` on Android. `LogDir` config was added to allow adding of custom dir for log file. Configs concerned: `DataDir` `LogDir` `LogFile` `KeystoreDir` `BackupDisabledDataDir` --- VERSION | 2 +- api/geth_backend.go | 10 ++++++++++ api/nimbus_backend.go | 11 +++++++++++ lib/library_test_utils.go | 15 +++++++++++++-- node/get_status_node.go | 2 +- node/geth_status_node_test.go | 2 +- node/nimbus_status_node.go | 2 +- params/config.go | 3 +++ t/e2e/suites.go | 11 ++++++++--- 9 files changed, 49 insertions(+), 9 deletions(-) diff --git a/VERSION b/VERSION index 9ed317fb462..787ffc30a81 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.41.1 +0.42.0 diff --git a/api/geth_backend.go b/api/geth_backend.go index 62b5c45c31f..875f24ad6c5 100644 --- a/api/geth_backend.go +++ b/api/geth_backend.go @@ -205,6 +205,7 @@ func (b *GethStatusBackend) startNodeWithKey(acc multiaccounts.Account, password if err != nil { return err } + if err := logutils.OverrideRootLogWithConfig(conf, false); err != nil { return err } @@ -372,6 +373,15 @@ func (b *GethStatusBackend) loadNodeConfig() (*params.NodeConfig, error) { // which is set at the compile time. // What's cached is usually outdated so we overwrite it here. conf.Version = params.Version + conf.DataDir = filepath.Join(b.rootDataDir, conf.DataDir) + conf.ShhextConfig.BackupDisabledDataDir = filepath.Join(b.rootDataDir, conf.ShhextConfig.BackupDisabledDataDir) + if len(conf.LogDir) == 0 { + conf.LogFile = filepath.Join(b.rootDataDir, conf.LogFile) + } else { + conf.LogFile = filepath.Join(conf.LogDir, conf.LogFile) + } + conf.KeyStoreDir = filepath.Join(b.rootDataDir, conf.KeyStoreDir) + return &conf, nil } diff --git a/api/nimbus_backend.go b/api/nimbus_backend.go index 611b645b5a4..ed3cda16dbe 100644 --- a/api/nimbus_backend.go +++ b/api/nimbus_backend.go @@ -366,6 +366,17 @@ func (b *nimbusStatusBackend) loadNodeConfig() (*params.NodeConfig, error) { // which is set at the compile time. // What's cached is usually outdated so we overwrite it here. conf.Version = params.Version + + // Replace all relative paths with absolute + conf.DataDir = filepath.Join(b.rootDataDir, conf.DataDir) + conf.ShhextConfig.BackupDisabledDataDir = filepath.Join(b.rootDataDir, conf.ShhextConfig.BackupDisabledDataDir) + if len(conf.LogDir) == 0 { + conf.LogFile = filepath.Join(b.rootDataDir, conf.LogFile) + } else { + conf.LogFile = filepath.Join(conf.LogDir, conf.LogFile) + } + conf.KeyStoreDir = filepath.Join(b.rootDataDir, conf.KeyStoreDir) + return &conf, nil } diff --git a/lib/library_test_utils.go b/lib/library_test_utils.go index 94d06fb99cb..f8e4f2b1042 100644 --- a/lib/library_test_utils.go +++ b/lib/library_test_utils.go @@ -37,6 +37,7 @@ import ( . "github.com/status-im/status-go/t/utils" //nolint: golint "github.com/status-im/status-go/transactions" ) +import "github.com/status-im/status-go/params" var ( testChainDir string @@ -109,13 +110,18 @@ func createAccountAndLogin(t *testing.T, feed *event.Feed) account.Info { signalErrC <- waitSignal(feed, signal.EventLoggedIn, 5*time.Second) }() + nodeConfig, _ := params.NewConfigFromJSON(nodeConfigJSON) + nodeConfig.KeyStoreDir = "keystore" + nodeConfig.DataDir = "/" + cnf, _ := json.Marshal(nodeConfig) + // SaveAccountAndLogin must be called only once when an account is created. // If the account already exists, Login should be used. rawResponse := SaveAccountAndLogin( buildAccountData("test", account1.WalletAddress), C.CString(TestConfig.Account1.Password), buildAccountSettings("test"), - C.CString(nodeConfigJSON), + C.CString(string(cnf)), buildSubAccountData(account1.WalletAddress), ) var loginResponse APIResponse @@ -131,13 +137,18 @@ func loginUsingAccount(t *testing.T, feed *event.Feed, addr string) { signalErrC <- waitSignal(feed, signal.EventLoggedIn, 5*time.Second) }() + nodeConfig, _ := params.NewConfigFromJSON(nodeConfigJSON) + nodeConfig.KeyStoreDir = "keystore" + nodeConfig.DataDir = "/" + cnf, _ := json.Marshal(nodeConfig) + // SaveAccountAndLogin must be called only once when an account is created. // If the account already exists, Login should be used. rawResponse := SaveAccountAndLogin( buildAccountData("test", addr), C.CString(TestConfig.Account1.Password), buildAccountSettings("test"), - C.CString(nodeConfigJSON), + C.CString(string(cnf)), buildSubAccountData(addr), ) var loginResponse APIResponse diff --git a/node/get_status_node.go b/node/get_status_node.go index e4c434d0864..cb2d131f785 100644 --- a/node/get_status_node.go +++ b/node/get_status_node.go @@ -693,7 +693,7 @@ func (n *StatusNode) ChaosModeCheckRPCClientsUpstreamURL(on bool) error { if on { if strings.Contains(url, "infura.io") { - url = "https://httpstat.us/500" + url = "https://httpbin.org/status/500" } } diff --git a/node/geth_status_node_test.go b/node/geth_status_node_test.go index 284b0458e49..cee41d9cea1 100644 --- a/node/geth_status_node_test.go +++ b/node/geth_status_node_test.go @@ -364,7 +364,7 @@ func TestChaosModeCheckRPCClientsUpstreamURL(t *testing.T) { // assert err = client.Call(nil, "net_version") - require.EqualError(t, err, `500 Internal Server Error {"code": 500, "description": "Internal Server Error"}`) + require.EqualError(t, err, `500 Internal Server Error `) // act err = n.ChaosModeCheckRPCClientsUpstreamURL(false) diff --git a/node/nimbus_status_node.go b/node/nimbus_status_node.go index 4f1f95bed86..2b7c561a03e 100644 --- a/node/nimbus_status_node.go +++ b/node/nimbus_status_node.go @@ -703,7 +703,7 @@ func (n *NimbusStatusNode) ChaosModeCheckRPCClientsUpstreamURL(on bool) error { if on { if strings.Contains(url, "infura.io") { - url = "https://httpstat.us/500" + url = "https://httpbin.org/status/500" } } diff --git a/params/config.go b/params/config.go index bcd15885317..0e4c35bd4a7 100644 --- a/params/config.go +++ b/params/config.go @@ -386,6 +386,9 @@ type NodeConfig struct { // LogMobileSystem enables log redirection to android/ios system logger. LogMobileSystem bool + // LogFile is a folder which contains LogFile + LogDir string + // LogFile is filename where exposed logs get written to LogFile string diff --git a/t/e2e/suites.go b/t/e2e/suites.go index 63fbd3332b0..622edb7676a 100644 --- a/t/e2e/suites.go +++ b/t/e2e/suites.go @@ -134,11 +134,16 @@ func (s *BackendTestSuite) StartTestBackendWithAccount(account multiaccounts.Acc for i := range opts { opts[i](nodeConfig) } + + keystoreDir := nodeConfig.KeyStoreDir + dataDir := nodeConfig.DataDir + nodeConfig.KeyStoreDir = "keystore" + nodeConfig.DataDir = "/" // accounts must be imported before keystore is initialized - s.NoError(importTestAccounts(nodeConfig.KeyStoreDir)) - s.Backend.UpdateRootDataDir(nodeConfig.DataDir) + s.NoError(importTestAccounts(keystoreDir)) + s.Backend.UpdateRootDataDir(dataDir) s.NoError(s.Backend.OpenAccounts()) - s.NoError(s.Backend.AccountManager().InitKeystore(nodeConfig.KeyStoreDir)) + s.NoError(s.Backend.AccountManager().InitKeystore(keystoreDir)) s.Require().NoError(s.Backend.StartNodeWithAccountAndConfig(account, password, settings, nodeConfig, subaccs)) }