Skip to content

Commit

Permalink
perf: refactor args in dive starlark package (#198)
Browse files Browse the repository at this point in the history
* refactor: refactor argument passing in the starlark and go package of neutron and archway (#191)

* refactor: refactor argument passing in the starlark and go package of neutron and archway

* chore: remove print statement

* chore: remove services json

* chore: format document

* ref: update doc strings  and formatting

* chore: update string

---------

Co-authored-by: shreyasbhat0 <[email protected]>

* refactor: refactor argument passing in eth's starlark and go package (#192)

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

* refactor: refactor argument passing in eth's contract configuration starlark and Go packages

* refactor: add doc strings in eth starlark package

* refactor: refactor argument passing in icon's starlark and Go packages for starting node (#195)

* 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 icon's, eth's, btp, ibc bridge  kurtosis and go package of contract configuration, bridge btp (#197)

* 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

* refactor: refactor args in main.star and move setup ibc function from 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

* refactor: remove unnecessary code from input_parser.star and main.star (#201)

* 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

* refactor: removing unnecessary code from main.star and bridge.star

* refactor: remove unnecessary code from input_parser.star

---------

Co-authored-by: Abhishek Harde <[email protected]>
  • Loading branch information
shreyasbhat0 and abhiyana authored Oct 18, 2023
1 parent 6cdcdb8 commit 076867f
Show file tree
Hide file tree
Showing 13 changed files with 167 additions and 472 deletions.
9 changes: 3 additions & 6 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 @@ -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 {
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
4 changes: 2 additions & 2 deletions cli/commands/bridge/relays/ibc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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
75 changes: 17 additions & 58 deletions cli/commands/chain/types/archway.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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) {
Expand Down Expand Up @@ -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())
}
Expand All @@ -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())

Expand Down
2 changes: 1 addition & 1 deletion cli/commands/chain/types/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
34 changes: 4 additions & 30 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())
}

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")
Expand Down Expand Up @@ -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) {
Expand Down
28 changes: 16 additions & 12 deletions cli/commands/chain/types/neutron.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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.
Expand Down Expand Up @@ -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())
}
Expand All @@ -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
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
2 changes: 1 addition & 1 deletion cli/sample-jsons/archway.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"cid": "archway-node-0",
"chain_id": "archway-node-0",
"key": "archway-node-0-key",
"private_grpc": 9090,
"private_http": 9091,
Expand Down
2 changes: 1 addition & 1 deletion cli/sample-jsons/archway1.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"cid": "archway-node-1",
"chain_id": "archway-node-1",
"key": "archway-node-1-key",
"private_grpc": 9090,
"private_http": 9091,
Expand Down
2 changes: 1 addition & 1 deletion cli/sample-jsons/neutron.json
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion cli/sample-jsons/neutron1.json
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Loading

0 comments on commit 076867f

Please sign in to comment.