diff --git a/cli/commands/bridge/relays/btp.go b/cli/commands/bridge/relays/btp.go index 5f11ff09..824d1672 100644 --- a/cli/commands/bridge/relays/btp.go +++ b/cli/commands/bridge/relays/btp.go @@ -194,7 +194,7 @@ func BtpRelayCmd(diveContext *common.DiveContext) *cobra.Command { func runBtpSetupByRunningNodes(diveContext *common.DiveContext, enclaveCtx *enclaves.EnclaveContext, params string) { diveContext.SetSpinnerMessage(" Executing BTP Starlark Package") - starlarkConfig := diveContext.GetStarlarkRunConfig(params, common.DiveBridgeScript, bridgeMainFunction) + starlarkConfig := diveContext.GetStarlarkRunConfig(params, common.DiveBridgeBtpScript, bridgeMainFunction) data, _, err := enclaveCtx.RunStarlarkRemotePackage(diveContext.Ctx, common.DiveRemotePackagePath, starlarkConfig) if err != nil { @@ -213,11 +213,8 @@ func runBtpSetupByRunningNodes(diveContext *common.DiveContext, enclaveCtx *encl func runBtpSetupForAlreadyRunningNodes(diveContext *common.DiveContext, enclaveCtx *enclaves.EnclaveContext, mainFunctionName string, srcChain string, dstChain string, srcChainServiceName string, dstChainServiceName string, bridge bool, srcChainServiceResponse string, dstChainServiceResponse string) { - configData := fmt.Sprintf(`{"links": {"src":"%s","dst":"%s"},"chains" : { "%s" : %s,"%s" : %s},"contracts" : {"%s" : {},"%s" : {}},"bridge" : "%s"}`, srcChain, dstChain, srcChainServiceName, srcChainServiceResponse, dstChainServiceName, dstChainServiceResponse, srcChainServiceName, dstChainServiceName, strconv.FormatBool(bridge)) - - params := fmt.Sprintf(`{"src_chain":"%s", "dst_chain":"%s", "config_data":%s, "src_service_name":"%s", "dst_service_name":"%s"}`, srcChain, dstChain, configData, srcChainServiceName, dstChainServiceName) - - starlarkConfig := diveContext.GetStarlarkRunConfig(params, common.DiveBridgeScript, mainFunctionName) + params := fmt.Sprintf(`{"src_chain":"%s","dst_chain":"%s", "src_chain_config":%s, "dst_chain_config":%s, "bridge":%s}`, chainA, chainB, srcChainServiceResponse, dstChainServiceResponse, strconv.FormatBool(bridge)) + starlarkConfig := diveContext.GetStarlarkRunConfig(params, common.DiveBridgeBtpScript, mainFunctionName) data, _, err := enclaveCtx.RunStarlarkRemotePackage(diveContext.Ctx, common.DiveRemotePackagePath, starlarkConfig) if err != nil { diff --git a/cli/commands/bridge/relays/common.go b/cli/commands/bridge/relays/common.go index 0d33d7f1..9f97cb69 100644 --- a/cli/commands/bridge/relays/common.go +++ b/cli/commands/bridge/relays/common.go @@ -23,6 +23,7 @@ type Chains struct { func initChains(chainA, chainB, serviceA, serviceB string, bridge bool) *Chains { return &Chains{ + chainA: strings.ToLower(chainA), chainB: strings.ToLower(chainB), chainAServiceName: serviceA, @@ -36,11 +37,11 @@ func (c *Chains) areChainsIcon() bool { } func (chains *Chains) getParams() string { - return fmt.Sprintf(`{"args":{"links": {"src": "%s", "dst": "%s"},"bridge":"%s"}}`, chains.chainA, chains.chainB, chains.bridge) + return fmt.Sprintf(`{"src_chain": "%s", "dst_chain": "%s", "bridge":"%s"}`, chains.chainA, chains.chainB, chains.bridge) } func (chains *Chains) getIbcRelayParams() string { - return fmt.Sprintf(`{"args":{"links": {"src": "%s", "dst": "%s"}, "src_config":{"data":{}}, "dst_config":{"data":{}}}}`, chains.chainA, chains.chainB) + return fmt.Sprintf(`{"src_chain": "%s", "dst_chain": "%s"}`, chains.chainA, chains.chainB) } func (chains *Chains) getServicesResponse() (string, string, error) { diff --git a/cli/commands/bridge/relays/ibc.go b/cli/commands/bridge/relays/ibc.go index 55178c4b..9655b3a8 100644 --- a/cli/commands/bridge/relays/ibc.go +++ b/cli/commands/bridge/relays/ibc.go @@ -126,7 +126,7 @@ func startCosmosChainsAndSetupIbcRelay(diveContext *common.DiveContext, enclaveC func setupIbcRelayforAlreadyRunningCosmosChain(diveContext *common.DiveContext, enclaveCtx *enclaves.EnclaveContext, chainA, chainB, chainAServiceResponse, chainBServiceResponse string) (string, error) { - params := fmt.Sprintf(`{"src_chain_config":%s,"dst_chain_config":%s, "args":{"links": {"src": "%s", "dst": "%s"}, "src_config":{"data":{}}, "dst_config":{"data":{}}}}`, chainAServiceResponse, chainBServiceResponse, chainA, chainB) + params := fmt.Sprintf(`{"src_chain":"%s","dst_chain":"%s", "src_chain_config":%s, "dst_chain_config":%s}`, chainA, chainB, chainAServiceResponse, chainBServiceResponse) executionResult, err := runStarlarkPackage(diveContext, enclaveCtx, params, "run_cosmos_ibc_relay_for_already_running_chains") @@ -138,7 +138,7 @@ func setupIbcRelayforAlreadyRunningCosmosChain(diveContext *common.DiveContext, } func runStarlarkPackage(diveContext *common.DiveContext, enclaveContext *enclaves.EnclaveContext, params, functionName string) (string, error) { - starlarkConfig := diveContext.GetStarlarkRunConfig(params, common.DiveBridgeScript, functionName) + starlarkConfig := diveContext.GetStarlarkRunConfig(params, common.DiveBridgeIbcScript, functionName) executionData, _, err := enclaveContext.RunStarlarkRemotePackage(diveContext.Ctx, common.DiveRemotePackagePath, starlarkConfig) if err != nil { diff --git a/cli/commands/chain/types/archway.go b/cli/commands/chain/types/archway.go index a38db42a..3961329b 100644 --- a/cli/commands/chain/types/archway.go +++ b/cli/commands/chain/types/archway.go @@ -2,7 +2,6 @@ package types import ( "encoding/json" - "fmt" "github.com/hugobyte/dive/cli/common" "github.com/kurtosis-tech/kurtosis/api/golang/core/lib/enclaves" @@ -20,17 +19,13 @@ var ( ) type ArchwayServiceConfig struct { - Cid string `json:"cid"` - Key string `json:"key"` - PrivateGrpcPort int `json:"private_grpc"` - PrivateHttpPort int `json:"private_http"` - PrivateTcpPort int `json:"private_tcp"` - PrivateRpcPort int `json:"private_rpc"` - PublicGrpcPort int `json:"public_grpc"` - PublicHttpPort int `json:"public_http"` - PublicTcpPort int `json:"public_tcp"` - PublicRpcPort int `json:"public_rpc"` - Password string `json:"password"` + Cid *string `json:"chain_id"` + Key *string `json:"key"` + PublicGrpcPort *int `json:"public_grpc"` + PublicHttpPort *int `json:"public_http"` + PublicTcpPort *int `json:"public_tcp"` + PublicRpcPort *int `json:"public_rpc"` + Password *string `json:"password"` } func (as *ArchwayServiceConfig) EncodeToString() (string, error) { @@ -102,13 +97,19 @@ func RunArchwayNode(diveContext *common.DiveContext) *common.DiveserviceResponse diveContext.FatalError("Failed encode service config", err.Error()) } - starlarkExecutionData, err = runArchwayWithCustomServiceConfig(diveContext, kurtosisEnclaveContext, encodedServiceConfigDataString) + starlarkExecutionData, err = RunArchwayNodeWithConfig(diveContext, kurtosisEnclaveContext, encodedServiceConfigDataString) if err != nil { diveContext.FatalError("Starlark Run Failed", err.Error()) } } else { - starlarkExecutionData, err = runArchwayWithDefaultServiceConfig(diveContext, kurtosisEnclaveContext) + + encodedServiceConfigDataString, err := serviceConfig.EncodeToString() + + if err != nil { + diveContext.FatalError("Failed encode service config", err.Error()) + } + starlarkExecutionData, err = RunArchwayNodeWithConfig(diveContext, kurtosisEnclaveContext, encodedServiceConfigDataString) if err != nil { diveContext.FatalError("Starlark Run Failed", err.Error()) } @@ -122,58 +123,16 @@ func RunArchwayNode(diveContext *common.DiveContext) *common.DiveserviceResponse return archwayResponse } -func runArchwayWithCustomServiceConfig(diveContext *common.DiveContext, enclaveContext *enclaves.EnclaveContext, data string) (string, error) { - starlarkConfig := diveContext.GetStarlarkRunConfig(data, common.DiveArchwayNodeScript, constructServiceConfigFunctionName) - serviceExecutionResponse, _, err := enclaveContext.RunStarlarkRemotePackage(diveContext.Ctx, common.DiveRemotePackagePath, starlarkConfig) - - if err != nil { - - return "", err - - } - - serviceExecutionResponseData, _, _, err := diveContext.GetSerializedData(serviceExecutionResponse) - if err != nil { - - return "", err - - } - params := fmt.Sprintf(`{"args":%s}`, serviceExecutionResponseData) - starlarkConfig = diveContext.GetStarlarkRunConfig(params, common.DiveArchwayNodeScript, runArchwayNodeWithCustomServiceFunctionName) - - nodeExecutionResponse, _, err := enclaveContext.RunStarlarkRemotePackage(diveContext.Ctx, common.DiveRemotePackagePath, starlarkConfig) - - if err != nil { - - return "", err - - } - - nodeExecutionResponseData, _, _, err := diveContext.GetSerializedData(nodeExecutionResponse) - if err != nil { - - return "", err - - } - - return nodeExecutionResponseData, nil -} - -func runArchwayWithDefaultServiceConfig(diveContext *common.DiveContext, enclaveContext *enclaves.EnclaveContext) (string, error) { - - params := `{"args":{"data":{}}}` - starlarkConfig := diveContext.GetStarlarkRunConfig(params, common.DiveArchwayDefaultNodeScript, runArchwayNodeWithDefaultConfigFunctionName) +func RunArchwayNodeWithConfig(diveContext *common.DiveContext, enclaveContext *enclaves.EnclaveContext, config string) (string, error) { + starlarkConfig := diveContext.GetStarlarkRunConfig(config, common.DiveArchwayDefaultNodeScript, runArchwayNodeWithDefaultConfigFunctionName) nodeServiceResponse, _, err := enclaveContext.RunStarlarkRemotePackage(diveContext.Ctx, common.DiveRemotePackagePath, starlarkConfig) if err != nil { - return "", err - } nodeServiceResponseData, services, skippedInstructions, err := diveContext.GetSerializedData(nodeServiceResponse) if err != nil { - diveContext.StopServices(services) diveContext.FatalError("Starlark Run Failed", err.Error()) diff --git a/cli/commands/chain/types/eth.go b/cli/commands/chain/types/eth.go index 5ff72be7..4995b955 100644 --- a/cli/commands/chain/types/eth.go +++ b/cli/commands/chain/types/eth.go @@ -44,7 +44,7 @@ func RunEthNode(diveContext *common.DiveContext) *common.DiveserviceResponse { diveContext.FatalError("Failed To Retrive Enclave Context", err.Error()) } diveContext.StartSpinner(" Starting ETH Node") - starlarkConfig := diveContext.GetStarlarkRunConfig(`{"args":{}}`, common.DiveEthHardhatNodeScript, "start_eth_node") + starlarkConfig := diveContext.GetStarlarkRunConfig(`{}`, common.DiveEthHardhatNodeScript, "start_eth_node") data, _, err := kurtosisEnclaveContext.RunStarlarkRemotePackage(diveContext.Ctx, common.DiveRemotePackagePath, starlarkConfig) if err != nil { diff --git a/cli/commands/chain/types/icon.go b/cli/commands/chain/types/icon.go index 2894051b..9e304a0b 100644 --- a/cli/commands/chain/types/icon.go +++ b/cli/commands/chain/types/icon.go @@ -147,48 +147,24 @@ func RunIconNode(diveContext *common.DiveContext) *common.DiveserviceResponse { diveContext.FatalError("Failed To Get Node Service Config", err.Error()) } - paramData, err := serviceConfig.EncodeToString() - if err != nil { - diveContext.FatalError("Encoding Failed", err.Error()) - } - diveContext.StartSpinner(" Starting Icon Node") kurtosisEnclaveContext, err := diveContext.GetEnclaveContext() if err != nil { diveContext.FatalError("Failed To Retrive Enclave Context", err.Error()) } - starlarkConfig := diveContext.GetStarlarkRunConfig(paramData, common.DiveIconNodeScript, "get_service_config") - data, _, err := kurtosisEnclaveContext.RunStarlarkRemotePackage(diveContext.Ctx, common.DiveRemotePackagePath, starlarkConfig) - - if err != nil { - diveContext.FatalError("Starlark Run Failed", err.Error()) - } - - responseData, services, skippedInstructions, err := diveContext.GetSerializedData(data) - - if err != nil { - diveContext.StopServices(services) - diveContext.FatalError("Starlark Run Failed", err.Error()) - - } genesisHandler, err := genesismanager(kurtosisEnclaveContext) if err != nil { diveContext.FatalError("Failed To Get Genesis", err.Error()) } - diveContext.CheckInstructionSkipped(skippedInstructions, "Instruction Executed Already") - - params := fmt.Sprintf(`{"service_config":%s,"uploaded_genesis":%s,"genesis_file_path":"%s","genesis_file_name":"%s"}`, responseData, genesisHandler.uploadedFiles, genesisHandler.genesisPath, genesisHandler.genesisFile) - starlarkConfig = diveContext.GetStarlarkRunConfig(params, common.DiveIconNodeScript, "start_icon_node") + params := fmt.Sprintf(`{"private_port":%d, "public_port":%d, "p2p_listen_address": %s, "p2p_address":%s, "cid": "%s","uploaded_genesis":%s,"genesis_file_path":"%s","genesis_file_name":"%s"}`, serviceConfig.Port, serviceConfig.PublicPort, serviceConfig.P2PListenAddress, serviceConfig.P2PAddress, serviceConfig.Cid, genesisHandler.uploadedFiles, genesisHandler.genesisPath, genesisHandler.genesisFile) + starlarkConfig := diveContext.GetStarlarkRunConfig(params, common.DiveIconNodeScript, "start_icon_node") icon_data, _, err := kurtosisEnclaveContext.RunStarlarkRemotePackage(diveContext.Ctx, common.DiveRemotePackagePath, starlarkConfig) if err != nil { - - diveContext.StopServices(services) - - diveContext.FatalError("Starlark Run Failed", err.Error()) + diveContext.FatalError("Error while running kurtosis package to run icon node", err.Error()) } diveContext.SetSpinnerMessage(" Finalizing Icon Node") @@ -244,9 +220,7 @@ func Decentralisation(diveContext *common.DiveContext, params string) { } func GetDecentralizeParms(serviceName, nodeEndpoint, keystorePath, keystorepassword, networkID string) string { - - return fmt.Sprintf(`{"args":{"service_name":"%s","endpoint":"%s","keystore_path":"%s","keypassword":"%s","nid":"%s"}}`, serviceName, nodeEndpoint, keystorePath, keystorepassword, networkID) - + return fmt.Sprintf(`{"service_name":"%s","uri":"%s","keystorepath":"%s","keypassword":"%s","nid":"%s"}`, serviceName, nodeEndpoint, keystorePath, keystorepassword, networkID) } func getConfig() (*IconServiceConfig, error) { diff --git a/cli/commands/chain/types/neutron.go b/cli/commands/chain/types/neutron.go index 744c9421..50851fbc 100644 --- a/cli/commands/chain/types/neutron.go +++ b/cli/commands/chain/types/neutron.go @@ -2,7 +2,6 @@ package types import ( "encoding/json" - "fmt" "github.com/hugobyte/dive/cli/common" "github.com/kurtosis-tech/kurtosis/api/golang/core/lib/enclaves" @@ -23,13 +22,13 @@ var ( // NeutronServiceConfig stores configuration parameters for the Neutron service. type NeutronServiceConfig struct { - ChainID string `json:"chainId"` - Key string `json:"key"` - Password string `json:"password"` - PublicGrpc int `json:"public_grpc"` - PublicTCP int `json:"public_tcp"` - PublicHTTP int `json:"public_http"` - PublicRPC int `json:"public_rpc"` + ChainID *string `json:"chain_id"` + Key *string `json:"key"` + Password *string `json:"password"` + PublicGrpc *int `json:"public_grpc"` + PublicTCP *int `json:"public_tcp"` + PublicHTTP *int `json:"public_http"` + PublicRPC *int `json:"public_rpc"` } // EncodeToString encodes the NeutronServiceConfig struct to a JSON string. @@ -100,9 +99,14 @@ func RunNeutronNode(diveContext *common.DiveContext) *common.DiveserviceResponse if err != nil { diveContext.FatalError("Starlark Run Failed", err.Error()) } + } else { // Run Neutron Node with default service config - starlarkExecutionData, err = RunNeutronWithServiceConfig(diveContext, kurtosisEnclaveContext, "{}") + encodedServiceConfigDataString, err := serviceConfig.EncodeToString() + if err != nil { + diveContext.FatalError("Failed to encode service config", err.Error()) + } + starlarkExecutionData, err = RunNeutronWithServiceConfig(diveContext, kurtosisEnclaveContext, encodedServiceConfigDataString) if err != nil { diveContext.FatalError("Starlark Run Failed", err.Error()) } @@ -117,9 +121,9 @@ func RunNeutronNode(diveContext *common.DiveContext) *common.DiveserviceResponse } // RunNeutronWithServiceConfig runs the Neutron service with the provided configuration data. -func RunNeutronWithServiceConfig(diveContext *common.DiveContext, enclaveContext *enclaves.EnclaveContext, data string) (string, error) { - params := fmt.Sprintf(`{"args":{"data":%s}}`, data) - starlarkConfig := diveContext.GetStarlarkRunConfig(params, common.DiveNeutronDefaultNodeScript, runNeutronNodeWithDefaultConfigFunctionName) +func RunNeutronWithServiceConfig(diveContext *common.DiveContext, enclaveContext *enclaves.EnclaveContext, config string) (string, error) { + + starlarkConfig := diveContext.GetStarlarkRunConfig(config, common.DiveNeutronDefaultNodeScript, runNeutronNodeWithDefaultConfigFunctionName) nodeServiceResponse, _, err := enclaveContext.RunStarlarkRemotePackage(diveContext.Ctx, common.DiveRemotePackagePath, starlarkConfig) if err != nil { return "", err diff --git a/cli/common/constants.go b/cli/common/constants.go index 9ce23a34..6418ffa4 100644 --- a/cli/common/constants.go +++ b/cli/common/constants.go @@ -16,7 +16,8 @@ const ( DiveNeutronNodeScript = "services/cosmvm/neutron/src/node-setup/start_node.star" RelayServiceNameIconToCosmos = "ibc-relayer" DiveNeutronDefaultNodeScript = "services/cosmvm/neutron/neutron.star" - DiveBridgeScript = "main.star" + DiveBridgeBtpScript = "/services/bridges/btp/src/bridge.star" + DiveBridgeIbcScript = "/services/bridges/ibc/src/bridge.star" DiveDryRun = false DiveDefaultParallelism = 4 DiveEthNodeAlreadyRunning = "Eth Node Already Running" diff --git a/cli/sample-jsons/archway.json b/cli/sample-jsons/archway.json index 103a451e..38ba230c 100644 --- a/cli/sample-jsons/archway.json +++ b/cli/sample-jsons/archway.json @@ -1,5 +1,5 @@ { - "cid": "archway-node-0", + "chain_id": "archway-node-0", "key": "archway-node-0-key", "private_grpc": 9090, "private_http": 9091, diff --git a/cli/sample-jsons/archway1.json b/cli/sample-jsons/archway1.json index 682bca30..92eb2a45 100644 --- a/cli/sample-jsons/archway1.json +++ b/cli/sample-jsons/archway1.json @@ -1,5 +1,5 @@ { - "cid": "archway-node-1", + "chain_id": "archway-node-1", "key": "archway-node-1-key", "private_grpc": 9090, "private_http": 9091, diff --git a/cli/sample-jsons/neutron.json b/cli/sample-jsons/neutron.json index 1124d236..9db0c90f 100644 --- a/cli/sample-jsons/neutron.json +++ b/cli/sample-jsons/neutron.json @@ -1,5 +1,5 @@ { - "chainId":"test-chain2", + "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, diff --git a/cli/sample-jsons/neutron1.json b/cli/sample-jsons/neutron1.json index 442c858d..52af695a 100644 --- a/cli/sample-jsons/neutron1.json +++ b/cli/sample-jsons/neutron1.json @@ -1,5 +1,5 @@ { - "chainId":"test-chain3", + "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, diff --git a/main.star b/main.star index 1f898b77..b4be77c2 100644 --- a/main.star +++ b/main.star @@ -1,4 +1,5 @@ icon_setup_node = import_module("./services/jvm/icon/src/node-setup/setup_icon_node.star") +icon_node_launcher = import_module("./src/node-setup/start_icon_node.star") eth_contract_service = import_module("./services/evm/eth/src/node-setup/contract-service.star") eth_relay_setup = import_module("./services/evm/eth/src/relay-setup/contract_configuration.star") eth_node = import_module("./services/evm/eth/eth.star") @@ -10,381 +11,139 @@ cosmvm_node = import_module("./services/cosmvm/cosmvm.star") cosmvm_relay = import_module("./services/bridges/ibc/src/bridge.star") cosmvm_relay_setup = import_module("./services/cosmvm/archway/src/relay-setup/contract-configuration.star") neutron_relay_setup = import_module("./services/cosmvm/neutron/src/relay-setup/contract-configuration.star") +btp_relay_setup = import_module("./services/bridges/btp/src/bridge.star") +ibc_relay_setup = import_module("./services/bridges/ibc/src/bridge.star") -def run(plan, args): - return parse_input(plan, args) -def parse_input(plan, args): - if args["action"] == "start_node": - node_name = args["node_name"] +def run(plan, command, node_name= None, custom_config = None, icon_service_config = None ,decentralize = false, chain_a = None, chain_b = None, service_config_a = None, service_config_b = None, bridge = false): + """ + Parse the input and execute the specified action. + + Parameters: + plan (Plan): The Kurtosis plan. + command (str): The action to perform. + - 'chain': Start a node. + - 'bridge': Start a relay. + - 'decentralize': decentralize already running icon node. + + node_name (str, optional): Name of the node to start. + - Currently supported options: 'eth', 'hardhat', 'icon', 'neutron', 'archway'. + + custom_config (dict, optional): Custom configuration for node or relay. If empty, the node will start with default settings. + bridge + For ICON node with custom configuration, the following fields should be provided in custom_config_dict: + - private_port (int): The private port for the node. + - public_port (int): The public port for the node. + - p2p_listen_address (str): The p2p listen address. + - p2p_address (str): The p2p address. + - cid (str): The CID (Chain ID) of the node. + - genesis_file_path (str): The file path to the genesis file. + - genesis_file_name (str): The name of the genesis file. + + For Cosmos (Archway/Neutron) node with custom configuration, the following fields should be provided in the custom config dict: + - chain_id (str): The chain ID. + - key (str): The key. + - password (str): The password. + - public_grpc (str): The public gRPC address. + - public_http (str): The public HTTP address. + - public_tcp (str): The public TCP address. + - public_rpc (str): The public RPC address. + + icon_service_config (dict, optional): ServiceConfig, this field should be provided when wanna decentralize already running icon node + + decentralize (bool, optional): Flag indicating whether to decentralize the ICON node. + relay_type (str, optional): The type of relay. + - 'ibc': Start an IBC relay. + - 'btp': Start a BTP bridge. + + chain_a (str): The source chain for relaying. + chain_b (str): The destination chain for relaying. + service_config_a (dict): Service configuration for chain A (source chain for relaying, Note: fields in dictonary should be same as output return after running node). + service_config_b (dict): Service configuration for chain B (destination chain for relaying, Note: fields in dictonary should be same as output return after running node). + bridge (bool): Flag indicating whether to use a BMV bridge. - run_node(plan, node_name, args) + Returns: + service_details (dict): Details about the service started. + """ + return parse_input(plan, command, node_name, custom_config, icon_service_config ,decentralize, chain_a, chain_b, service_config_a, service_config_b, bridge) - if args["action"] == "start_nodes": - nodes = args["nodes"] - if len(nodes) == 1: - if nodes[0] == "icon": - data = icon_service.start_node_service_icon_to_icon(plan) +def parse_input(plan, action, node_name= None, custom_config = None, icon_service_config = None, decentralize = false, relay_type = None, chain_a = None, chain_b = None, service_config_a = None, service_config_b = None, bridge = false): + # start the single node + if action == "chain": + if node_name != None: + run_node(plan, node_name, decentralize, custom_config) + else: + fail("node_name parameter is missing, node_name require to start node.") + + + elif action == "bridge": + # Start btp relay between two nodes + if relay_type == "btp": + if chain_a != None and chain_b != None: + if service_config_a == None and service_config_b == None: + data = btp_relay_setup.run_btp_setup(plan, chain_a, chain_b, bridge) + elif service_config_a != None and service_config_b != None: + if chain_a == "icon" and chain_b == "icon": + data = btp_relay_setup.start_btp_for_already_running_icon_nodes(plan, chain_a, chain_b, service_config_a, service_config_b, bridge) + elif chain_a == "icon" and chain_b in ["eth", "hardhat"]: + data = btp_relay_setup.start_btp_icon_to_eth_for_already_running_nodes(plan, chain_a, chain_b, service_config_a, service_config_b, bridge) + else: + fail("unsupported chain {0} - {1}".format(src_chain, dst_chain)) + else: + fail("Add Service configs for both chain_a and chain_b") return data else: - fail("Only Icon Supported for MutliRun") - - if len(nodes) > 2: - fail("Maximum two nodes are allowed") - - if nodes[0] == "icon" and nodes[1] == "icon": - data = icon_service.start_node_service_icon_to_icon(plan) - return data + fail("chain_a and chain_b paramter are missing, Add chain_a and chain_b to start relay between them.") + + # Start ibc relay between two nodes + elif relay_type == "ibc": + if chain_a != None and chain_b != None: + if service_config_a == None and service_config_b == None: + data = ibc_relay_setup.run_cosmos_ibc_setup(plan, chain_a, chain_b) + elif service_config_a != None and service_config_b != None: + data = ibc_relay_setup.run_cosmos_ibc_relay_for_already_running_chains(plan, chain_a, chain_b, service_config_a, service_config_b) + else: + fail("Add Service configs for both chain_a and chain_b") + return data + else: + fail("chain_a and chain_b paramter are missing, Add chain_a and chain_b to start relay between them.") else: - node_0 = run_node(plan, nodes[0], args) - node_1 = run_node(plan, nodes[1], args) - - return node_0, node_1 - - if args["action"] == "setup_relay": - if args["relay"]["name"] == "btp": - data = run_btp_setup(plan, args["relay"]) - - return data + fail("More Relay Support will be added soon") + + elif action == "decentralize": + if icon_service_config != None: + icon_setup_node.configure_node(icon_service_config["service_name"], icon_service_config["enpoint"], icon_service_config["keystore_path"], icon_service_config["keypassword"], icon_service_config["nid"]) + else: fail("icon_service_config paramter is missing, Add icon_service_config to decentralise the already running icon node") + + else: + fail("commands only support 'chain', 'bridge' and 'decentralize'") - elif args["relay"]["name"] == "ibc": - data = run_cosmos_ibc_setup(plan, args["relay"]) - return data - else: - fail("More Relay Support will be added soon") - if args["action"] == "start_relay": - if args["relay"]["name"] == "ibc": - service_name = args["relay"]["service"] - cosmvm_relay.start_relay(plan, service_name) - -def run_node(plan, node_name, args): +def run_node(plan, node_name, decentralize, custom_config = None): if node_name == "icon": - return icon_service.start_node_service(plan) + if custom_config == None: + service_config = icon_service.start_node_service(plan) + else: + service_config = icon_node_launcher.start_icon_node(plan, custom_config["private_port"], custom_config["private_port"], custom_config["p2p_listen_address"], custom_config["p2p_address"], custom_config["cid"], {}, custom_config["genesis_file_path"], custom_config["genesis_file_name"]) + + if decentralize == true: + icon_setup_node.configure_node(service_config["service_name"], service_config["enpoint"], service_config["keystore_path"], service_config["keypassword"], service_config["nid"]) + + return service_config elif node_name == "eth" or node_name == "hardhat": - return eth_node.start_eth_node_serivce(plan, args, node_name) + return eth_node.start_eth_node_service(plan, node_name) elif node_name == "archway" or node_name == "neutron": - return cosmvm_node.start_cosmvm_chains(plan, node_name, args) + if cutsom_config == None: + return cosmvm_node.start_cosmvm_chains(plan, node_name) + else: + return cosmvm_node.start_cosmvm_chains(plan, node_name, custom_config["chain_id"], custom_config["key"], custom_config["password"], custom_config["public_grpc"], custom_config["public_http"], custom_config["public_tcp"], custom_config["public_rpc"]) else: fail("Unknown Chain Type. Expected ['icon','eth','hardhat','cosmwasm']") -def run_btp_setup(plan, args): - links = args["links"] - source_chain = links["src"] - destination_chain = links["dst"] - bridge = args["bridge"] - - if source_chain == "icon" and destination_chain == "icon": - data = icon_service.start_node_service_icon_to_icon(plan) - src_chain_service_name = data.src_config["service_name"] - dst_chain_service_name = data.dst_config["service_name"] - - config_data = input_parser.generate_new_config_data(links, src_chain_service_name, dst_chain_service_name, bridge) - config_data["chains"][src_chain_service_name] = data.src_config - config_data["chains"][dst_chain_service_name] = data.dst_config - - icon_service.configure_icon_to_icon_node(plan, data.src_config, data.dst_config) - - config = start_btp_for_already_running_icon_nodes(plan, source_chain, destination_chain, config_data, data.src_config["service_name"], data.dst_config["service_name"]) - - return config - else: - if (source_chain == "eth" or source_chain == "hardhat") and destination_chain == "icon": - destination_chain = source_chain - source_chain = "icon" - - if destination_chain == "eth" or destination_chain == "hardhat": - src_chain_config = icon_service.start_node_service(plan) - dst_chain_config = eth_node.start_eth_node_serivce(plan, args, destination_chain) - - src_chain_service_name = src_chain_config["service_name"] - dst_chain_service_name = dst_chain_config["service_name"] - - config_data = input_parser.generate_new_config_data(links, src_chain_service_name, dst_chain_service_name, bridge) - config_data["chains"][src_chain_service_name] = src_chain_config - config_data["chains"][dst_chain_service_name] = dst_chain_config - - icon_service.configure_icon_node(plan, src_chain_config) - config = start_btp_icon_to_eth_for_already_running_nodes(plan, source_chain, destination_chain, config_data, src_chain_service_name, dst_chain_service_name) - - return config - - else: - fail("unsupported chain {0} - {1}".format(source_chain, destination_chain)) - -def start_btp_for_already_running_icon_nodes(plan, src_chain, dst_chain, config_data, src_service_name, dst_service_name): - src_bmc_address, dst_bmc_address = icon_service.deploy_bmc_icon(plan, src_chain, dst_chain, src_service_name, dst_service_name, config_data) - - response = icon_service.deploy_bmv_icon_to_icon(plan, src_service_name, dst_service_name, src_bmc_address, dst_bmc_address, config_data) - - src_xcall_address, dst_xcall_address = icon_service.deploy_xcall_icon(plan, src_chain, dst_chain, src_bmc_address, dst_bmc_address, config_data, src_service_name, dst_service_name) - - src_dapp_address, dst_dapp_address = icon_service.deploy_dapp_icon(plan, src_chain, dst_chain, src_xcall_address, dst_xcall_address, config_data, src_service_name, dst_service_name) - - src_block_height = icon_setup_node.hex_to_int(plan, src_service_name, response.src_block_height) - dst_block_height = icon_setup_node.hex_to_int(plan, dst_service_name, response.dst_block_height) - - src_contract_addresses = { - "bmc": response.src_bmc, - "bmv": response.src_bmv, - "xcall": src_xcall_address, - "dapp": src_dapp_address, - } - - dst_contract_addresses = { - "bmc": response.dst_bmc, - "bmv": response.dst_bmv, - "xcall": dst_xcall_address, - "dapp": dst_dapp_address, - } - - config_data["chains"][src_service_name]["networkTypeId"] = response.src_network_type_id - config_data["chains"][src_service_name]["networkId"] = response.src_network_id - config_data["chains"][dst_service_name]["networkTypeId"] = response.dst_network_type_id - config_data["chains"][dst_service_name]["networkId"] = response.dst_network_id - - config_data["contracts"][src_service_name] = src_contract_addresses - config_data["contracts"][dst_service_name] = dst_contract_addresses - config_data["chains"][src_service_name]["block_number"] = src_block_height - config_data["chains"][dst_service_name]["block_number"] = dst_block_height - - config_data = start_btp_relayer(plan, src_chain, dst_chain, config_data, src_service_name, dst_service_name) - - config_data["links"]["src"] = src_service_name - config_data["links"]["dst"] = dst_service_name - - return config_data - -def start_btp_icon_to_eth_for_already_running_nodes(plan, src_chain, dst_chain, config_data, src_service_name, dst_service_name): - dst_chain_config = config_data["chains"][dst_service_name] - src_chain_config = config_data["chains"][src_service_name] - - eth_contract_service.start_deploy_service(plan, dst_chain_config) - - src_bmc_address = icon_service.deploy_bmc_icon(plan, src_chain, dst_chain, src_service_name, dst_service_name, config_data) - - dst_bmc_deploy_response = eth_relay_setup.deploy_bmc(plan, config_data, dst_chain, dst_service_name) - - dst_bmc_address = dst_bmc_deploy_response.bmc - - dst_last_block_height_number = eth_contract_service.get_latest_block(plan, dst_chain, "localnet") - - dst_last_block_height_hex = icon_setup_node.int_to_hex(plan, src_service_name, dst_last_block_height_number) - - src_response = icon_service.deploy_bmv_icon(plan, src_service_name, dst_service_name, src_bmc_address, dst_bmc_address, dst_last_block_height_hex, config_data) - - dst_bmv_address = eth_node.deploy_bmv_eth(plan, config_data["bridge"], src_response, config_data, dst_chain, dst_service_name) - - src_xcall_address = icon_service.deploy_xcall_icon(plan, src_chain, dst_chain, src_bmc_address, dst_bmc_address, config_data, src_service_name, dst_service_name) - - dst_xcall_address = eth_relay_setup.deploy_xcall(plan, config_data, dst_chain, dst_service_name) - - src_dapp_address = icon_service.deploy_dapp_icon(plan, src_chain, dst_chain, src_xcall_address, dst_xcall_address, config_data, src_service_name, dst_service_name) - - dst_dapp_address = eth_relay_setup.deploy_dapp(plan, config_data, dst_chain, dst_service_name) - - src_block_height = icon_setup_node.hex_to_int(plan, src_service_name, src_response.block_height) - - src_contract_addresses = { - "bmc": src_response.bmc, - "bmv": src_response.bmvbridge, - "xcall": src_xcall_address, - "dapp": src_dapp_address, - } - - dst_contract_addresses = { - "bmc": dst_bmc_address, - "bmcm": dst_bmc_deploy_response.bmcm, - "bmcs": dst_bmc_deploy_response.bmcs, - "bmv": dst_bmv_address, - "xcall": dst_xcall_address, - "dapp": dst_dapp_address, - } - - config_data["contracts"][src_service_name] = src_contract_addresses - config_data["contracts"][dst_service_name] = dst_contract_addresses - config_data["chains"][src_service_name]["networkTypeId"] = src_response.network_type_id - config_data["chains"][src_service_name]["networkId"] = src_response.network_id - config_data["chains"][src_service_name]["block_number"] = src_block_height - config_data["chains"][dst_service_name]["block_number"] = dst_last_block_height_number - - config_data = start_btp_relayer(plan, src_chain, dst_chain, config_data, src_service_name, dst_service_name) - - config_data["links"]["src"] = src_service_name - config_data["links"]["dst"] = dst_service_name - - return config_data - -def start_btp_relayer(plan, src_chain, dst_chain, config_data, src_service_name, dst_service_name): - src_network = config_data["chains"][src_service_name]["network"] - src_bmc = config_data["contracts"][src_service_name]["bmc"] - - dst_network = config_data["chains"][dst_service_name]["network"] - dst_bmc = config_data["contracts"][dst_service_name]["bmc"] - - src_btp_address = "btp://{0}/{1}".format(src_network, src_bmc) - dst_btp_address = "btp://{0}/{1}".format(dst_network, dst_bmc) - - btp_bridge.start_relayer(plan, src_service_name, dst_service_name, config_data, src_btp_address, dst_btp_address, config_data["bridge"]) - - return config_data - -def run_cosmos_ibc_setup(plan, args): - """ - Start the Cosmos IBC relay setup process between chains. - - Args: - plan (plan): The execution plan. - args (dict): Arguments for configuring the setup. - - Returns: - dict: Configuration response data (will return data for dive.json) - """ - links = args["links"] - source_chain = links["src"] - destination_chain = links["dst"] - - # Check if source and destination chains are both CosmVM-based chains (archway or neutron) - if (source_chain in ["archway", "neutron"]) and (destination_chain in ["archway", "neutron"]): - # Start IBC between two CosmVM chains - data = cosmvm_node.start_ibc_between_cosmvm_chains(plan, source_chain, destination_chain, args) - config_data = run_cosmos_ibc_relay_for_already_running_chains(plan, data.src_config, data.dst_config, args) - return config_data - - # Check if the destination chain is CosmVM-based and the source chain is ICON - if destination_chain in ["archway", "neutron"] and source_chain == "icon": - # Start ICON node service - src_chain_config = icon_service.start_node_service(plan) - # Start CosmVM node service - data = {"data": {}} - dst_chain_config = cosmvm_node.start_cosmvm_chains(plan, destination_chain, data) - dst_chain_config = input_parser.struct_to_dict(dst_chain_config) - # Get service names and new generate configuration data - config_data = run_cosmos_ibc_relay_for_already_running_chains(plan, src_chain_config , dst_chain_config, args) - return config_data - -def run_cosmos_ibc_relay_for_already_running_chains(plan, src_chain_config, dst_chain_config, args): - source_chain = args["links"]["src"] - destination_chain = args["links"]["dst"] - if source_chain in ["archway", "neutron"] and destination_chain in ["archway", "neutron"]: - src_chain_service_name = src_chain_config["service_name"] - dst_chain_service_name = dst_chain_config["service_name"] - src_chain_id = src_chain_config["chain_id"] - src_chain_key = src_chain_config["chain_key"] - dst_chain_id = dst_chain_config["chain_id"] - dst_chain_key = dst_chain_config["chain_key"] - - config_data = input_parser.generate_new_config_data_cosmvm_cosmvm(args["links"], src_chain_service_name, dst_chain_service_name) - config_data["chains"][src_chain_service_name] = src_chain_config - config_data["chains"][dst_chain_service_name] = dst_chain_config - cosmvm_relay.start_cosmos_relay(plan, src_chain_key, src_chain_id, dst_chain_key, dst_chain_id, src_chain_config, dst_chain_config, args["links"]) - - elif source_chain == "icon" and destination_chain in ["archway", "neutron"]: - src_chain_service_name = src_chain_config["service_name"] - dst_chain_service_name = dst_chain_config["service_name"] - config_data = input_parser.generate_new_config_data(args["links"], src_chain_service_name, dst_chain_service_name, "") - # Add chain configurations to the configuration data - config_data["chains"][src_chain_service_name] = src_chain_config - config_data["chains"][dst_chain_service_name] = dst_chain_config - - # Setup ICON contracts for IBC - deploy_icon_contracts = icon_relay_setup.setup_contracts_for_ibc_java(plan, src_chain_config) - icon_register_client = icon_relay_setup.registerClient(plan, src_chain_service_name, deploy_icon_contracts["light_client"], src_chain_config["keystore_path"], src_chain_config["keypassword"], src_chain_config["nid"], src_chain_config["endpoint"], deploy_icon_contracts["ibc_core"]) - - # Configure ICON node - icon_setup_node.configure_node(plan, src_chain_config) - - src_chain_last_block_height = icon_setup_node.get_last_block(plan, src_chain_service_name) - - plan.print("source block height %s" % src_chain_last_block_height) - - network_name = "{0}-{1}".format("dst_chain_network_name", src_chain_last_block_height) - - src_data = { - "name": network_name, - "owner": deploy_icon_contracts["ibc_core"], - } - - # Open BTP network on ICON chain - tx_result_open_btp_network = icon_setup_node.open_btp_network(plan, src_chain_service_name, src_data, src_chain_config["endpoint"], src_chain_config["keystore_path"], src_chain_config["keypassword"], src_chain_config["nid"]) - - icon_bind_port = icon_relay_setup.bindPort(plan, src_chain_service_name, deploy_icon_contracts["xcall_connection"], src_chain_config["keystore_path"], src_chain_config["keypassword"], src_chain_config["nid"], src_chain_config["endpoint"], deploy_icon_contracts["ibc_core"], "xcall") - - # Depending on the destination chain (archway or neutron), set up Cosmos contracts - if destination_chain == "archway": - deploy_cosmos_contracts = cosmvm_relay_setup.setup_contracts_for_ibc_wasm(plan, dst_chain_service_name, dst_chain_config["chain_id"], dst_chain_config["chain_key"], dst_chain_config["chain_id"], "stake", "xcall") - cosmvm_relay_setup.registerClient(plan, dst_chain_service_name, dst_chain_config["chain_id"], dst_chain_config["chain_key"], deploy_cosmos_contracts["ibc_core"], deploy_cosmos_contracts["light_client"]) - plan.wait(service_name = dst_chain_service_name, recipe = ExecRecipe(command = ["/bin/sh", "-c", "sleep 10s && echo 'success'"]), field = "code", assertion = "==", target_value = 0, timeout = "200s") - cosmvm_relay_setup.bindPort(plan, dst_chain_service_name, dst_chain_config["chain_id"], dst_chain_config["chain_key"], deploy_cosmos_contracts["ibc_core"], deploy_cosmos_contracts["xcall_connection"]) - elif destination_chain == "neutron": - deploy_cosmos_contracts = neutron_relay_setup.setup_contracts_for_ibc_wasm(plan, dst_chain_service_name, dst_chain_config["chain_id"], dst_chain_config["chain_key"], dst_chain_config["chain_id"], "stake", "xcall") - neutron_relay_setup.registerClient(plan, dst_chain_service_name, dst_chain_config["chain_id"], dst_chain_config["chain_key"], deploy_cosmos_contracts["ibc_core"], deploy_cosmos_contracts["light_client"]) - plan.wait(service_name = dst_chain_service_name, recipe = ExecRecipe(command = ["/bin/sh", "-c", "sleep 10s && echo 'success'"]), field = "code", assertion = "==", target_value = 0, timeout = "200s") - neutron_relay_setup.bindPort(plan, dst_chain_service_name, dst_chain_config["chain_id"], dst_chain_config["chain_key"], deploy_cosmos_contracts["ibc_core"], deploy_cosmos_contracts["xcall_connection"]) - - # Add contract information to configuration data - config_data["contracts"][src_chain_service_name] = deploy_icon_contracts - config_data["contracts"][dst_chain_service_name] = deploy_cosmos_contracts - - src_chain_id = src_chain_config["network_name"].split('-', 1)[1] - - network_id = icon_setup_node.hex_to_int(plan, src_chain_service_name, src_chain_config["nid"]) - btp_network_id = icon_setup_node.hex_to_int(plan, src_chain_service_name, tx_result_open_btp_network["extract.network_id"]) - btp_network_type_id = icon_setup_node.hex_to_int(plan, src_chain_service_name, tx_result_open_btp_network["extract.network_type_id"]) - - src_chain_data = { - "chain_id": src_chain_id, - "rpc_address": src_chain_config["endpoint"], - "ibc_address": deploy_icon_contracts["ibc_core"], - "password": src_chain_config["keypassword"], - "network_id": network_id, - "btp_network_id": btp_network_id, - "btp_network_type_id": btp_network_type_id - } - - dst_chain_data = { - "chain_id": dst_chain_config["chain_id"], - "key": dst_chain_config["chain_key"], - "rpc_address": dst_chain_config["endpoint"], - "ibc_address": deploy_cosmos_contracts["ibc_core"], - "service_name": dst_chain_config["service_name"], - } - - # Start the Cosmos relay for ICON to Cosmos communication - relay_service_response = cosmvm_relay.start_cosmos_relay_for_icon_to_cosmos(plan, src_chain_data, dst_chain_data, args) - path_name = cosmvm_relay.setup_relay(plan, src_chain_data, dst_chain_data) - - relay_data = cosmvm_relay.get_relay_path_data(plan, relay_service_response.service_name, path_name) - - dapp_result_java = icon_relay_setup.deploy_and_configure_dapp_java(plan, src_chain_config, deploy_icon_contracts["xcall"], dst_chain_config["chain_id"], deploy_icon_contracts["xcall_connection"], deploy_cosmos_contracts["xcall_connection"], src_chain_service_name, src_chain_config["endpoint"], src_chain_config["keystore_path"], src_chain_config["keypassword"], src_chain_config["nid"]) - - # Depending on the destination chain (archway or neutron), deploy and configure the DApp for Wasm - if destination_chain == "archway": - dapp_result_wasm = cosmvm_relay_setup.deploy_and_configure_xcall_dapp(plan, dst_chain_service_name, dst_chain_config["chain_id"], dst_chain_config["chain_key"], deploy_cosmos_contracts["xcall"], deploy_cosmos_contracts["xcall_connection"], deploy_icon_contracts["xcall_connection"], src_chain_config["network"]) - cosmvm_relay_setup.configure_connection_for_wasm(plan, dst_chain_service_name, dst_chain_config["chain_id"], dst_chain_config["chain_key"], deploy_cosmos_contracts["xcall_connection"], relay_data.dst_connection_id, "xcall", src_chain_config["network"], relay_data.dst_client_id, deploy_cosmos_contracts["xcall"]) - elif destination_chain == "neutron": - dapp_result_wasm = neutron_relay_setup.deploy_and_configure_xcall_dapp(plan, dst_chain_service_name, dst_chain_config["chain_id"], dst_chain_config["chain_key"], deploy_cosmos_contracts["xcall"], deploy_cosmos_contracts["xcall_connection"], deploy_icon_contracts["xcall_connection"], src_chain_config["network"]) - neutron_relay_setup.configure_connection_for_wasm(plan, dst_chain_service_name, dst_chain_config["chain_id"], dst_chain_config["chain_key"], deploy_cosmos_contracts["xcall_connection"], relay_data.dst_connection_id, "xcall", src_chain_config["network"], relay_data.dst_client_id, deploy_cosmos_contracts["xcall"]) - - icon_relay_setup.configure_connection_for_java(plan, deploy_icon_contracts["xcall"], deploy_icon_contracts["xcall_connection"], dst_chain_config["chain_id"], relay_data.src_connection_id, "xcall", dst_chain_config["chain_id"], relay_data.src_client_id, src_chain_service_name, src_chain_config["endpoint"], src_chain_config["keystore_path"], src_chain_config["keypassword"], src_chain_config["nid"]) - - config_data["contracts"][src_chain_service_name]["dapp"] = dapp_result_java["xcall_dapp"] - config_data["contracts"][dst_chain_service_name]["dapp"] = dapp_result_wasm["xcall_dapp"] - - # Start relay channel - cosmvm_relay.start_channel(plan, relay_service_response.service_name, path_name, "xcall", "xcall") - - - return config_data - - - - -