From 6de044111d2022e4db19881e49d95e1adff3ecf7 Mon Sep 17 00:00:00 2001 From: zhangkai Date: Mon, 6 Nov 2023 11:05:08 +0800 Subject: [PATCH] Support websocket to register nacos (#33) * add nacos support for websocket * lint code --- .../environments/local/local.node.config.toml | 7 +- config/environments/mainnet/node.config.toml | 7 +- config/environments/testnet/node.config.toml | 7 +- docs/config-file/node-config-doc.html | 2 +- docs/config-file/node-config-doc.md | 69 +++++++++++++++++++ docs/config-file/node-config-schema.json | 27 ++++++++ jsonrpc/config.go | 5 +- jsonrpc/server.go | 5 ++ 8 files changed, 124 insertions(+), 5 deletions(-) diff --git a/config/environments/local/local.node.config.toml b/config/environments/local/local.node.config.toml index 0b4e098834..2e489ed077 100644 --- a/config/environments/local/local.node.config.toml +++ b/config/environments/local/local.node.config.toml @@ -52,7 +52,12 @@ EnableL2SuggestedGasPricePolling = true [RPC.WebSockets] Enabled = true Port = 8546 - [RCP.Nacos] + [RPC.Nacos] + URLs = "" + NamespaceId = "public" + ApplicationName = "" + ExternalListenAddr = "127.0.0.1:8123" + [RPC.NacosWs] URLs = "" NamespaceId = "public" ApplicationName = "" diff --git a/config/environments/mainnet/node.config.toml b/config/environments/mainnet/node.config.toml index 4d43ec48cc..2f7b4f4add 100644 --- a/config/environments/mainnet/node.config.toml +++ b/config/environments/mainnet/node.config.toml @@ -47,7 +47,12 @@ EnableL2SuggestedGasPricePolling = false [RPC.WebSockets] Enabled = true Port = 8546 - [RCP.Nacos] + [RPC.Nacos] + URLs = "" + NamespaceId = "public" + ApplicationName = "" + ExternalListenAddr = "127.0.0.1:8123" + [RPC.NacosWs] URLs = "" NamespaceId = "public" ApplicationName = "" diff --git a/config/environments/testnet/node.config.toml b/config/environments/testnet/node.config.toml index 20490287d4..6b2b4c2183 100644 --- a/config/environments/testnet/node.config.toml +++ b/config/environments/testnet/node.config.toml @@ -49,7 +49,12 @@ EnableL2SuggestedGasPricePolling = false [RPC.WebSockets] Enabled = true Port = 8546 - [RCP.Nacos] + [RPC.Nacos] + URLs = "" + NamespaceId = "public" + ApplicationName = "" + ExternalListenAddr = "127.0.0.1:8123" + [RPC.NacosWs] URLs = "" NamespaceId = "public" ApplicationName = "" diff --git a/docs/config-file/node-config-doc.html b/docs/config-file/node-config-doc.html index 6983be2331..9f8f96387e 100644 --- a/docs/config-file/node-config-doc.html +++ b/docs/config-file/node-config-doc.html @@ -14,7 +14,7 @@
"300ms"
 

Default: "1m0s"Type: string

WriteTimeout is the HTTP server write timeout
check net/http.server.WriteTimeout


Examples:

"1m"
 
"300ms"
-

Default: 500Type: number

MaxRequestsPerIPAndSecond defines how much requests a single IP can
send within a single second


Default: ""Type: string

SequencerNodeURI is used allow Non-Sequencer nodes
to relay transactions to the Sequencer node


Default: 0Type: integer

MaxCumulativeGasUsed is the max gas allowed per batch


WebSockets configuration
Default: trueType: boolean

Enabled defines if the WebSocket requests are enabled or disabled


Default: "0.0.0.0"Type: string

Host defines the network adapter that will be used to serve the WS requests


Default: 8546Type: integer

Port defines the port to serve the endpoints via WS


Default: trueType: boolean

EnableL2SuggestedGasPricePolling enables polling of the L2 gas price to block tx in the RPC with lower gas price.


Default: trueType: boolean

TraceBatchUseHTTPS enables, in the debugtraceBatchByNum endpoint, the use of the HTTPS protocol (instead of HTTP)
to do the parallel requests to RPC.debug
traceTransaction endpoint


Default: falseType: boolean

EnablePendingTransactionFilter enables pending transaction filter that can support query L2 pending transaction


Nacos configuration
Default: ""Type: string

URLs nacos server urls for discovery service of rest api, url is separated by ","


Default: ""Type: string

NamespaceId nacos namepace id for discovery service of rest api


Default: ""Type: string

ApplicationName rest application name in nacos


Default: ""Type: string

ExternalListenAddr Set the rest-server external ip and port, when it is launched by Docker


Configuration of service `Syncrhonizer`. For this service is also really important the value of `IsTrustedSequencer` because depending of this values is going to ask to a trusted node for trusted transactions or not
Default: "1s"Type: string

SyncInterval is the delay interval between reading new rollup information


Examples:

"1m"
+

Default: 500Type: number

MaxRequestsPerIPAndSecond defines how much requests a single IP can
send within a single second


Default: ""Type: string

SequencerNodeURI is used allow Non-Sequencer nodes
to relay transactions to the Sequencer node


Default: 0Type: integer

MaxCumulativeGasUsed is the max gas allowed per batch


WebSockets configuration
Default: trueType: boolean

Enabled defines if the WebSocket requests are enabled or disabled


Default: "0.0.0.0"Type: string

Host defines the network adapter that will be used to serve the WS requests


Default: 8546Type: integer

Port defines the port to serve the endpoints via WS


Default: trueType: boolean

EnableL2SuggestedGasPricePolling enables polling of the L2 gas price to block tx in the RPC with lower gas price.


Default: trueType: boolean

TraceBatchUseHTTPS enables, in the debugtraceBatchByNum endpoint, the use of the HTTPS protocol (instead of HTTP)
to do the parallel requests to RPC.debug
traceTransaction endpoint


Default: falseType: boolean

EnablePendingTransactionFilter enables pending transaction filter that can support query L2 pending transaction


Nacos configuration
Default: ""Type: string

URLs nacos server urls for discovery service of rest api, url is separated by ","


Default: ""Type: string

NamespaceId nacos namepace id for discovery service of rest api


Default: ""Type: string

ApplicationName rest application name in nacos


Default: ""Type: string

ExternalListenAddr Set the rest-server external ip and port, when it is launched by Docker


NacosWs configuration
Default: ""Type: string

URLs nacos server urls for discovery service of rest api, url is separated by ","


Default: ""Type: string

NamespaceId nacos namepace id for discovery service of rest api


Default: ""Type: string

ApplicationName rest application name in nacos


Default: ""Type: string

ExternalListenAddr Set the rest-server external ip and port, when it is launched by Docker


Configuration of service `Syncrhonizer`. For this service is also really important the value of `IsTrustedSequencer` because depending of this values is going to ask to a trusted node for trusted transactions or not
Default: "1s"Type: string

SyncInterval is the delay interval between reading new rollup information


Examples:

"1m"
 
"300ms"
 

Default: 100Type: integer

SyncChunkSize is the number of blocks to sync on each chunk


Default: ""Type: string

TrustedSequencerURL is the rpc url to connect and sync the trusted state


Configuration of the sequencer service
Default: "1s"Type: string

WaitPeriodPoolIsEmpty is the time the sequencer waits until
trying to add new txs to the state


Examples:

"1m"
 
"300ms"
diff --git a/docs/config-file/node-config-doc.md b/docs/config-file/node-config-doc.md
index f8ed88ed8b..76441910f9 100644
--- a/docs/config-file/node-config-doc.md
+++ b/docs/config-file/node-config-doc.md
@@ -762,6 +762,7 @@ FreeGasAddress="0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
 | - [TraceBatchUseHTTPS](#RPC_TraceBatchUseHTTPS )                             | No      | boolean | No         | -          | TraceBatchUseHTTPS enables, in the debug_traceBatchByNum endpoint, the use of the HTTPS protocol (instead of HTTP)
to do the parallel requests to RPC.debug_traceTransaction endpoint | | - [EnablePendingTransactionFilter](#RPC_EnablePendingTransactionFilter ) | No | boolean | No | - | EnablePendingTransactionFilter enables pending transaction filter that can support query L2 pending transaction | | - [Nacos](#RPC_Nacos ) | No | object | No | - | Nacos configuration | +| - [NacosWs](#RPC_NacosWs ) | No | object | No | - | NacosWs configuration | ### 8.1. `RPC.Host` @@ -1053,6 +1054,74 @@ ApplicationName="" ExternalListenAddr="" ``` +### 8.13. `[RPC.NacosWs]` + +**Type:** : `object` +**Description:** NacosWs configuration + +| Property | Pattern | Type | Deprecated | Definition | Title/Description | +| -------------------------------------------------------- | ------- | ------ | ---------- | ---------- | ------------------------------------------------------------------------------------------ | +| - [URLs](#RPC_NacosWs_URLs ) | No | string | No | - | URLs nacos server urls for discovery service of rest api, url is separated by "," | +| - [NamespaceId](#RPC_NacosWs_NamespaceId ) | No | string | No | - | NamespaceId nacos namepace id for discovery service of rest api | +| - [ApplicationName](#RPC_NacosWs_ApplicationName ) | No | string | No | - | ApplicationName rest application name in nacos | +| - [ExternalListenAddr](#RPC_NacosWs_ExternalListenAddr ) | No | string | No | - | ExternalListenAddr Set the rest-server external ip and port, when it is launched by Docker | + +#### 8.13.1. `RPC.NacosWs.URLs` + +**Type:** : `string` + +**Default:** `""` + +**Description:** URLs nacos server urls for discovery service of rest api, url is separated by "," + +**Example setting the default value** (""): +``` +[RPC.NacosWs] +URLs="" +``` + +#### 8.13.2. `RPC.NacosWs.NamespaceId` + +**Type:** : `string` + +**Default:** `""` + +**Description:** NamespaceId nacos namepace id for discovery service of rest api + +**Example setting the default value** (""): +``` +[RPC.NacosWs] +NamespaceId="" +``` + +#### 8.13.3. `RPC.NacosWs.ApplicationName` + +**Type:** : `string` + +**Default:** `""` + +**Description:** ApplicationName rest application name in nacos + +**Example setting the default value** (""): +``` +[RPC.NacosWs] +ApplicationName="" +``` + +#### 8.13.4. `RPC.NacosWs.ExternalListenAddr` + +**Type:** : `string` + +**Default:** `""` + +**Description:** ExternalListenAddr Set the rest-server external ip and port, when it is launched by Docker + +**Example setting the default value** (""): +``` +[RPC.NacosWs] +ExternalListenAddr="" +``` + ## 9. `[Synchronizer]` **Type:** : `object` diff --git a/docs/config-file/node-config-schema.json b/docs/config-file/node-config-schema.json index e84d9bb3be..3d41f1f3e3 100644 --- a/docs/config-file/node-config-schema.json +++ b/docs/config-file/node-config-schema.json @@ -391,6 +391,33 @@ "additionalProperties": false, "type": "object", "description": "Nacos configuration" + }, + "NacosWs": { + "properties": { + "URLs": { + "type": "string", + "description": "URLs nacos server urls for discovery service of rest api, url is separated by \",\"", + "default": "" + }, + "NamespaceId": { + "type": "string", + "description": "NamespaceId nacos namepace id for discovery service of rest api", + "default": "" + }, + "ApplicationName": { + "type": "string", + "description": "ApplicationName rest application name in nacos", + "default": "" + }, + "ExternalListenAddr": { + "type": "string", + "description": "ExternalListenAddr Set the rest-server external ip and port, when it is launched by Docker", + "default": "" + } + }, + "additionalProperties": false, + "type": "object", + "description": "NacosWs configuration" } }, "additionalProperties": false, diff --git a/jsonrpc/config.go b/jsonrpc/config.go index 39ffe10d68..aefe6a738a 100644 --- a/jsonrpc/config.go +++ b/jsonrpc/config.go @@ -43,7 +43,10 @@ type Config struct { EnablePendingTransactionFilter bool `mapstructure:"EnablePendingTransactionFilter"` // Nacos configuration - Nacos NacosConfig `mspstructure:"Nacos"` + Nacos NacosConfig `mapstructure:"Nacos"` + + // NacosWs configuration + NacosWs NacosConfig `mapstructure:"NacosWs"` } // WebSocketsConfig has parameters to config the rpc websocket support diff --git a/jsonrpc/server.go b/jsonrpc/server.go index b49c7f36e2..1c1505261a 100644 --- a/jsonrpc/server.go +++ b/jsonrpc/server.go @@ -422,4 +422,9 @@ func (s *Server) registerNacos() { if s.config.Nacos.URLs != "" { nacos.StartNacosClient(s.config.Nacos.URLs, s.config.Nacos.NamespaceId, s.config.Nacos.ApplicationName, s.config.Nacos.ExternalListenAddr) } + + // start nacos client for registering restful service + if s.config.NacosWs.URLs != "" { + nacos.StartNacosClient(s.config.NacosWs.URLs, s.config.NacosWs.NamespaceId, s.config.NacosWs.ApplicationName, s.config.NacosWs.ExternalListenAddr) + } }