Skip to content

Commit

Permalink
build: improve localnet scripts and containers (#127)
Browse files Browse the repository at this point in the history
<!-- < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < ☺
v                               ✰  Thanks for creating a PR! ✰
v    Before smashing the submit button please review the checkboxes.
v If a checkbox is n/a - please still include it but + a little note why
☺ > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >  -->

## Overview

<!-- Add a description of the changes that this PR introduces and the
files that
are the most critical to review.
-->

This PR updates the Dockerfiles and scripts to run a localnet with all
the contracts required for the liquid staking protocol. These updates
account for the fact that the liquid staking contract now uses a single
oracle contract and the newer version of the treasury contract.

closes: #XXXX

## What changes have been made in this PR?

- Refactored the scripts to use a set of shared params defined in the
`params.sh` file
- Added a script to dowload all the required binaries
- Refactored the `init-stake-contract.sh` script to use only a single
oracle contract
- Updated the Dockerfiles to used the new scripts 

## Checklist

- [ ] Appropriate labels applied
- [ ] Targeted PR against correct branch
- [ ] Linked to Github issue with discussion and accepted design OR link
to spec that describes this work.
- [ ] Wrote unit and integration
- [ ] Updated relevant documentation

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
manu0466 and coderabbitai[bot] authored Jun 14, 2024
1 parent 7a61644 commit 4329aa6
Show file tree
Hide file tree
Showing 32 changed files with 737 additions and 345 deletions.
28 changes: 0 additions & 28 deletions scripts/deploy/init_stake_contract_testnet.sh

This file was deleted.

14 changes: 0 additions & 14 deletions scripts/deploy/tia-osmo-pool.sh

This file was deleted.

1 change: 1 addition & 0 deletions scripts/testnet/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bins/bins
92 changes: 39 additions & 53 deletions scripts/testnet/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,52 +1,38 @@
FROM ubuntu:latest

RUN apt-get update
RUN apt-get install -y tmux
RUN apt-get install -y git
RUN apt-get install -y make
RUN apt-get install -y golang-go
RUN apt-get install -y wget
RUN apt install unzip

RUN wget https://github.com/osmosis-labs/osmosis/releases/download/v20.1.1/osmosisd-20.1.1-linux-amd64
RUN mv osmosisd-20.1.1-linux-amd64 /usr/local/bin/osmosisd
RUN chmod +x /usr/local/bin/osmosisd

RUN ARCH=$(arch | sed s/aarch64/arm64/) && \
wget https://github.com/celestiaorg/celestia-app/releases/download/v1.3.0/celestia-app_Linux_$ARCH.tar.gz && \
tar -xvf celestia-app_Linux_$ARCH.tar.gz
RUN mv celestia-appd /usr/local/bin
RUN chmod +x /usr/local/bin/celestia-appd

RUN ARCH=$(arch) && \
wget https://github.com/informalsystems/hermes/releases/download/v1.7.0/hermes-v1.7.0-$ARCH-unknown-linux-gnu.zip && \
unzip hermes-v1.7.0-$ARCH-unknown-linux-gnu.zip
RUN mv hermes /usr/local/bin
RUN chmod +x /usr/local/bin/hermes

RUN apt-get install -y psmisc
RUN apt-get install -y jq


COPY ./check-node-running.sh ./check-node-running.sh
COPY ./local-osmosis-testnet-new.sh ./local-osmosis-testnet-new.sh
RUN sh ./local-osmosis-testnet-new.sh
COPY ./local-celestia-testnet-multi-new.sh ./local-celestia-testnet-multi-new.sh
RUN sh ./local-celestia-testnet-multi-new.sh

COPY ./local-osmosis-testnet-continue.sh ./local-osmosis-testnet-continue.sh
COPY ./local-celestia-testnet-multi-continue.sh ./local-celestia-testnet-multi-continue.sh
COPY ./local-hermes-continue.sh ./local-hermes-continue.sh
COPY ./local-hermes-new.sh ./local-hermes-new.sh
COPY ./local-account.sh ./local-account.sh
COPY ./hermes-config.toml ./hermes-config.toml
COPY ./local-hermes-clear-packets.sh ./local-hermes-clear-packets.sh
RUN sh ./local-celestia-testnet-multi-continue.sh && \
sh ./local-osmosis-testnet-continue.sh && \
sh ./check-node-running.sh osmosis1 && \
sh ./check-node-running.sh celestia1 && \
sh ./local-hermes-new.sh && \
sh ./local-account.sh
RUN apt-get update && \
apt-get install -y tmux git make golang-go wget unzip psmisc jq

# Binaries versions
# Remember to update the hermes compatibility mode when bumping the versions
# https://hermes.informal.systems/documentation/configuration/comet-compat-mode.html
ENV OSMOSISD_VERSION="25.0.0" \
CELESTIA_APP_VERSION="1.11.0" \
HERMES_VERSION="1.9.0"

# Prepare the container environment
RUN mkdir /milkiway
COPY ./* /milkiway/
COPY ./bins /milkiway/bins
COPY ./utils /milkiway/utils
WORKDIR /milkiway

# Install binaries
RUN bash -c "source /milkiway/bins/download.sh && \
ensure_installed osmosisd && \
ensure_installed celestia-appd && \
ensure_installed hermes"

RUN ./local-osmosis-testnet-new.sh
RUN ./local-celestia-testnet-multi-new.sh
RUN ./local-celestia-testnet-multi-continue.sh && \
./local-osmosis-testnet-continue.sh && \
./check-node-running.sh osmosis1 && \
./check-node-running.sh celestia1 && \
./fund-accounts.sh && \
./local-hermes-new.sh && \
./tia-osmo-pool.sh

EXPOSE 26661
EXPOSE 26657
Expand All @@ -55,10 +41,10 @@ EXPOSE 1314
EXPOSE 9090

# last command needs to be persistant to keep container running
CMD sh ./local-celestia-testnet-multi-continue.sh && \
sh ./local-osmosis-testnet-continue.sh && \
sh ./check-node-running.sh osmosis1 && \
sh ./check-node-running.sh celestia1 && \
sh ./local-hermes-clear-packets.sh && \
sh ./local-hermes-continue.sh && \
tail -f /dev/null
CMD ./local-celestia-testnet-multi-continue.sh && \
./local-osmosis-testnet-continue.sh && \
./check-node-running.sh osmosis1 && \
./check-node-running.sh celestia1 && \
./local-hermes-clear-packets.sh && \
./local-hermes-continue.sh && \
tail -f /dev/null
81 changes: 32 additions & 49 deletions scripts/testnet/Dockerfile.fast
Original file line number Diff line number Diff line change
@@ -1,48 +1,31 @@
FROM ubuntu:latest

RUN apt-get update
RUN apt-get install -y tmux
RUN apt-get install -y git
RUN apt-get install -y make
RUN apt-get install -y golang-go
RUN apt-get install -y wget
RUN apt install unzip

RUN wget https://github.com/osmosis-labs/osmosis/releases/download/v20.1.1/osmosisd-20.1.1-linux-amd64
RUN mv osmosisd-20.1.1-linux-amd64 /usr/local/bin/osmosisd
RUN chmod +x /usr/local/bin/osmosisd

RUN ARCH=$(arch | sed s/aarch64/arm64/) && \
wget https://github.com/celestiaorg/celestia-app/releases/download/v1.3.0/celestia-app_Linux_$ARCH.tar.gz && \
tar -xvf celestia-app_Linux_$ARCH.tar.gz
RUN mv celestia-appd /usr/local/bin
RUN chmod +x /usr/local/bin/celestia-appd

RUN ARCH=$(arch) && \
wget https://github.com/informalsystems/hermes/releases/download/v1.7.0/hermes-v1.7.0-$ARCH-unknown-linux-gnu.zip && \
unzip hermes-v1.7.0-$ARCH-unknown-linux-gnu.zip
RUN mv hermes /usr/local/bin
RUN chmod +x /usr/local/bin/hermes

RUN apt-get install -y psmisc
RUN apt-get install -y jq


COPY ./check-node-running.sh ./check-node-running.sh
COPY ./local-osmosis-testnet-new.sh ./local-osmosis-testnet-new.sh
RUN sh ./local-osmosis-testnet-new.sh

COPY ./local-celestia-testnet-multi-new.sh ./local-celestia-testnet-multi-new.sh
RUN apt-get update && \
apt-get install -y tmux git make golang-go wget unzip psmisc jq

# Binaries versions
# Remember to update the hermes compatibility mode when bumping the versions
# https://hermes.informal.systems/documentation/configuration/comet-compat-mode.html
ENV OSMOSISD_VERSION="25.0.0" \
CELESTIA_APP_VERSION="1.11.0" \
HERMES_VERSION="1.9.0"

# Prepare the container environment
RUN mkdir /milkiway
COPY ./* /milkiway/
COPY ./bins /milkiway/bins
COPY ./utils /milkiway/utils
WORKDIR /milkiway

# Install binaries
RUN bash -c "source /milkiway/bins/download.sh && \
ensure_installed osmosisd && \
ensure_installed celestia-appd && \
ensure_installed hermes"

RUN ./local-osmosis-testnet-new.sh
# Reduce unbonding time to 6 minutes
RUN UNBONDING_TIME=360s sh ./local-celestia-testnet-multi-new.sh

COPY ./local-osmosis-testnet-continue.sh ./local-osmosis-testnet-continue.sh
COPY ./local-celestia-testnet-multi-continue.sh ./local-celestia-testnet-multi-continue.sh
COPY ./local-hermes-continue.sh ./local-hermes-continue.sh
COPY ./local-hermes-new.sh ./local-hermes-new.sh
COPY ./local-account.sh ./local-account.sh
COPY ./hermes-config.toml ./hermes-config.toml
COPY ./local-hermes-clear-packets.sh ./local-hermes-clear-packets.sh
RUN UNBONDING_TIME=360s ./local-celestia-testnet-multi-new.sh

# Reduce the trust threshold according to the fast unbonding time
RUN sed -i -E 's|14d|300s|g' ./hermes-config.toml
Expand All @@ -55,10 +38,10 @@ EXPOSE 9090

# As the relayer times out very fast, we do create a bridge on start of the docker.
# Continues runs will though create new bridges so you need to reset the docker every time.
CMD sh ./local-celestia-testnet-multi-continue.sh && \
sh ./local-osmosis-testnet-continue.sh && \
sh ./check-node-running.sh osmosis1 && \
sh ./check-node-running.sh celestia1 && \
sh ./local-hermes-new.sh && \
sh ./local-account.sh && \
tail -f /dev/null
CMD ./local-celestia-testnet-multi-continue.sh && \
./local-osmosis-testnet-continue.sh && \
./check-node-running.sh osmosis1 && \
./check-node-running.sh celestia1 && \
./local-hermes-new.sh && \
./local-account.sh && \
tail -f /dev/null
49 changes: 33 additions & 16 deletions scripts/testnet/Local-Testnet.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,50 @@ Now you can always boot into the clean config
docker run --name mw-testnet -d -p 26661:26661/udp -p 26657:26657/udp -p 26661:26661/tcp -p 26657:26657/tcp -p 1317:1317 -p 1314:1314 -p 9090:9090 docker.io/library/mw-testnet
```

Test accounts are funded, check out `./local-accounts.sh`
But you need to import the mnemonic:
Upon creation, the following accounts will be funded:
- `osmo1sfhy3emrgp26wnzuu64p06kpkxd9phel8ym0ge`: Osmosis account used to deploy the contracts on the chain.
- `osmo1lh0u9sug6qh922gjpal3frwtacaums4s7lkyl9`: Osmosis trader account used to swap the fee collected by the treasury contract.
- `celestia1sfhy3emrgp26wnzuu64p06kpkxd9phel74e0yx`: Celestia account that stakes the TIA on the Celestia chain (staker).
- `celestia1lh0u9sug6qh922gjpal3frwtacaums4s8w5yn6`: Celestia account that operates the staker account through the `x/authz` module (grantee).
- `celestia12rzczckgh8fqq533t0xqhqrrzdk76du3dxrx9q`: Celestia account where the staking reward will be withdrawn.

```
MNEMONIC="boy view flame close solar robust crunch slot govern false jungle dirt blade minor shield bounce rent expand anxiety busy pull inject grace require"
NOTE: The `grantee` account will have all the on chain permissions to control the staker account.

echo $MNEMONIC | osmosisd keys add test_master --recover
echo $MNEMONIC | celestia-appd keys add test_master --recover
```
Those accounts can be imported into a test keyring through the `utils/import-accounts-keys.sh` script.

Now you can deploy the contract:
After the network is ready, you can configure the clients by using the `utils/configure-localnet.sh` script.

You will need the bech32 dep to parse validator addresses:
## Deploy Contracts

```
cargo install --git https://github.com/cmoog/bech32
```
Before deploying the contracts, you need to:

1. Import the accounts using the `utils/import-accounts-keys.sh` script.
2. Compile the contracts by navigating to the project root directory and running the `make optimize` command.
3. Download the oracle contract from [here](https://github.com/milkyway-labs/milkyway-oracle/releases) and store it in the `artifacts/` folder.

After completing the above steps, you can deploy the contracts by running:

```sh
./init_stake_contract.sh
```
sh ./init_stake_contract.sh
```

After this you can liquid stake (currently you need to wait a couple of seconds after ibc transfer TIA to Osmosis):
This script will initialize all the contracts and print out their addresses.

Next, you can IBC transfer some TIA using the following command:

```sh
celestia-appd tx ibc-transfer transfer transfer channel-0 osmo1sfhy3emrgp26wnzuu64p06kpkxd9phel8ym0ge 1000000utia \
--from staker --fees 21000utia -b block -y
```
sh ./liquid_stake.sh

Upon reception, you can liquid stake the received tokens using the following command:

```sh
osmosisd tx wasm execute osmo1suhgf5svhu4usrurvxzlgn54ksxmn8gljarjtxqnapv8kjnp4nrsll0sqv '{"liquid_stake":{}}' \
--amount 1000000ibc/C3E53D20BC7A4CC993B17C7971F8ECD06A433C10B6A96F4C4C3714F0624C56DA \
--from test_master
```
NOTE: All the application binaries are available in the `bins` folder and will be lazily downloaded on first use.

### Fast testnet to test unbonding

Expand Down
3 changes: 3 additions & 0 deletions scripts/testnet/bins/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Ignore downloaded binaries
bins/

20 changes: 20 additions & 0 deletions scripts/testnet/bins/celestia-appd
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

# This script serves as a wrapper for various applications
# needed to run a testnet for testing our smart contracts.
# The application to run is determined by the name of this file,
# allowing the creation of links to this script with the actual application names.
# This way, other software depending on these applications
# will think they are using the actual application.

set -e

SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
BINS_DIR="$SCRIPT_DIR/bins"
source "$SCRIPT_DIR/download.sh"
SCRIPT_NAME="$(basename "$0")"

# Ensure that we have the proper a application installed
ensure_installed "$SCRIPT_NAME"
# Run the application passing the arguments to it
"$BINS_DIR/$SCRIPT_NAME" "$@"
Loading

0 comments on commit 4329aa6

Please sign in to comment.