From 5a5e00f8c89a789279a85da30c1e0d92d4d453f3 Mon Sep 17 00:00:00 2001 From: EclesioMeloJunior Date: Thu, 14 Apr 2022 10:07:13 -0400 Subject: [PATCH 1/8] fix: include unsafe flags to be considered by RPC layer --- cmd/gossamer/config.go | 16 ++++++++++++++++ cmd/gossamer/export.go | 20 ++++++++++++-------- cmd/gossamer/flags.go | 4 ++-- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/cmd/gossamer/config.go b/cmd/gossamer/config.go index 14ae28f9cf..6e0774295f 100644 --- a/cmd/gossamer/config.go +++ b/cmd/gossamer/config.go @@ -736,6 +736,22 @@ func setDotRPCConfig(ctx *cli.Context, tomlCfg ctoml.RPCConfig, cfg *dot.RPCConf cfg.External = false } + cfg.Unsafe = ctx.GlobalBool(RPCUnsafeEnabledFlag.Name) + + // check --ws-unsafe flag value + if externalUnsafe := ctx.GlobalBool(RPCUnsafeExternalFlag.Name); externalUnsafe { + cfg.Unsafe = true + cfg.UnsafeExternal = true + } + + cfg.WSUnsafe = ctx.GlobalBool(WSUnsafeEnabledFlag.Name) + + // check --ws-unsafe-external flag value + if wsExternalUnsafe := ctx.GlobalBool(WSUnsafeExternalFlag.Name); wsExternalUnsafe { + cfg.WSUnsafe = true + cfg.WSUnsafeExternal = true + } + // check --rpcport flag and update node configuration if port := ctx.GlobalUint(RPCPortFlag.Name); port != 0 { cfg.Port = uint32(port) diff --git a/cmd/gossamer/export.go b/cmd/gossamer/export.go index 4c845d7601..5f10cdc3b5 100644 --- a/cmd/gossamer/export.go +++ b/cmd/gossamer/export.go @@ -115,14 +115,18 @@ func dotConfigToToml(dcfg *dot.Config) *ctoml.Config { } cfg.RPC = ctoml.RPCConfig{ - Enabled: dcfg.RPC.Enabled, - External: dcfg.RPC.External, - Port: dcfg.RPC.Port, - Host: dcfg.RPC.Host, - Modules: dcfg.RPC.Modules, - WSPort: dcfg.RPC.WSPort, - WS: dcfg.RPC.WS, - WSExternal: dcfg.RPC.WSExternal, + Enabled: dcfg.RPC.Enabled, + External: dcfg.RPC.External, + Unsafe: dcfg.RPC.Unsafe, + UnsafeExternal: dcfg.RPC.UnsafeExternal, + Port: dcfg.RPC.Port, + Host: dcfg.RPC.Host, + Modules: dcfg.RPC.Modules, + WSPort: dcfg.RPC.WSPort, + WS: dcfg.RPC.WS, + WSExternal: dcfg.RPC.WSExternal, + WSUnsafe: dcfg.RPC.WSUnsafe, + WSUnsafeExternal: dcfg.RPC.WSUnsafeExternal, } return cfg diff --git a/cmd/gossamer/flags.go b/cmd/gossamer/flags.go index 6222bcd224..f69518b4d8 100644 --- a/cmd/gossamer/flags.go +++ b/cmd/gossamer/flags.go @@ -287,7 +287,7 @@ var ( Usage: "Enable external websocket connections", } // WSFlag Enable the websockets server - WSUnsafeFlag = cli.BoolFlag{ + WSUnsafeEnabledFlag = cli.BoolFlag{ Name: "ws-unsafe", Usage: "Enable access to websocket unsafe calls", } @@ -436,7 +436,7 @@ var ( RPCModulesFlag, WSFlag, WSExternalFlag, - WSUnsafeFlag, + WSUnsafeEnabledFlag, WSUnsafeExternalFlag, WSPortFlag, From e66752c860b4d447f8eeb562d7494e4ebe32c12b Mon Sep 17 00:00:00 2001 From: EclesioMeloJunior Date: Thu, 14 Apr 2022 10:15:00 -0400 Subject: [PATCH 2/8] chore: improve comments --- cmd/gossamer/config.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cmd/gossamer/config.go b/cmd/gossamer/config.go index 6e0774295f..b3143e1a70 100644 --- a/cmd/gossamer/config.go +++ b/cmd/gossamer/config.go @@ -736,14 +736,16 @@ func setDotRPCConfig(ctx *cli.Context, tomlCfg ctoml.RPCConfig, cfg *dot.RPCConf cfg.External = false } + // check --rpc-unsafe flag value cfg.Unsafe = ctx.GlobalBool(RPCUnsafeEnabledFlag.Name) - // check --ws-unsafe flag value + // check --rpc-unsafe-external flag value if externalUnsafe := ctx.GlobalBool(RPCUnsafeExternalFlag.Name); externalUnsafe { cfg.Unsafe = true cfg.UnsafeExternal = true } + // check --ws-unsafe flag value cfg.WSUnsafe = ctx.GlobalBool(WSUnsafeEnabledFlag.Name) // check --ws-unsafe-external flag value From 34ee274f6cc14adad5d3441696bbf98c1e3f2ad3 Mon Sep 17 00:00:00 2001 From: EclesioMeloJunior Date: Thu, 14 Apr 2022 10:33:39 -0400 Subject: [PATCH 3/8] chore: add unsafe to rpc tests --- tests/utils/gossamer_utils.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/utils/gossamer_utils.go b/tests/utils/gossamer_utils.go index b229920bb1..61023dcf65 100644 --- a/tests/utils/gossamer_utils.go +++ b/tests/utils/gossamer_utils.go @@ -119,6 +119,7 @@ func startGossamer(t *testing.T, node Node, websocket bool) ( "--rpcport", node.RPCPort, "--rpcmods", "system,author,chain,state,dev,rpc", "--rpc", + "--rpc-unsafe", "--no-telemetry", "--log", "info"} @@ -135,7 +136,7 @@ func startGossamer(t *testing.T, node Node, websocket bool) ( } if websocket { - params = append(params, "--ws", + params = append(params, "--ws", "--ws-unsafe", "--wsport", node.WSPort) } node.Process = exec.Command(gossamerCMD, params...) From b27e723248fe463a3c2f60d6cdf9b166f9584333 Mon Sep 17 00:00:00 2001 From: EclesioMeloJunior Date: Thu, 14 Apr 2022 11:15:14 -0400 Subject: [PATCH 4/8] chore: remove unsafe flags from polkadot js tests --- tests/polkadotjs_test/start_polkadotjs_test.go | 8 ++++---- tests/utils/gossamer_utils.go | 3 +-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/tests/polkadotjs_test/start_polkadotjs_test.go b/tests/polkadotjs_test/start_polkadotjs_test.go index 61714c2b6c..2258919a43 100644 --- a/tests/polkadotjs_test/start_polkadotjs_test.go +++ b/tests/polkadotjs_test/start_polkadotjs_test.go @@ -17,10 +17,10 @@ import ( var polkadotSuite = "polkadot" func TestStartGossamerAndPolkadotAPI(t *testing.T) { - if utils.MODE != polkadotSuite { - t.Log("Going to skip polkadot.js/api suite tests") - return - } + // if utils.MODE != polkadotSuite { + // t.Log("Going to skip polkadot.js/api suite tests") + // return + // } t.Log("starting gossamer for polkadot.js/api tests...") utils.CreateDefaultConfig() diff --git a/tests/utils/gossamer_utils.go b/tests/utils/gossamer_utils.go index 61023dcf65..b229920bb1 100644 --- a/tests/utils/gossamer_utils.go +++ b/tests/utils/gossamer_utils.go @@ -119,7 +119,6 @@ func startGossamer(t *testing.T, node Node, websocket bool) ( "--rpcport", node.RPCPort, "--rpcmods", "system,author,chain,state,dev,rpc", "--rpc", - "--rpc-unsafe", "--no-telemetry", "--log", "info"} @@ -136,7 +135,7 @@ func startGossamer(t *testing.T, node Node, websocket bool) ( } if websocket { - params = append(params, "--ws", "--ws-unsafe", + params = append(params, "--ws", "--wsport", node.WSPort) } node.Process = exec.Command(gossamerCMD, params...) From 9f77e8c2f6adca0e9610eebef1c7f06057a8d764 Mon Sep 17 00:00:00 2001 From: EclesioMeloJunior Date: Fri, 15 Apr 2022 23:55:07 -0400 Subject: [PATCH 5/8] chore: uncomment important test check --- tests/polkadotjs_test/start_polkadotjs_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/polkadotjs_test/start_polkadotjs_test.go b/tests/polkadotjs_test/start_polkadotjs_test.go index 2258919a43..61714c2b6c 100644 --- a/tests/polkadotjs_test/start_polkadotjs_test.go +++ b/tests/polkadotjs_test/start_polkadotjs_test.go @@ -17,10 +17,10 @@ import ( var polkadotSuite = "polkadot" func TestStartGossamerAndPolkadotAPI(t *testing.T) { - // if utils.MODE != polkadotSuite { - // t.Log("Going to skip polkadot.js/api suite tests") - // return - // } + if utils.MODE != polkadotSuite { + t.Log("Going to skip polkadot.js/api suite tests") + return + } t.Log("starting gossamer for polkadot.js/api tests...") utils.CreateDefaultConfig() From 0e0c29865a12bd074f32bde1aae61afeca65e1fb Mon Sep 17 00:00:00 2001 From: EclesioMeloJunior Date: Sun, 17 Apr 2022 18:48:23 +0200 Subject: [PATCH 6/8] chore: enable unsafe calls on tests --- tests/utils/gossamer_utils.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/utils/gossamer_utils.go b/tests/utils/gossamer_utils.go index b229920bb1..bf92e7c7c8 100644 --- a/tests/utils/gossamer_utils.go +++ b/tests/utils/gossamer_utils.go @@ -118,6 +118,7 @@ func startGossamer(t *testing.T, node Node, websocket bool) ( "--rpchost", HOSTNAME, "--rpcport", node.RPCPort, "--rpcmods", "system,author,chain,state,dev,rpc", + "--unsafe", "--rpc", "--no-telemetry", "--log", "info"} @@ -135,7 +136,7 @@ func startGossamer(t *testing.T, node Node, websocket bool) ( } if websocket { - params = append(params, "--ws", + params = append(params, "--ws", "--ws-unsafe", "--wsport", node.WSPort) } node.Process = exec.Command(gossamerCMD, params...) From a0de17418fec84d1753d2c4b73bff496135290cd Mon Sep 17 00:00:00 2001 From: EclesioMeloJunior Date: Mon, 18 Apr 2022 13:27:18 +0200 Subject: [PATCH 7/8] chore: fiz the flag name --- tests/utils/gossamer_utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/utils/gossamer_utils.go b/tests/utils/gossamer_utils.go index bf92e7c7c8..556ae14666 100644 --- a/tests/utils/gossamer_utils.go +++ b/tests/utils/gossamer_utils.go @@ -118,7 +118,7 @@ func startGossamer(t *testing.T, node Node, websocket bool) ( "--rpchost", HOSTNAME, "--rpcport", node.RPCPort, "--rpcmods", "system,author,chain,state,dev,rpc", - "--unsafe", + "--rpc-unsafe", "--rpc", "--no-telemetry", "--log", "info"} From 125cfa6aafbedf35b4fa8490f4815dabfa8dc1b9 Mon Sep 17 00:00:00 2001 From: EclesioMeloJunior Date: Mon, 18 Apr 2022 16:15:28 +0200 Subject: [PATCH 8/8] chore: not overwrite the config tomll value if flag not defined --- cmd/gossamer/config.go | 8 ++++++-- tests/utils/gossamer_utils.go | 3 +-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/cmd/gossamer/config.go b/cmd/gossamer/config.go index b3143e1a70..eaeb049e6a 100644 --- a/cmd/gossamer/config.go +++ b/cmd/gossamer/config.go @@ -737,7 +737,9 @@ func setDotRPCConfig(ctx *cli.Context, tomlCfg ctoml.RPCConfig, cfg *dot.RPCConf } // check --rpc-unsafe flag value - cfg.Unsafe = ctx.GlobalBool(RPCUnsafeEnabledFlag.Name) + if rpcUnsafe := ctx.GlobalBool(RPCUnsafeEnabledFlag.Name); rpcUnsafe { + cfg.Unsafe = true + } // check --rpc-unsafe-external flag value if externalUnsafe := ctx.GlobalBool(RPCUnsafeExternalFlag.Name); externalUnsafe { @@ -746,7 +748,9 @@ func setDotRPCConfig(ctx *cli.Context, tomlCfg ctoml.RPCConfig, cfg *dot.RPCConf } // check --ws-unsafe flag value - cfg.WSUnsafe = ctx.GlobalBool(WSUnsafeEnabledFlag.Name) + if wsUnsafe := ctx.GlobalBool(WSUnsafeEnabledFlag.Name); wsUnsafe { + cfg.WSUnsafe = true + } // check --ws-unsafe-external flag value if wsExternalUnsafe := ctx.GlobalBool(WSUnsafeExternalFlag.Name); wsExternalUnsafe { diff --git a/tests/utils/gossamer_utils.go b/tests/utils/gossamer_utils.go index 556ae14666..b229920bb1 100644 --- a/tests/utils/gossamer_utils.go +++ b/tests/utils/gossamer_utils.go @@ -118,7 +118,6 @@ func startGossamer(t *testing.T, node Node, websocket bool) ( "--rpchost", HOSTNAME, "--rpcport", node.RPCPort, "--rpcmods", "system,author,chain,state,dev,rpc", - "--rpc-unsafe", "--rpc", "--no-telemetry", "--log", "info"} @@ -136,7 +135,7 @@ func startGossamer(t *testing.T, node Node, websocket bool) ( } if websocket { - params = append(params, "--ws", "--ws-unsafe", + params = append(params, "--ws", "--wsport", node.WSPort) } node.Process = exec.Command(gossamerCMD, params...)