refactor_: add more default node config values for frontend when doing local pair sync

This commit is contained in:
frank 2024-04-26 22:11:49 +08:00
parent 9c2c638aaf
commit 4f4b7a9ce4
7 changed files with 131 additions and 70 deletions

View File

@ -26,12 +26,20 @@ const defaultMnemonicLength = 12
const shardsTestClusterID = 16 const shardsTestClusterID = 16
const walletAccountDefaultName = "Account 1" const walletAccountDefaultName = "Account 1"
const keystoreRelativePath = "keystore" const keystoreRelativePath = "keystore"
const defaultKeycardPairingDataFile = "/ethereum/mainnet_rpc/keycard/pairings.json" const DefaultKeycardPairingDataFile = "/ethereum/mainnet_rpc/keycard/pairings.json"
const defaultArchivesRelativePath = "data/archivedata" const DefaultArchivesRelativePath = "data/archivedata"
const defaultTorrentTorrentsRelativePath = "data/torrents" const DefaultTorrentTorrentsRelativePath = "data/torrents"
const DefaultDataDir = "/ethereum/mainnet_rpc" 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} 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 { func SetFleet(fleet string, nodeConfig *params.NodeConfig) error {
specifiedWakuV2Config := nodeConfig.WakuV2Config
nodeConfig.WakuV2Config = params.WakuV2Config{ nodeConfig.WakuV2Config = params.WakuV2Config{
Enabled: true, Enabled: true,
EnableDiscV5: true, EnableDiscV5: true,
DiscoveryLimit: 20, DiscoveryLimit: 20,
Host: "0.0.0.0", Host: "0.0.0.0",
AutoUpdate: true, AutoUpdate: true,
// mobile may need override following options
LightClient: specifiedWakuV2Config.LightClient,
Nameserver: specifiedWakuV2Config.Nameserver,
} }
clusterConfig, err := params.LoadClusterConfigFromFleet(fleet) clusterConfig, err := params.LoadClusterConfigFromFleet(fleet)
@ -211,11 +223,11 @@ func defaultNodeConfig(installationID string, request *requests.CreateAccount, o
// Set mainnet // Set mainnet
nodeConfig := &params.NodeConfig{} nodeConfig := &params.NodeConfig{}
nodeConfig.LogEnabled = request.LogEnabled nodeConfig.LogEnabled = request.LogEnabled
nodeConfig.LogFile = "geth.log" nodeConfig.LogFile = DefaultLogFile
nodeConfig.LogDir = request.LogFilePath nodeConfig.LogDir = request.LogFilePath
nodeConfig.LogLevel = "ERROR" nodeConfig.LogLevel = DefaultLogLevel
nodeConfig.DataDir = DefaultDataDir nodeConfig.DataDir = DefaultDataDir
nodeConfig.KeycardPairingDataFile = defaultKeycardPairingDataFile nodeConfig.KeycardPairingDataFile = DefaultKeycardPairingDataFile
nodeConfig.ProcessBackedupMessages = false nodeConfig.ProcessBackedupMessages = false
if request.LogLevel != nil { if request.LogLevel != nil {
@ -243,11 +255,11 @@ func defaultNodeConfig(installationID string, request *requests.CreateAccount, o
nodeConfig.UpstreamConfig.Enabled = true nodeConfig.UpstreamConfig.Enabled = true
} }
nodeConfig.Name = "StatusIM" nodeConfig.Name = DefaultNodeName
nodeConfig.Rendezvous = false nodeConfig.Rendezvous = false
nodeConfig.NoDiscovery = true nodeConfig.NoDiscovery = true
nodeConfig.MaxPeers = 20 nodeConfig.MaxPeers = DefaultMaxPeers
nodeConfig.MaxPendingPeers = 20 nodeConfig.MaxPendingPeers = DefaultMaxPendingPeers
nodeConfig.WalletConfig = buildWalletConfig(&request.WalletSecretsConfig) nodeConfig.WalletConfig = buildWalletConfig(&request.WalletSecretsConfig)
@ -256,7 +268,7 @@ func defaultNodeConfig(installationID string, request *requests.CreateAccount, o
nodeConfig.PermissionsConfig = params.PermissionsConfig{Enabled: true} nodeConfig.PermissionsConfig = params.PermissionsConfig{Enabled: true}
nodeConfig.MailserversConfig = params.MailserversConfig{Enabled: true} nodeConfig.MailserversConfig = params.MailserversConfig{Enabled: true}
nodeConfig.ListenAddr = ":0" nodeConfig.ListenAddr = DefaultListenAddr
err := SetDefaultFleet(nodeConfig) err := SetDefaultFleet(nodeConfig)
if err != nil { if err != nil {
@ -274,9 +286,9 @@ func defaultNodeConfig(installationID string, request *requests.CreateAccount, o
nodeConfig.ShhextConfig = params.ShhextConfig{ nodeConfig.ShhextConfig = params.ShhextConfig{
BackupDisabledDataDir: request.BackupDisabledDataDir, BackupDisabledDataDir: request.BackupDisabledDataDir,
InstallationID: installationID, InstallationID: installationID,
MaxMessageDeliveryAttempts: 6, MaxMessageDeliveryAttempts: DefaultMaxMessageDeliveryAttempts,
MailServerConfirmations: true, MailServerConfirmations: true,
VerifyTransactionChainID: 1, VerifyTransactionChainID: DefaultVerifyTransactionChainID,
DataSyncEnabled: true, DataSyncEnabled: true,
PFSEnabled: true, PFSEnabled: true,
} }
@ -301,14 +313,6 @@ func defaultNodeConfig(installationID string, request *requests.CreateAccount, o
nodeConfig.ShhextConfig.VerifyENSContractAddress = *request.VerifyENSContractAddress nodeConfig.ShhextConfig.VerifyENSContractAddress = *request.VerifyENSContractAddress
} }
if request.LogLevel != nil {
nodeConfig.LogLevel = *request.LogLevel
nodeConfig.LogEnabled = true
} else {
nodeConfig.LogEnabled = false
}
if request.NetworkID != nil { if request.NetworkID != nil {
nodeConfig.NetworkID = *request.NetworkID nodeConfig.NetworkID = *request.NetworkID
} }
@ -316,8 +320,8 @@ func defaultNodeConfig(installationID string, request *requests.CreateAccount, o
nodeConfig.TorrentConfig = params.TorrentConfig{ nodeConfig.TorrentConfig = params.TorrentConfig{
Enabled: false, Enabled: false,
Port: 0, Port: 0,
DataDir: filepath.Join(nodeConfig.RootDataDir, defaultArchivesRelativePath), DataDir: filepath.Join(nodeConfig.RootDataDir, DefaultArchivesRelativePath),
TorrentDir: filepath.Join(nodeConfig.RootDataDir, defaultTorrentTorrentsRelativePath), TorrentDir: filepath.Join(nodeConfig.RootDataDir, DefaultTorrentTorrentsRelativePath),
} }
if request.TorrentConfigEnabled != nil { if request.TorrentConfigEnabled != nil {

View File

@ -617,7 +617,7 @@ func (b *GethStatusBackend) loginAccount(request *requests.Login) error {
defaultCfg := &params.NodeConfig{ defaultCfg := &params.NodeConfig{
// why we need this? relate PR: https://github.com/status-im/status-go/pull/4014 // why we need this? relate PR: https://github.com/status-im/status-go/pull/4014
KeycardPairingDataFile: defaultKeycardPairingDataFile, KeycardPairingDataFile: DefaultKeycardPairingDataFile,
} }
defaultCfg.WalletConfig = buildWalletConfig(&request.WalletSecretsConfig) defaultCfg.WalletConfig = buildWalletConfig(&request.WalletSecretsConfig)

View File

@ -371,12 +371,12 @@ func defaultNodeConfig(installationID string) (*params.NodeConfig, error) {
nodeConfig.ShhextConfig = params.ShhextConfig{ nodeConfig.ShhextConfig = params.ShhextConfig{
BackupDisabledDataDir: "", BackupDisabledDataDir: "",
InstallationID: installationID, InstallationID: installationID,
MaxMessageDeliveryAttempts: 6, MaxMessageDeliveryAttempts: api.DefaultMaxMessageDeliveryAttempts,
MailServerConfirmations: true, MailServerConfirmations: true,
VerifyTransactionURL: "", VerifyTransactionURL: "",
VerifyENSURL: "", VerifyENSURL: "",
VerifyENSContractAddress: "", VerifyENSContractAddress: "",
VerifyTransactionChainID: 1, VerifyTransactionChainID: api.DefaultVerifyTransactionChainID,
DataSyncEnabled: true, DataSyncEnabled: true,
PFSEnabled: true, PFSEnabled: true,
} }

View File

@ -420,12 +420,12 @@ func defaultNodeConfig(installationID string) (*params.NodeConfig, error) {
nodeConfig.ShhextConfig = params.ShhextConfig{ nodeConfig.ShhextConfig = params.ShhextConfig{
BackupDisabledDataDir: "", BackupDisabledDataDir: "",
InstallationID: installationID, InstallationID: installationID,
MaxMessageDeliveryAttempts: 6, MaxMessageDeliveryAttempts: api.DefaultMaxMessageDeliveryAttempts,
MailServerConfirmations: true, MailServerConfirmations: true,
VerifyTransactionURL: "", VerifyTransactionURL: "",
VerifyENSURL: "", VerifyENSURL: "",
VerifyENSContractAddress: "", VerifyENSContractAddress: "",
VerifyTransactionChainID: 1, VerifyTransactionChainID: api.DefaultVerifyTransactionChainID,
DataSyncEnabled: true, DataSyncEnabled: true,
PFSEnabled: true, PFSEnabled: true,
} }

View File

@ -311,12 +311,12 @@ func defaultNodeConfig(installationID string) (*params.NodeConfig, error) {
nodeConfig.ShhextConfig = params.ShhextConfig{ nodeConfig.ShhextConfig = params.ShhextConfig{
BackupDisabledDataDir: "", BackupDisabledDataDir: "",
InstallationID: installationID, InstallationID: installationID,
MaxMessageDeliveryAttempts: 6, MaxMessageDeliveryAttempts: api.DefaultMaxMessageDeliveryAttempts,
MailServerConfirmations: true, MailServerConfirmations: true,
VerifyTransactionURL: "", VerifyTransactionURL: "",
VerifyENSURL: "", VerifyENSURL: "",
VerifyENSContractAddress: "", VerifyENSContractAddress: "",
VerifyTransactionChainID: 1, VerifyTransactionChainID: api.DefaultVerifyTransactionChainID,
DataSyncEnabled: true, DataSyncEnabled: true,
PFSEnabled: true, PFSEnabled: true,
} }

View File

@ -10,6 +10,8 @@ import (
"regexp" "regexp"
"strings" "strings"
"github.com/google/uuid"
"github.com/status-im/status-go/params" "github.com/status-im/status-go/params"
"github.com/status-im/status-go/protocol/requests" "github.com/status-im/status-go/protocol/requests"
@ -246,6 +248,10 @@ func validateKeystoreFilesConfig(backend *api.GethStatusBackend, conf interface{
return nil 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 { func setDefaultNodeConfig(c *params.NodeConfig) error {
if c == nil { if c == nil {
return nil return nil
@ -256,22 +262,94 @@ func setDefaultNodeConfig(c *params.NodeConfig) error {
return err 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{}) c.Networks = api.BuildDefaultNetworks(&requests.WalletSecretsConfig{})
} }
if c.NetworkID == 0 { if specifiedNetworkID == 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
c.NetworkID = c.Networks[0].ChainID 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 == "" { if specifiedInstallationID == "" {
c.DataDir = api.DefaultDataDir 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 return nil

View File

@ -115,13 +115,9 @@ func (s *SyncDeviceSuite) prepareBackendWithAccount(mnemonic, tmpdir string) *ap
account.Name = settings.Name account.Name = settings.Name
nodeConfig, err := nodeConfigForLocalPairSync(settings.InstallationID, account.KeyUID, tmpdir) nodeConfig, err := nodeConfigForLocalPairSync(settings.InstallationID, account.KeyUID, tmpdir)
nodeConfig.RootDataDir = tmpdir
require.NoError(s.T(), err) require.NoError(s.T(), err)
nodeConfig.NetworkID = 1 require.NoError(s.T(), setDefaultNodeConfig(nodeConfig))
nodeConfig.UpstreamConfig = params.UpstreamRPCConfig{
Enabled: true,
URL: "https://mainnet.infura.io/v3/800c641949d64d768a5070a1b0511938",
}
nodeConfig.DataDir = api.DefaultDataDir
walletDerivedAccount := derivedAddresses[pathDefaultWallet] walletDerivedAccount := derivedAddresses[pathDefaultWallet]
walletAccount := &accounts.Account{ walletAccount := &accounts.Account{
@ -733,40 +729,23 @@ func defaultSettings(generatedAccountInfo generator.GeneratedAccountInfo, derive
func nodeConfigForLocalPairSync(installationID, keyUID, tmpDir string) (*params.NodeConfig, error) { func nodeConfigForLocalPairSync(installationID, keyUID, tmpDir string) (*params.NodeConfig, error) {
// Set mainnet // Set mainnet
nodeConfig := &params.NodeConfig{} nodeConfig := &params.NodeConfig{}
nodeConfig.LogEnabled = true
nodeConfig.LogLevel = "DEBUG" nodeConfig.LogLevel = "DEBUG"
nodeConfig.LogDir = tmpDir
nodeConfig.KeyStoreDir = filepath.Join(keystoreDir, keyUID) nodeConfig.KeyStoreDir = filepath.Join(keystoreDir, keyUID)
nodeConfig.KeycardPairingDataFile = filepath.Join("keycard", "pairings.json") nodeConfig.KeycardPairingDataFile = filepath.Join("keycard", "pairings.json")
nodeConfig.Name = "StatusIM" nodeConfig.ShhextConfig = params.ShhextConfig{
clusterConfig, err := params.LoadClusterConfigFromFleet("eth.prod") 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 { if err != nil {
return nil, err return nil, err
} }
nodeConfig.ClusterConfig = *clusterConfig 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 return nodeConfig, nil
} }