From 4d4185c3f847604db0b2e02334223c4f6a06de35 Mon Sep 17 00:00:00 2001 From: riyasng12 Date: Tue, 16 Jan 2024 14:00:52 +0530 Subject: [PATCH] feat: implement allocation of ports inside dive cli instead of passing in config --- cli/cmd/chains/polkadot/run.go | 2 +- cli/cmd/chains/utils/types.go | 38 ++++++++++++++++-- .../dive/services_dive_f4bd60ed5923.json | 1 - cli/sample-jsons/archway.json | 8 ---- cli/sample-jsons/archway1.json | 8 ---- cli/sample-jsons/config0.json | 2 - cli/sample-jsons/config1.json | 2 - cli/sample-jsons/local.json | 39 ------------------- cli/sample-jsons/neutron.json | 8 +--- cli/sample-jsons/neutron1.json | 8 +--- cli/sample-jsons/polkadot_config.json | 39 +++++++++++++++++++ 11 files changed, 79 insertions(+), 76 deletions(-) delete mode 100644 cli/output/dive/services_dive_f4bd60ed5923.json delete mode 100644 cli/sample-jsons/local.json create mode 100644 cli/sample-jsons/polkadot_config.json diff --git a/cli/cmd/chains/polkadot/run.go b/cli/cmd/chains/polkadot/run.go index 2bb6ef5c..17753201 100644 --- a/cli/cmd/chains/polkadot/run.go +++ b/cli/cmd/chains/polkadot/run.go @@ -48,7 +48,7 @@ func RunPolkadot(cli *common.Cli) (*common.DiveMultipleServiceResponse, error) { for _, paraChain := range serviceConfig.Para { if !slices.Contains(polkadotParachains, paraChain.Name) { - return nil, common.WrapMessageToErrorf(common.ErrInvalidConfig, "Invalid Parachain - Parachain %s is not Supported for PolkaDot", paraChain.Name) + return nil, common.WrapMessageToErrorf(common.ErrInvalidConfig, "Invalid Parachain - Parachain %s is not Supported for Polkadot", paraChain.Name) } } diff --git a/cli/cmd/chains/utils/types.go b/cli/cmd/chains/utils/types.go index b2121699..ebd177fa 100644 --- a/cli/cmd/chains/utils/types.go +++ b/cli/cmd/chains/utils/types.go @@ -71,12 +71,36 @@ func (cs *CosmosServiceConfig) LoadConfigFromFile(cliContext *common.Cli, filePa if err != nil { return common.WrapMessageToError(err, "Failed To Load Configuration") } + + publicGrpc, err := common.GetAvailablePort() + if err != nil { + return common.WrapMessageToError(err, "error getting available gRPC port") + } + cs.PublicGrpc = &publicGrpc + + publicHTTP, err := common.GetAvailablePort() + if err != nil { + return common.WrapMessageToError(err, "error getting available HTTP port") + } + cs.PublicHTTP = &publicHTTP + + publicRPC, err := common.GetAvailablePort() + if err != nil { + return common.WrapMessageToError(err, "error getting available Rpc port") + } + cs.PublicRPC = &publicRPC + + publicTCP, err := common.GetAvailablePort() + if err != nil { + return common.WrapMessageToError(err, "error getting available Tcp port") + } + cs.PublicTCP = &publicTCP + return nil } func (cc *CosmosServiceConfig) IsEmpty() error { - if cc.ChainID == nil || cc.Key == nil || cc.Password == nil || - cc.PublicGrpc == nil || cc.PublicHTTP == nil || cc.PublicTCP == nil || cc.PublicRPC == nil { + if cc.ChainID == nil || cc.Key == nil || cc.Password == nil { return common.WrapMessageToErrorf(common.ErrEmptyFields, "Missing Fields In The Config File") } @@ -126,11 +150,19 @@ func (sc *IconServiceConfig) LoadConfigFromFile(cliContext *common.Cli, filePath return common.WrapMessageToError(err, "Failed To Load Configuration") } + sc.Port = 9080 + + availablePort, err := common.GetAvailablePort() + if err != nil { + return err + } + sc.PublicPort = availablePort + return nil } func (sc *IconServiceConfig) IsEmpty() error { - if sc.Port == 0 || sc.PublicPort == 0 || sc.P2PListenAddress == "" || sc.P2PAddress == "" || sc.Cid == "" { + if sc.P2PListenAddress == "" || sc.P2PAddress == "" || sc.Cid == "" { return common.WrapMessageToErrorf(common.ErrEmptyFields, "Missing Fields In The Config File") } return nil diff --git a/cli/output/dive/services_dive_f4bd60ed5923.json b/cli/output/dive/services_dive_f4bd60ed5923.json deleted file mode 100644 index 8f990e01..00000000 --- a/cli/output/dive/services_dive_f4bd60ed5923.json +++ /dev/null @@ -1 +0,0 @@ -{"node-service-archway-node-0":{"service_name":"node-service-archway-node-0","endpoint_public":"http://127.0.0.1:4564","endpoint":"http://172.16.4.5:26657","chain_id":"archway-node-0","chain_key":"archway-node-0-key"}} \ No newline at end of file diff --git a/cli/sample-jsons/archway.json b/cli/sample-jsons/archway.json index 38ba230c..db38ac5d 100644 --- a/cli/sample-jsons/archway.json +++ b/cli/sample-jsons/archway.json @@ -1,14 +1,6 @@ { "chain_id": "archway-node-0", "key": "archway-node-0-key", - "private_grpc": 9090, - "private_http": 9091, - "private_tcp": 26656, - "private_rpc": 26657, - "public_grpc": 9090, - "public_http": 9091, - "public_tcp": 26656, - "public_rpc": 4564, "password": "password" } diff --git a/cli/sample-jsons/archway1.json b/cli/sample-jsons/archway1.json index 92eb2a45..19949950 100644 --- a/cli/sample-jsons/archway1.json +++ b/cli/sample-jsons/archway1.json @@ -1,14 +1,6 @@ { "chain_id": "archway-node-1", "key": "archway-node-1-key", - "private_grpc": 9090, - "private_http": 9091, - "private_tcp": 26656, - "private_rpc": 26657, - "public_grpc": 9080, - "public_http": 9092, - "public_tcp": 26659, - "public_rpc": 4566, "password": "password" } diff --git a/cli/sample-jsons/config0.json b/cli/sample-jsons/config0.json index c23f2214..88d57c14 100644 --- a/cli/sample-jsons/config0.json +++ b/cli/sample-jsons/config0.json @@ -1,6 +1,4 @@ { - "private_port": 9080, - "public_port": 8090, "p2p_listen_address": "7080", "p2p_address": "8080", "cid": "0xacbc4e" diff --git a/cli/sample-jsons/config1.json b/cli/sample-jsons/config1.json index fc1e7786..b7861045 100644 --- a/cli/sample-jsons/config1.json +++ b/cli/sample-jsons/config1.json @@ -1,6 +1,4 @@ { - "private_port": 9081, - "public_port": 8091, "p2p_listen_address": "7081", "p2p_address": "8081", "cid": "0x42f1f3" diff --git a/cli/sample-jsons/local.json b/cli/sample-jsons/local.json deleted file mode 100644 index 8155ed30..00000000 --- a/cli/sample-jsons/local.json +++ /dev/null @@ -1,39 +0,0 @@ -{ - "chain-type": "local", - "relaychain": { - "name": "rococo-local", - "nodes": [ - { - "name": "alice", - "node-type": "validator", - "prometheus": false - }, - { - "name": "bob", - "node-type": "full", - "prometheus": true - - } - ] - }, - - "para": [ - { - "name":"mangata", - "nodes": [ - { - "name": "alice", - "node-type": "validator", - "prometheus": false - - }, - { - "name": "bob", - "node-type": "full", - "prometheus": true - } - ] - } - ], - "explorer": true - } \ No newline at end of file diff --git a/cli/sample-jsons/neutron.json b/cli/sample-jsons/neutron.json index 9db0c90f..b3e37cc6 100644 --- a/cli/sample-jsons/neutron.json +++ b/cli/sample-jsons/neutron.json @@ -1,9 +1,5 @@ { "chain_id":"test-chain2", "key":"test-key", - "password":"clock post desk civil pottery foster expand merit dash seminar song memory figure uniform spice circle try happy obvious trash crime hybrid hood cushion", - "public_grpc":8033, - "public_tcp":26634, - "public_http":1315, - "public_rpc":26696 - } \ No newline at end of file + "password":"clock post desk civil pottery foster expand merit dash seminar song memory figure uniform spice circle try happy obvious trash crime hybrid hood cushion" +} \ No newline at end of file diff --git a/cli/sample-jsons/neutron1.json b/cli/sample-jsons/neutron1.json index 52af695a..a12114a3 100644 --- a/cli/sample-jsons/neutron1.json +++ b/cli/sample-jsons/neutron1.json @@ -1,9 +1,5 @@ { "chain_id":"test-chain3", "key":"test-key", - "password":"clock post desk civil pottery foster expand merit dash seminar song memory figure uniform spice circle try happy obvious trash crime hybrid hood cushion", - "public_grpc":8043, - "public_tcp":26642, - "public_http":1389, - "public_rpc":26638 - } \ No newline at end of file + "password":"clock post desk civil pottery foster expand merit dash seminar song memory figure uniform spice circle try happy obvious trash crime hybrid hood cushion" +} \ No newline at end of file diff --git a/cli/sample-jsons/polkadot_config.json b/cli/sample-jsons/polkadot_config.json new file mode 100644 index 00000000..68820f4c --- /dev/null +++ b/cli/sample-jsons/polkadot_config.json @@ -0,0 +1,39 @@ +{ + "chain_type": "local", + "relaychain": { + "name": "rococo-local", + "nodes": [ + { + "name": "alice", + "node_type": "validator", + "prometheus": false + }, + { + "name": "bob", + "node_type": "full", + "prometheus": true + + } + ] + }, + + "parachains": [ + { + "name":"acala", + "nodes": [ + { + "name": "alice", + "node_type": "collator", + "prometheus": false + + }, + { + "name": "bob", + "node_type": "full", + "prometheus": true + } + ] + } + ], + "explorer": true +} \ No newline at end of file