Skip to content

Commit

Permalink
[status-im/status-mobile#9942] Upgradable paths in configs
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
rasom committed Feb 3, 2020
1 parent c2f22f1 commit 9cf6408
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 9 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.41.1
0.42.0
10 changes: 10 additions & 0 deletions api/geth_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}

Expand Down
11 changes: 11 additions & 0 deletions api/nimbus_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
15 changes: 13 additions & 2 deletions lib/library_test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion node/get_status_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

Expand Down
2 changes: 1 addition & 1 deletion node/geth_status_node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion node/nimbus_status_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

Expand Down
3 changes: 3 additions & 0 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 8 additions & 3 deletions t/e2e/suites.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down

0 comments on commit 9cf6408

Please sign in to comment.