Ver código fonte

node: Fix url verification bug where <ip>:<port> is not supported (#3719)

* node: update url verification logic to support ip:port format

Signed-off-by: bingyuyap <bingyu.yap.21@gmail.com>

* node: add test case for ip:port

Signed-off-by: bingyuyap <bingyu.yap.21@gmail.com>

* node: change neon rpc scheme from websocket to HTTP

Signed-off-by: bingyuyap <bingyu.yap.21@gmail.com>

* node: update comment to be more accurate

Signed-off-by: bingyuyap <bingyu.yap.21@gmail.com>

* node: remove neon from devmode

Signed-off-by: bingyuyap <bingyu.yap.21@gmail.com>

* node: ignore internal xlabs testing file

Signed-off-by: bingyuyap <bingyu.yap.21@gmail.com>

* node: add ws:// prefix to Sui

Signed-off-by: bingyuyap <bingyu.yap.21@gmail.com>

* node: add ws:// and wss:// prefixes to Sui schemes

Signed-off-by: bingyuyap <bingyu.yap.21@gmail.com>

* node: update testnet yaml naming

Signed-off-by: bingyuyap <bingyu.yap.21@gmail.com>

---------

Signed-off-by: bingyuyap <bingyu.yap.21@gmail.com>
Bing Yu 1 ano atrás
pai
commit
3d16cca785

+ 3 - 1
.gitignore

@@ -31,4 +31,6 @@ devnet-consts.json
 /ethereum/cache/
 sui.log.*
 sui/examples/wrapped_coin
-*.prof
+*.prof
+# Only used for internal testing
+*.testnet.yaml

+ 1 - 1
Tiltfile

@@ -188,7 +188,7 @@ def build_node_yaml():
                     "--suiMoveEventType",
                     "0x7f6cebb8a489654d7a759483bd653c4be3e5ccfef17a8b5fd3ba98bd072fabc3::publish_message::WormholeMessage",
                     "--suiWS",
-                    "sui:9000",
+                    "ws://sui:9000",
                 ]
 
             if evm2:

+ 0 - 2
devnet/node.yaml

@@ -99,8 +99,6 @@ spec:
             - ws://eth-devnet:8545
             - --optimismRPC
             - ws://eth-devnet:8545
-            - --neonRPC
-            - ws://eth-devnet:8545
             - --baseRPC
             - ws://eth-devnet:8545
             - --scrollRPC

+ 2 - 3
node/cmd/guardiand/node.go

@@ -283,7 +283,7 @@ func init() {
 	moonbeamRPC = node.RegisterFlagWithValidationOrFail(NodeCmd, "moonbeamRPC", "Moonbeam RPC URL", "ws://eth-devnet:8545", []string{"ws", "wss"})
 	moonbeamContract = NodeCmd.Flags().String("moonbeamContract", "", "Moonbeam contract address")
 
-	neonRPC = node.RegisterFlagWithValidationOrFail(NodeCmd, "neonRPC", "Neon RPC URL", "ws://eth-devnet:8545", []string{"ws", "wss"})
+	neonRPC = node.RegisterFlagWithValidationOrFail(NodeCmd, "neonRPC", "Neon RPC URL", "http://eth-devnet:8545", []string{"http", "https"})
 	neonContract = NodeCmd.Flags().String("neonContract", "", "Neon contract address")
 
 	terraWS = node.RegisterFlagWithValidationOrFail(NodeCmd, "terraWS", "Path to terrad root for websocket connection", "ws://terra-terrad:26657/websocket", []string{"ws", "wss"})
@@ -336,7 +336,7 @@ func init() {
 	aptosHandle = NodeCmd.Flags().String("aptosHandle", "", "aptos handle")
 
 	suiRPC = node.RegisterFlagWithValidationOrFail(NodeCmd, "suiRPC", "Sui RPC URL", "http://sui:9000", []string{"http", "https"})
-	suiWS = node.RegisterFlagWithValidationOrFail(NodeCmd, "suiWS", "Sui WS URL", "sui:9000", []string{""})
+	suiWS = node.RegisterFlagWithValidationOrFail(NodeCmd, "suiWS", "Sui WS URL", "ws://sui:9000", []string{"ws", "wss"})
 	suiMoveEventType = NodeCmd.Flags().String("suiMoveEventType", "", "Sui move event type for publish_message")
 
 	solanaRPC = node.RegisterFlagWithValidationOrFail(NodeCmd, "solanaRPC", "Solana RPC URL (required)", "http://solana-devnet:8899", []string{"http", "https"})
@@ -521,7 +521,6 @@ func runNode(cmd *cobra.Command, args []string) {
 		*klaytnContract = unsafeDevModeEvmContractAddress(*klaytnContract)
 		*celoContract = unsafeDevModeEvmContractAddress(*celoContract)
 		*moonbeamContract = unsafeDevModeEvmContractAddress(*moonbeamContract)
-		*neonContract = unsafeDevModeEvmContractAddress(*neonContract)
 		*arbitrumContract = unsafeDevModeEvmContractAddress(*arbitrumContract)
 		*optimismContract = unsafeDevModeEvmContractAddress(*optimismContract)
 		*baseContract = unsafeDevModeEvmContractAddress(*baseContract)

+ 6 - 5
node/pkg/node/url_verification.go

@@ -21,17 +21,18 @@ func hasKnownSchemePrefix(urlStr string) bool {
 }
 
 func validateURL(urlStr string, validSchemes []string) bool {
-	parsedURL, err := url.Parse(urlStr)
-	if err != nil {
-		return false
-	}
-
 	// If no scheme is required, validate host:port format
 	if len(validSchemes) == 1 && validSchemes[0] == "" {
 		host, port, err := net.SplitHostPort(urlStr)
 		return err == nil && host != "" && port != "" && !hasKnownSchemePrefix(urlStr)
 	}
 
+	// url.Parse() has to come later because it will fail if the scheme is empty
+	parsedURL, err := url.Parse(urlStr)
+	if err != nil {
+		return false
+	}
+
 	for _, scheme := range validSchemes {
 		if parsedURL.Scheme == scheme {
 			return true

+ 1 - 0
node/pkg/node/url_verification_test.go

@@ -25,6 +25,7 @@ func TestValidateURL(t *testing.T) {
 		{[]string{""}, "example.com:8080", true},
 		{[]string{""}, "http://invalid-scheme:8080", false},
 		{[]string{""}, "ws://invalid-scheme:8080", false},
+		{[]string{""}, "170.0.0.1:8080", true},
 	}
 
 	for _, test := range tests {