Skip to content

Commit

Permalink
feat!: local-ic remove relayer file dependency (#908) (#909)
Browse files Browse the repository at this point in the history
* Remove `relayer.json` in favor of CLI arguments

* py: make nested directories for config

* git keep `configs`

* exist_ok=True

* remove .gitkeep

* remove forced `config` directory check

(cherry picked from commit b85a060)

Co-authored-by: Reece Williams <[email protected]>
  • Loading branch information
mergify[bot] and Reecepbcups authored Dec 14, 2023
1 parent 0feecac commit 99786bb
Show file tree
Hide file tree
Showing 14 changed files with 100 additions and 100 deletions.
30 changes: 15 additions & 15 deletions .github/workflows/local-interchain.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ jobs:
with:
go-version: ${{ env.GO_VERSION }}

- name: build local-interchain
- name: build local-interchain
run: go mod tidy && make install

- name: Upload localic artifact
uses: actions/upload-artifact@v3
with:
name: local-ic
path: ~/go/bin/local-ic
path: ~/go/bin/local-ic


rust-e2e:
Expand All @@ -46,7 +46,7 @@ jobs:
working-directory: ./local-interchain
strategy:
fail-fast: false

steps:
- name: checkout chain
uses: actions/checkout@v3
Expand All @@ -64,17 +64,17 @@ jobs:
with:
name: local-ic
path: /tmp

- name: Make local-ic executable
run: chmod +x /tmp/local-ic

- name: Start background ibc local-interchain
- name: Start background ibc local-interchain
run: /tmp/local-ic start juno_ibc --api-port 8080 &

- name: Run Rust Script
run: cd rust && cargo run --package localic-bin --bin localic-bin

- name: Cleanup
- name: Cleanup
run: killall local-ic && exit 0

python-e2e:
Expand All @@ -85,12 +85,12 @@ jobs:
run:
working-directory: ./local-interchain
strategy:
matrix:
test:
matrix:
test:
- ["api_test", 8081]
- ["ibc_contract", 8082]
fail-fast: false

steps:
- name: checkout chain
uses: actions/checkout@v3
Expand All @@ -100,22 +100,22 @@ jobs:
with:
python-version: '3.10'
cache: 'pip'
- run: pip install -r python/requirements.txt --break-system-packages
- run: pip install -r python/requirements.txt --break-system-packages

- name: Download Tarball Artifact
uses: actions/download-artifact@v3
with:
name: local-ic
path: /tmp

- name: Make local-ic executable
run: chmod +x /tmp/local-ic

- name: Start background ibc local-interchain
run: /tmp/local-ic start juno_ibc --api-port ${{ matrix.test[1] }} &
- name: Run Python Script

- name: Run Python Script
run: python3 ./python/${{ matrix.test[0] }}.py --api-port ${{ matrix.test[1] }}

- name: Cleanup
- name: Cleanup
run: killall local-ic && exit 0
25 changes: 13 additions & 12 deletions local-interchain/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ A simple way to config and run IBC local chain testing environments with any lan

**Install on Mac / Linux**
```bash
git clone https://github.com/strangelove-ventures/interchaintest.git
git clone https://github.com/strangelove-ventures/interchaintest.git

cd interchaintest/local-interchain

Expand All @@ -24,14 +24,15 @@ Follow [this guide](./docs/WINDOWS.md) to setup the Windows OS environment for i

## Running

- *(optional)* Edit `./configs/relayer.json`
- Copy: `cp ./configs/base_ibc.json ./configs/mytest1_ignored.json`
- Run: `local-ic start mytest1_ignored.json`
- Run in different directory: `ICTEST_HOME=/root/local-interchain local-ic start myother_ignored.json`
- Run: `local-ic start mytest1_ignored.json [flags]`
- Run in different directory: `ICTEST_HOME=/root/local-interchain local-ic start myother_ignored.json [flags]`

Modify the relayer information on `start` with the --relayer-* flags.

**NOTE** The ICTEST_HOME path must contain the directories `chains` and `configs` to be valid.

*(Default: `make install` links to the cloned directory. `go install .` will use your home directory /local-interchain)*
*(Default: `make install` links to the cloned directory. `go install .` will use your home directory ~/local-interchain)*

*(Ending the config file with `_ignored.json` or `_ignore.json` will ignore it from git)*

Expand Down Expand Up @@ -71,12 +72,12 @@ Read more about the API [here](./docs/REST_API.md)

```json
{
"name": "juno",
"name": "juno",
"chain_id": "localjuno-2",
"denom": "ujuno",
"docker_image": {
"docker_image": {
"version": "v14.1.0"
},
},
"gas_prices": "0%DENOM%",
"gas_adjustment": 2.0
}
Expand All @@ -90,7 +91,7 @@ Here is a base chain template with every feature the configuration accepts. Acco

```json
{
"name": "juno",
"name": "juno",
"chain_id": "localjuno-1",
"denom": "ujuno",
"binary": "junod",
Expand All @@ -106,7 +107,7 @@ Here is a base chain template with every feature the configuration accepts. Acco
"gas_prices": "0%DENOM%",
"gas_adjustment": 2.0,
"number_vals": 1,
"number_node": 0,
"number_node": 0,
"ibc_paths": ["juno-ibc-1"],
"debugging": true,
"block_time": "500ms",
Expand All @@ -125,15 +126,15 @@ Here is a base chain template with every feature the configuration accepts. Acco
"key": "app_state.gov.deposit_params.min_deposit.0.denom",
"value": "ujuno"
}
],
],
"accounts": [
{
"name": "acc0",
"address": "juno1efd63aw40lxf3n4mhf7dzhjkr453axurv2zdzk",
"amount": "10000000%DENOM%",
"mnemonic": "decorate bright ozone fork gallery riot bus exhaust worth way bone indoor calm squirrel merry zero scheme cotton until shop any excess stage laundry"
}
]
]
}
},
```
2 changes: 1 addition & 1 deletion local-interchain/cmd/local-ic/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func GetDirectory() string {
MakeFileInstallDirectory = path.Join(dirname, "local-interchain")
}

if err := directoryRequirementChecks(MakeFileInstallDirectory, "configs", "chains"); err != nil {
if err := directoryRequirementChecks(MakeFileInstallDirectory, "chains"); err != nil {
log.Fatal(err)
}

Expand Down
26 changes: 26 additions & 0 deletions local-interchain/cmd/local-ic/start_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@ package main
import (
"path"
"path/filepath"
"strings"

"github.com/spf13/cobra"
"github.com/strangelove-ventures/localinterchain/interchain"
"github.com/strangelove-ventures/localinterchain/interchain/types"
)

const (
FlagAPIAddressOverride = "api-address"
FlagAPIPortOverride = "api-port"

FlagRelayerImage = "relayer-image"
FlagRelayerVersion = "relayer-version"
FlagRelayerUidGid = "relayer-uidgid"
FlagRelayerStartupFlags = "relayer-startup-flags"
)

var startCmd = &cobra.Command{
Expand All @@ -35,14 +42,33 @@ var startCmd = &cobra.Command{
apiAddr, _ := cmd.Flags().GetString(FlagAPIAddressOverride)
apiPort, _ := cmd.Flags().GetUint16(FlagAPIPortOverride)

relayerImg := cmd.Flag(FlagRelayerImage).Value.String()
relayerVer := cmd.Flag(FlagRelayerVersion).Value.String()
relayerUidGid := cmd.Flag(FlagRelayerUidGid).Value.String()
relayerFlags := strings.Split(cmd.Flag(FlagRelayerStartupFlags).Value.String(), " ")

interchain.StartChain(parentDir, configPath, &interchain.AppConfig{
Address: apiAddr,
Port: apiPort,

Relayer: types.Relayer{
DockerImage: types.DockerImage{
Repository: relayerImg,
Version: relayerVer,
UidGid: relayerUidGid,
},
StartupFlags: relayerFlags,
},
})
},
}

func init() {
startCmd.Flags().String(FlagAPIAddressOverride, "127.0.0.1", "override the default API address")
startCmd.Flags().Uint16(FlagAPIPortOverride, 8080, "override the default API port")

startCmd.Flags().String(FlagRelayerImage, "ghcr.io/cosmos/relayer", "override the docker relayer image")
startCmd.Flags().String(FlagRelayerVersion, "latest", "override the default relayer version")
startCmd.Flags().String(FlagRelayerUidGid, "100:1000", "override the default image UID:GID")
startCmd.Flags().String(FlagRelayerStartupFlags, "--block-history=100", "override the default relayer startup flags")
}
9 changes: 0 additions & 9 deletions local-interchain/configs/relayer.json

This file was deleted.

8 changes: 0 additions & 8 deletions local-interchain/interchain/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,15 @@ func LoadConfig(installDir, chainCfgFile string) (*types.Config, error) {
chainsDir := filepath.Join(installDir, "chains")
cfgFilePath := filepath.Join(chainsDir, configFile)

// configs Folder
configsDir := filepath.Join(installDir, "configs")
relayerFilePath := filepath.Join(configsDir, "relayer.json")

config, err := loadConfig(config, cfgFilePath)
if err != nil {
return nil, err
}
config, _ = loadConfig(config, relayerFilePath)

log.Println("Using directory:", installDir)
log.Println("Using chain config:", cfgFilePath)

chains := config.Chains
relayer := config.Relayer

for i := range chains {
chain := chains[i]
Expand All @@ -73,8 +67,6 @@ func LoadConfig(installDir, chainCfgFile string) (*types.Config, error) {
}
}

config.Relayer = relayer.SetRelayerDefaults()

return config, nil
}

Expand Down
6 changes: 4 additions & 2 deletions local-interchain/interchain/handlers/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,13 @@ func (a *actions) relayerCheck(w http.ResponseWriter, r *http.Request) error {

func KillAll(ctx context.Context, ic *interchaintest.Interchain, vals map[string]*cosmos.ChainNode, relayer ibc.Relayer, eRep ibc.RelayerExecReporter) {
if relayer != nil {
relayer.StopRelayer(ctx, eRep)
if err := relayer.StopRelayer(ctx, eRep); err != nil {
panic(err)
}
}

for _, v := range vals {
go v.StopContainer(ctx)
go v.StopContainer(ctx) // nolint:errcheck
}

ic.Close()
Expand Down
9 changes: 7 additions & 2 deletions local-interchain/interchain/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ import (
)

func WriteRunningChains(configsDir string, bz []byte) {
filepath := filepath.Join(configsDir, "configs", "logs.json")
_ = os.WriteFile(filepath, bz, 0644)
path := filepath.Join(configsDir, "configs")
if _, err := os.Stat(path); os.IsNotExist(err) {
os.MkdirAll(path, os.ModePerm)
}

file := filepath.Join(path, "logs.json")
_ = os.WriteFile(file, bz, 0644)
}

func DumpChainsInfoToLogs(configDir string, config *types.Config, chains []ibc.Chain, connections []types.IBCChannel) {
Expand Down
13 changes: 11 additions & 2 deletions local-interchain/interchain/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
type AppConfig struct {
Address string
Port uint16

Relayer types.Relayer
}

func StartChain(installDir, chainCfgFile string, ac *AppConfig) {
Expand Down Expand Up @@ -63,6 +65,8 @@ func StartChain(installDir, chainCfgFile string, ac *AppConfig) {
}
}

config.Relayer = ac.Relayer

WriteRunningChains(installDir, []byte("{}"))

// ibc-path-name -> index of []cosmos.CosmosChain
Expand Down Expand Up @@ -151,9 +155,14 @@ func StartChain(installDir, chainCfgFile string, ac *AppConfig) {
paths = append(paths, k)
}

relayer.StartRelayer(ctx, eRep, paths...)
if err := relayer.StartRelayer(ctx, eRep, paths...); err != nil {
log.Fatal("relayer.StartRelayer", err)
}

defer func() {
relayer.StopRelayer(ctx, eRep)
if err := relayer.StopRelayer(ctx, eRep); err != nil {
log.Fatal("relayer.StopRelayer", err)
}
}()
}

Expand Down
22 changes: 0 additions & 22 deletions local-interchain/interchain/types/relayer.go

This file was deleted.

5 changes: 5 additions & 0 deletions local-interchain/interchain/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ type DockerImage struct {
UidGid string `json:"uid_gid"`
}

type Relayer struct {
DockerImage DockerImage `json:"docker_image"`
StartupFlags []string `json:"startup_flags"`
}

type IBCChannel struct {
ChainID string `json:"chain_id"`
Channel *ibc.ChannelOutput `json:"channel"`
Expand Down
2 changes: 2 additions & 0 deletions local-interchain/python/helpers/file_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Cache:
@staticmethod
def reset_contracts_cache_json():
if not os.path.exists(contracts_json_path):
os.makedirs(os.path.dirname(contracts_json_path), exist_ok=True)
with open(contracts_json_path, "w") as f:
f.write(json.dumps({"start_time": 0, "file_cache": {}}))

Expand All @@ -33,6 +34,7 @@ def get_chain_start_time_from_logs() -> int:
def get_cache_or_default(contracts: dict, ictest_chain_start: int) -> dict:
cache_time: str | int = 0
if os.path.exists(contracts_json_path):
os.makedirs(os.path.dirname(contracts_json_path), exist_ok=True)
with open(contracts_json_path, "r") as f:
c = dict(json.load(f))
cache_time = c.get("start_time", 0)
Expand Down
Loading

0 comments on commit 99786bb

Please sign in to comment.