fix: override unsupported settings.fleet (#4785) (#4797)

* chore: remove fleet enum duplication
* fix: `updateNodeConfigFleet` on login
This commit is contained in:
Igor Sirotin 2024-02-22 19:32:24 +00:00 committed by GitHub
parent ba7faea027
commit 34c693bdea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 69 additions and 38 deletions

View File

@ -1461,13 +1461,13 @@ func TestSetFleet(t *testing.T) {
accountsDB, err := b.accountsDB()
require.NoError(t, err)
err = accountsDB.SaveSettingField(settings.Fleet, statusTestFleet)
err = accountsDB.SaveSettingField(settings.Fleet, params.FleetShardsTest)
require.NoError(t, err)
savedSettings, err = b.GetSettings()
require.NoError(t, err)
require.NotEmpty(t, savedSettings.Fleet)
require.Equal(t, statusTestFleet, *savedSettings.Fleet)
require.Equal(t, params.FleetShardsTest, *savedSettings.Fleet)
require.NoError(t, b.Logout())
@ -1483,7 +1483,7 @@ func TestSetFleet(t *testing.T) {
t.FailNow()
}
// Check is using the right fleet
require.Equal(t, b.config.ClusterConfig.WakuNodes, DefaultWakuNodes[statusTestFleet])
require.Equal(t, b.config.ClusterConfig.WakuNodes, params.DefaultWakuNodes(params.FleetShardsTest))
require.NoError(t, b.Logout())
}

View File

@ -27,23 +27,7 @@ const defaultKeycardPairingDataFile = "/ethereum/mainnet_rpc/keycard/pairings.js
var paths = []string{pathWalletRoot, pathEIP1581, pathDefaultChat, pathDefaultWallet}
const (
statusProdFleet = "status.prod"
statusTestFleet = "status.test"
wakuv2ProdFleet = "wakuv2.prod"
wakuv2TestFleet = "wakuv2.test"
shardsTest = "shards.test"
)
var DefaultWakuNodes = map[string][]string{
statusProdFleet: []string{"enrtree://AL65EKLJAUXKKPG43HVTML5EFFWEZ7L4LOKTLZCLJASG4DSESQZEC@prod.status.nodes.status.im"},
statusTestFleet: []string{"enrtree://AIO6LUM3IVWCU2KCPBBI6FEH2W42IGK3ASCZHZGG5TIXUR56OGQUO@test.status.nodes.status.im"},
wakuv2ProdFleet: []string{"enrtree://ANEDLO25QVUGJOUTQFRYKWX6P4Z4GKVESBMHML7DZ6YK4LGS5FC5O@prod.wakuv2.nodes.status.im"},
wakuv2TestFleet: []string{"enrtree://AO47IDOLBKH72HIZZOXQP6NMRESAN7CHYWIBNXDXWRJRZWLODKII6@test.wakuv2.nodes.status.im"},
shardsTest: []string{"enrtree://AMOJVZX4V6EXP7NTJPMAYJYST2QP6AJXYW76IU6VGJS7UVSNDYZG4@boot.test.shards.nodes.status.im"},
}
var DefaultFleet = shardsTest
var DefaultFleet = params.FleetShardsTest
func defaultSettings(generatedAccountInfo generator.GeneratedAccountInfo, derivedAddresses map[string]generator.AccountInfo, mnemonic *string) (*settings.Settings, error) {
chatKeyString := derivedAddresses[pathDefaultChat].PublicKey
@ -134,10 +118,10 @@ func SetFleet(fleet string, nodeConfig *params.NodeConfig) error {
}
nodeConfig.ClusterConfig = *clusterConfig
nodeConfig.ClusterConfig.Fleet = fleet
nodeConfig.ClusterConfig.WakuNodes = DefaultWakuNodes[fleet]
nodeConfig.ClusterConfig.DiscV5BootstrapNodes = DefaultWakuNodes[fleet]
nodeConfig.ClusterConfig.WakuNodes = params.DefaultWakuNodes(fleet)
nodeConfig.ClusterConfig.DiscV5BootstrapNodes = params.DefaultWakuNodes(fleet)
if fleet == shardsTest {
if fleet == params.FleetShardsTest {
nodeConfig.ClusterConfig.ClusterID = shardsTestClusterID
nodeConfig.WakuV2Config.UseShardAsDefaultTopic = true
}

View File

@ -624,20 +624,7 @@ func (b *GethStatusBackend) loginAccount(request *requests.Login) error {
defaultCfg.WalletConfig = buildWalletConfig(&request.WalletSecretsConfig)
settings, err := b.GetSettings()
if err != nil {
return err
}
var fleet string
fleetPtr := settings.Fleet
if fleetPtr == nil || *fleetPtr == "" {
fleet = DefaultFleet
} else {
fleet = *fleetPtr
}
err = SetFleet(fleet, defaultCfg)
err = b.updateNodeConfigFleet(defaultCfg)
if err != nil {
return err
}
@ -705,7 +692,32 @@ func (b *GethStatusBackend) loginAccount(request *requests.Login) error {
}
return nil
}
// updateNodeConfigFleet loads the fleet from the settings and updates the node configuration
// If the fleet in settings is empty, or not supported anymore, it will be overridden with the default fleet.
// In that case settings fleet value remain the same, only runtime node configuration is updated.
func (b *GethStatusBackend) updateNodeConfigFleet(config *params.NodeConfig) error {
accountSettings, err := b.GetSettings()
if err != nil {
return err
}
fleet := accountSettings.GetFleet()
if !params.IsFleetSupported(fleet) {
b.log.Warn("fleet is not supported, overriding with default value",
"fleet", fleet,
"defaultFleet", DefaultFleet)
fleet = DefaultFleet
}
err = SetFleet(fleet, config)
if err != nil {
return err
}
return nil
}
func (b *GethStatusBackend) startNodeWithAccount(acc multiaccounts.Account, password string, inputNodeCfg *params.NodeConfig) error {
@ -714,6 +726,13 @@ func (b *GethStatusBackend) startNodeWithAccount(acc multiaccounts.Account, pass
return err
}
// NOTE: This is code duplication from `loginAccount` method
// We should stop using this endpoint in desktop: https://github.com/status-im/status-desktop/issues/12977
err = b.updateNodeConfigFleet(inputNodeCfg)
if err != nil {
return err
}
err = b.loadNodeConfig(inputNodeCfg)
if err != nil {
return err

View File

@ -998,7 +998,7 @@ type FleetDescription struct {
func Fleets() string {
fleets := FleetDescription{
DefaultFleet: api.DefaultFleet,
Fleets: api.DefaultWakuNodes,
Fleets: params.GetSupportedFleets(),
}
data, err := json.Marshal(fleets)

View File

@ -6,6 +6,7 @@ import (
accountJson "github.com/status-im/status-go/account/json"
"github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/params"
"github.com/status-im/status-go/protocol/common"
"github.com/status-im/status-go/protocol/protobuf"
)
@ -230,3 +231,10 @@ func (s Settings) IsEmpty() bool {
empty := reflect.Zero(reflect.TypeOf(s)).Interface()
return reflect.DeepEqual(s, empty)
}
func (s Settings) GetFleet() string {
if s.Fleet == nil {
return params.FleetUndefined
}
return *s.Fleet
}

View File

@ -20,3 +20,23 @@ type Cluster struct {
MailServers []string `json:"mailservers"` // list of trusted mail servers
RendezvousNodes []string `json:"rendezvousnodes"`
}
// DefaultWakuNodes is a list of "supported" fleets. This list is populated to clients UI settings.
var supportedFleets = map[string][]string{
FleetWakuV2Prod: {"enrtree://ANEDLO25QVUGJOUTQFRYKWX6P4Z4GKVESBMHML7DZ6YK4LGS5FC5O@prod.wakuv2.nodes.status.im"},
FleetWakuV2Test: {"enrtree://AO47IDOLBKH72HIZZOXQP6NMRESAN7CHYWIBNXDXWRJRZWLODKII6@test.wakuv2.nodes.status.im"},
FleetShardsTest: {"enrtree://AMOJVZX4V6EXP7NTJPMAYJYST2QP6AJXYW76IU6VGJS7UVSNDYZG4@boot.test.shards.nodes.status.im"},
}
func DefaultWakuNodes(fleet string) []string {
return supportedFleets[fleet]
}
func IsFleetSupported(fleet string) bool {
_, ok := supportedFleets[fleet]
return ok
}
func GetSupportedFleets() map[string][]string {
return supportedFleets
}