Skip to content

Commit

Permalink
fix_: handle missing columns 'connector_enabled' and 'log_namespaces'
Browse files Browse the repository at this point in the history
  • Loading branch information
qfrank committed Jan 21, 2025
1 parent b2bb680 commit 45d97be
Show file tree
Hide file tree
Showing 23 changed files with 137 additions and 23 deletions.
49 changes: 49 additions & 0 deletions api/old_mobile_v1_user_login_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package api

import (
"testing"

"github.com/stretchr/testify/suite"
"go.uber.org/zap"

"github.com/status-im/status-go/protocol/requests"
"github.com/status-im/status-go/t/utils"
)

const (
v1_10_keyUID = "0x88f310d80e3d5821c00714c52bf4fae15f571ba5abae6d804b1e8a9723136a9c"
v1_10_passwd = "0x20756cad9b728c8225fd8cedb6badaf8731e174506950219ea657cd54f35f46c" // #nosec G101
v1_10_srcFolder = "../static/test-mobile-release-1.10.1"
)

type OldMobileV1_10_UserLoginTest struct {
suite.Suite
tmpdir string
logger *zap.Logger
}

func (s *OldMobileV1_10_UserLoginTest) SetupTest() {
utils.Init()
s.tmpdir = s.T().TempDir()
copyDir(v1_10_srcFolder, s.tmpdir, s.T())

var err error
s.logger, err = zap.NewDevelopment()
s.Require().NoError(err)
}

func TestOldMobileV1_10_UserLogin(t *testing.T) {
suite.Run(t, new(OldMobileV1_10_UserLoginTest))
}

func (s *OldMobileV1_10_UserLoginTest) TestLogin() {
b := NewGethStatusBackend(s.logger)
b.UpdateRootDataDir(s.tmpdir)
s.Require().NoError(b.OpenAccounts())
loginRequest := &requests.Login{
KeyUID: v1_10_keyUID,
Password: v1_10_passwd,
}
s.Require().NoError(b.LoginAccount(loginRequest))
s.Require().NoError(b.Logout())
}
10 changes: 9 additions & 1 deletion appdatabase/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,16 @@ func doMigration(db *sql.DB) error {
if err != nil {
return err
}
}

// NodeConfig migration cannot be done with SQL
if lastMigration > 0 && lastMigration <= nodeCfgMigrationDate {
// Check if migration needs to handle node config updates
// This condition handles a specific edge case where:
// 1. The last migration may have stopped at nodeCfgMigrationDate due to MigrateNodeConfig failure
// 2. This typically happens when columns (e.g. 'connector_enabled') are missing because they
// were added in later migrations, we should not query missing columns when during invoke MigrateNodeConfig
// 3. Using <= instead of < ensures we don't skip this step if a user logs in again after MigrateNodeConfig failed
// it should stop here rather than ignore this step and continue other migrations
err = nodecfg.MigrateNodeConfig(db)
if err != nil {
return err
Expand Down
76 changes: 54 additions & 22 deletions nodecfg/node_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package nodecfg
import (
"context"
"database/sql"
"strings"

"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/p2p/discv5"
Expand Down Expand Up @@ -31,33 +32,46 @@ func nodeConfigWasMigrated(tx *sql.Tx) (migrated bool, err error) {

type insertFn func(tx *sql.Tx, c *params.NodeConfig) error

func insertNodeConfig(tx *sql.Tx, c *params.NodeConfig) error {
_, err := tx.Exec(`
func insertNodeConfigBase(tx *sql.Tx, c *params.NodeConfig, includeConnector bool) error {
query := `
INSERT OR REPLACE INTO node_config (
network_id, data_dir, keystore_dir, node_key, no_discovery,
listen_addr, advertise_addr, name, version, api_modules, tls_enabled,
max_peers, max_pending_peers, enable_status_service, enable_ntp_sync,
bridge_enabled, wallet_enabled, local_notifications_enabled,
browser_enabled, permissions_enabled, mailservers_enabled,
swarm_enabled, mailserver_registry_address, web3provider_enabled, connector_enabled,
synthetic_id
) VALUES (
?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
?, ?, ?, ?, ?, 'id'
)`,
browser_enabled, permissions_enabled, mailservers_enabled,
swarm_enabled, mailserver_registry_address, web3provider_enabled`

args := []any{
c.NetworkID, c.DataDir, c.KeyStoreDir, c.NodeKey, c.NoDiscovery,
c.ListenAddr, c.AdvertiseAddr, c.Name, c.Version, c.APIModules,
c.TLSEnabled, c.MaxPeers, c.MaxPendingPeers,
c.EnableStatusService, true,
c.BridgeConfig.Enabled, c.WalletConfig.Enabled, c.LocalNotificationsConfig.Enabled,
c.BrowsersConfig.Enabled, c.PermissionsConfig.Enabled, c.MailserversConfig.Enabled,
c.SwarmConfig.Enabled, c.MailServerRegistryAddress, c.Web3ProviderConfig.Enabled,
c.ConnectorConfig.Enabled,
)
}

if includeConnector {
query += `, connector_enabled`
args = append(args, c.ConnectorConfig.Enabled)
}

query += `, synthetic_id) VALUES (?` + strings.Repeat(",?", len(args)) + `)`
args = append(args, "id")

_, err := tx.Exec(query, args...)
return err
}

func insertNodeConfig(tx *sql.Tx, c *params.NodeConfig) error {
return insertNodeConfigBase(tx, c, false)
}

func insertNodeConfigWithConnector(tx *sql.Tx, c *params.NodeConfig) error {
return insertNodeConfigBase(tx, c, true)
}

func insertHTTPConfig(tx *sql.Tx, c *params.NodeConfig) error {
if _, err := tx.Exec(`INSERT OR REPLACE INTO http_config (enabled, host, port, synthetic_id) VALUES (?, ?, ?, 'id')`, c.HTTPEnabled, c.HTTPHost, c.HTTPPort); err != nil {
return err
Expand Down Expand Up @@ -86,19 +100,37 @@ func insertHTTPConfig(tx *sql.Tx, c *params.NodeConfig) error {
return nil
}

func insertLogConfig(tx *sql.Tx, c *params.NodeConfig) error {
_, err := tx.Exec(`
func insertLogConfigBase(tx *sql.Tx, c *params.NodeConfig, includeNamespaces bool) error {
query := `
INSERT OR REPLACE INTO log_config (
enabled, log_dir, log_level, log_namespaces, max_backups, max_size,
file, compress_rotated, log_to_stderr, synthetic_id
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, 'id')`,
c.LogEnabled, c.LogDir, c.LogLevel, c.LogNamespaces, c.LogMaxBackups, c.LogMaxSize,
enabled, log_dir, log_level, max_backups, max_size,
file, compress_rotated, log_to_stderr`

args := []any{
c.LogEnabled, c.LogDir, c.LogLevel, c.LogMaxBackups, c.LogMaxSize,
c.LogFile, c.LogCompressRotated, c.LogToStderr,
)
}

if includeNamespaces {
query += `, log_namespaces`
args = append(args, c.LogNamespaces)
}

query += `, synthetic_id) VALUES (?` + strings.Repeat(",?", len(args)) + `)`
args = append(args, "id")

_, err := tx.Exec(query, args...)
return err
}

func insertLogConfigWithNamespaces(tx *sql.Tx, c *params.NodeConfig) error {
return insertLogConfigBase(tx, c, true)
}

func insertLogConfig(tx *sql.Tx, c *params.NodeConfig) error {
return insertLogConfigBase(tx, c, false)
}

func insertLightETHConfigTrustedNodes(tx *sql.Tx, c *params.NodeConfig) error {
if _, err := tx.Exec(`DELETE FROM light_eth_trusted_nodes WHERE synthetic_id = 'id'`); err != nil {
return err
Expand Down Expand Up @@ -350,10 +382,10 @@ func nodeConfigNormalInserts() []insertFn {
// the selects being used there are not affected.

return []insertFn{
insertNodeConfig,
insertNodeConfigWithConnector,
insertHTTPConfig,
insertIPCConfig,
insertLogConfig,
insertLogConfigWithNamespaces,
insertClusterConfig,
insertClusterConfigNodes,
insertLightETHConfig,
Expand Down Expand Up @@ -731,7 +763,7 @@ func loadNodeConfig(tx *sql.Tx) (*params.NodeConfig, error) {
return nodecfg, nil
}

func MigrateNodeConfig(db *sql.DB) error {
func MigrateNodeConfig(db *sql.DB) (err error) {
tx, err := db.BeginTx(context.Background(), &sql.TxOptions{})
if err != nil {
return err
Expand Down
Binary file not shown.
2 changes: 2 additions & 0 deletions static/test-mobile-release-1.10.1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The account data files in this directory are generated with android release apk v1.10.1.
It's used to test whether older status-go accounts can log in with the latest version of status-go.
Binary file added static/test-mobile-release-1.10.1/accounts.sql
Binary file not shown.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
37d8e2a10dc12253a48ca9fe8af4edd3176b76563b2ce2a17eaa3c65e2b15a35
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MANIFEST-000000
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
=============== Jan 10, 2025 (UTC) ===============
08:28:04.874809 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed
08:28:04.876561 db@open opening
08:28:04.877163 version@stat F·[] S·0B[] Sc·[]
08:28:04.881631 db@janitor F·2 G·0
08:28:04.881703 db@open done T·5.131458ms
08:45:33.946633 db@close closing
08:45:33.947813 db@close done T·1.201375ms
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MANIFEST-000000
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
=============== Jan 10, 2025 (UTC) ===============
08:28:04.869465 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed
08:28:04.871618 db@open opening
08:28:04.872157 version@stat F·[] S·0B[] Sc·[]
08:28:04.873259 db@janitor F·2 G·0
08:28:04.873299 db@open done T·1.661375ms
08:45:33.947909 db@close closing
08:45:33.948202 db@close done T·290µs
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"address":"a64e3fa6f903bcecb15626b86e7ebb23a1f51637","crypto":{"cipher":"aes-128-ctr","ciphertext":"2be636220812a32406bd788693186e4cc10389a6dd0c9219f19c0d8549df29fe","cipherparams":{"iv":"b9bde28266ec3c6cbdd261fa291fc6c7"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":4096,"p":6,"r":8,"salt":"24d55064449be0b55db1540fd617db259ba157633d564929305d32844732e265"},"mac":"97fe060748cc119a9bacb877d614043ee587e672ad3b03243a012e2f508d431a"},"id":"079a7e5f-b2a5-4db5-9609-90559bd4e76d","version":3,"extendedkey":{"cipher":"aes-128-ctr","ciphertext":"9d5b24438b27be2efd7bf124d8a171b7936d1c36ab70ded50e912d8e40719b895538875391963948eaee256c92c4fa78df31b8dc119365698a8a0567c01f218a3cf1959fc4139af53279563816921d9665f7846de14272d3ec31306ffccc6fa9c894843578f7808b0379031572a958","cipherparams":{"iv":"1736cb5848feb3276c1086a6b0ed3a8c"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":4096,"p":6,"r":8,"salt":"5661a7fed8196676e860c67ea8cbd98b23bb43601d4b3145ec8c3272fbb09666"},"mac":"d47edca606e668ddb92135cd14bac6eda65a0207837a2435d621562cd6075f6b"},"subaccountindex":0}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"address":"33ec2bc1dafd01868ef846747cc639a22f9f9ac8","crypto":{"cipher":"aes-128-ctr","ciphertext":"3d70719bd93c15c1617c81cacbc50cb2d968b0ec19494711d3a9716493589a06","cipherparams":{"iv":"ad346e2abd8e18877868a27202db56b8"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":4096,"p":6,"r":8,"salt":"e7ec638ee76bd15a8407385f0e0db09e2f543d8fe51224a914d2be05739b53da"},"mac":"eb9c2442ace5cd28b51bf066e6780ab98750a34ad6736f0154ef660ed45ef084"},"id":"7fa6c3fb-c79a-453c-a387-51e44be5ff73","version":3,"extendedkey":{"cipher":"aes-128-ctr","ciphertext":"50fd960987eccef995ab5dba9515254c565690452cae6fc2d4d36fa7ef79487b6e49b6c8b4fd940306c32e47c18beb7b4cf9f43c223808fcc580ec2bc6048397e03d014569e88ea17cc32009761c73d96e1faf2a80388ae4ca6fdd3c39135d42de3e23809e83fc87b8150294ef9ea7","cipherparams":{"iv":"da011707bdfe431903bf2d42ad2a5440"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":4096,"p":6,"r":8,"salt":"b3f7656df7e7bef77f002b5d31a0d0549ffa4139aba108ff855aa66b1301bffd"},"mac":"7444f44a3c9a50c0bf52dba24b1b516c790e6f7b28b718d14540f1dece477862"},"subaccountindex":0}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"address":"0e90e6bbe03c68b570c3a12bf327e31d590c262a","crypto":{"cipher":"aes-128-ctr","ciphertext":"c5fedc26b5a36a77dc4406799de1188dd7da6ff7dbda232d312ab098342fdeac","cipherparams":{"iv":"9436848e6e9431f5381a16b059ef674c"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":4096,"p":6,"r":8,"salt":"a88217ef4e823cdbcd08c773dca37a0ac3989729ff75916526a41120a16f81c8"},"mac":"ef9729843b99edbc762c2f19f4af52ea55c7083884ba93ba7727f71f677c4f55"},"id":"14dba39a-2ffe-4f2b-973b-4b7dfcfa33ef","version":3,"extendedkey":{"cipher":"aes-128-ctr","ciphertext":"87e76dd157cd81e134692df6c62159e9c290647fc7cf634b7f7dacff3da0f766c2fe08f96533dd124ed7e9e50ba033b3d4e7f236b95f95a01839a3654b32e562414dc70c006cda5c4f7394bc3b9b3dbde2d36b52a21f77c0de590e22292c310fff1f91d0abdd8453b85ff913f76b99","cipherparams":{"iv":"7699daf7f3f3e924217cabbd454055c6"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":4096,"p":6,"r":8,"salt":"18a0192018134313395f590f2f8e715f54d6680187af59a9de1644a2593b4cba"},"mac":"cb7db464595b921b2f0fb4b158e1aceedef8df0acce51b70b5ea5c4032b4b56a"},"subaccountindex":0}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"address":"38fb3454a695aa1ba434604b550d9a439f764346","crypto":{"cipher":"aes-128-ctr","ciphertext":"7a5671cade118faf184a1a162ab906c260f63e7f45ba1a678bec3626b56ac10d","cipherparams":{"iv":"ae5c7a380054eef5ddad4046ca1ade9b"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":4096,"p":6,"r":8,"salt":"b825bebb3977671dd42844dbe6d81984e0e721cb7dd23d444ce392411a2172c7"},"mac":"ad55f72fc4702af1473d7da13e8dd0f69added33412e867818bd289aef503569"},"id":"b49c1e46-cb86-451b-bde7-bb10481c6919","version":3,"extendedkey":{"cipher":"aes-128-ctr","ciphertext":"eb5029c62a9d66bbf15b3c3f12e5d76f676c92cf3a1b33a1413cba72dbfcf4dd093b96eabbf2d8c07fb95a530dc3e78ebef9e0786b9c2fd9bd9d0dbe24c5010d868904b74f8d02e7cd34a37f56195c85cea1566f0e95aaabf24d83ad7b606bce6b0fbabae84898fd3b468bdf0dd067","cipherparams":{"iv":"42bbdebb5b7bb8f6c598ec24f189ab43"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":4096,"p":6,"r":8,"salt":"49271401aedc577b17ef864340782727c642589cb6003421364520d068dd6b0f"},"mac":"490e845666b3e32af69ffd7cd1eb212120f6ee2dfb809f2b679d5415d53d2efc"},"subaccountindex":0}
Empty file.

0 comments on commit 45d97be

Please sign in to comment.