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

build: improve localnet scripts and containers #127

Merged
merged 24 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
84bee4e
refactor: update scripts to support new osmosis and celestia versions
manu0466 Jun 7, 2024
cc6021d
feat: add utilities to download binaries
manu0466 Jun 7, 2024
5f25654
feat: start moving nodes params to params file
manu0466 Jun 7, 2024
83490ad
wip: sync changes
manu0466 Jun 11, 2024
79a717c
feat: prepare celestia accounts
manu0466 Jun 11, 2024
63c2e3c
wip: contracts initialization
manu0466 Jun 11, 2024
b1eb053
refactor: update init stake contract script
manu0466 Jun 11, 2024
650fd76
feat: create tia/osmo pool
manu0466 Jun 11, 2024
e4acfca
refactor: reorganized testenet scripts
manu0466 Jun 11, 2024
83d6fd3
refactor: removed unused scripts
manu0466 Jun 11, 2024
1069452
feat: download binaries
manu0466 Jun 11, 2024
d42bb08
feat: add osmosis trader account
manu0466 Jun 13, 2024
bcabb4d
feat: update dao trasury fee
manu0466 Jun 13, 2024
4c94966
docs: revert changes
manu0466 Jun 13, 2024
4bd79e5
refactor: removed cargo dependency
manu0466 Jun 14, 2024
43da80f
feat: add script to configure the clients
manu0466 Jun 14, 2024
5816464
docs: update localnet configurations
manu0466 Jun 14, 2024
d55007e
fix: Dockerfile.fast
manu0466 Jun 14, 2024
593e8fb
refactor: link the wrapper.sh instead of the whole file
manu0466 Jun 14, 2024
0a58470
refactor: applied coderabit suggestions
manu0466 Jun 14, 2024
a13cd55
docs: applied coderabbit suggestions
manu0466 Jun 14, 2024
1bc6318
Update scripts/testnet/Local-Testnet.md
manu0466 Jun 14, 2024
62d9af1
Update scripts/testnet/Local-Testnet.md
manu0466 Jun 14, 2024
0719247
docs: applied coderabbit suggestions
manu0466 Jun 14, 2024
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
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
manu0466 marked this conversation as resolved.
Show resolved Hide resolved

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
manu0466 marked this conversation as resolved.
Show resolved Hide resolved

# 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
manu0466 marked this conversation as resolved.
Show resolved Hide resolved

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
manu0466 marked this conversation as resolved.
Show resolved Hide resolved

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
manu0466 marked this conversation as resolved.
Show resolved Hide resolved

# 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
47 changes: 30 additions & 17 deletions scripts/testnet/Local-Testnet.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,46 @@ 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 operate the staker account trough 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 account can be imported into a test keyring trough 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:

```
sh ./init_stake_contract.sh
```
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 this you can liquid stake (currently you need to wait a couple of seconds after ibc transfer TIA to Osmosis):
After completing the above steps, you can deploy the contracts by running:
```sh
./init_stake_contract.sh
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

Codebase Verification

The script init_stake_contract.sh is not found in the repository. Please ensure that the script is added to the repository and correctly referenced in the documentation.

Analysis chain

Ensure the script init_stake_contract.sh is correctly referenced and functional.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Check if the `init_stake_contract.sh` script is present and executable.
fd "init_stake_contract.sh" --exec echo "Script found and executable: {}"

Length of output: 73



Script:

#!/bin/bash
# Description: Check if the `init_stake_contract.sh` script exists and is executable.
if [ -f "./init_stake_contract.sh" ]; then
    if [ -x "./init_stake_contract.sh" ]; then
        echo "Script found and is executable."
    else
        echo "Script found but is not executable."
    fi
else
    echo "Script not found."
fi

Length of output: 82

```
manu0466 marked this conversation as resolved.
Show resolved Hide resolved
This script will initialize all the contracts and print out their addresses.

Next, you can IBC transfer some TIA using the following command:
```sh
manu0466 marked this conversation as resolved.
Show resolved Hide resolved
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
manu0466 marked this conversation as resolved.
Show resolved Hide resolved
osmosisd tx wasm execute osmo1suhgf5svhu4usrurvxzlgn54ksxmn8gljarjtxqnapv8kjnp4nrsll0sqv '{"liquid_stake":{}}' \
--amount 1000000ibc/C3E53D20BC7A4CC993B17C7971F8ECD06A433C10B6A96F4C4C3714F0624C56DA \
--from test_master
manu0466 marked this conversation as resolved.
Show resolved Hide resolved
```
NOTE: All the applications binaries are available in the `bins` folder and they will be lazy downloaded on first use.
manu0466 marked this conversation as resolved.
Show resolved Hide resolved

### 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
Loading