Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: neutron-neutron connection using ibc bridge using dive cli #172

32 changes: 0 additions & 32 deletions .circleci/config.yml

This file was deleted.

4 changes: 2 additions & 2 deletions cli/commands/bridge/relyas/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

var suppottedChainsForBtp = []string{"icon", "eth", "hardhat"}
var supportedChainsForIbc = []string{"archway"}
var supportedChainsForIbc = []string{"archway", "neutron"}

type Chains struct {
chainA string
Expand Down Expand Up @@ -40,7 +40,7 @@ func (chains *Chains) getParams() string {
}
func (chains *Chains) getIbcRelayParams() string {

return fmt.Sprintf(`{"args":{"links": {"src": "%s", "dst": "%s"}}}`, chains.chainA, chains.chainB)
return fmt.Sprintf(`{"args":{"links": {"src": "%s", "dst": "%s"}, "src_config":{"data":{}}, "dst_config":{"data":{}}}}`, chains.chainA, chains.chainB)
}

func (chains *Chains) getServicesResponse() (string, string, error) {
Expand Down
105 changes: 78 additions & 27 deletions cli/commands/chain/types/neutron.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,84 +2,135 @@ package types

import (
"encoding/json"
"fmt"

"github.com/hugobyte/dive/cli/common"
"github.com/kurtosis-tech/kurtosis/api/golang/core/kurtosis_core_rpc_api_bindings"
"github.com/kurtosis-tech/kurtosis/api/golang/core/lib/enclaves"
"github.com/spf13/cobra"
)

// Constants for function names
const (
runNeutronNodeWithDefaultConfigFunctionName = "start_node_service"
runNeutronNodeWithCustomServiceFunctionName = "start_neutron_node"
construcNeutrontServiceConfigFunctionName = "get_service_config"
)

// Variable to store the Neutron node configuration file path
var (
neutron_node_config string
)

func NewNeutronCmd(diveContext *common.DiveContext) *cobra.Command {
// 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"`
}

// EncodeToString encodes the NeutronServiceConfig struct to a JSON string.
func (as *NeutronServiceConfig) EncodeToString() (string, error) {
data, err := json.Marshal(as)
if err != nil {
return "", err
}
return string(data), nil
}

// ReadServiceConfig reads the Neutron service configuration from a JSON file.
func (as *NeutronServiceConfig) ReadServiceConfig(path string) error {
configData, err := common.ReadConfigFile(neutron_node_config)
if err != nil {
return err
}
err = json.Unmarshal(configData, as)
if err != nil {
return err
}
return nil
}

// NewNeutronCmd creates a new Cobra command for the Neutron service.
func NewNeutronCmd(diveContext *common.DiveContext) *cobra.Command {
neutronCmd := &cobra.Command{
Use: "neutron",
Short: "Build, initialize and start a neutron node",
Long: "The command starts the neutron network and allows node in executing contracts",
Run: func(cmd *cobra.Command, args []string) {
common.ValidateCmdArgs(diveContext, args, cmd.UsageString())
runResponse := RunNeutronNode(diveContext)

common.WriteToServiceFile(runResponse.ServiceName, *runResponse)

diveContext.StopSpinner("Neutron Node Started. Please find service details in current working directory(services.json)")
},
}
neutronCmd.Flags().StringVarP(&config, "config", "c", "", "path to custom config json file to start neutron node ")

neutronCmd.Flags().StringVarP(&neutron_node_config, "config", "c", "", "path to custom config json file to start neutron node ")
return neutronCmd
}


// RunNeutronNode starts the Neutron node.
func RunNeutronNode(diveContext *common.DiveContext) *common.DiveserviceResponse {
diveContext.InitKurtosisContext()
kurtosisEnclaveContext, err := diveContext.GetEnclaveContext()

if err != nil {
diveContext.FatalError("Failed To Retrive Enclave Context", err.Error())
diveContext.FatalError("Failed To Retrieve Enclave Context", err.Error())
}

diveContext.StartSpinner(" Starting Neutron Node")
diveContext.StartSpinner("Starting Neutron Node")
var serviceConfig = &NeutronServiceConfig{}
var neutronResponse = &common.DiveserviceResponse{}
var starlarkExecutionData = ""
starlarkExecutionData, err = runNeutronWithDefaultServiceConfig(diveContext, kurtosisEnclaveContext)
if err != nil {
diveContext.FatalError("Starlark Run Failed", err.Error())

if neutron_node_config != "" {
err := serviceConfig.ReadServiceConfig(neutron_node_config)
if err != nil {
diveContext.FatalError("Failed read service config", err.Error())
}

encodedServiceConfigDataString, err := serviceConfig.EncodeToString()
if err != nil {
diveContext.FatalError("Failed to encode service config", err.Error())
}

// Run Neutron Node with custom service config
starlarkExecutionData, err = RunNeutronWithServiceConfig(diveContext, kurtosisEnclaveContext, encodedServiceConfigDataString)
if err != nil {
diveContext.FatalError("Starlark Run Failed", err.Error())
}
} else {
// Run Neutron Node with default service config
starlarkExecutionData, err = RunNeutronWithServiceConfig(diveContext, kurtosisEnclaveContext, "{}")
if err != nil {
diveContext.FatalError("Starlark Run Failed", err.Error())
}
}
err = json.Unmarshal([]byte(starlarkExecutionData), neutronResponse)

err = json.Unmarshal([]byte(starlarkExecutionData), neutronResponse)
if err != nil {
diveContext.FatalError("Failed to Unmarshall Service Response", err.Error())
diveContext.FatalError("Failed to Unmarshal Service Response", err.Error())
}

return neutronResponse

}


func runNeutronWithDefaultServiceConfig(diveContext *common.DiveContext, enclaveContext *enclaves.EnclaveContext) (string, error) {

params := `{"args":{"data":{}}}`
nodeServiceResponse, _, err := enclaveContext.RunStarlarkRemotePackage(diveContext.Ctx, common.DiveRemotePackagePath, common.DiveNeutronDefaultNodeScript, runNeutronNodeWithDefaultConfigFunctionName, params, common.DiveDryRun, common.DiveDefaultParallelism, []kurtosis_core_rpc_api_bindings.KurtosisFeatureFlag{})

// 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)
nodeServiceResponse, _, err := enclaveContext.RunStarlarkPackage(diveContext.Ctx, common.DiveRemotePackagePath, common.DiveNeutronDefaultNodeScript, runNeutronNodeWithDefaultConfigFunctionName, params, common.DiveDryRun, common.DiveDefaultParallelism, []kurtosis_core_rpc_api_bindings.KurtosisFeatureFlag{})
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())

}
diveContext.CheckInstructionSkipped(skippedInstructions, "Nueutron Node Already Running")

diveContext.CheckInstructionSkipped(skippedInstructions, "Neutron Node Already Running")
return nodeServiceResponseData, nil
}
}
17 changes: 11 additions & 6 deletions main.star
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,18 @@ def run_cosmos_ibc_setup(plan, args):
links = args["links"]
source_chain = links["src"]
destination_chain = links["dst"]

if source_chain ="archway" and destination_chain = "archway":
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, links, data.src_config, data.dst_config, args)
return config_data

if source_chain == "archway" and destination_chain == "archway":
data = cosmvm_node.start_ibc_between_cosmvm_chains(plan,source_chain,destination_chain)

config_data = run_cosmos_ibc_relay_for_already_running_chains(plan,links,data.src_config,data.dst_config)
if source_chain ="neutron" and destination_chain = "neutron":
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, links, data.src_config, data.dst_config, args)
return config_data


if destination_chain == "archway":

src_chain_config = icon_service.start_node_service(plan)
Expand Down Expand Up @@ -334,7 +339,7 @@ def run_cosmos_ibc_setup(plan, args):



def run_cosmos_ibc_relay_for_already_running_chains(plan,links,src_config,dst_config):
def run_cosmos_ibc_relay_for_already_running_chains(plan,links,src_config,dst_config, args):

src_chain_service_name = src_config["service_name"]
dst_chain_service_name = dst_config["service_name"]
Expand All @@ -346,7 +351,7 @@ def run_cosmos_ibc_relay_for_already_running_chains(plan,links,src_config,dst_co
config_data = input_parser.generate_new_config_data_cosmvm_cosmvm(links, src_chain_service_name, dst_chain_service_name)
config_data["chains"][src_chain_service_name] = src_config
config_data["chains"][dst_chain_service_name] = dst_config
cosmvm_relay.start_cosmos_relay(plan, src_chain_key, src_chain_id, dst_chain_key, dst_chain_id, src_config, dst_config)
cosmvm_relay.start_cosmos_relay(plan, src_chain_key, src_chain_id, dst_chain_key, dst_chain_id, src_config, dst_config, args)

return config_data

29 changes: 23 additions & 6 deletions package_io/constants.star
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,15 @@ ARCHWAY_SERVICE_CONFIG = struct(

NEUTRON_SERVICE_CONFIG = struct(
service_name = "neutron-node",
image = "hugobyte/neutron-node:v0.2"
image = "hugobyte/neutron-node:v0.2",
init_script = "github.com/hugobyte/dive/services/cosmvm/neutron/static_files/init.sh",
start_script = "github.com/hugobyte/dive/services/cosmvm/neutron/static_files/start.sh",
init_nutrond_script = "github.com/hugobyte/dive/services/cosmvm/neutron/static_files/init-neutrond.sh",
path = "/start-scripts/",
)

IBC_RELAYER_SERVICE = struct(
ibc_relay_config_file_template = "github.com/hugobyte/dive/services/bridges/ibc/static-files/config/archwayjson.tpl",
ibc_relay_config_file_template = "github.com/hugobyte/dive/services/bridges/ibc/static-files/config/cosmosjson.tpl",
relay_service_name = "cosmos-ibc-relay",
# updated the ibc relay image
relay_service_image = "hugobyte/ibc-relay:v0.1",
Expand Down Expand Up @@ -94,7 +98,7 @@ ARCHAY_NODE1_CONFIG = struct(
chain_id = "archway-node-1",
grpc = 9080,
http = 9092,
tcp = 26658,
tcp = 26659,
rpc = 4566,
key = "archway-node-1-key",
)
Expand All @@ -113,9 +117,22 @@ NEUTRON_PRIVATE_PORTS = struct(
grpc = 9090,
)

NEUTRON_PUBLIC_PORTS = struct(
NEUTRON_NODE1_CONFIG = struct(
http = 1317,
rpc = 26659,
rpc = 26669,
tcp = 26656,
grpc = 8090,
)
chain_id = "test-chain1",
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",
)

NEUTRON_NODE2_CONFIG = struct(
http = 1311,
rpc = 26653,
tcp = 26652,
grpc = 8091,
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",
)
7 changes: 6 additions & 1 deletion package_io/input_parser.star
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,9 @@ def generate_new_config_data_cosmvm_cosmvm(links, srcchain_service_name, dst_cha
},
}

return config_data
return config_data


def struct_to_dict(s):
fields = dir(s)
return {field: getattr(s, field) for field in fields if not field.startswith("_")}
Loading