[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`
This commit is contained in:
parent
c2f22f1fbc
commit
9cf640842b
|
@ -205,6 +205,7 @@ func (b *GethStatusBackend) startNodeWithKey(acc multiaccounts.Account, password
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := logutils.OverrideRootLogWithConfig(conf, false); err != nil {
|
if err := logutils.OverrideRootLogWithConfig(conf, false); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -372,6 +373,15 @@ func (b *GethStatusBackend) loadNodeConfig() (*params.NodeConfig, error) {
|
||||||
// which is set at the compile time.
|
// which is set at the compile time.
|
||||||
// What's cached is usually outdated so we overwrite it here.
|
// What's cached is usually outdated so we overwrite it here.
|
||||||
conf.Version = params.Version
|
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
|
return &conf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -366,6 +366,17 @@ func (b *nimbusStatusBackend) loadNodeConfig() (*params.NodeConfig, error) {
|
||||||
// which is set at the compile time.
|
// which is set at the compile time.
|
||||||
// What's cached is usually outdated so we overwrite it here.
|
// What's cached is usually outdated so we overwrite it here.
|
||||||
conf.Version = params.Version
|
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
|
return &conf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,7 @@ import (
|
||||||
. "github.com/status-im/status-go/t/utils" //nolint: golint
|
. "github.com/status-im/status-go/t/utils" //nolint: golint
|
||||||
"github.com/status-im/status-go/transactions"
|
"github.com/status-im/status-go/transactions"
|
||||||
)
|
)
|
||||||
|
import "github.com/status-im/status-go/params"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
testChainDir string
|
testChainDir string
|
||||||
|
@ -109,13 +110,18 @@ func createAccountAndLogin(t *testing.T, feed *event.Feed) account.Info {
|
||||||
signalErrC <- waitSignal(feed, signal.EventLoggedIn, 5*time.Second)
|
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.
|
// SaveAccountAndLogin must be called only once when an account is created.
|
||||||
// If the account already exists, Login should be used.
|
// If the account already exists, Login should be used.
|
||||||
rawResponse := SaveAccountAndLogin(
|
rawResponse := SaveAccountAndLogin(
|
||||||
buildAccountData("test", account1.WalletAddress),
|
buildAccountData("test", account1.WalletAddress),
|
||||||
C.CString(TestConfig.Account1.Password),
|
C.CString(TestConfig.Account1.Password),
|
||||||
buildAccountSettings("test"),
|
buildAccountSettings("test"),
|
||||||
C.CString(nodeConfigJSON),
|
C.CString(string(cnf)),
|
||||||
buildSubAccountData(account1.WalletAddress),
|
buildSubAccountData(account1.WalletAddress),
|
||||||
)
|
)
|
||||||
var loginResponse APIResponse
|
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)
|
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.
|
// SaveAccountAndLogin must be called only once when an account is created.
|
||||||
// If the account already exists, Login should be used.
|
// If the account already exists, Login should be used.
|
||||||
rawResponse := SaveAccountAndLogin(
|
rawResponse := SaveAccountAndLogin(
|
||||||
buildAccountData("test", addr),
|
buildAccountData("test", addr),
|
||||||
C.CString(TestConfig.Account1.Password),
|
C.CString(TestConfig.Account1.Password),
|
||||||
buildAccountSettings("test"),
|
buildAccountSettings("test"),
|
||||||
C.CString(nodeConfigJSON),
|
C.CString(string(cnf)),
|
||||||
buildSubAccountData(addr),
|
buildSubAccountData(addr),
|
||||||
)
|
)
|
||||||
var loginResponse APIResponse
|
var loginResponse APIResponse
|
||||||
|
|
|
@ -693,7 +693,7 @@ func (n *StatusNode) ChaosModeCheckRPCClientsUpstreamURL(on bool) error {
|
||||||
|
|
||||||
if on {
|
if on {
|
||||||
if strings.Contains(url, "infura.io") {
|
if strings.Contains(url, "infura.io") {
|
||||||
url = "https://httpstat.us/500"
|
url = "https://httpbin.org/status/500"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -364,7 +364,7 @@ func TestChaosModeCheckRPCClientsUpstreamURL(t *testing.T) {
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
err = client.Call(nil, "net_version")
|
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
|
// act
|
||||||
err = n.ChaosModeCheckRPCClientsUpstreamURL(false)
|
err = n.ChaosModeCheckRPCClientsUpstreamURL(false)
|
||||||
|
|
|
@ -703,7 +703,7 @@ func (n *NimbusStatusNode) ChaosModeCheckRPCClientsUpstreamURL(on bool) error {
|
||||||
|
|
||||||
if on {
|
if on {
|
||||||
if strings.Contains(url, "infura.io") {
|
if strings.Contains(url, "infura.io") {
|
||||||
url = "https://httpstat.us/500"
|
url = "https://httpbin.org/status/500"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -386,6 +386,9 @@ type NodeConfig struct {
|
||||||
// LogMobileSystem enables log redirection to android/ios system logger.
|
// LogMobileSystem enables log redirection to android/ios system logger.
|
||||||
LogMobileSystem bool
|
LogMobileSystem bool
|
||||||
|
|
||||||
|
// LogFile is a folder which contains LogFile
|
||||||
|
LogDir string
|
||||||
|
|
||||||
// LogFile is filename where exposed logs get written to
|
// LogFile is filename where exposed logs get written to
|
||||||
LogFile string
|
LogFile string
|
||||||
|
|
||||||
|
|
|
@ -134,11 +134,16 @@ func (s *BackendTestSuite) StartTestBackendWithAccount(account multiaccounts.Acc
|
||||||
for i := range opts {
|
for i := range opts {
|
||||||
opts[i](nodeConfig)
|
opts[i](nodeConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
keystoreDir := nodeConfig.KeyStoreDir
|
||||||
|
dataDir := nodeConfig.DataDir
|
||||||
|
nodeConfig.KeyStoreDir = "keystore"
|
||||||
|
nodeConfig.DataDir = "/"
|
||||||
// accounts must be imported before keystore is initialized
|
// accounts must be imported before keystore is initialized
|
||||||
s.NoError(importTestAccounts(nodeConfig.KeyStoreDir))
|
s.NoError(importTestAccounts(keystoreDir))
|
||||||
s.Backend.UpdateRootDataDir(nodeConfig.DataDir)
|
s.Backend.UpdateRootDataDir(dataDir)
|
||||||
s.NoError(s.Backend.OpenAccounts())
|
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))
|
s.Require().NoError(s.Backend.StartNodeWithAccountAndConfig(account, password, settings, nodeConfig, subaccs))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue