Skip to content

Commit

Permalink
feat: add ws port for parachains
Browse files Browse the repository at this point in the history
  • Loading branch information
riyasng12 committed Jan 23, 2024
1 parent fea9a1b commit 4dd31b5
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 40 deletions.
50 changes: 20 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,30 +178,17 @@ To set up an individual node, simply pass the name of the chain to the dive chai
dive chain archway
```

After running the command, **DIVE CLI** will automatically start the ICON node and handle the necessary initialization processes. Please wait for the ICON node to fully initialize, which may take a few moments.
After running the command, **DIVE CLI** will automatically start the Archway node and handle the necessary initialization processes. Please wait for the Archway node to fully initialize, which may take a few moments.

Once the initialization is complete, you can interact with the local ICON chain as needed.**DIVE CLI** sets up the ICON node on your local environment, enabling you to deploy and test smart contracts, explore transactions, and experiment with various ICON blockchain features
Once the initialization is complete, you can interact with the local Archway chain as needed.**DIVE CLI** sets up the Archway node on your local environment, enabling you to deploy and test smart contracts, explore transactions, and experiment with various Archway blockchain features

> Detailed output during execution can be enabled via Verbose flag.
> example: `dive chain archway --verbose`
> Each Dive cli execution will be logged into log files under log folder in current working directory.
After successful execution one can find service details in `services.json` created in output folder in current working directory.
Example `services.json`:

```json
{
"node-service-constantine-3": {
"service_name": "node-service-constantine-3",
"endpoint_public": "http://127.0.0.1:9431",
"endpoint": "http://172.16.4.5:26657",
"chain_id": "constantine-3",
"chain_key": "constantine-3-key"
}
}
```
After successful execution service details can be found in `services_xxxx_xxxx123xx.json`. For more details, refer to the [Service Details](#service-details)

You can also pass your custom config using the `-c` flag:

Expand Down Expand Up @@ -258,19 +245,19 @@ dive bridge btp --chainA icon --chainB eth -b
This command sets up btp bridge between icon and eth . After running this command **DIVE CLI** will automatically starts the ICON & ETH node, deploy contracts which is used for BTP and starts the relay to constantly exchange messages between the established connection.

After successful bridge setup all the neccessary details with respect to bridge will be added to `dive.json` file that will be present in the output folder in current working directory.
After successful bridge setup all the neccessary details with respect to bridge will be added to `dive_xxxx_xxxx123xx.json`. For more details, refer to the [Service Details](#service-details)

> Checkout More details on how to setup [BTP](https://www.xcall.dev/quickstart/setting-up-a-local-environment-with-dive-cli) bridge
## Setting Up Relay and Para Chains

To set up a relay chain, run this command:
To set up a relaychain, run this command:

```bash
dive chain kusama
```

To set up a parachain in polkadot along with the relay chain, run this command:
To set up a parachain in polkadot along with the relaychain, run this command:

```bash
dive chain polkadot -p frequency
Expand Down Expand Up @@ -308,7 +295,7 @@ dive chain kusama -c path/to/config/file

For detailed instructions on writing the configuration file, refer to the [Configuration File Guidelines](#configuration-file-guidelines)

> Note: You can run a parachain without a relay chain only in testnet and mainnet networks.
> Note: You can run a parachain without a relaychain only in testnet and mainnet networks.
> Note: The default network type is localnet.
Expand Down Expand Up @@ -386,32 +373,34 @@ For **cosmos chain (Archway/Neutron):**

- **chain_id:** The Chain ID of the chain.
- **key:** The Key to use to spawn the node.
- **password:** The pPassword to use to spawn the node.
- **password:** The Password to use to spawn the node.

For **Icon chain:**

- **p2p_listen_address:** The p2p listen address.
- **p2p_address:** The p2p address.
- **cid:** The CID (Chain ID) of the node.

> Note: The cid for ICON chain must be dervied from the genesis file.
For **Polkadot/Kusama:**

- **chain_type:** Specifies the type of the network (e.g., "localnet","testnet", "mainnet").
- **relaychain:** Configuration for the relay chain. (When chain_type is "testnet" or "mainenet", the "relaychain" can be an empty dictonary).
- **name:** Name of the relay chain (e.g., "rococo-local", "rococo", "polkadot" or "kusama").
- **nodes:** List of nodes on the relay chain, each with:
- **relaychain:** Configuration for the relaychain. (When chain_type is "testnet" or "mainenet", the "relaychain" can be an empty dictonary).
- **name:** Name of the relaychain (e.g., "rococo-local", "rococo", "polkadot" or "kusama").
- **nodes:** List of nodes on the relaychain, each with:
- **name:** Node name (e.g., "alice").
- **node_type:** Node type, can be "validator" or "full".
- **prometheus:** Whether Prometheus monitoring is enabled (true/false).
- **parachains:** List of parachains, each with:
- **name:** Parachain name (e.g., "kilt").
- **nodes:** List of nodes on the parachain, similar to relay chain nodes.
- **nodes:** List of nodes on the parachain, similar to relaychain nodes.
- **name:** Node name (e.g., "alice").
- **node_type:** Node type, can be "collator" or "full".
- **prometheus:** Whether Prometheus monitoring is enabled (true/false).
- **explorer:** Whether Polkadot js explorer is enabled (true/false).

> Note: The polkadot/kusama command start two nodes in relay chain and one node in parachain by default in localnet. In testnet and mainnet, only one node is started for both by default.
> Note: The polkadot/kusama command start two nodes in relaychain and one node in parachain by default in localnet. In testnet and mainnet, only one node is started for both by default.
## Config Templates

Expand Down Expand Up @@ -490,7 +479,7 @@ The service details returned after running a bridge command is as follows:
```
## Relay and Para Chains

The service details returned after running a relay chain/para chain is as follows:
The service details returned after running a relaychain/parachain is as follows:

```json
{
Expand Down Expand Up @@ -542,7 +531,7 @@ The service details returned after running a relay chain/para chain is as follow
}
```

> Note: The service files are name as `services.json` and `dive.json` for chain and bridge commands respectively.
> Note: The service files are named as `services_xxxx_xxxx123xx.json` and `dive_xxxx_xxxx123xx.json` for chain and bridge commands respectively.
> Note: The file names for both chain and bridge commands contain the name of the enclave and the short UUID of the enclave.
Expand All @@ -553,8 +542,9 @@ The logs are located within the 'logs' folder, further organized into individual
You can find the 'logs' folder in the current working directory.

Each folder named after the enclave, has two files:
- **dive.log** : It is created when the execution of a command starts. It contains the execution logs.
- **error.log** : It is created when an error occurs during the execution of the command. It contains the error logs.

- **dive.log** : It is created when the execution of a command starts. It contains the execution logs.
- **error.log** : It is created when an error occurs during the execution of the command. It contains the error logs.

The file names also contain the timestamp which can be helpful to find a particular log file.

Expand Down
4 changes: 2 additions & 2 deletions cli/cmd/chains/kusama/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,12 @@ func configureService(serviceConfig *utils.PolkadotServiceConfig) error {
}

for i := range serviceConfig.RelayChain.Nodes {
serviceConfig.RelayChain.Nodes[i].AssignPorts(serviceConfig.RelayChain.Nodes[i].Prometheus)
serviceConfig.RelayChain.Nodes[i].AssignPorts(serviceConfig.RelayChain.Nodes[i].Prometheus, serviceConfig.RelayChain.Name)
}

for _, paraChain := range serviceConfig.Para {
for i := range paraChain.Nodes {
paraChain.Nodes[i].AssignPorts(paraChain.Nodes[i].Prometheus)
paraChain.Nodes[i].AssignPorts(paraChain.Nodes[i].Prometheus, paraChain.Name)
}
}

Expand Down
4 changes: 2 additions & 2 deletions cli/cmd/chains/polkadot/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,12 @@ func configureService(serviceConfig *utils.PolkadotServiceConfig) error {
}

for i := range serviceConfig.RelayChain.Nodes {
serviceConfig.RelayChain.Nodes[i].AssignPorts(serviceConfig.RelayChain.Nodes[i].Prometheus)
serviceConfig.RelayChain.Nodes[i].AssignPorts(serviceConfig.RelayChain.Nodes[i].Prometheus, serviceConfig.RelayChain.Name)
}

for _, paraChain := range serviceConfig.Para {
for i := range paraChain.Nodes {
paraChain.Nodes[i].AssignPorts(paraChain.Nodes[i].Prometheus)
paraChain.Nodes[i].AssignPorts(paraChain.Nodes[i].Prometheus, paraChain.Name)
}
}

Expand Down
25 changes: 19 additions & 6 deletions cli/cmd/chains/utils/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ type Ports struct {
RPCPort int `json:"rpc_port"`
Lib2LibPort int `json:"lib2lib_port"`
PrometheusPort int `json:"prometheus_port,omitempty"`
WSPort int `json:"ws_port,omitempty"`
}

type RelayChainConfig struct {
Expand Down Expand Up @@ -273,12 +274,12 @@ func (sc *PolkadotServiceConfig) LoadConfigFromFile(cliContext *common.Cli, file
}

for i := range sc.RelayChain.Nodes {
sc.RelayChain.Nodes[i].AssignPorts(sc.RelayChain.Nodes[i].Prometheus)
sc.RelayChain.Nodes[i].AssignPorts(sc.RelayChain.Nodes[i].Prometheus, sc.RelayChain.Name)
}

for _, parachain := range sc.Para {
for i := range parachain.Nodes {
parachain.Nodes[i].AssignPorts(parachain.Nodes[i].Prometheus)
parachain.Nodes[i].AssignPorts(parachain.Nodes[i].Prometheus, parachain.Name)
}
}

Expand All @@ -295,15 +296,16 @@ func (sc *PolkadotServiceConfig) LoadDefaultConfig() error {
}

for i := range sc.RelayChain.Nodes {
sc.RelayChain.Nodes[i].AssignPorts(sc.RelayChain.Nodes[i].Prometheus)
sc.RelayChain.Nodes[i].AssignPorts(sc.RelayChain.Nodes[i].Prometheus, sc.RelayChain.Name)
}

sc.Para = []ParaNodeConfig{}
return nil
}

func (nc *NodeConfig) AssignPorts(prometheus bool) error {
var rpcPort, lib2libPort, prometheusPort int
func (nc *NodeConfig) AssignPorts(prometheus bool, chainName string) error {
var wsPortEnabled = []string{"robonomics", "parallel", "subsocial", "litmus", "pendulum", "kilt"}
var rpcPort, lib2libPort, prometheusPort, wsPort int
var err error
rpcPort, err = common.GetAvailablePort()
if err != nil {
Expand All @@ -320,7 +322,13 @@ func (nc *NodeConfig) AssignPorts(prometheus bool) error {
return err
}
}
nc.Ports = Ports{RPCPort: rpcPort, Lib2LibPort: lib2libPort, PrometheusPort: prometheusPort}
if slices.Contains(wsPortEnabled, chainName) {
wsPort, err = common.GetAvailablePort()
if err != nil {
return err
}
}
nc.Ports = Ports{RPCPort: rpcPort, Lib2LibPort: lib2libPort, PrometheusPort: prometheusPort, WSPort: wsPort}
return nil
}

Expand Down Expand Up @@ -421,6 +429,7 @@ func (sc *PolkadotServiceConfig) ValidateConfig() error {
var validRelayNodeType = []string{"validator", "full", "archive"}
var validParaNodeType = []string{"collator", "full"}
var invalidTestNetParaChains = []string{"parallel", "subzero"}
var inactiveTestNetParaChains = []string{"karura", "khala", "robonomics", "altair", "litmus", "calamari", "subsocial", "moonsama", "manta", "kylin", "centrifuge", "acala", "polkadex", "clover"}

if !slices.Contains(validChainTypes, sc.ChainType) {
return fmt.Errorf("invalid Chain Type: %s", sc.ChainType)
Expand Down Expand Up @@ -460,6 +469,10 @@ func (sc *PolkadotServiceConfig) ValidateConfig() error {
if slices.Contains(invalidTestNetParaChains, paraChain.Name) {
return fmt.Errorf("no testnet for parachain: %s", paraChain.Name)
}

if slices.Contains(inactiveTestNetParaChains, paraChain.Name) {
return fmt.Errorf("inactive testnet for parachain: %s", paraChain.Name)
}
}
}

Expand Down

0 comments on commit 4dd31b5

Please sign in to comment.