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: implement neutron-archway ibc realy using dive cli #174

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 0 additions & 32 deletions .circleci/config.yml

This file was deleted.

8 changes: 4 additions & 4 deletions cli/commands/bridge/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"fmt"
"os"

"github.com/hugobyte/dive/cli/commands/bridge/relyas"
"github.com/hugobyte/dive/cli/commands/bridge/relays"
"github.com/hugobyte/dive/cli/common"
"github.com/spf13/cobra"
"golang.org/x/exp/slices"
Expand All @@ -30,7 +30,7 @@ This will create an relay to connect two different chains and pass any messages

if len(args) == 0 {
cmd.Help()

} else if !slices.Contains(cmd.ValidArgs, args[0]) {

diveContext.Log.SetOutput(os.Stderr)
Expand All @@ -42,9 +42,9 @@ This will create an relay to connect two different chains and pass any messages
},
}

bridgeCmd.AddCommand(relyas.BtpRelayCmd(diveContext))
bridgeCmd.AddCommand(relays.BtpRelayCmd(diveContext))

bridgeCmd.AddCommand(relyas.IbcRelayCmd(diveContext))
bridgeCmd.AddCommand(relays.IbcRelayCmd(diveContext))

return bridgeCmd
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package relyas
package relays

import (
"fmt"
Expand Down Expand Up @@ -64,7 +64,7 @@ func BtpRelayCmd(diveContext *common.DiveContext) *cobra.Command {
chains := initChains(chainA, chainB, serviceA, serviceB, bridge)

if err := chains.checkForBtpSupportedChains(); err != nil {
diveContext.FatalError(err.Error(), fmt.Sprintf("Supported Chains for BTP: %v", suppottedChainsForBtp))
diveContext.FatalError(err.Error(), fmt.Sprintf("Supported Chains for BTP: %v", supportedChainsForBtp))
}

diveContext.StartSpinner(fmt.Sprintf(" Starting BTP Bridge for %s,%s", chains.chainA, chains.chainB))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package relyas
package relays

import (
"fmt"
Expand All @@ -10,8 +10,8 @@ import (
"github.com/hugobyte/dive/cli/common"
)

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

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 Expand Up @@ -74,10 +74,10 @@ func (chains *Chains) getServicesResponse() (string, string, error) {
}

func (chains *Chains) checkForBtpSupportedChains() error {
if !slices.Contains(suppottedChainsForBtp, chains.chainA) {
if !slices.Contains(supportedChainsForBtp, chains.chainA) {
return fmt.Errorf("invalid Chain: %s", chains.chainA)
}
if !slices.Contains(suppottedChainsForBtp, chains.chainB) {
if !slices.Contains(supportedChainsForBtp, chains.chainB) {
return fmt.Errorf("invalid Chain: %s", chains.chainB)
}
return nil
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package relyas
package relays

import (
"fmt"
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
}
}
13 changes: 6 additions & 7 deletions main.star
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,11 @@ def run_cosmos_ibc_setup(plan, args):
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)

config_data = run_cosmos_ibc_relay_for_already_running_chains(plan,links,data.src_config,data.dst_config)
if (source_chain in ["archway", "neutron"]) and (destination_chain in ["archway", "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 +333,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 +345,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