diff --git a/api/defaults.go b/api/defaults.go index 188e4891e..6ad0bb82a 100644 --- a/api/defaults.go +++ b/api/defaults.go @@ -26,12 +26,20 @@ const defaultMnemonicLength = 12 const shardsTestClusterID = 16 const walletAccountDefaultName = "Account 1" const keystoreRelativePath = "keystore" -const defaultKeycardPairingDataFile = "/ethereum/mainnet_rpc/keycard/pairings.json" +const DefaultKeycardPairingDataFile = "/ethereum/mainnet_rpc/keycard/pairings.json" -const defaultArchivesRelativePath = "data/archivedata" -const defaultTorrentTorrentsRelativePath = "data/torrents" +const DefaultArchivesRelativePath = "data/archivedata" +const DefaultTorrentTorrentsRelativePath = "data/torrents" const DefaultDataDir = "/ethereum/mainnet_rpc" +const DefaultNodeName = "StatusIM" +const DefaultLogFile = "geth.log" +const DefaultLogLevel = "ERROR" +const DefaultMaxPeers = 20 +const DefaultMaxPendingPeers = 20 +const DefaultListenAddr = ":0" +const DefaultMaxMessageDeliveryAttempts = 6 +const DefaultVerifyTransactionChainID = 1 var paths = []string{pathWalletRoot, pathEIP1581, pathDefaultChat, pathDefaultWallet} @@ -125,12 +133,16 @@ func SetDefaultFleet(nodeConfig *params.NodeConfig) error { } func SetFleet(fleet string, nodeConfig *params.NodeConfig) error { + specifiedWakuV2Config := nodeConfig.WakuV2Config nodeConfig.WakuV2Config = params.WakuV2Config{ Enabled: true, EnableDiscV5: true, DiscoveryLimit: 20, Host: "0.0.0.0", AutoUpdate: true, + // mobile may need override following options + LightClient: specifiedWakuV2Config.LightClient, + Nameserver: specifiedWakuV2Config.Nameserver, } clusterConfig, err := params.LoadClusterConfigFromFleet(fleet) @@ -211,11 +223,11 @@ func defaultNodeConfig(installationID string, request *requests.CreateAccount, o // Set mainnet nodeConfig := ¶ms.NodeConfig{} nodeConfig.LogEnabled = request.LogEnabled - nodeConfig.LogFile = "geth.log" + nodeConfig.LogFile = DefaultLogFile nodeConfig.LogDir = request.LogFilePath - nodeConfig.LogLevel = "ERROR" + nodeConfig.LogLevel = DefaultLogLevel nodeConfig.DataDir = DefaultDataDir - nodeConfig.KeycardPairingDataFile = defaultKeycardPairingDataFile + nodeConfig.KeycardPairingDataFile = DefaultKeycardPairingDataFile nodeConfig.ProcessBackedupMessages = false if request.LogLevel != nil { @@ -243,11 +255,11 @@ func defaultNodeConfig(installationID string, request *requests.CreateAccount, o nodeConfig.UpstreamConfig.Enabled = true } - nodeConfig.Name = "StatusIM" + nodeConfig.Name = DefaultNodeName nodeConfig.Rendezvous = false nodeConfig.NoDiscovery = true - nodeConfig.MaxPeers = 20 - nodeConfig.MaxPendingPeers = 20 + nodeConfig.MaxPeers = DefaultMaxPeers + nodeConfig.MaxPendingPeers = DefaultMaxPendingPeers nodeConfig.WalletConfig = buildWalletConfig(&request.WalletSecretsConfig) @@ -256,7 +268,7 @@ func defaultNodeConfig(installationID string, request *requests.CreateAccount, o nodeConfig.PermissionsConfig = params.PermissionsConfig{Enabled: true} nodeConfig.MailserversConfig = params.MailserversConfig{Enabled: true} - nodeConfig.ListenAddr = ":0" + nodeConfig.ListenAddr = DefaultListenAddr err := SetDefaultFleet(nodeConfig) if err != nil { @@ -274,9 +286,9 @@ func defaultNodeConfig(installationID string, request *requests.CreateAccount, o nodeConfig.ShhextConfig = params.ShhextConfig{ BackupDisabledDataDir: request.BackupDisabledDataDir, InstallationID: installationID, - MaxMessageDeliveryAttempts: 6, + MaxMessageDeliveryAttempts: DefaultMaxMessageDeliveryAttempts, MailServerConfirmations: true, - VerifyTransactionChainID: 1, + VerifyTransactionChainID: DefaultVerifyTransactionChainID, DataSyncEnabled: true, PFSEnabled: true, } @@ -301,14 +313,6 @@ func defaultNodeConfig(installationID string, request *requests.CreateAccount, o nodeConfig.ShhextConfig.VerifyENSContractAddress = *request.VerifyENSContractAddress } - if request.LogLevel != nil { - nodeConfig.LogLevel = *request.LogLevel - nodeConfig.LogEnabled = true - - } else { - nodeConfig.LogEnabled = false - } - if request.NetworkID != nil { nodeConfig.NetworkID = *request.NetworkID } @@ -316,8 +320,8 @@ func defaultNodeConfig(installationID string, request *requests.CreateAccount, o nodeConfig.TorrentConfig = params.TorrentConfig{ Enabled: false, Port: 0, - DataDir: filepath.Join(nodeConfig.RootDataDir, defaultArchivesRelativePath), - TorrentDir: filepath.Join(nodeConfig.RootDataDir, defaultTorrentTorrentsRelativePath), + DataDir: filepath.Join(nodeConfig.RootDataDir, DefaultArchivesRelativePath), + TorrentDir: filepath.Join(nodeConfig.RootDataDir, DefaultTorrentTorrentsRelativePath), } if request.TorrentConfigEnabled != nil { diff --git a/api/geth_backend.go b/api/geth_backend.go index 8464992cd..f4b744f92 100644 --- a/api/geth_backend.go +++ b/api/geth_backend.go @@ -617,7 +617,7 @@ func (b *GethStatusBackend) loginAccount(request *requests.Login) error { defaultCfg := ¶ms.NodeConfig{ // why we need this? relate PR: https://github.com/status-im/status-go/pull/4014 - KeycardPairingDataFile: defaultKeycardPairingDataFile, + KeycardPairingDataFile: DefaultKeycardPairingDataFile, } defaultCfg.WalletConfig = buildWalletConfig(&request.WalletSecretsConfig) diff --git a/cmd/ping-community/main.go b/cmd/ping-community/main.go index 7cfbaee23..f276b3337 100644 --- a/cmd/ping-community/main.go +++ b/cmd/ping-community/main.go @@ -371,12 +371,12 @@ func defaultNodeConfig(installationID string) (*params.NodeConfig, error) { nodeConfig.ShhextConfig = params.ShhextConfig{ BackupDisabledDataDir: "", InstallationID: installationID, - MaxMessageDeliveryAttempts: 6, + MaxMessageDeliveryAttempts: api.DefaultMaxMessageDeliveryAttempts, MailServerConfirmations: true, VerifyTransactionURL: "", VerifyENSURL: "", VerifyENSContractAddress: "", - VerifyTransactionChainID: 1, + VerifyTransactionChainID: api.DefaultVerifyTransactionChainID, DataSyncEnabled: true, PFSEnabled: true, } diff --git a/cmd/populate-db/main.go b/cmd/populate-db/main.go index 372c37ff4..f6a160101 100644 --- a/cmd/populate-db/main.go +++ b/cmd/populate-db/main.go @@ -420,12 +420,12 @@ func defaultNodeConfig(installationID string) (*params.NodeConfig, error) { nodeConfig.ShhextConfig = params.ShhextConfig{ BackupDisabledDataDir: "", InstallationID: installationID, - MaxMessageDeliveryAttempts: 6, + MaxMessageDeliveryAttempts: api.DefaultMaxMessageDeliveryAttempts, MailServerConfirmations: true, VerifyTransactionURL: "", VerifyENSURL: "", VerifyENSContractAddress: "", - VerifyTransactionChainID: 1, + VerifyTransactionChainID: api.DefaultVerifyTransactionChainID, DataSyncEnabled: true, PFSEnabled: true, } diff --git a/cmd/spiff-workflow/main.go b/cmd/spiff-workflow/main.go index 4a4a44d08..43d1da8dc 100644 --- a/cmd/spiff-workflow/main.go +++ b/cmd/spiff-workflow/main.go @@ -311,12 +311,12 @@ func defaultNodeConfig(installationID string) (*params.NodeConfig, error) { nodeConfig.ShhextConfig = params.ShhextConfig{ BackupDisabledDataDir: "", InstallationID: installationID, - MaxMessageDeliveryAttempts: 6, + MaxMessageDeliveryAttempts: api.DefaultMaxMessageDeliveryAttempts, MailServerConfirmations: true, VerifyTransactionURL: "", VerifyENSURL: "", VerifyENSContractAddress: "", - VerifyTransactionChainID: 1, + VerifyTransactionChainID: api.DefaultVerifyTransactionChainID, DataSyncEnabled: true, PFSEnabled: true, } diff --git a/server/pairing/common.go b/server/pairing/common.go index aa24bc156..eeb4b0ba7 100644 --- a/server/pairing/common.go +++ b/server/pairing/common.go @@ -10,6 +10,8 @@ import ( "regexp" "strings" + "github.com/google/uuid" + "github.com/status-im/status-go/params" "github.com/status-im/status-go/protocol/requests" @@ -246,6 +248,10 @@ func validateKeystoreFilesConfig(backend *api.GethStatusBackend, conf interface{ return nil } +// setDefaultNodeConfig sets default values for the node configuration. +// Config Values still needed from the mobile include +// VerifyTransactionURL/VerifyENSURL/VerifyENSContractAddress/VerifyTransactionChainID +// LogEnabled/LogDir/RootDataDir/LightClient/Nameserver func setDefaultNodeConfig(c *params.NodeConfig) error { if c == nil { return nil @@ -256,22 +262,94 @@ func setDefaultNodeConfig(c *params.NodeConfig) error { return err } - if len(c.Networks) == 0 { + // following specifiedXXX variables are used to check if frontend has specified the value + // if not, the default value is set. NOTE: we also check 2 extra fields: WakuV2Config(LightClient|Nameserver) + // see api.SetFleet for more details + specifiedVerifyTransactionURL := c.ShhextConfig.VerifyTransactionURL + specifiedVerifyENSURL := c.ShhextConfig.VerifyENSURL + specifiedVerifyENSContractAddress := c.ShhextConfig.VerifyENSContractAddress + specifiedVerifyTransactionChainID := c.ShhextConfig.VerifyTransactionChainID + specifiedNetworkID := c.NetworkID + specifiedNetworks := c.Networks + specifiedUpstreamConfigURL := c.UpstreamConfig.URL + specifiedLogEnabled := c.LogEnabled + specifiedLogLevel := c.LogLevel + specifiedFleet := c.ClusterConfig.Fleet + specifiedInstallationID := c.ShhextConfig.InstallationID + specifiedTorrentConfigEnabled := c.TorrentConfig.Enabled + specifiedTorrentConfigPort := c.TorrentConfig.Port + + if len(specifiedNetworks) == 0 { c.Networks = api.BuildDefaultNetworks(&requests.WalletSecretsConfig{}) } - if c.NetworkID == 0 { - // because PR https://github.com/status-im/status-mobile/pull/19467/files removed :networks/networks, - // we need to set the networkID and RPCURL here to make local pairing work again + if specifiedNetworkID == 0 { c.NetworkID = c.Networks[0].ChainID - c.UpstreamConfig = params.UpstreamRPCConfig{ - URL: c.Networks[0].RPCURL, - Enabled: true, + } + + c.UpstreamConfig.Enabled = true + if specifiedUpstreamConfigURL == "" { + c.UpstreamConfig.URL = c.Networks[0].RPCURL + } + + if specifiedLogEnabled && specifiedLogLevel == "" { + c.LogLevel = api.DefaultLogLevel + } + c.LogFile = api.DefaultLogFile + + c.Name = api.DefaultNodeName + c.DataDir = api.DefaultDataDir + c.KeycardPairingDataFile = api.DefaultKeycardPairingDataFile + c.Rendezvous = false + c.NoDiscovery = true + c.MaxPeers = api.DefaultMaxPeers + c.MaxPendingPeers = api.DefaultMaxPendingPeers + + c.LocalNotificationsConfig = params.LocalNotificationsConfig{Enabled: true} + c.BrowsersConfig = params.BrowsersConfig{Enabled: true} + c.PermissionsConfig = params.PermissionsConfig{Enabled: true} + c.MailserversConfig = params.MailserversConfig{Enabled: true} + + c.ListenAddr = api.DefaultListenAddr + + if specifiedFleet == "" { + err = api.SetDefaultFleet(c) + if err != nil { + return err } } - if c.DataDir == "" { - c.DataDir = api.DefaultDataDir + if specifiedInstallationID == "" { + specifiedInstallationID = uuid.New().String() + } + + c.ShhextConfig = params.ShhextConfig{ + BackupDisabledDataDir: c.RootDataDir, + InstallationID: specifiedInstallationID, + MaxMessageDeliveryAttempts: api.DefaultMaxMessageDeliveryAttempts, + MailServerConfirmations: true, + DataSyncEnabled: true, + PFSEnabled: true, + VerifyTransactionURL: specifiedVerifyTransactionURL, + VerifyENSURL: specifiedVerifyENSURL, + VerifyENSContractAddress: specifiedVerifyENSContractAddress, + } + if specifiedVerifyTransactionChainID == 0 { + c.ShhextConfig.VerifyTransactionChainID = int64(c.Networks[0].ChainID) + } + + if specifiedVerifyTransactionURL == "" { + c.ShhextConfig.VerifyTransactionURL = c.Networks[0].FallbackURL + } + if specifiedVerifyENSURL == "" { + c.ShhextConfig.VerifyENSURL = c.Networks[0].FallbackURL + } + + c.TorrentConfig = params.TorrentConfig{ + Enabled: specifiedTorrentConfigEnabled, + Port: specifiedTorrentConfigPort, + DataDir: filepath.Join(c.RootDataDir, api.DefaultArchivesRelativePath), + TorrentDir: filepath.Join(c.RootDataDir, api.DefaultTorrentTorrentsRelativePath), } return nil diff --git a/server/pairing/sync_device_test.go b/server/pairing/sync_device_test.go index cde5937d0..7cfffcf7d 100644 --- a/server/pairing/sync_device_test.go +++ b/server/pairing/sync_device_test.go @@ -115,13 +115,9 @@ func (s *SyncDeviceSuite) prepareBackendWithAccount(mnemonic, tmpdir string) *ap account.Name = settings.Name nodeConfig, err := nodeConfigForLocalPairSync(settings.InstallationID, account.KeyUID, tmpdir) + nodeConfig.RootDataDir = tmpdir require.NoError(s.T(), err) - nodeConfig.NetworkID = 1 - nodeConfig.UpstreamConfig = params.UpstreamRPCConfig{ - Enabled: true, - URL: "https://mainnet.infura.io/v3/800c641949d64d768a5070a1b0511938", - } - nodeConfig.DataDir = api.DefaultDataDir + require.NoError(s.T(), setDefaultNodeConfig(nodeConfig)) walletDerivedAccount := derivedAddresses[pathDefaultWallet] walletAccount := &accounts.Account{ @@ -733,40 +729,23 @@ func defaultSettings(generatedAccountInfo generator.GeneratedAccountInfo, derive func nodeConfigForLocalPairSync(installationID, keyUID, tmpDir string) (*params.NodeConfig, error) { // Set mainnet nodeConfig := ¶ms.NodeConfig{} + nodeConfig.LogEnabled = true nodeConfig.LogLevel = "DEBUG" + nodeConfig.LogDir = tmpDir nodeConfig.KeyStoreDir = filepath.Join(keystoreDir, keyUID) nodeConfig.KeycardPairingDataFile = filepath.Join("keycard", "pairings.json") - nodeConfig.Name = "StatusIM" - clusterConfig, err := params.LoadClusterConfigFromFleet("eth.prod") + nodeConfig.ShhextConfig = params.ShhextConfig{ + InstallationID: installationID, + } + + // need specify cluster config here, otherwise TestPairingThreeDevices will fail due to no messages(CR) received + // TODO(frank) need to figure out why above happen + clusterConfig, err := params.LoadClusterConfigFromFleet(params.FleetProd) if err != nil { return nil, err } nodeConfig.ClusterConfig = *clusterConfig - nodeConfig.WalletConfig = params.WalletConfig{Enabled: false} - nodeConfig.LocalNotificationsConfig = params.LocalNotificationsConfig{Enabled: true} - nodeConfig.BrowsersConfig = params.BrowsersConfig{Enabled: false} - nodeConfig.PermissionsConfig = params.PermissionsConfig{Enabled: true} - nodeConfig.MailserversConfig = params.MailserversConfig{Enabled: true} - nodeConfig.WakuConfig = params.WakuConfig{ - Enabled: true, - LightClient: true, - MinimumPoW: 0.000001, - } - - nodeConfig.ShhextConfig = params.ShhextConfig{ - BackupDisabledDataDir: tmpDir, - InstallationID: installationID, - MaxMessageDeliveryAttempts: 6, - MailServerConfirmations: true, - VerifyTransactionURL: "", - VerifyENSURL: "", - VerifyENSContractAddress: "", - VerifyTransactionChainID: 1, - DataSyncEnabled: true, - PFSEnabled: true, - } - return nodeConfig, nil }