Skip to content

Commit

Permalink
ci(docker): fix chaosnet and add profiles (#1937)
Browse files Browse the repository at this point in the history
* chore: delete multi-node docker compose file

* fix: enable gRPC server

* feat: add profiles and remove liquidator/faucet

* fix: force go-heartmonitor linux/amd64

* feat: add make commands for chaosnet-ibc and chaosnet-heartmonitor

* chore: update docs
  • Loading branch information
k-yang authored Jun 26, 2024
1 parent cc4ddd4 commit 4a73c37
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 139 deletions.
21 changes: 12 additions & 9 deletions CHAOSNET.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,18 @@

Chaosnet is an expanded version of localnet that runs:

- two validators (nibiru-0 and nibiru-1)
- up to two validators (nibiru-0 and nibiru-1)
- pricefeeders for each validator
- a hermes relayer between the two validators
- a faucet
- a postgres:14 database
- a heartmonitor instance
- a liquidator instance
- a graphql server
- a hermes relayer between the two validators (if the `ibc` profile is used)
- a postgres:14 database (if the `heartmonitor` profile is used)
- a heartmonitor instance (if the `heartmonitor` profile is used)
- a graphql server (if the `heartmonitor` profile is used)

## How to run "chaosnet"

1. Make sure you have [Docker](https://docs.docker.com/engine/install/) installed and running
2. Make sure you have `make` installed
3. Docker login to ghcr.io
3. (Optional) Docker login to ghcr.io (only if you want to use the `heartmonitor` profile)

```bash
docker login ghcr.io
Expand All @@ -42,9 +40,14 @@ Enter your GitHub username for the `username` field, and your personal access to

Note that this will take a while the first time you run it, as it will need to pull all the images from the registry, build the chaonset image locally, and set up the IBC channel (which has a lot of round trip packet commits).

Other profiles include

- `make chaosnet-ibc`: creates two validator instances and a hermes relayer
- `make chaosnet-heartmonitor`: single validator with heartmonitor+graphql instance

## How to force pull images from the registry

By default, most images (heart-monitor, liquidator, etc.) are cached locally and won't re-fetch from upstream registries. To force a pull, you can run
By default, most images (heartmonitor, etc.) are cached locally and won't re-fetch from upstream registries. To force a pull, you can run

```sh
make chaosnet-build
Expand Down
67 changes: 42 additions & 25 deletions contrib/docker-compose/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
# contrib/docker-compose

- [docker-compose-chaosnet](#docker-compose-chaosnet)
- [Usage Commands:](#usage-commands)
- [Nibiru node services](#nibiru-node-services)
- [Oracle feeder services](#oracle-feeder-services)
- [Hermes IBC relayer services](#hermes-ibc-relayer-services)
- [Faucet Service](#faucet-service)
- [Heart Monitor Services](#heart-monitor-services)
- [Reference Materials](#reference-materials)
- [contrib/docker-compose](#contribdocker-compose)
- [docker-compose-chaosnet](#docker-compose-chaosnet)
- [Usage](#usage)
- [Single validator node + pricefeeder](#single-validator-node--pricefeeder)
- [Two validator nodes + pricefeeder + IBC relayer](#two-validator-nodes--pricefeeder--ibc-relayer)
- [Single validator node + heartmonitor](#single-validator-node--heartmonitor)
- [Other Commands](#other-commands)
- [Services Overview](#services-overview)
- [Nibiru node services](#nibiru-node-services)
- [Pricefeeder services](#pricefeeder-services)
- [Hermes IBC relayer services](#hermes-ibc-relayer-services)
- [Heart Monitor Services](#heart-monitor-services)
- [Reference Materials](#reference-materials)

## docker-compose-chaosnet

Expand All @@ -18,32 +23,54 @@ Nibiru-specific containers.

Features:

- Data volume mounts ensure persistent storage.
- Different ports are utilized to mimic a multi-chain configuration on a single machine.
- Enables testing of cross-chain transactions, chain health monitoring, liquidations, and more in a local Docker context across two chains.
- Enables testing of cross-chain transactions, chain health monitoring, and more in a local Docker context across two chains.

### Usage Commands:
## Usage

### Single validator node + pricefeeder

```sh
docker compose -f docker-compose-chaosnet.yml up
```

### Two validator nodes + pricefeeder + IBC relayer

```sh
docker compose -f docker-compose-chaosnet.yml --profile ibc up
```

### Single validator node + heartmonitor

```sh
docker compose -f docker-compose-chaosnet.yml --profile heartmonitor up
```

### Other Commands

- `docker compose up`: Start the services.
- `docker compose down`: Stop the services.
- `docker compose restart`: Restart all services.
- `docker compose ps`: List containers, their status, ports, etc.
- `docker compose logs`: View std output from containers
- `docker compose logs`: View std output from containers

## Services Overview

### Nibiru node services

- `nibiru-0` and `nibiru-1` (Service): Represents two distinct Nibiru Chain nodes (nibiru-0 and nibiru-1)
running on different ports, using unique mnemonics and chain IDs, imitating two
independent blockchain networks.

### Oracle feeder services
### Pricefeeder services

- `pricefeeder-0` and `pricefeeder-1` (Service): Two price feeder services that push price
data to the respective Nibiru nodes.

### Hermes IBC relayer services

An IBC relayer is set up to connect the two chains using [hermes](https://hermes.informal.systems/).

1. `hermes-keys-task-0` and `hermes-keys-task-1` (Service): Tasks to generate
keys for the validators on `nibiru-0` and `nibiru-1`.
2. `hermes-client-connection-channel-task` (Service): Creates a new channel
Expand All @@ -59,34 +86,24 @@ Brief IBC reference:
Put simply, **connections** represent a secure communication line between two
blockchain to transfer IBC **packets** (data). Once a connection is established,
light client of two chains, usually called the source chain and destination
chain, is established.
chain, is established.

Once a connection is established, **channels** can be formed. A channel
represents a logical pathway for specific types communication over the connection
(like token transfers and other relaying of IBC packets.

### Faucet Service

Dispenses testnet tokens. Faucets provide liquidity on test chains.

Repository: [NibiruChain/go-faucet](https://github.com/NibiruChain/go-faucet)

### Heart Monitor Services

- `heartmonitor-db`: A postgres database for the heart monitor.

- `heartmonitor`: An indexing solution that populates a DB based on events and
block responses emitted from Nibiru nodes.

- `liquidator` : Liquidates underwater positions using the tracked state inside
`hearmonitor-db`.
block responses emitted from Nibiru nodes.

- `graphql`: GraphQL API for the heart monitor data. Used in the Nibiru web app
and other off-chain tools.

Repository: [NibiruChain/go-heartmonitor](https://github.com/NibiruChain/go-heartmonitor).


## Reference Materials

- [Docker Compose file](https://docs.docker.com/compose/compose-file/03-compose-file/)
Expand Down
43 changes: 11 additions & 32 deletions contrib/docker-compose/docker-compose-chaosnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ services:
RPC_PORT: 36657
GRPC_PORT: 19090
LCD_PORT: 11317
profiles: [ibc]
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:36657"]
interval: 60s
Expand All @@ -63,6 +64,7 @@ services:

pricefeeder-1:
image: ghcr.io/nibiruchain/pricefeeder:latest
profiles: [ibc]
restart: always
environment:
CHAIN_ID: nibiru-localnet-1
Expand All @@ -77,6 +79,7 @@ services:

hermes-keys-task-0:
image: informalsystems/hermes:1.6.0
profiles: [ibc]
user: root
command:
[
Expand Down Expand Up @@ -107,6 +110,7 @@ services:

hermes-keys-task-1:
image: informalsystems/hermes:1.6.0
profiles: [ibc]
user: root
command:
[
Expand Down Expand Up @@ -139,6 +143,7 @@ services:

hermes-client-connection-channel-task:
image: informalsystems/hermes:1.6.0
profiles: [ibc]
user: root
command:
[
Expand Down Expand Up @@ -172,6 +177,7 @@ services:

hermes:
image: informalsystems/hermes:1.6.0
profiles: [ibc]
restart: always
user: root
command: ["start"]
Expand All @@ -191,22 +197,9 @@ services:
hermes-client-connection-channel-task:
condition: service_completed_successfully

faucet:
restart: always
image: ghcr.io/nibiruchain/go-faucet:latest
environment:
NODE: nibiru-0:9090
MNEMONIC: undo donkey arena rule old portion long forget rescue post stuff normal reduce raw unable warrior method stairs valley enhance glory lens sign zero
SEND_COINS: 11000000unibi
MAX_SEND_COINS: 110000000unibi
depends_on:
nibiru-0:
condition: service_healthy
ports:
- 8000:8000

heartmonitor-db:
image: postgres:14
profiles: [heartmonitor]
restart: always
environment:
POSTGRES_PASSWORD: postgres
Expand All @@ -216,6 +209,8 @@ services:

heartmonitor:
image: ghcr.io/nibiruchain/go-heartmonitor:latest
platform: linux/amd64
profiles: [heartmonitor]
restart: always
command: --clean
volumes:
Expand All @@ -231,26 +226,10 @@ services:
heartmonitor-db:
condition: service_started

liquidator:
image: ghcr.io/nibiruchain/go-heartmonitor:latest
restart: always
command: --liquidator
environment:
- DATABASE_URI=postgresql://postgres:postgres@heartmonitor-db:5432/heart-monitor?sslmode=disable
- TENDERMINT_RPC_ENDPOINT=http://nibiru-0:26657
- GRPC_ENDPOINT=tcp://nibiru-0:9090
- GRPC_INSECURE=true
- NO_PARTITIONS=true
- LIQUIDATOR_MNEMONIC=record damage person caution truly riot resource luxury rude guide mushroom athlete fantasy dentist friend mule depth salmon photo unfold exclude coyote idea evoke
- LIQUIDATOR_GAS_LIMIT_INITIAL=500000
- LIQUIDATOR_GAS_MULTIPLIER=5
- LIQUIDATOR_GAS_MAX_ATTEMPTS=10
depends_on:
heartmonitor:
condition: service_started

graphql:
image: ghcr.io/nibiruchain/go-heartmonitor:latest
platform: linux/amd64
profiles: [heartmonitor]
restart: always
command: --graphql
environment:
Expand Down
64 changes: 0 additions & 64 deletions contrib/docker-compose/docker-compose-multi-node.yml

This file was deleted.

30 changes: 21 additions & 9 deletions contrib/make/chaosnet.mk
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,22 @@ chaosnet-build:
chaosnet: chaosnet-down
docker compose -f ./contrib/docker-compose/docker-compose-chaosnet.yml up --detach --build

# Stop chaosnet
# Run a chaosnet testnet locally with IBC enabled
.PHONY: chaosnet-ibc
chaosnet-ibc: chaosnet-down
docker compose -f ./contrib/docker-compose/docker-compose-chaosnet.yml --profile ibc up --detach --build

# Run a chaosnet testnet locally with heartmonitor+graphql stack enabled
.PHONY: chaosnet-heartmonitor
chaosnet-heartmonitor: chaosnet-down
docker compose -f ./contrib/docker-compose/docker-compose-chaosnet.yml --profile heartmonitor up --detach --build

# Stop chaosnet, need to specify all profiles to ensure all services are stopped
# See https://stackoverflow.com/questions/76781634/docker-compose-down-all-profiles
.PHONY: chaosnet-down
chaosnet-down:
docker compose -f ./contrib/docker-compose/docker-compose-chaosnet.yml down --timeout 1 --volumes
docker compose -f ./contrib/docker-compose/docker-compose-chaosnet.yml --profile ibc down --timeout 1 --volumes
docker compose -f ./contrib/docker-compose/docker-compose-chaosnet.yml --profile heartmonitor down --timeout 1 --volumes

###############################################################################
### Chaosnet Logs ###
Expand All @@ -25,10 +37,6 @@ chaosnet-down:
chaosnet-logs:
docker compose -f ./contrib/docker-compose/docker-compose-chaosnet.yml logs

.PHONY: chaosnet-logs-faucet
chaosnet-logs-faucet:
docker compose -f ./contrib/docker-compose/docker-compose-chaosnet.yml logs go-faucet

.PHONY: chaosnet-logs-pricefeeder
chaosnet-logs-pricefeeder:
docker compose -f ./contrib/docker-compose/docker-compose-chaosnet.yml logs pricefeeder --follow
Expand All @@ -41,9 +49,13 @@ chaosnet-logs-go-heartmonitor:
### Chaosnet SSH ###
###############################################################################

.PHONY: chaosnet-ssh-nibiru
chaosnet-ssh-nibiru:
docker compose -f ./contrib/docker-compose/docker-compose-chaosnet.yml exec -it nibiru /bin/sh
.PHONY: chaosnet-ssh-nibiru-0
chaosnet-ssh-nibiru-0:
docker compose -f ./contrib/docker-compose/docker-compose-chaosnet.yml exec -it nibiru-0 /bin/sh

.PHONY: chaosnet-ssh-nibiru-1
chaosnet-ssh-nibiru-1:
docker compose -f ./contrib/docker-compose/docker-compose-chaosnet.yml exec -it nibiru-1 /bin/sh

.PHONY: chaosnet-ssh-go-heartmonitor
chaosnet-ssh-go-heartmonitor:
Expand Down
Loading

0 comments on commit 4a73c37

Please sign in to comment.