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

Initial working model of client with kubectl cmd runner #143

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- main
- anmol/remote-exec-commands
release:
types:
- published
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@ Session.vim
.history

# Ignore docs site created
**/site/
**/site/

tests/.kubeconfig
2 changes: 1 addition & 1 deletion charts/devnet/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.38
version: 0.1.39-rc5

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
Expand Down
5 changes: 3 additions & 2 deletions charts/devnet/scripts/setup_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,20 @@ sed -i -e 's/timeout_commit = "5s"/timeout_commit = "1s"/g' $CHAIN_DIR/config/co
sed -i -e 's/timeout_propose = "3s"/timeout_propose = "1s"/g' $CHAIN_DIR/config/config.toml
sed -i -e 's/index_all_keys = false/index_all_keys = true/g' $CHAIN_DIR/config/config.toml
sed -i -e 's/seeds = ".*"/seeds = ""/g' $CHAIN_DIR/config/config.toml

sed -i -e 's#cors_allowed_origins = \[\]#cors_allowed_origins = \["*"\]#g' $CHAIN_DIR/config/config.toml

echo "Update client.toml file"
sed -i -e 's#keyring-backend = "os"#keyring-backend = "test"#g' $CHAIN_DIR/config/client.toml
sed -i -e 's#output = "text"#output = "json"#g' $CHAIN_DIR/config/client.toml
sed -i -e "s#chain-id = \"\"#chain-id = \"$CHAIN_ID\"#g" $CHAIN_DIR/config/client.toml


echo "Update app.toml file"
sed -i -e "s#minimum-gas-prices = \".*\"#minimum-gas-prices = \"0$DENOM\"#g" $CHAIN_DIR/config/app.toml
sed -i -e "s#pruning = \".*\"#pruning = \"default\"#g" $CHAIN_DIR/config/app.toml
sed -i -e 's#enabled-unsafe-cors = false#enabled-unsafe-cors = true#g' $CHAIN_DIR/config/app.toml
sed -i -e 's#swagger = false#swagger = true#g' $CHAIN_DIR/config/app.toml
sed -i -e 's/enable-unsafe-cors = false/enable-unsafe-cors = true/g' $CHAIN_DIR/config/app.toml
sed -i -e 's/enabled-unsafe-cors = false/enabled-unsafe-cors = true/g' $CHAIN_DIR/config/app.toml

function get_next_line_number() {
local txt=$1
Expand Down
30 changes: 23 additions & 7 deletions charts/devnet/scripts/setup_genesis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,26 @@ echo "Update genesis.json file with updated local params"
sed -i -e "s/\"stake\"/\"$DENOM\"/g" $CHAIN_DIR/config/genesis.json
sed -i "s/\"time_iota_ms\": \".*\"/\"time_iota_ms\": \"$TIME_IOTA_MS\"/" $CHAIN_DIR/config/genesis.json

jq -r '.app_state.staking.params.unbonding_time |= "90s"' $CHAIN_DIR/config/genesis.json > /tmp/genesis.json; mv /tmp/genesis.json $CHAIN_DIR/config/genesis.json
jq -r '.app_state.staking.params.unbonding_time |= "200s"' $CHAIN_DIR/config/genesis.json > /tmp/genesis.json; mv /tmp/genesis.json $CHAIN_DIR/config/genesis.json
jq -r '.app_state.slashing.params.downtime_jail_duration |= "6s"' $CHAIN_DIR/config/genesis.json > /tmp/genesis.json; mv /tmp/genesis.json $CHAIN_DIR/config/genesis.json
jq -r '.app_state.gov.deposit_params.max_deposit_period |= "30s"' $CHAIN_DIR/config/genesis.json > /tmp/genesis.json; mv /tmp/genesis.json $CHAIN_DIR/config/genesis.json
jq -r '.app_state.gov.deposit_params.min_deposit[0].amount |= "10"' $CHAIN_DIR/config/genesis.json > /tmp/genesis.json; mv /tmp/genesis.json $CHAIN_DIR/config/genesis.json
jq -r '.app_state.gov.voting_params.voting_period |= "30s"' $CHAIN_DIR/config/genesis.json > /tmp/genesis.json; mv /tmp/genesis.json $CHAIN_DIR/config/genesis.json
jq -r '.app_state.gov.tally_params.quorum |= "0.000000000000000000"' $CHAIN_DIR/config/genesis.json > /tmp/genesis.json; mv /tmp/genesis.json $CHAIN_DIR/config/genesis.json
jq -r '.app_state.gov.tally_params.threshold |= "0.000000000000000000"' $CHAIN_DIR/config/genesis.json > /tmp/genesis.json; mv /tmp/genesis.json $CHAIN_DIR/config/genesis.json
jq -r '.app_state.gov.tally_params.veto_threshold |= "0.000000000000000000"' $CHAIN_DIR/config/genesis.json > /tmp/genesis.json; mv /tmp/genesis.json $CHAIN_DIR/config/genesis.json

# overide for non 47 sdk
if [ "$(jq -r '.app_state.gov.params' $CHAIN_DIR/config/genesis.json)" == "null" ]; then
jq -r '.app_state.gov.deposit_params.max_deposit_period |= "30s"' $CHAIN_DIR/config/genesis.json > /tmp/genesis.json; mv /tmp/genesis.json $CHAIN_DIR/config/genesis.json
jq -r '.app_state.gov.deposit_params.min_deposit[0].amount |= "10"' $CHAIN_DIR/config/genesis.json > /tmp/genesis.json; mv /tmp/genesis.json $CHAIN_DIR/config/genesis.json
jq -r '.app_state.gov.voting_params.voting_period |= "30s"' $CHAIN_DIR/config/genesis.json > /tmp/genesis.json; mv /tmp/genesis.json $CHAIN_DIR/config/genesis.json
jq -r '.app_state.gov.tally_params.quorum |= "0.000000000000000000"' $CHAIN_DIR/config/genesis.json > /tmp/genesis.json; mv /tmp/genesis.json $CHAIN_DIR/config/genesis.json
jq -r '.app_state.gov.tally_params.threshold |= "0.000000000000000000"' $CHAIN_DIR/config/genesis.json > /tmp/genesis.json; mv /tmp/genesis.json $CHAIN_DIR/config/genesis.json
jq -r '.app_state.gov.tally_params.veto_threshold |= "0.000000000000000000"' $CHAIN_DIR/config/genesis.json > /tmp/genesis.json; mv /tmp/genesis.json $CHAIN_DIR/config/genesis.json
else
# overrides for 47 sdk
jq -r '.app_state.gov.params.max_deposit_period |= "30s"' $CHAIN_DIR/config/genesis.json > /tmp/genesis.json; mv /tmp/genesis.json $CHAIN_DIR/config/genesis.json
jq -r '.app_state.gov.params.min_deposit[0].amount |= "10"' $CHAIN_DIR/config/genesis.json > /tmp/genesis.json; mv /tmp/genesis.json $CHAIN_DIR/config/genesis.json
jq -r '.app_state.gov.params.voting_period |= "30s"' $CHAIN_DIR/config/genesis.json > /tmp/genesis.json; mv /tmp/genesis.json $CHAIN_DIR/config/genesis.json
jq -r '.app_state.gov.params.quorum |= "0.000000000000000000"' $CHAIN_DIR/config/genesis.json > /tmp/genesis.json; mv /tmp/genesis.json $CHAIN_DIR/config/genesis.json
jq -r '.app_state.gov.params.threshold |= "0.000000000000000000"' $CHAIN_DIR/config/genesis.json > /tmp/genesis.json; mv /tmp/genesis.json $CHAIN_DIR/config/genesis.json
jq -r '.app_state.gov.params.veto_threshold |= "0.000000000000000000"' $CHAIN_DIR/config/genesis.json > /tmp/genesis.json; mv /tmp/genesis.json $CHAIN_DIR/config/genesis.json
fi
# Set wasm as permissioned or permissionless based on environment variable
wasm_permission="Nobody"
if [ $WASM_PERMISSIONLESS == "true" ]
Expand All @@ -54,4 +65,9 @@ fi
jq -r ".app_state.wasm.params.code_upload_access.permission |= \"${wasm_permission}\"" $CHAIN_DIR/config/genesis.json > /tmp/genesis.json; mv /tmp/genesis.json $CHAIN_DIR/config/genesis.json
jq -r ".app_state.wasm.params.instantiate_default_permission |= \"${wasm_permission}\"" $CHAIN_DIR/config/genesis.json > /tmp/genesis.json; mv /tmp/genesis.json $CHAIN_DIR/config/genesis.json

if [ "$CHAIN_BIN" == "meshd" ]
then
jq -r ".app_state.meshsecurity.params.epoch_length |= \"10\"" $CHAIN_DIR/config/genesis.json > /tmp/genesis.json; mv /tmp/genesis.json $CHAIN_DIR/config/genesis.json
fi

$CHAIN_BIN tendermint show-node-id
1 change: 1 addition & 0 deletions charts/devnet/templates/chain/genesis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ spec:
labels:
app.kubernetes.io/instance: {{ $chain.type }}
app.kubernetes.io/type: {{ $chain.name }}
app.kubernetes.io/rawname: {{ $chain.name }}
app.kubernetes.io/name: {{ $chain.name }}-genesis
app.kubernetes.io/version: {{ $.Chart.AppVersion }}
spec:
Expand Down
3 changes: 3 additions & 0 deletions charts/devnet/templates/chain/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ metadata:
labels:
app.kubernetes.io/name: {{ $chain.name }}-genesis
spec:
{{- if eq $.Values.service.type "ClusterIP" }}
clusterIP: None
{{- end }}
type: {{ $.Values.service.type }}
ports:
{{- range $name, $port := $portMap }}
- name: {{ $name }}
Expand Down
3 changes: 3 additions & 0 deletions charts/devnet/templates/collector.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ metadata:
labels:
app.kubernetes.io/name: collector
spec:
{{- if eq $.Values.service.type "ClusterIP" }}
clusterIP: None
{{- end }}
type: {{ $.Values.service.type }}
ports:
- name: http
port: 8070
Expand Down
4 changes: 4 additions & 0 deletions charts/devnet/templates/explorer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ metadata:
labels:
app.kubernetes.io/name: explorer
spec:
{{- if eq $.Values.service.type "ClusterIP" }}
clusterIP: None
{{- end }}
type: {{ $.Values.service.type }}
ports:
- name: http
port: 8080
Expand Down Expand Up @@ -81,6 +84,7 @@ data:
{{- if not $.Values.explorer.localhost }}
{{ $host := printf "%s-genesis.%s.svc.cluster.local" $chain.name $.Release.Namespace }}
{{- end }}
{{/*todo: chain rpc would need to be converted to external ip for service LoadBalancer*/}}
{{ $chain.name }}.json: |-
{
"chain_name": "{{ $chain.name }}",
Expand Down
3 changes: 3 additions & 0 deletions charts/devnet/templates/registry.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ metadata:
labels:
app.kubernetes.io/name: registry
spec:
{{- if eq $.Values.service.type "ClusterIP" }}
clusterIP: None
{{- end }}
type: {{ $.Values.service.type }}
ports:
- name: http
port: 8080
Expand Down
4 changes: 2 additions & 2 deletions charts/devnet/templates/relayers/hermes/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ data:
# Interval (in number of blocks) at which pending packets
# should be periodically cleared. A value of '0' will disable
# periodic packet clearing. [Default: 100]
clear_interval = 100
clear_interval = 50
# Whether or not to clear packets on start. [Default: false]
clear_on_start = true
# Toggle the transaction confirmation mechanism.
Expand Down Expand Up @@ -88,9 +88,9 @@ data:
key_name = "{{ $chain }}"
rpc_addr = "http://{{ $chain }}-genesis.{{ $.Release.Namespace }}.svc.cluster.local:26657"
grpc_addr = "http://{{ $chain }}-genesis.{{ $.Release.Namespace }}.svc.cluster.local:9090"
websocket_addr = "ws://{{ $chain }}-genesis.{{ $.Release.Namespace }}.svc.cluster.local:26657/websocket"
account_prefix = "{{ $fullchain.prefix }}"
gas_price = { price = 0.25, denom = "{{ $fullchain.denom }}" }
event_source = { mode = 'push', url = 'ws://{{ $chain }}-genesis.{{ $.Release.Namespace }}.svc.cluster.local:26657/websocket', batch_delay = '100ms' }
default_gas = 500000000
max_gas = 1000000000
rpc_timeout = "10s"
Expand Down
1 change: 1 addition & 0 deletions charts/devnet/templates/relayers/hermes/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ spec:
labels:
app.kubernetes.io/instance: relayer
app.kubernetes.io/type: {{ $relayer.type }}
app.kubernetes.io/rawname: {{ $relayer.name }}
app.kubernetes.io/name: {{ $relayer.type }}-{{ $relayer.name }}
app.kubernetes.io/version: {{ $.Chart.AppVersion }}
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ spec:
labels:
app.kubernetes.io/instance: relayer
app.kubernetes.io/type: {{ $relayer.type }}
app.kubernetes.io/rawname: {{ $relayer.name }}
app.kubernetes.io/name: {{ $relayer.type }}-{{ $relayer.name }}
app.kubernetes.io/version: {{ $.Chart.AppVersion }}
spec:
Expand Down
5 changes: 4 additions & 1 deletion charts/devnet/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ resources:
cpu: "0.1"
memory: "100M"

service:
type: ClusterIP

exposer:
image: ghcr.io/cosmology-tech/starship/exposer:20230617-eea58bd
ports:
Expand Down Expand Up @@ -345,7 +348,7 @@ explorer:

registry:
enabled: false
image: ghcr.io/cosmology-tech/starship/registry:20230614-7173db2
image: ghcr.io/cosmology-tech/starship/registry:20230705-8892590
ports:
rest: 6060
grpc: 7070
Expand Down
1 change: 1 addition & 0 deletions clients/go/client/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go_library(
srcs = [
"chain.go",
"config.go",
"runner.go",
],
importpath = "github.com/cosmology-tech/starship/clients/go/client",
visibility = ["//visibility:public"],
Expand Down
53 changes: 46 additions & 7 deletions clients/go/client/chain.go
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
package client

import (
"bytes"
"context"
"encoding/json"
"fmt"
"net/http"
"os"

coretypes "github.com/cometbft/cometbft/rpc/core/types"
pb "github.com/cosmology-tech/starship/registry/registry"
"github.com/cosmos/cosmos-sdk/client/tx"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/go-bip39"
"github.com/golang/protobuf/jsonpb"
lens "github.com/strangelove-ventures/lens/client"
coretypes "github.com/tendermint/tendermint/rpc/core/types"
"go.uber.org/zap"

pb "github.com/cosmology-tech/starship/registry/registry"
)

type ChainClients []*ChainClient

func NewChainClients(logger *zap.Logger, config *Config) (ChainClients, error) {
func NewChainClients(logger *zap.Logger, config *Config, chainModuleBasic map[string][]module.AppModuleBasic) (ChainClients, error) {
var clients []*ChainClient
var moduleBasic []module.AppModuleBasic
for _, chain := range config.Chains {
client, err := NewChainClient(logger, config, chain.Name)
if chainModuleBasic != nil {
moduleBasic = chainModuleBasic[chain.Name]
}
client, err := NewChainClient(logger, config, chain.Name, moduleBasic)
if err != nil {
logger.Error("unable to create client for chain",
zap.String("chain_id", chain.Name),
Expand Down Expand Up @@ -58,9 +64,12 @@ type ChainClient struct {
Client *lens.ChainClient
}

func NewChainClient(logger *zap.Logger, config *Config, chainID string) (*ChainClient, error) {
func NewChainClient(logger *zap.Logger, config *Config, chainID string, moduleBasics []module.AppModuleBasic) (*ChainClient, error) {
cc := config.GetChain(chainID)

if moduleBasics == nil {
moduleBasics = lens.ModuleBasics
}
chainClient := &ChainClient{
Logger: logger,
Config: config,
Expand All @@ -85,7 +94,7 @@ func NewChainClient(logger *zap.Logger, config *Config, chainID string) (*ChainC
GasPrices: fmt.Sprintf("%f%s", registry.Fees.FeeTokens[0].HighGasPrice, registry.Fees.FeeTokens[0].Denom),
MinGasAmount: 10000,
Slip44: int(registry.Slip44),
Modules: lens.ModuleBasics,
Modules: moduleBasics,
}

client, err := lens.NewChainClient(logger, ccc, os.Getenv("HOME"), os.Stdin, os.Stdout)
Expand Down Expand Up @@ -170,6 +179,9 @@ func (c *ChainClient) CreateWallet(keyName, mnemonic string) (string, error) {
}

func (c *ChainClient) CreateRandWallet(keyName string) (string, error) {
// delete key if already exists
_ = c.Client.DeleteKey(keyName)

entropy, err := bip39.NewEntropy(256)
if err != nil {
return "", err
Expand Down Expand Up @@ -277,6 +289,33 @@ func (c *ChainClient) GetStatus() (*coretypes.ResultStatus, error) {
return status, nil
}

// CreditFromFaucet will request facuet of the chain for tokens to address
func (c *ChainClient) CreditFromFaucet(address string) error {
url := fmt.Sprintf("%s/credit", c.Config.GetChain(c.ChainID).GetFaucetAddr())

body := map[string]string{
"address": address,
"denom": c.MustGetChainDenom(),
}

jsonBody, err := json.Marshal(body)
if err != nil {
return err
}

res, err := http.Post(url, "application/json", bytes.NewBuffer(jsonBody))
if err != nil {
return err
}

// Check the response status code
if res.StatusCode != http.StatusOK {
return fmt.Errorf("request failed with status code:", res.StatusCode)
}

return nil
}

func (c *ChainClient) GetHeight() (int64, error) {
status, err := c.GetStatus()
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions clients/go/client/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ func (c *Chain) GetRESTAddr() string {
return fmt.Sprintf("http://localhost:%d", c.Ports.Rest)
}

func (c *Chain) GetFaucetAddr() string {
return fmt.Sprintf("http://localhost:%d", c.Ports.Faucet)
}

type Upgrade struct {
Enabled bool `name:"eanbled" json:"enabled" yaml:"enabled"`
Type string `name:"type" json:"type" yaml:"type"`
Expand All @@ -35,6 +39,7 @@ type Port struct {
Rpc int `name:"rpc" json:"rpc" yaml:"rpc"`
Grpc int `name:"grpc" json:"grpc" yaml:"grpc"`
Exposer int `name:"exposer" json:"exposer" yaml:"exposer"`
Faucet int `name:"faucet" json:"faucet" yaml:"faucet"`
}

type Relayer struct {
Expand Down
Loading