From ff12bec63178126ca2c7f811cdc95b9b4be4f39e Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Thu, 17 Mar 2022 15:47:18 -0400 Subject: [PATCH] feat: switch fleet --- src/app_service/common/network_constants.nim | 3 +- .../node_configuration/dto/node_config.nim | 40 ++++++++++++++++++- .../service/node_configuration/service.nim | 10 ++++- src/app_service/service/settings/service.nim | 8 ++-- src/backend/node_config.nim | 9 +++++ vendor/nim-status-go | 2 +- vendor/status-go | 2 +- 7 files changed, 62 insertions(+), 12 deletions(-) diff --git a/src/app_service/common/network_constants.nim b/src/app_service/common/network_constants.nim index 1cabacd030..e55ca9a48f 100644 --- a/src/app_service/common/network_constants.nim +++ b/src/app_service/common/network_constants.nim @@ -173,7 +173,8 @@ var NODE_CONFIG* = %* { "Enabled": false, "Host": "0.0.0.0", "Port": 0, - "LightClient": false + "LightClient": false, + "PersistPeers": true, }, "WalletConfig": { "Enabled": true, diff --git a/src/app_service/service/node_configuration/dto/node_config.nim b/src/app_service/service/node_configuration/dto/node_config.nim index a2431bed92..a40e5cfc8a 100644 --- a/src/app_service/service/node_configuration/dto/node_config.nim +++ b/src/app_service/service/node_configuration/dto/node_config.nim @@ -85,6 +85,24 @@ type DiscoveryLimit*: int Rendezvous*: bool + Waku2Config = object + Enabled*: bool + Rendezvous*: bool + Host*: string + Port*: int + KeepAliveInterval*: int + LightClient*: bool + FullNode*: bool + DiscoveryLimit*: int + PersistPeers*: bool + DataDir*: string + MaxMessageSize*: int + EnableConfirmations*: bool + PeerExchange*: bool + EnableDiscV5*: bool + UDPPort*: int + AutoUpdate*: bool + ShhextConfig* = object PFSEnabled*: bool BackupDisabledDataDir*: string @@ -189,7 +207,7 @@ type ClusterConfig*: ClusterConfig LightEthConfig*: LightEthConfig WakuConfig*: WakuConfig - WakuV2Config*: WakuConfig + WakuV2Config*: Waku2Config BridgeConfig*: BridgeConfig ShhextConfig*: ShhextConfig WalletConfig*: WalletConfig @@ -296,6 +314,24 @@ proc toDatabaseConfig*(jsonObj: JsonNode): DatabaseConfig = if(jsonObj.getProp("PGConfig", pgConfigObj)): result.PGConfig = toPGConfig(pgConfigObj) +proc toWaku2Config*(jsonObj: JsonNode): Waku2Config = + discard jsonObj.getProp("Enabled", result.Enabled) + discard jsonObj.getProp("Rendezvous", result.Rendezvous) + discard jsonObj.getProp("Host", result.Host) + discard jsonObj.getProp("Port", result.Port) + discard jsonObj.getProp("KeepAliveInterval", result.KeepAliveInterval) + discard jsonObj.getProp("LightClient", result.LightClient) + discard jsonObj.getProp("FullNode", result.FullNode) + discard jsonObj.getProp("DiscoveryLimit", result.DiscoveryLimit) + discard jsonObj.getProp("PersistPeers", result.PersistPeers) + discard jsonObj.getProp("DataDir", result.DataDir) + discard jsonObj.getProp("MaxMessageSize", result.MaxMessageSize) + discard jsonObj.getProp("EnableConfirmations", result.EnableConfirmations) + discard jsonObj.getProp("PeerExchange", result.PeerExchange) + discard jsonObj.getProp("EnableDiscV5", result.EnableDiscV5) + discard jsonObj.getProp("UDPPort", result.UDPPort) + discard jsonObj.getProp("AutoUpdate", result.AutoUpdate) + proc toWakuConfig*(jsonObj: JsonNode): WakuConfig = discard jsonObj.getProp("Enabled", result.Enabled) discard jsonObj.getProp("LightClient", result.LightClient) @@ -469,7 +505,7 @@ proc toNodeConfigDto*(jsonObj: JsonNode): NodeConfigDto = var wakuV2ConfigObj: JsonNode if(jsonObj.getProp("WakuV2Config", wakuV2ConfigObj)): - result.WakuV2Config = toWakuConfig(wakuV2ConfigObj) + result.WakuV2Config = toWaku2Config(wakuV2ConfigObj) var shhextConfigObj: JsonNode if(jsonObj.getProp("ShhextConfig", shhextConfigObj)): diff --git a/src/app_service/service/node_configuration/service.nim b/src/app_service/service/node_configuration/service.nim index 74347a967b..0b40e42104 100644 --- a/src/app_service/service/node_configuration/service.nim +++ b/src/app_service/service/node_configuration/service.nim @@ -159,7 +159,7 @@ proc setFleet*(self: Service, fleet: string): bool = if(not self.settingsService.saveFleet(fleet)): error "error saving fleet ", procName="setFleet" return false - + let fleetType = parseEnum[Fleet](fleet) var newConfiguration = self.configuration newConfiguration.ClusterConfig.Fleet = fleet @@ -189,7 +189,13 @@ proc setFleet*(self: Service, fleet: string): bool = # Disabling go-waku rendezvous # newConfiguration.ClusterConfig.WakuRendezvousNodes = self.fleetConfiguration.getNodes(Fleet.GoWakuTest, FleetNodes.LibP2P) - return self.saveConfiguration(newConfiguration) + + try: + discard status_node_config.switchFleet(fleet, newConfiguration.toJsonNode()) + return true + except: + error "Could not switch fleet" + return false proc getV2LightMode*(self: Service): bool = return self.configuration.WakuV2Config.LightClient diff --git a/src/app_service/service/settings/service.nim b/src/app_service/service/settings/service.nim index 3474802542..a27338f805 100644 --- a/src/app_service/service/settings/service.nim +++ b/src/app_service/service/settings/service.nim @@ -305,11 +305,9 @@ proc saveTelemetryServerUrl*(self: Service, value: string): bool = proc getTelemetryServerUrl*(self: Service): string = return self.settings.telemetryServerUrl -proc saveFleet*(self: Service, value: string): bool = - if(self.saveSetting(KEY_FLEET, value)): - self.settings.fleet = value - return true - return false +method saveFleet*(self: Service, value: string): bool = + self.settings.fleet = value + return true proc getFleetAsString*(self: Service): string = if(self.settings.fleet.len == 0): diff --git a/src/backend/node_config.nim b/src/backend/node_config.nim index cdac688850..2c13f029b5 100644 --- a/src/backend/node_config.nim +++ b/src/backend/node_config.nim @@ -17,3 +17,12 @@ proc getNodeConfig*(): RpcResponse[JsonNode] {.raises: [Exception].} = except RpcException as e: error "error doing rpc request", methodName = "getNodeConfig", exception=e.msg raise newException(RpcException, e.msg) + +proc switchFleet*(fleet: string, nodeConfig: JsonNode): RpcResponse[JsonNode] {.raises: [Exception].} = + try: + info "switching fleet", fleet + let response = status_go.switchFleet(fleet, $nodeConfig) + result.result = Json.decode(response, JsonNode) + except RpcException as e: + error "error doing rpc request", methodName = "saveAccountAndLogin", exception=e.msg + raise newException(RpcException, e.msg) \ No newline at end of file diff --git a/vendor/nim-status-go b/vendor/nim-status-go index a46e18940f..091d500421 160000 --- a/vendor/nim-status-go +++ b/vendor/nim-status-go @@ -1 +1 @@ -Subproject commit a46e18940fbd8dd338f248429d2e3b02dd387cc2 +Subproject commit 091d500421e87360d0558e1c87c1001db87d3493 diff --git a/vendor/status-go b/vendor/status-go index 8f4c8da953..16311512cb 160000 --- a/vendor/status-go +++ b/vendor/status-go @@ -1 +1 @@ -Subproject commit 8f4c8da9533d1f71359c2e4541b9a47789db209b +Subproject commit 16311512cbf66c9eeaf03194707faa19c9390649