diff --git a/p2p/kademlia/bootstrap.go b/p2p/kademlia/bootstrap.go index 18669da6..f8080977 100644 --- a/p2p/kademlia/bootstrap.go +++ b/p2p/kademlia/bootstrap.go @@ -153,12 +153,7 @@ func (s *DHT) ConfigureBootstrapNodes(ctx context.Context, bootstrapNodes string } // Extract IP from the address (remove port if present) - var ip string - if idx := strings.LastIndex(latestIP, ":"); idx != -1 { - ip = latestIP[:idx] - } else { - ip = latestIP - } + ip := parseSupernodeAddress(latestIP) // Use p2p_port from supernode record p2pPort := defaultSuperNodeP2PPort diff --git a/sdk/config/constants.go b/sdk/config/constants.go new file mode 100644 index 00000000..385522ea --- /dev/null +++ b/sdk/config/constants.go @@ -0,0 +1,4 @@ +package config + +// DefaultSupernodePort is the default port used for supernode gRPC connections +const DefaultSupernodePort = "4444" \ No newline at end of file diff --git a/sdk/net/impl.go b/sdk/net/impl.go index ab0f7b28..07bda471 100644 --- a/sdk/net/impl.go +++ b/sdk/net/impl.go @@ -10,6 +10,7 @@ import ( "github.com/LumeraProtocol/supernode/v2/pkg/net/grpc/client" "github.com/LumeraProtocol/supernode/v2/sdk/adapters/lumera" "github.com/LumeraProtocol/supernode/v2/sdk/adapters/supernodeservice" + "github.com/LumeraProtocol/supernode/v2/sdk/config" "github.com/LumeraProtocol/supernode/v2/sdk/log" "github.com/cosmos/cosmos-sdk/crypto/keyring" @@ -64,13 +65,16 @@ func NewSupernodeClient(ctx context.Context, logger log.Logger, keyring keyring. return nil, fmt.Errorf("failed to create credentials: %w", err) } + // Append default port to the IP address from blockchain + endpointWithPort := fmt.Sprintf("%s:%s", targetSupernode.GrpcEndpoint, config.DefaultSupernodePort) + // Format connection address with identity for secure connection targetAddress := ltc.FormatAddressWithIdentity( targetSupernode.CosmosAddress, - targetSupernode.GrpcEndpoint, + endpointWithPort, ) - logger.Info(ctx, "Connecting to supernode securely", "endpoint", targetSupernode.GrpcEndpoint, "target_id", targetSupernode.CosmosAddress, "local_id", factoryConfig.LocalCosmosAddress, "peer_type", factoryConfig.PeerType) + logger.Info(ctx, "Connecting to supernode securely", "endpoint", endpointWithPort, "target_id", targetSupernode.CosmosAddress, "local_id", factoryConfig.LocalCosmosAddress, "peer_type", factoryConfig.PeerType) // Use provided client options or defaults options := clientOptions @@ -87,7 +91,7 @@ func NewSupernodeClient(ctx context.Context, logger log.Logger, keyring keyring. targetSupernode.CosmosAddress, err) } - logger.Info(ctx, "Connected to supernode securely", "address", targetSupernode.CosmosAddress, "endpoint", targetSupernode.GrpcEndpoint) + logger.Info(ctx, "Connected to supernode securely", "address", targetSupernode.CosmosAddress, "endpoint", endpointWithPort) // Create service clients cascadeClient := supernodeservice.NewCascadeAdapter( diff --git a/tests/system/config.test-1.yml b/tests/system/config.test-1.yml index eb214cd4..74fc85a2 100644 --- a/tests/system/config.test-1.yml +++ b/tests/system/config.test-1.yml @@ -2,7 +2,7 @@ supernode: key_name: "testkey1" identity: "lumera1em87kgrvgttrkvuamtetyaagjrhnu3vjy44at4" - host: "0.0.0.0" + host: "127.0.0.1" port: 4444 gateway_port: 8002 diff --git a/tests/system/config.test-2.yml b/tests/system/config.test-2.yml index 1b044a89..d9cb5d2b 100644 --- a/tests/system/config.test-2.yml +++ b/tests/system/config.test-2.yml @@ -3,9 +3,9 @@ supernode: key_name: "testkey2" identity: "lumera1cf0ms9ttgdvz6zwlqfty4tjcawhuaq69p40w0c" - host: "0.0.0.0" - port: 4446 - gateway_port: 8003 + host: "127.0.0.2" + port: 4444 + gateway_port: 8002 # Keyring Configuration keyring: @@ -15,7 +15,7 @@ keyring: # P2P Network Configuration p2p: - port: 4447 + port: 4445 data_dir: "data/p2p" # Lumera Chain Configuration diff --git a/tests/system/config.test-3.yml b/tests/system/config.test-3.yml index 2a259066..e3003693 100644 --- a/tests/system/config.test-3.yml +++ b/tests/system/config.test-3.yml @@ -3,9 +3,9 @@ supernode: key_name: "testkey3" identity: "lumera1cjyc4ruq739e2lakuhargejjkr0q5vg6x3d7kp" - host: "0.0.0.0" - port: 4448 - gateway_port: 8004 + host: "127.0.0.3" + port: 4444 + gateway_port: 8002 # Keyring Configuration keyring: @@ -15,7 +15,7 @@ keyring: # P2P Network Configuration p2p: - port: 4449 + port: 4445 data_dir: "data/p2p" # Lumera Chain Configuration diff --git a/tests/system/e2e_cascade_test.go b/tests/system/e2e_cascade_test.go index 851ef28e..bfabacbd 100644 --- a/tests/system/e2e_cascade_test.go +++ b/tests/system/e2e_cascade_test.go @@ -87,7 +87,7 @@ func TestCascadeE2E(t *testing.T) { t.Log("Registering multiple supernodes to process requests") // Helper function to register a supernode - registerSupernode := func(nodeKey string, port string, addr string, p2pPort string) { + registerSupernode := func(nodeKey string, ipAddr string, addr string, p2pPort string) { // Get account and validator addresses for registration accountAddr := cli.GetKeyAddr(nodeKey) valAddrOutput := cli.Keys("keys", "show", nodeKey, "--bech", "val", "-a") @@ -99,7 +99,7 @@ func TestCascadeE2E(t *testing.T) { registerCmd := []string{ "tx", "supernode", "register-supernode", valAddr, - "localhost:" + port, + ipAddr, addr, "--p2p-port", p2pPort, "--from", nodeKey, @@ -112,10 +112,10 @@ func TestCascadeE2E(t *testing.T) { sut.AwaitNextBlock(t) } - // Register three supernodes with different ports - registerSupernode("node0", "4444", "lumera1em87kgrvgttrkvuamtetyaagjrhnu3vjy44at4", "4445") - registerSupernode("node1", "4446", "lumera1cf0ms9ttgdvz6zwlqfty4tjcawhuaq69p40w0c", "4447") - registerSupernode("node2", "4448", "lumera1cjyc4ruq739e2lakuhargejjkr0q5vg6x3d7kp", "4449") + // Register three supernodes with different IP addresses + registerSupernode("node0", "127.0.0.1", "lumera1em87kgrvgttrkvuamtetyaagjrhnu3vjy44at4", "4445") + registerSupernode("node1", "127.0.0.2", "lumera1cf0ms9ttgdvz6zwlqfty4tjcawhuaq69p40w0c", "4447") + registerSupernode("node2", "127.0.0.3", "lumera1cjyc4ruq739e2lakuhargejjkr0q5vg6x3d7kp", "4449") t.Log("Successfully registered three supernodes") // Fund Lume