From be46e91bc079fd472d5fcebbea64316982b226af Mon Sep 17 00:00:00 2001 From: shreyasbhat0 Date: Fri, 14 Jul 2023 11:12:52 +0530 Subject: [PATCH 1/5] chore: update dive banner --- cli/styles/banner.go | 8 ++++++-- cli/styles/colors.go | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/cli/styles/banner.go b/cli/styles/banner.go index 90f9206b..75d5334f 100644 --- a/cli/styles/banner.go +++ b/cli/styles/banner.go @@ -6,11 +6,15 @@ var banner = ` ___ _____ _____ | \_ _\ \ / / __| | |) | | \ V /| _| - |___/___| \_/ |___| + |___/___| \_/ |___| + + %s ` func RenderBanner() { - fmt.Println(BANNER_COLOR(banner)) + banner := fmt.Sprintf(BANNER_COLOR(banner), TAG_COLOR("Developed by Hugobyte AI Labs and Powered by Kurtosis")) + + fmt.Println(banner) } diff --git a/cli/styles/colors.go b/cli/styles/colors.go index 8cd6d5b6..45d7dafd 100644 --- a/cli/styles/colors.go +++ b/cli/styles/colors.go @@ -12,3 +12,4 @@ func color(colorString string) func(...interface{}) string { var ERROR_COLOR = color("\033[0;31m]") var BANNER_COLOR = color("\033[1;34m%s\033[0m") +var TAG_COLOR = color("\033[3;32m%s\033[0m") From bfbd52010bd4aefb9b68af879e50465d416f68cb Mon Sep 17 00:00:00 2001 From: shreyasbhat0 Date: Fri, 14 Jul 2023 18:18:50 +0530 Subject: [PATCH 2/5] feat: implement bridge command --- cli/commands/bridge/bridge.go | 87 ++++++++++++++++++++++++++--- cli/commands/chain/chains.go | 57 +++++-------------- cli/commands/chain/types/eth.go | 4 +- cli/commands/chain/types/hardhat.go | 4 +- cli/commands/chain/types/icon.go | 52 ++++++++--------- cli/commands/root.go | 8 ++- cli/common/types.go | 60 ++++++++++++++++++++ cli/styles/banner.go | 2 +- 8 files changed, 189 insertions(+), 85 deletions(-) diff --git a/cli/commands/bridge/bridge.go b/cli/commands/bridge/bridge.go index 4fa8e979..7bbe2b21 100644 --- a/cli/commands/bridge/bridge.go +++ b/cli/commands/bridge/bridge.go @@ -5,16 +5,87 @@ package bridge import ( "fmt" + "strconv" + "strings" + "github.com/hugobyte/dive/common" + "github.com/kurtosis-tech/kurtosis/api/golang/core/kurtosis_core_rpc_api_bindings" "github.com/spf13/cobra" ) -// bridgeCmd represents the bridge command -var BridgeCmd = &cobra.Command{ - Use: "bridge", - Short: "Command for cross chain communication between two different chains", - Long: `To connect two different chains using any of the supported cross chain communication protocols. This will create an relay to connect two different chains and pass any messages between them.`, - Run: func(cmd *cobra.Command, args []string) { - fmt.Println("bridge called") - }, +var ( + chainA string + chainB string +) + +const ( + genesisIcon0 = "../services/jvm/icon/static-files/config/genesis-icon-0.zip" + genesisIcon1 = "../services/jvm/icon/static-files/config/genesis-icon-1.zip" +) + +func NewBridgeCmd(diveContext *common.DiveContext) *cobra.Command { + + var bridgeCmd = &cobra.Command{ + Use: "bridge", + Short: "Command for cross chain communication between two different chains", + Long: `To connect two different chains using any of the supported cross chain communication protocols. This will create an relay to connect two different chains and pass any messages between them.`, + Run: func(cmd *cobra.Command, args []string) { + cmd.Help() + }, + } + + bridgeCmd.AddCommand(btpBridgeCmd(diveContext)) + + return bridgeCmd +} + +func btpBridgeCmd(diveContext *common.DiveContext) *cobra.Command { + + var btpbridgeCmd = &cobra.Command{ + Use: "btp", + Short: "", + Long: `.`, + Run: func(cmd *cobra.Command, args []string) { + + enclaveCtx, err := diveContext.GetEnclaveContext() + if err != nil { + panic(err) + + } + + bridge, _ := cmd.Flags().GetBool("bridge") + + params := fmt.Sprintf(`{"args":{"links": {"src": "%s", "dst": "%s"},"bridge":"%s"}}`, chainA, chainB, strconv.FormatBool(bridge)) + + if strings.ToLower(chainA) == "icon" && strings.ToLower(chainB) == "icon" { + + data, _, err := enclaveCtx.RunStarlarkPackage(diveContext.Ctx, "../", "main.star", "run_btp_setup", params, false, 4, []kurtosis_core_rpc_api_bindings.KurtosisFeatureFlag{}) + + if err != nil { + fmt.Println(err) + } + response := common.GetSerializedData(data) + + common.WriteToFile(response) + } else { + data, _, err := enclaveCtx.RunStarlarkPackage(diveContext.Ctx, "../", "main.star", "run_btp_setup", params, false, 4, []kurtosis_core_rpc_api_bindings.KurtosisFeatureFlag{}) + + if err != nil { + fmt.Println(err) + } + response := common.GetSerializedData(data) + + common.WriteToFile(response) + } + }, + } + + btpbridgeCmd.Flags().StringVar(&chainA, "chainA", "", "specify chain A") + btpbridgeCmd.Flags().StringVar(&chainB, "chainB", "", "specify chain B") + btpbridgeCmd.Flags().Bool("bridge", false, "sepcify bridge falg") + + btpbridgeCmd.MarkFlagRequired("chainA") + btpbridgeCmd.MarkFlagRequired("chainB") + + return btpbridgeCmd } diff --git a/cli/commands/chain/chains.go b/cli/commands/chain/chains.go index a48ecc1e..adec3ae7 100644 --- a/cli/commands/chain/chains.go +++ b/cli/commands/chain/chains.go @@ -4,65 +4,34 @@ Copyright © 2023 Hugobyte AI Labs package chain import ( - "context" - "github.com/hugobyte/dive/commands/chain/types" "github.com/hugobyte/dive/common" - "github.com/kurtosis-tech/kurtosis/api/golang/core/lib/enclaves" - "github.com/kurtosis-tech/kurtosis/api/golang/engine/lib/kurtosis_context" "github.com/spf13/cobra" ) // chainCmd represents the chain command +func NewChainCmd(diveContext *common.DiveContext) *cobra.Command { + var chainCmd = &cobra.Command{ + Use: "chain", + Short: "runs specfied chain", + Long: ``, -var ChainCmd = &cobra.Command{ - Use: "chain", - Short: "runs specfied chain", - Long: ``, - - Run: func(cmd *cobra.Command, args []string) { - cmd.Help() - - }, -} - -func init() { - - ctx := context.Background() - - kurtosisContext, err := kurtosis_context.NewKurtosisContextFromLocalEngine() - if err != nil { - panic(err) + Run: func(cmd *cobra.Command, args []string) { + cmd.Help() + }, } - enclaveCtx, err := getEnclaveContext(ctx, common.DiveEnclave, kurtosisContext) + enclaveCtx, err := diveContext.GetEnclaveContext() if err != nil { panic(err) } - ChainCmd.AddCommand(types.NewIconCmd(ctx, enclaveCtx)) - ChainCmd.AddCommand(types.NewEthCmd(ctx, enclaveCtx)) - ChainCmd.AddCommand(types.NewHardhatCmd(ctx, enclaveCtx)) + chainCmd.AddCommand(types.NewIconCmd(diveContext.Ctx, enclaveCtx)) + chainCmd.AddCommand(types.NewEthCmd(diveContext.Ctx, enclaveCtx)) + chainCmd.AddCommand(types.NewHardhatCmd(diveContext.Ctx, enclaveCtx)) -} - -func getEnclaveContext(ctx context.Context, identifier string, kurtosisContext *kurtosis_context.KurtosisContext) (*enclaves.EnclaveContext, error) { - - _, err := kurtosisContext.GetEnclave(ctx, common.DiveEnclave) - if err != nil { - enclaveCtx, err := kurtosisContext.CreateEnclave(ctx, identifier, false) - if err != nil { - return nil, err + return chainCmd - } - return enclaveCtx, nil - } - enclaveCtx, err := kurtosisContext.GetEnclaveContext(ctx, identifier) - - if err != nil { - return nil, err - } - return enclaveCtx, nil } diff --git a/cli/commands/chain/types/eth.go b/cli/commands/chain/types/eth.go index cc3425f7..4e7e6450 100644 --- a/cli/commands/chain/types/eth.go +++ b/cli/commands/chain/types/eth.go @@ -18,7 +18,7 @@ func NewEthCmd(ctx context.Context, kurtosisEnclaveContext *enclaves.EnclaveCont Long: ``, Run: func(cmd *cobra.Command, args []string) { - fmt.Println(runEthNode(ctx, kurtosisEnclaveContext).EncodeToString()) + fmt.Println(RunEthNode(ctx, kurtosisEnclaveContext).EncodeToString()) }, } @@ -26,7 +26,7 @@ func NewEthCmd(ctx context.Context, kurtosisEnclaveContext *enclaves.EnclaveCont } -func runEthNode(ctx context.Context, kurtosisEnclaveContext *enclaves.EnclaveContext) *common.DiveserviceResponse { +func RunEthNode(ctx context.Context, kurtosisEnclaveContext *enclaves.EnclaveContext) *common.DiveserviceResponse { data, _, err := kurtosisEnclaveContext.RunStarlarkPackage(ctx, "../", "services/evm/eth/eth.star", "start_eth_node_serivce", `{"args":{},"node_type":"eth"}`, false, 4, []kurtosis_core_rpc_api_bindings.KurtosisFeatureFlag{}) diff --git a/cli/commands/chain/types/hardhat.go b/cli/commands/chain/types/hardhat.go index 41c5cb49..93f6aa7a 100644 --- a/cli/commands/chain/types/hardhat.go +++ b/cli/commands/chain/types/hardhat.go @@ -18,7 +18,7 @@ func NewHardhatCmd(ctx context.Context, kurtosisEnclaveContext *enclaves.Enclave Long: ``, Run: func(cmd *cobra.Command, args []string) { - fmt.Println(runHardhatNode(ctx, kurtosisEnclaveContext).EncodeToString()) + fmt.Println(RunHardhatNode(ctx, kurtosisEnclaveContext).EncodeToString()) }, } @@ -26,7 +26,7 @@ func NewHardhatCmd(ctx context.Context, kurtosisEnclaveContext *enclaves.Enclave } -func runHardhatNode(ctx context.Context, kurtosisEnclaveContext *enclaves.EnclaveContext) *common.DiveserviceResponse { +func RunHardhatNode(ctx context.Context, kurtosisEnclaveContext *enclaves.EnclaveContext) *common.DiveserviceResponse { data, _, err := kurtosisEnclaveContext.RunStarlarkPackage(ctx, "../", "services/evm/eth/eth.star", "start_eth_node_serivce", `{"args":{},"node_type":"hardhat"}`, false, 4, []kurtosis_core_rpc_api_bindings.KurtosisFeatureFlag{}) diff --git a/cli/commands/chain/types/icon.go b/cli/commands/chain/types/icon.go index cb3ee25d..717020c4 100644 --- a/cli/commands/chain/types/icon.go +++ b/cli/commands/chain/types/icon.go @@ -6,8 +6,6 @@ import ( "fmt" "path/filepath" - "os" - "github.com/hugobyte/dive/common" "github.com/kurtosis-tech/kurtosis/api/golang/core/kurtosis_core_rpc_api_bindings" "github.com/kurtosis-tech/kurtosis/api/golang/core/lib/enclaves" @@ -35,7 +33,7 @@ type IconServiceConfig struct { Cid string `json:"cid"` } -func (sc *IconServiceConfig) defaultServiceConfig() { +func (sc *IconServiceConfig) GetDefaultConfigIconNode0() { sc.Id = "0" sc.Port = 9080 @@ -43,6 +41,18 @@ func (sc *IconServiceConfig) defaultServiceConfig() { sc.P2PListenAddress = "7080" sc.P2PAddress = "8080" sc.Cid = "0xacbc4e" + +} + +func (sc *IconServiceConfig) GetDefaultConfigIconNode1() { + + sc.Id = "1" + sc.Port = 9081 + sc.PublicPort = 8091 + sc.P2PListenAddress = "7081" + sc.P2PAddress = "8081" + sc.Cid = "0x42f1f3" + } func (sc *IconServiceConfig) EncodeToString() (string, error) { @@ -66,11 +76,11 @@ func NewIconCmd(ctx context.Context, kurtosisEnclaveContext *enclaves.EnclaveCon serviceConfig := &IconServiceConfig{} if configFilePath == "" { - serviceConfig.defaultServiceConfig() + serviceConfig.GetDefaultConfigIconNode0() } else { - data, err := readConfigFile(configFilePath) + data, err := common.ReadConfigFile(configFilePath) if err != nil { - serviceConfig.defaultServiceConfig() + serviceConfig.GetDefaultConfigIconNode0() } err = json.Unmarshal(data, serviceConfig) @@ -83,15 +93,15 @@ func NewIconCmd(ctx context.Context, kurtosisEnclaveContext *enclaves.EnclaveCon if decentralisation { - data := runIconNode(ctx, kurtosisEnclaveContext, serviceConfig) + data := RunIconNode(ctx, kurtosisEnclaveContext, serviceConfig, genesis) - params := getDecentralizeParms(data.ServiceName, data.PrivateEndpoint, data.KeystorePath, data.KeyPassword, data.NetworkId) + params := GetDecentralizeParms(data.ServiceName, data.PrivateEndpoint, data.KeystorePath, data.KeyPassword, data.NetworkId) Decentralisation(ctx, kurtosisEnclaveContext, params) } else { - data := runIconNode(ctx, kurtosisEnclaveContext, serviceConfig) + data := RunIconNode(ctx, kurtosisEnclaveContext, serviceConfig, genesis) fmt.Println(data.EncodeToString()) @@ -121,7 +131,7 @@ func IconDecentralisationCmd(ctx context.Context, kurtosisEnclaveContext *enclav Run: func(cmd *cobra.Command, args []string) { fmt.Println("Decentralisation") - params := getDecentralizeParms(serviceName, nodeEndpoint, keystorePath, keystorepassword, networkID) + params := GetDecentralizeParms(serviceName, nodeEndpoint, keystorePath, keystorepassword, networkID) Decentralisation(ctx, kurtosisEnclaveContext, params) @@ -143,7 +153,7 @@ func IconDecentralisationCmd(ctx context.Context, kurtosisEnclaveContext *enclav } -func runIconNode(ctx context.Context, kurtosisEnclaveContext *enclaves.EnclaveContext, serviceConfig *IconServiceConfig) *common.DiveserviceResponse { +func RunIconNode(ctx context.Context, kurtosisEnclaveContext *enclaves.EnclaveContext, serviceConfig *IconServiceConfig, genesisFilePath string) *common.DiveserviceResponse { paramData, err := serviceConfig.EncodeToString() if err != nil { @@ -158,16 +168,17 @@ func runIconNode(ctx context.Context, kurtosisEnclaveContext *enclaves.EnclaveCo responseData := common.GetSerializedData(data) - genesis_file_name := filepath.Base(genesis) - r, d, err := kurtosisEnclaveContext.UploadFiles(genesis, genesis_file_name) + genesis_file_name := filepath.Base(genesisFilePath) + r, d, err := kurtosisEnclaveContext.UploadFiles(genesisFilePath, genesis_file_name) if err != nil { panic(err) } logrus.Infof("File Uploaded sucessfully : UUID %s", r) + uploadedFiles := fmt.Sprintf(`{"file_path":"%s","file_name":"%s"}`, d, genesis_file_name) - params := fmt.Sprintf(`{"service_config":%s,"id":"%s","start_file_name":"start-icon.sh","genesis_file_path":"%s","genesis_file_name":"%s"}`, responseData, serviceConfig.Id, d, genesis_file_name) + params := fmt.Sprintf(`{"service_config":%s,"id":"%s","uploaded_genesis":%s,"genesis_file_path":"%s","genesis_file_name":"%s"}`, responseData, serviceConfig.Id, uploadedFiles, "", "") icon_data, _, err := kurtosisEnclaveContext.RunStarlarkPackage(ctx, "../", "services/jvm/icon/src/node-setup/start_icon_node.star", "start_icon_node", params, false, 4, []kurtosis_core_rpc_api_bindings.KurtosisFeatureFlag{}) if err != nil { @@ -200,19 +211,8 @@ func Decentralisation(ctx context.Context, kurtosisEnclaveContext *enclaves.Encl } -func getDecentralizeParms(serviceName, nodeEndpoint, keystorePath, keystorepassword, networkID string) 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) } - -func readConfigFile(filePath string) ([]byte, error) { - - file, err := os.ReadFile(filePath) - - if err != nil { - return nil, err - } - - return file, nil -} diff --git a/cli/commands/root.go b/cli/commands/root.go index a4ca6b05..2eee17df 100644 --- a/cli/commands/root.go +++ b/cli/commands/root.go @@ -8,6 +8,7 @@ import ( "github.com/hugobyte/dive/commands/bridge" "github.com/hugobyte/dive/commands/chain" + "github.com/hugobyte/dive/common" "github.com/hugobyte/dive/commands/clean" "github.com/hugobyte/dive/commands/discord" @@ -38,12 +39,15 @@ func Execute() { } func init() { + + diveContext := common.NewDiveContext() + rootCmd.CompletionOptions.DisableDefaultCmd = true rootCmd.CompletionOptions.DisableNoDescFlag = true rootCmd.AddCommand(version.VersionCmd) - rootCmd.AddCommand(chain.ChainCmd) - rootCmd.AddCommand(bridge.BridgeCmd) + rootCmd.AddCommand(chain.NewChainCmd(diveContext)) + rootCmd.AddCommand(bridge.NewBridgeCmd(diveContext)) rootCmd.AddCommand(clean.CleanCmd) rootCmd.AddCommand(discord.DiscordCmd) rootCmd.AddCommand(twitter.TwitterCmd) diff --git a/cli/common/types.go b/cli/common/types.go index 339f8853..d1ba68aa 100644 --- a/cli/common/types.go +++ b/cli/common/types.go @@ -1,12 +1,16 @@ package common import ( + "context" "encoding/json" "fmt" + "os" "os/exec" "runtime" "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/kurtosis-tech/kurtosis/api/golang/engine/lib/kurtosis_context" "github.com/kurtosis-tech/stacktrace" "github.com/sirupsen/logrus" ) @@ -91,3 +95,59 @@ func OpenFile(URL string) error { } return nil } + +type DiveContext struct { + Ctx context.Context + KurtosisContext *kurtosis_context.KurtosisContext +} + +func NewDiveContext() *DiveContext { + + ctx := context.Background() + + kurtosisContext, err := kurtosis_context.NewKurtosisContextFromLocalEngine() + if err != nil { + panic(err) + + } + return &DiveContext{Ctx: ctx, KurtosisContext: kurtosisContext} +} + +func (diveContext *DiveContext) GetEnclaveContext() (*enclaves.EnclaveContext, error) { + + _, err := diveContext.KurtosisContext.GetEnclave(diveContext.Ctx, DiveEnclave) + if err != nil { + enclaveCtx, err := diveContext.KurtosisContext.CreateEnclave(diveContext.Ctx, DiveEnclave, false) + if err != nil { + return nil, err + + } + return enclaveCtx, nil + } + enclaveCtx, err := diveContext.KurtosisContext.GetEnclaveContext(diveContext.Ctx, DiveEnclave) + + if err != nil { + return nil, err + } + return enclaveCtx, nil +} + +func ReadConfigFile(filePath string) ([]byte, error) { + + file, err := os.ReadFile(filePath) + + if err != nil { + return nil, err + } + + return file, nil +} +func WriteToFile(data string) { + file, err := os.Create("bridge.json") + if err != nil { + return + } + defer file.Close() + + file.WriteString(data) +} diff --git a/cli/styles/banner.go b/cli/styles/banner.go index 75d5334f..820d516e 100644 --- a/cli/styles/banner.go +++ b/cli/styles/banner.go @@ -13,7 +13,7 @@ var banner = ` func RenderBanner() { - banner := fmt.Sprintf(BANNER_COLOR(banner), TAG_COLOR("Developed by Hugobyte AI Labs and Powered by Kurtosis")) + banner := fmt.Sprintf(BANNER_COLOR(banner), TAG_COLOR("Developed by HugoByte and Powered by Kurtosis")) fmt.Println(banner) From 9fa44eef220a8e1870293fb60788729f6e20790a Mon Sep 17 00:00:00 2001 From: shreyasbhat0 Date: Fri, 14 Jul 2023 18:19:10 +0530 Subject: [PATCH 3/5] feat: update service packages --- services/jvm/icon/icon.star | 12 ++++-- .../icon/src/node-setup/start_icon_node.star | 41 +++++++++++++------ .../icon/static-files/config/start-icon-0.sh | 34 --------------- .../config/{start-icon.sh => start.sh} | 0 4 files changed, 37 insertions(+), 50 deletions(-) delete mode 100755 services/jvm/icon/static-files/config/start-icon-0.sh rename services/jvm/icon/static-files/config/{start-icon.sh => start.sh} (100%) diff --git a/services/jvm/icon/icon.star b/services/jvm/icon/icon.star index 6e5bedb3..4166364c 100644 --- a/services/jvm/icon/icon.star +++ b/services/jvm/icon/icon.star @@ -3,8 +3,8 @@ setup_node = import_module("github.com/hugobyte/dive/services/jvm/icon/src/node- icon_node_launcher = import_module("github.com/hugobyte/dive/services/jvm/icon/src/node-setup/start_icon_node.star") icon_relay_setup = import_module("github.com/hugobyte/dive/services/jvm/icon/src/relay-setup/contract_configuration.star") -START_FILE_FOR_ICON0 = "start-icon-0.sh" -START_FILE_FOR_ICON1 = "start-icon-1.sh" +START_FILE_FOR_ICON0 = "start-icon.sh" +START_FILE_FOR_ICON1 = "start-icon.sh" ICON0_NODE_ID = 0 ICON1_NODE_ID = 1 ICON0_NODE_PRIVATE_RPC_PORT = 9080 @@ -17,13 +17,17 @@ ICON1_NODE_P2P_LISTEN_ADDRESS = 7081 ICON1_NODE_P2P_ADDRESS = 8081 ICON0_NODE_CID = "0xacbc4e" ICON1_NODE_CID = "0x42f1f3" +ICON0_GENESIS_FILE_PATH = "github.com/hugobyte/dive/services/jvm/icon/static-files/config/genesis-icon-0.zip" +ICON1_GENESIS_FILE_PATH = "github.com/hugobyte/dive/services/jvm/icon/static-files/config/genesis-icon-1.zip" +ICON0_GENESIS_FILE_NAME= "genesis-icon-0.zip" +ICON1_GENESIS_FILE_NAME= "genesis-icon-1.zip" # Spins up ICON Node ID 0 def start_icon_node_0(plan,service_config): plan.print("Starting Icon Node: Id 0") - node_service = icon_node_launcher.start_icon_node(plan,service_config,ICON0_NODE_ID,START_FILE_FOR_ICON0) + node_service = icon_node_launcher.start_icon_node(plan,service_config,ICON0_NODE_ID,{},ICON0_GENESIS_FILE_PATH,ICON0_GENESIS_FILE_NAME) return node_service @@ -32,7 +36,7 @@ def start_icon_node_1(plan,service_config): plan.print("Starting Icon Node: Id 1") - node_service = icon_node_launcher.start_icon_node(plan,service_config,ICON1_NODE_ID,START_FILE_FOR_ICON1) + node_service = icon_node_launcher.start_icon_node(plan,service_config,ICON1_NODE_ID,{},ICON1_GENESIS_FILE_PATH,ICON1_GENESIS_FILE_NAME) return node_service diff --git a/services/jvm/icon/src/node-setup/start_icon_node.star b/services/jvm/icon/src/node-setup/start_icon_node.star index 33e40dc6..e83f1e8b 100644 --- a/services/jvm/icon/src/node-setup/start_icon_node.star +++ b/services/jvm/icon/src/node-setup/start_icon_node.star @@ -1,7 +1,9 @@ constants = import_module("github.com/hugobyte/dive/package_io/constants.star") # Starts The Icon Node -def start_icon_node(plan,service_config,id,start_file_name,genesis_file_path,genesis_file_name): +def start_icon_node(plan,service_config,id,uploaded_genesis,genesis_file_path,genesis_file_name): + + plan.print(uploaded_genesis) icon_node_constants = constants.ICON_NODE_CLIENT @@ -22,6 +24,16 @@ def start_icon_node(plan,service_config,id,start_file_name,genesis_file_path,gen plan.upload_files(src=icon_node_constants.contract_files_path,name="contracts-{0}".format(id)) plan.upload_files(src=icon_node_constants.keystore_files_path,name="kesytore-{0}".format(id) ) + file_path = "" + file_name = "" + if len(uploaded_genesis) == 0: + plan.upload_files(src=genesis_file_path,name=genesis_file_name) + file_path = genesis_file_name + file_name = genesis_file_name + else: + file_path = uploaded_genesis["file_path"] + file_name = uploaded_genesis["file_name"] + icon_node_service_config = ServiceConfig( image=icon_node_constants.node_image, ports={ @@ -34,7 +46,7 @@ def start_icon_node(plan,service_config,id,start_file_name,genesis_file_path,gen icon_node_constants.config_files_directory : "config-files-{0}".format(id), icon_node_constants.contracts_directory : "contracts-{0}".format(id), icon_node_constants.keystore_directory : "kesytore-{0}".format(id), - icon_node_constants.genesis_file_path : genesis_file_path + icon_node_constants.genesis_file_path : file_path }, env_vars={ @@ -44,7 +56,7 @@ def start_icon_node(plan,service_config,id,start_file_name,genesis_file_path,gen "GOLOOP_P2P": ":%s" % p2p_address, "ICON_CONFIG": icon_node_constants.config_files_directory+"icon_config.json" }, - cmd= ["/bin/sh","-c",icon_node_constants.config_files_directory+"%s %s %s" % (start_file_name,cid,genesis_file_name)] + cmd= ["/bin/sh","-c",icon_node_constants.config_files_directory+"start.sh %s %s" % (cid,file_name)] ) @@ -59,6 +71,8 @@ def start_icon_node(plan,service_config,id,start_file_name,genesis_file_path,gen network = "{0}.icon".format(chain_id["output"]) + + return struct( service_name = service_name, network_name = network_name, @@ -86,12 +100,15 @@ def get_service_url(ip_address,ports,path): # Retruns Service Config def get_service_config(id,private_port,public_port,p2p_listen_address,p2p_address,cid): - return struct( - service_name = "{0}{1}".format(constants.ICON_NODE_CLIENT.service_name,id), - private_port = private_port, - public_port = public_port, - network_name = "icon-{0}".format(id), - p2p_listen_address = p2p_listen_address, - p2p_address = p2p_address, - cid = cid - ) \ No newline at end of file + config = { + "service_name" : "{0}{1}".format(constants.ICON_NODE_CLIENT.service_name,id), + "private_port" : private_port, + "public_port" : public_port, + "network_name" : "icon-{0}".format(id), + "p2p_listen_address" : p2p_listen_address, + "p2p_address" : p2p_address, + "cid":cid + } + + + return config \ No newline at end of file diff --git a/services/jvm/icon/static-files/config/start-icon-0.sh b/services/jvm/icon/static-files/config/start-icon-0.sh deleted file mode 100755 index 90d86c2b..00000000 --- a/services/jvm/icon/static-files/config/start-icon-0.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/sh - -start_chain() { - while true; do - RES=$(goloop system info 2>&1) - if [ "$?" == "0" ]; then - break - fi - sleep 1 - done - echo $RES - - CID=acbc4e - if [ ! -e ${GOLOOP_NODE_DIR}/${CID} ]; then - # join chain - GENESIS=/goloop/config/genesis-icon-0.zip - goloop chain join \ - --platform icon \ - --channel icon_dex \ - --genesis ${GENESIS} \ - --tx_timeout 10000 \ - --node_cache small \ - --normal_tx_pool 1000 \ - --db_type rocksdb \ - --role 3 - fi - goloop chain start 0x${CID} -} - -# start chain in backgound -start_chain & - -# start goloop server -exec goloop server start diff --git a/services/jvm/icon/static-files/config/start-icon.sh b/services/jvm/icon/static-files/config/start.sh similarity index 100% rename from services/jvm/icon/static-files/config/start-icon.sh rename to services/jvm/icon/static-files/config/start.sh From 582bbe7869a32e819a00c9fd2e32cf8831eaebf3 Mon Sep 17 00:00:00 2001 From: shreyasbhat0 Date: Mon, 17 Jul 2023 11:56:52 +0530 Subject: [PATCH 4/5] chore: update bridge --- package_io/constants.star | 2 +- services/jvm/icon/src/node-setup/contract_deploy.star | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/package_io/constants.star b/package_io/constants.star index 60155350..b77ff0de 100644 --- a/package_io/constants.star +++ b/package_io/constants.star @@ -1,5 +1,5 @@ ICON_NODE_CLIENT = struct( - node_image = "iconloop/goloop-icon:v1.3.7", + node_image = "iconloop/goloop-icon:v1.3.8", config_files_directory = "/goloop/config/", contracts_directory = "/goloop/contracts/", keystore_directory = "/goloop/keystores/", diff --git a/services/jvm/icon/src/node-setup/contract_deploy.star b/services/jvm/icon/src/node-setup/contract_deploy.star index 23eea494..db502a58 100644 --- a/services/jvm/icon/src/node-setup/contract_deploy.star +++ b/services/jvm/icon/src/node-setup/contract_deploy.star @@ -1,4 +1,4 @@ -DEFAULT_STEP_LIMIT = "500000000000" +DEFAULT_STEP_LIMIT = "5000000000000" """ Deploys Contract on Icon Chain @@ -17,6 +17,7 @@ def deploy_contract(plan,contract_name,init_message,args): execute_command = ["./bin/goloop","rpc","sendtx","deploy","contracts/"+contract,"--content_type","application/java","--params",init_message,"--key_store",keystore_path,"--key_password",keystore_password,"--step_limit",DEFAULT_STEP_LIMIT,"--uri",uri,"--nid",nid] + plan.print(execute_command) result = plan.exec(service_name=service_name,recipe=ExecRecipe(command=execute_command)) return result["output"] From f7600e95c2dd6ed99b82342fa87736002c63f72a Mon Sep 17 00:00:00 2001 From: shreyasbhat0 Date: Mon, 17 Jul 2023 12:19:59 +0530 Subject: [PATCH 5/5] chore: update setplimit --- services/jvm/icon/src/node-setup/contract_deploy.star | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/jvm/icon/src/node-setup/contract_deploy.star b/services/jvm/icon/src/node-setup/contract_deploy.star index db502a58..2ca63ae2 100644 --- a/services/jvm/icon/src/node-setup/contract_deploy.star +++ b/services/jvm/icon/src/node-setup/contract_deploy.star @@ -1,4 +1,4 @@ -DEFAULT_STEP_LIMIT = "5000000000000" +DEFAULT_STEP_LIMIT = "500000000000" """ Deploys Contract on Icon Chain