Skip to content

Commit

Permalink
feat: implement allocation of ports inside dive cli instead of passin…
Browse files Browse the repository at this point in the history
…g in config
  • Loading branch information
riyasng12 committed Jan 16, 2024
1 parent a2512ce commit 4d4185c
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 76 deletions.
2 changes: 1 addition & 1 deletion cli/cmd/chains/polkadot/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
38 changes: 35 additions & 3 deletions cli/cmd/chains/utils/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion cli/output/dive/services_dive_f4bd60ed5923.json

This file was deleted.

8 changes: 0 additions & 8 deletions cli/sample-jsons/archway.json
Original file line number Diff line number Diff line change
@@ -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"
}

8 changes: 0 additions & 8 deletions cli/sample-jsons/archway1.json
Original file line number Diff line number Diff line change
@@ -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"
}

2 changes: 0 additions & 2 deletions cli/sample-jsons/config0.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{
"private_port": 9080,
"public_port": 8090,
"p2p_listen_address": "7080",
"p2p_address": "8080",
"cid": "0xacbc4e"
Expand Down
2 changes: 0 additions & 2 deletions cli/sample-jsons/config1.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{
"private_port": 9081,
"public_port": 8091,
"p2p_listen_address": "7081",
"p2p_address": "8081",
"cid": "0x42f1f3"
Expand Down
39 changes: 0 additions & 39 deletions cli/sample-jsons/local.json

This file was deleted.

8 changes: 2 additions & 6 deletions cli/sample-jsons/neutron.json
Original file line number Diff line number Diff line change
@@ -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
}
"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"
}
8 changes: 2 additions & 6 deletions cli/sample-jsons/neutron1.json
Original file line number Diff line number Diff line change
@@ -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
}
"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"
}
39 changes: 39 additions & 0 deletions cli/sample-jsons/polkadot_config.json
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 4d4185c

Please sign in to comment.