Skip to content

Commit

Permalink
refactor: refactor args in main.star and move setup ibc function from…
Browse files Browse the repository at this point in the history
… main.star to bridge.star (#199)

* refactor: refactor argument passing in icon's starlark and Go packages

* chore:change DiveRemotePackagePath in constant.go and RunStarlarkPackage to RunStarlarkRemotePackage in icon.go

* refactor: refactor argument passing  in icon's, eth's btp  setup starklark package

* refactor:  refactor icon's, eth's, btp, ibc bridge  kurtosis and go package of contract configuration, bridge btp

* fix: fix error getting while running single icon node through cli

* refactor: refactor args inside main.star and moving btp, ibc setup function in bridge.star respectively

* refactor: remove unnecessary spaces beween code lines
  • Loading branch information
abhiyana authored Oct 17, 2023
1 parent 181c6bc commit ed4ad82
Show file tree
Hide file tree
Showing 8 changed files with 459 additions and 125 deletions.
4 changes: 2 additions & 2 deletions cli/commands/bridge/relays/btp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -214,7 +214,7 @@ 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) {

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.DiveBridgeScript, mainFunctionName)
starlarkConfig := diveContext.GetStarlarkRunConfig(params, common.DiveBridgeBtpScript, mainFunctionName)
data, _, err := enclaveCtx.RunStarlarkRemotePackage(diveContext.Ctx, common.DiveRemotePackagePath, starlarkConfig)

if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions cli/commands/bridge/relays/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion cli/commands/bridge/relays/ibc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
28 changes: 2 additions & 26 deletions cli/commands/chain/types/icon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

_, 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(`{"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")
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")
Expand Down
3 changes: 2 additions & 1 deletion cli/common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading

0 comments on commit ed4ad82

Please sign in to comment.