Skip to content

Commit

Permalink
Dockerize deployment scripts (#204)
Browse files Browse the repository at this point in the history
* Add liquidity deployment script and improve deployments

* Remove proposals query

* Gitignore .seed file

* Add example file for .seed

* Rename script to relaying

* Rename script to relaying

* Adjust error reporting

* Adjust API node

* Start dockerizing deployment

* Start drafting instructions for deployment

* Fix relayer build

* Improve deployment readme

* Improve readability of tip

* Fix log outputs

* Reference docker running for all steps and fix submitter key parsing

* Move relayer instructions and rename tool

* Fix typo

* Fix typo in file path

* Remove extra log lines

* Mention neutron_query_relayer being in path

* Delete tool build artifacts and add the folder to gitignore

* Add deployment scripts branch to latest-contract workflow for testing

* Adjust populate contracts command

* Fix binary in relaying.sh script

* Compile neutron-query-relayer binary

* Shorten sleep before killing relayer

* Remove PR branch as workflow trigger
  • Loading branch information
p-offtermatt authored Dec 17, 2024
1 parent 752d4c9 commit 9b9ba75
Show file tree
Hide file tree
Showing 14 changed files with 345 additions and 63 deletions.
47 changes: 28 additions & 19 deletions .github/workflows/deploy-latest-contracts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,25 @@ jobs:
chmod +x ./tools/deployment/populate_contracts.sh
source ./tools/deployment/store_instantiate.sh $CONFIG_FILE true
source ./tools/deployment/populate_contracts.sh $CONFIG_FILE
source ./tools/deployment/populate_contracts.sh $CONFIG_FILE $HYDRO_CONTRACT_ADDRESS $TRIBUTE_CONTRACT_ADDRESS
# Run tools/script.sh to create validator ICQs in the contract and run the ICQ relayer to
# Run tools/relaying.sh to create validator ICQs in the contract and run the ICQ relayer to
# get the results into the contract
- name: Run ICQs setup script
run: |
cp ./tools/script.sh .
chmod +x script.sh
cd neutron-query-relayer
go build -ldflags "${LDFLAGS}" -o build/neutron_query_relayer ./cmd/neutron_query_relayer/*.go
cd ..
cd ./tools
go build -o build/icq-tool ./*.go
cd ..
cp ./tools/build/icq-tool .
cp ./neutron-query-relayer/build/neutron_query_relayer .
cp ./tools/relaying.sh .
chmod +x relaying.sh
CONFIG_FILE="./tools/deployment/config_testnet.json"
CHAIN_ID=$(echo $(jq -r '.chain_id' $CONFIG_FILE) | sed -E 's/([][\/.*?$^&|])/\\\1/g')
Expand All @@ -60,28 +71,26 @@ jobs:
HUB_RPC_NODE=$(echo $(jq -r '.hub_rpc_node' $CONFIG_FILE) | sed -E 's/([][\/.*?$^&|])/\\\1/g')
HUB_API_NODE=$(echo $(jq -r '.hub_api_node' $CONFIG_FILE) | sed -E 's/([][\/.*?$^&|])/\\\1/g')
sed -i "s|^RELAYER_REPO_PATH=.*$|RELAYER_REPO_PATH=\.\/neutron-query-relayer|" ./script.sh
sed -i "s/^export NEUTRON_CHAIN_ID=.*$/export NEUTRON_CHAIN_ID=$CHAIN_ID/" ./script.sh
sed -i "s/^export RELAYER_NEUTRON_CHAIN_RPC_ADDR=.*$/export RELAYER_NEUTRON_CHAIN_RPC_ADDR=$NEUTRON_RPC_NODE/" ./script.sh
sed -i "s/^export RELAYER_NEUTRON_CHAIN_REST_ADDR=.*$/export RELAYER_NEUTRON_CHAIN_REST_ADDR=$NEUTRON_API_NODE/" ./script.sh
sed -i "s/^export RELAYER_NEUTRON_CHAIN_SIGN_KEY_NAME=.*$/export RELAYER_NEUTRON_CHAIN_SIGN_KEY_NAME=$TX_SENDER_WALLET/" ./script.sh
sed -i "s/^export RELAYER_NEUTRON_CHAIN_CONNECTION_ID=.*$/export RELAYER_NEUTRON_CHAIN_CONNECTION_ID=$HUB_CONNECTION_ID/" ./script.sh
sed -i "s/^export RELAYER_TARGET_CHAIN_RPC_ADDR=.*$/export RELAYER_TARGET_CHAIN_RPC_ADDR=$HUB_RPC_NODE/" ./script.sh
sed -i "s/^export RELAYER_TARGET_CHAIN_API_ADDR=.*$/export RELAYER_TARGET_CHAIN_API_ADDR=$HUB_API_NODE/" ./script.sh
sed -i "s/^export RELAYER_REGISTRY_ADDRESSES=.*$/export RELAYER_REGISTRY_ADDRESSES=$HYDRO_CONTRACT_ADDRESS/" ./script.sh
sed -i "s/^export BATCH_SIZE=.*$/export BATCH_SIZE=5/" ./script.sh
sed -i "s/^export NUM_VALIDATORS_TO_ADD=.*$/export NUM_VALIDATORS_TO_ADD=5/" ./script.sh
sed -i "s/^export RELAYER_STORAGE_PATH=.*$/export RELAYER_STORAGE_PATH=\.neutron_queries_relayer\/leveldb/" ./script.sh
sed -i "s|^go run main\.go.*$|go run \./tools/main\.go|" ./script.sh
sed -i "s|^RELAYER_REPO_PATH=.*$|RELAYER_REPO_PATH=\.\/neutron-query-relayer|" ./relaying.sh
sed -i "s/^export NEUTRON_CHAIN_ID=.*$/export NEUTRON_CHAIN_ID=$CHAIN_ID/" ./relaying.sh
sed -i "s/^export RELAYER_NEUTRON_CHAIN_RPC_ADDR=.*$/export RELAYER_NEUTRON_CHAIN_RPC_ADDR=$NEUTRON_RPC_NODE/" ./relaying.sh
sed -i "s/^export RELAYER_NEUTRON_CHAIN_REST_ADDR=.*$/export RELAYER_NEUTRON_CHAIN_REST_ADDR=$NEUTRON_API_NODE/" ./relaying.sh
sed -i "s/^export RELAYER_NEUTRON_CHAIN_SIGN_KEY_NAME=.*$/export RELAYER_NEUTRON_CHAIN_SIGN_KEY_NAME=$TX_SENDER_WALLET/" ./relaying.sh
sed -i "s/^export RELAYER_NEUTRON_CHAIN_CONNECTION_ID=.*$/export RELAYER_NEUTRON_CHAIN_CONNECTION_ID=$HUB_CONNECTION_ID/" ./relaying.sh
sed -i "s/^export RELAYER_TARGET_CHAIN_RPC_ADDR=.*$/export RELAYER_TARGET_CHAIN_RPC_ADDR=$HUB_RPC_NODE/" ./relaying.sh
sed -i "s/^export RELAYER_TARGET_CHAIN_API_ADDR=.*$/export RELAYER_TARGET_CHAIN_API_ADDR=$HUB_API_NODE/" ./relaying.sh
sed -i "s/^export BATCH_SIZE=.*$/export BATCH_SIZE=5/" ./relaying.sh
sed -i "s/^export RELAYER_STORAGE_PATH=.*$/export RELAYER_STORAGE_PATH=\.neutron_queries_relayer\/leveldb/" ./relaying.sh
sed -i "s|^go run main\.go.*$|go run \./tools/main\.go|" ./relaying.sh
stop_icq_relayer() {
sleep 240
sleep 60
killall neutron_query_relayer
}
stop_icq_relayer &
bash ./script.sh
bash ./relaying.sh $HYDRO_CONTRACT_ADDRESS 5
echo 'Latest contracts are deployed and ready for testing!'
echo 'Hydro contract address:' $HYDRO_CONTRACT_ADDRESS
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Cargo.toml.orig
.idea/

# Ignore build artifacts
tools/build/*

*.rs.bk

Expand All @@ -28,3 +29,7 @@ Cargo.toml.orig
# log files from deployments
*_res.json
*_tx.json

.seed


1 change: 1 addition & 0 deletions .seed.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
assist lava fatigue enough delay swim mystery crater thank very nerve laugh annual belt bachelor front merge lonely eagle alpha lunch farm alley enough
79 changes: 79 additions & 0 deletions DEPLOYING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Manually deploying & interacting with contracts

This directory contains a set of shell scripts and JSON configuration files that allow us to easily store, instantiate and prepare our smart contracts for testing.

## Setting up the environment

To get started, you will need to have the following installed:
* [Docker](https://docs.docker.com/get-docker/)

You will need to create and prepare the `.seed` file in the repo root with the seed phrase of the test account; see the `.seed.example` file for an example.

This account will deploy the contracts, and send the transactions to populate the contracts.

Then, you need to build the dockerfile. Run the following command:

```bash
docker build -t hydro-docker .
```

## Setting up contracts

To deploy a new set of contracts to mainnet, run the following command:

```bash
docker run hydro-docker ./tools/deployment/setup_on_mainnet.sh
```

Take note of the contract addresses outputted by the script. You will need them to interact with the contracts.

## Populating contracts

If you already have contracts deployed, you can populate them with a new series of bids and tributes by running

```bash
docker run hydro-docker ./tools/deployment/populate_contracts.sh "tools/deployment/config_mainnet.json" $HYDRO_CONTRACT_ADDRESS $TRIBUTE_CONTRACT_ADDRESS
```
where you will need to replace the contract addresses with the addresses of the contracts you wish to populate.

This will create 3 bids with tributes in the current round of the contract.

Notice that the `.seed` file will need to contain the passphrase of the account that created the contracts.
> **TIP:** When you switch out the phrase in the `.seed` file, you will need to rebuild the docker image.
## Adding liquidity deployments

To make rewards claimable, liquidity deployments need to be added.
For a certain proposal in a certain round and certain tranche, here is how you can add a liquidity deployment for it, to make tributes claimable or refundable:

```bash
docker run hydro-docker ./tools/deployment/add_liquidity_deployments.sh "./tools/deployment/config_mainnet.json" $HYDRO_CONTRACT_ADDRESS $TRIBUTE_CONTRACT_ADDRESS $ROUND_ID $TRANCHE_ID $PROPOSAL_ID $FUNDS
```
FUNDS should be 0 if the tribute for the bid should become refundable; and non-zero if it should become claimable.
Don't worry about the non-zero number - this script isn't actually sending funds over. It only matters whether the number is zero or not.

## Issuing interchain queries and relaying

### Setting the Neutron Interchain Queries (ICQ) Relayer locally (optional)

If you want to run the relayer locally instead of through Docker, clone the [ICQ Relayer](https://github.com/neutron-org/neutron-query-relayer) repository and switch to the latest tag (v0.3.0 at the time of writing), then build the relayer.
Make sure that `neutron_query_relayer` is in the path and executable.

### Setting up the ICQ population tool

To set up the ICQ population tool, inside `./tools/`, run this command to build the binary:

```bash
go build -o build/icq-tool ./*.go
```

### Setting up variables (optional)

You can adjust parameters like the RPC nodes to connect to for relaying by modifying the exports in `./tools/relaying.sh`.

## Run the script

Simply run the script by running `docker run hydro-docker ./tools/relaying.sh HYDRO_CONTRACT_ADDRESS NUM_OF_VALIDATORS_TO_ADD`.

It will not stop on its own, but the script will eventually print out the relayer logs, and once there are no more regular changes in those, you can stop the container.

90 changes: 90 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# syntax=docker/dockerfile:1

# --------------------------------------------------------
# Stage 1: Build neutron-query-relayer
# --------------------------------------------------------
FROM golang:alpine3.21 AS builder

# Set up build arguments
ARG LDFLAGS

# Install dependencies for Go build and musl compatibility
RUN apk add --no-cache \
git \
gcc \
musl-dev \
libc-dev \
make

# Set up the build environment
WORKDIR /app

# Clone the neutron-query-relayer repository
RUN git clone --depth 1 https://github.com/neutron-org/neutron-query-relayer.git /app

# Download Go modules
RUN go mod download

# Build the neutron-query-relayer binary with Alpine-compatible settings
RUN go build -ldflags "${LDFLAGS}" -o build/neutron_query_relayer ./cmd/neutron_query_relayer/*.go

COPY tools /app/tools

# build the icq population tool
RUN go build -o build/icq-tool /app/tools/*.go

# --------------------------------------------------------
# Stage 3: Final image with all dependencies
# --------------------------------------------------------
FROM alpine:3.21.0

RUN apk add --no-cache file

# Install dependencies
RUN apk add --no-cache \
bash \
curl \
ca-certificates \
git \
jq

# Set the desired version of neutrond
ARG NEUTROND_VERSION="v5.0.2"
ARG NEUTROND_BINARY="neutrond-linux-amd64"
ARG NEUTROND_DOWNLOAD_URL="https://github.com/neutron-org/neutron/releases/download/${NEUTROND_VERSION}/${NEUTROND_BINARY}"

# Download and install the neutrond binary
RUN curl -L ${NEUTROND_DOWNLOAD_URL} -o /usr/local/bin/neutrond && \
chmod +x /usr/local/bin/neutrond

# Add the neutron-query-relayer binary from the builder stage
COPY --from=builder /app/build/neutron_query_relayer /usr/local/bin/neutron_query_relayer

# Add the icq-tool binary from the builder stage
COPY --from=builder /app/build/icq-tool /usr/local/bin/icq-tool

# Add CosmWasm libraries
ADD https://github.com/CosmWasm/wasmvm/releases/download/v1.5.2/libwasmvm.x86_64.so /lib/
ADD https://github.com/CosmWasm/wasmvm/releases/download/v1.5.2/libwasmvm.aarch64.so /lib/

# Copy scripts and other artifacts
COPY tools /usr/local/hydro/tools
COPY artifacts/ /usr/local/hydro/artifacts
COPY .seed /usr/local/hydro/.seed

# Set the default working directory
WORKDIR /usr/local/hydro

# Ensure scripts are executable
RUN chmod +x tools/relaying.sh tools/deployment/*.sh

# Import the seed phrase
RUN neutrond keys add submitter --recover --keyring-backend test --source /usr/local/hydro/.seed


# Expose the neutron-query-relayer port
EXPOSE 9999

# Default entry point
ENTRYPOINT ["bash"]

16 changes: 0 additions & 16 deletions tools/README.md

This file was deleted.

46 changes: 46 additions & 0 deletions tools/deployment/add_liquidity_deployments.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash
set -eux

# Check for required arguments
if [ $# -lt 7 ]; then
echo "Usage: $0 <config_file> <hydro_contract_address> <tribute_contract_address> <round_id> <tranche_id> <proposal_id> <deployed_fund_amount>"
exit 1
fi

CONFIG_FILE="$1"
HYDRO_CONTRACT_ADDRESS="$2"
TRIBUTE_CONTRACT_ADDRESS="$3"
ROUND_ID="$4"
TRANCHE_ID="$5"
PROPOSAL_ID="$6"
DEPLOYED_FUND_AMOUNT="$7"


NEUTRON_CHAIN_ID=$(jq -r '.chain_id' $CONFIG_FILE)
NEUTRON_NODE=$(jq -r '.neutron_rpc_node' $CONFIG_FILE)
TX_SENDER_WALLET=$(jq -r '.tx_sender_wallet' $CONFIG_FILE)

TRIBUTE_TOKEN_1=$(jq -r '.tribute_token_1' $CONFIG_FILE)
TRIBUTE_TOKEN_2=$(jq -r '.tribute_token_2' $CONFIG_FILE)
TRIBUTE_TOKEN_3=$(jq -r '.tribute_token_3' $CONFIG_FILE)

NEUTRON_BINARY="neutrond"
NEUTRON_CHAIN_ID_FLAG="--chain-id $NEUTRON_CHAIN_ID"
KEYRING_TEST_FLAG="--keyring-backend test"
TX_FLAG="--gas auto --gas-adjustment 1.3"
NEUTRON_NODE_FLAG="--node $NEUTRON_NODE"
NEUTRON_TX_FLAGS="$TX_FLAG --gas-prices 0.0053untrn --chain-id $NEUTRON_CHAIN_ID $NEUTRON_NODE_FLAG $KEYRING_TEST_FLAG -y"

# Customize these query parameters as needed
LIMIT=1000 # maximum number of proposals to retrieve at once
START_FROM=0 # where to start from if pagination is needed

if [ "$DEPLOYED_FUND_AMOUNT" -eq 0 ]; then
DEPLOYED_FUNDS="[]"
else
DEPLOYED_FUNDS='[{"amount":"'"$DEPLOYED_FUND_AMOUNT"'","denom":"uatom"}]'
fi

EXECUTE='{"add_liquidity_deployment":{"deployed_funds":'"$DEPLOYED_FUNDS"',"destinations":["Secret1a65a9xgqrlsgdszqjtxhz069pgsh8h4a83hwt0"],"funds_before_deployment":[{"amount":"1000000","denom":"uatom"}],"proposal_id":'"$PROPOSAL_ID"',"remaining_rounds":0,"round_id":'"$ROUND_ID"',"total_rounds":0,"tranche_id":'"$TRANCHE_ID"'}}'
$NEUTRON_BINARY tx wasm execute $HYDRO_CONTRACT_ADDRESS "$EXECUTE" --from $TX_SENDER_WALLET $NEUTRON_TX_FLAGS
sleep 10
4 changes: 2 additions & 2 deletions tools/deployment/config_mainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"neutron_api_node": "https://neutron-rest.publicnode.com",
"hub_rpc_node": "https://cosmos-rpc.publicnode.com:443",
"hub_api_node": "https://api.cosmos.nodestake.org",
"tx_sender_wallet": "hs",
"tx_sender_address": "neutron14fmxw54lgvheyn7m0p9efpr82fac68ysph96ch",
"tx_sender_wallet": "submitter",
"tx_sender_address": "neutron1r6rv879netg009eh6ty23v57qrq29afecuehlm",
"hub_connection_id": "connection-0",
"hub_channel_id": "channel-1",
"tribute_token_1": "untrn",
Expand Down
8 changes: 4 additions & 4 deletions tools/deployment/config_testnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"neutron_api_node": "https://rest-falcron.pion-1.ntrn.tech:443",
"hub_rpc_node": "https://rpc-rs.cosmos.nodestake.top:443",
"hub_api_node": "https://api-rs.cosmos.nodestake.top:443",
"tx_sender_wallet": "testnet_deployer",
"tx_sender_address": "neutron1e68032v8dr8rfeg9wuhd3jjsun83vvla2fsrfs",
"tx_sender_wallet": "submitter",
"tx_sender_address": "neutron1r6rv879netg009eh6ty23v57qrq29afecuehlm",
"hub_connection_id": "connection-42",
"hub_channel_id": "channel-96",
"tribute_token_1": "untrn",
"tribute_token_2": "untrn",
"tribute_token_3": "untrn"
"tribute_token_2": "ibc/D1283F23CC25C39F16BCFB2DFFA9997AE7A101B92810D0F9F0AA092F6FE332D0",
"tribute_token_3": "ibc/D1283F23CC25C39F16BCFB2DFFA9997AE7A101B92810D0F9F0AA092F6FE332D0"
}
Loading

0 comments on commit 9b9ba75

Please sign in to comment.