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

Add Docker IBC Test Environment #1248

Merged
merged 17 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ The `v1.13.0` release includes minor bug fixes and enhancements along with a res
* Publish Java/Kotlin JARs to Maven for release candidates [#1223](https://github.com/provenance-io/provenance/issues/1223).
* Added two new Makefile targets to install and start the relayer [#1051] (https://github.com/provenance-io/provenance/pull/1051)
* Updated relayer scripts to make them headless for external services [#1068] (https://github.com/provenance-io/provenance/pull/1068)
* Added docker environment for testing IBC and added Makefile targets to bring this environment up/down [#1248] (https://github.com/provenance-io/provenance/pull/1248).

### Bug Fixes

Expand Down
27 changes: 27 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,33 @@ localnet-start: localnet-generate localnet-up
localnet-stop:
docker-compose -f networks/local/docker-compose.yml --project-directory ./ down

# Quick build using ibc environment and go platform target options.
RELAYER_MNEMONIC ?= "list judge day spike walk easily outer state fashion library review include leisure casino wagon zoo chuckle alien stock bargain stone wait squeeze fade"
RELAYER_KEY ?= tp18uev5722xrwpfd2hnqducmt3qdjsyktmtw558y
RELAYER_VERSION ?= v2.1.2
docker-build-ibc: vendor
docker build --target provenance-$(shell uname -m) --tag provenance-io/blockchain-ibc -f networks/ibc/blockchain-ibc/Dockerfile .
docker build --target relayer --tag provenance-io/blockchain-relayer -f networks/ibc/blockchain-relayer/Dockerfile --build-arg MNEMONIC=$(RELAYER_MNEMONIC) --build-arg VERSION=$(RELAYER_VERSION) .

# Generate config files for a 2-node ibcnet with relayer
ibcnet-generate: ibcnet-stop docker-build-ibc
@if ! [ -f build/ibc0-0/config/genesis.json ]; then docker run --rm -v $(CURDIR)/build:/provenance:Z provenance-io/blockchain-ibc testnet --v 1 -o . --starting-ip-address 192.168.20.2 --node-dir-prefix=ibc0- --keyring-backend=test --chain-id=testing ; fi
mv build/gentxs/ibc0-0.json build/gentxs/tmp
@if ! [ -f build/ibc1-0/config/genesis.json ]; then docker run --rm -v $(CURDIR)/build:/provenance:Z provenance-io/blockchain-ibc testnet --v 1 -o . --starting-ip-address 192.168.20.3 --node-dir-prefix=ibc1- --keyring-backend=test --chain-id=testing2 ; fi
mv build/gentxs/tmp build/gentxs/ibc0-0.json
scripts/ibcnet-add-relayer-key.sh $(RELAYER_KEY)

# Run a 2-node testnet locally with a relayer
ibcnet-up:
docker-compose -f networks/ibc/docker-compose.yml --project-directory ./ up -d

# Run a 2-node testnet locally with a relayer
ibcnet-start: ibcnet-generate ibcnet-up

# Stop ibcnet
ibcnet-stop:
docker-compose -f networks/ibc/docker-compose.yml --project-directory ./ down

# Quick build using devnet environment and go platform target options.
docker-build-dev: vendor
docker build --target provenance-$(shell uname -m) --tag provenance-io/blockchain-dev -f networks/dev/blockchain-dev/Dockerfile .
Expand Down
115 changes: 115 additions & 0 deletions networks/ibc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
## Inter-Blockchain Communication (IBC) Test Cluster
# Overview

This folder contains the files to create 3 containers for testing IBC. The first container
is a single node running a blockchain with chain-id testing. The second container is also a
single node running a blockchain, but this chain has chain-id testing2. Lastly, the third container
holds the relayer used to forward packets between chains.

Two make targets `make ibcnet-start` and `make ibcnet-stop` were added to the project's Makefile to
easily bring the containers up and down. This will also handle all network configuration.

# Relayer Account

Each chain has an account for the relayer that is funded. The relayer uses this account
to publish packets from the sending chain to the receiving chain.

```
- type: local
address: tp18uev5722xrwpfd2hnqducmt3qdjsyktmtw558y
pubkey: '{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"Aj/FqZi4LKRTT+q0tByQsqk27uIMO9nf1UnkTyUaQRV5"}'
mnemonic: ""
- balances:
amount: "99999998039505445"
denom: nhash
```

# Networking

It's always important to first verify that your relayer is working before doing anything
IBC related. You can verify that your relayer is working as inteded by running the following
command on the relayer container.

```
rly --home /relayer paths list
0: local_local2 -> chns(✔) clnts(✔) conn(✔) (testing<>testing2)
```

Notice that the output above has 3 checkmarks. This is saying that the channels, clients,
and connections are all properly working.

# Transferring Currency

The simplest test that can be used to verify that IBC is working is using the Fungible Token
Transfer (ICS-20) subprotocol. This subprotocol is exposed through provenance with the `ibc-transfer`
transaction. It transfers coins from an account on one chain to an account on another chain.
In this example we will transfer from an account on ibc0-0 to an account on ibc1-0.

## Note
The following tutorial assumes the user has built provenanced, and their current working directory
is within the root of their provenance source directory.

All or some of the addresses in the examples may be different than what you have locally. They are
there just for example purposes.

1. First, obtain the receiving address from ibc1-0. In this example our receiving address is
`tp1vtvgsl9je747twlxkh4ycl2g3td6g5gcpc6t0y`.

```
./build/provenanced -t --home ./build/ibc1-0/ keys list

- address: tp1vtvgsl9je747twlxkh4ycl2g3td6g5gcpc6t0y
Taztingo marked this conversation as resolved.
Show resolved Hide resolved
name: ibc1-0
pubkey: '{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"AjOKuV/CkfDBmZgSHZFrCN2PXz68ZyUssvBiWfe4A/ut"}'
type: local
```

2. Next, obtain your sending address from ibc0-0. In this example our sending address is
`tp1u3ry0ry80hvj9vcfa8h5e30wkx9ec4l5jsqujd`.

```
./build/provenanced -t --home ./build/ibc0-0/ keys list

- address: tp1u3ry0ry80hvj9vcfa8h5e30wkx9ec4l5jsqujd
name: ibc0-0
pubkey: '{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"A5RlZL3Gn3uEyzrVIkk9nyDV5LxJeUqPF/kOQmGX6nnQ"}'
type: local
```

3. Now, we can transfer currency from ibc0-0 to ibc1-0. The following command sends 500nhash from our
sending account `tp1u3ry0ry80hvj9vcfa8h5e30wkx9ec4l5jsqujd` to our receiving account
`tp1vtvgsl9je747twlxkh4ycl2g3td6g5gcpc6t0y`.

```
./build/provenanced -t --home ./build/ibc0-0/ tx ibc-transfer transfer transfer channel-0 tp1vtvgsl9je747twlxkh4ycl2g3td6g5gcpc6t0y 500nhash --from tp1u3ry0ry80hvj9vcfa8h5e30wkx9ec4l5jsqujd --gas auto --gas-prices 1905nhash --gas-adjustment 1.5 --chain-id testing --node http://localhost:26657 -y
```

4. Lastly, let's check the balances for the receiving account on container ibc1-0. You should see the 500nhash sent
from ibc0-0. It will have its own denom specified with ibc/denom...

```
./build/provenanced -t --home ./build/ibc1-0/ q bank balances tp1vtvgsl9je747twlxkh4ycl2g3td6g5gcpc6t0y --node http://localhost:26660

balances:
- amount: "500"
denom: ibc/319937B2FDA7A07031DBE22EA76C34CAC9DCFBD9AA1A922FA2B87421107B545D
- amount: "99899999900000000000"
denom: nhash
```

# Smart Contracts

Smart Contracts can be stored and instantiated on this chain like any other. The only benefit
that this chain offers for testing smart contracts is support for the IBC entry points. Users
do not have to worry about setting up multiple chains and a relayer just to test out the IBC
portions of their smart contracts.

Please see the provwasm tutorial for more information on uploading and using contracts.
https://github.com/provenance-io/provwasm/blob/main/docs/tutorial/01-overview.md


NOTE: This folder contains files to run an image using a locally built binary
that leverages Go's ability to target platforms during builds. These docker
files are _not_ the ones used to build the release image. For those images
see the `docker/blockchain` folder in the project root.

97 changes: 97 additions & 0 deletions networks/ibc/blockchain-ibc/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# This docker file builds a test image using binaries built locally.
# Use `make docker-build-local` to build or `make localnet-start` to
# start the test network and `make localnet-stop` to stop it.

## Build provenance for x86_64
FROM golang:1.18-bullseye as build-x86_64
WORKDIR /go/src/github.com/provenance-io/provenance
ENV GOPRIVATE=github.com/provenance-io
RUN apt-get update && apt-get upgrade -y && apt-get install -y libleveldb-dev

COPY client/ ./client/
COPY app/ ./app/
COPY go.* ./
COPY cmd/ ./cmd/
COPY internal/ ./internal/
COPY x/ ./x/
COPY vendor/ ./vendor/

# Build the binaries
RUN go build -mod vendor -tags=cleveldb -ldflags '-w -s -X github.com/cosmos/cosmos-sdk/version.Name=Provenance-Blockchain' -o /go/bin/ ./cmd/...

## Run provenance for x86_64
FROM debian:bullseye-slim as provenance-x86_64
ENV LOCALNET=1
ENV LD_LIBRARY_PATH="/usr/local/lib"

RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y curl jq libleveldb-dev && \
apt-get clean && \
rm -rf /var/lib/apt/lists/

# Requires a mounted volume with the config in it.
VOLUME [ "/provenance" ]
WORKDIR /provenance
EXPOSE 26656 26657 1317 9090

# Source binaries from the build above
COPY --from=build-x86_64 /go/src/github.com/provenance-io/provenance/vendor/github.com/CosmWasm/wasmvm/internal/api/libwasmvm.x86_64.so /usr/local/lib/
COPY --from=build-x86_64 /go/bin/provenanced /usr/bin/provenanced

COPY networks/ibc/blockchain-ibc/entrypoint.sh /usr/bin/entrypoint.sh

STOPSIGNAL SIGTERM

ENTRYPOINT ["/usr/bin/entrypoint.sh"]
CMD ["start"]






## Build provenance for ARM
FROM golang:1.18-bullseye as build-arm64
WORKDIR /go/src/github.com/provenance-io/provenance
ENV GOPRIVATE=github.com/provenance-io
RUN apt-get update && apt-get upgrade -y && apt-get install -y libleveldb-dev

COPY client/ ./client/
COPY app/ ./app/
COPY go.* ./
COPY cmd/ ./cmd/
COPY internal/ ./internal/
COPY x/ ./x/
COPY vendor/ ./vendor/

# Build the binaries
RUN go build -mod vendor -tags=cleveldb -ldflags '-w -s -X github.com/cosmos/cosmos-sdk/version.Name=Provenance-Blockchain' -o /go/bin/ ./cmd/...

## Run provenance for ARM
FROM debian:bullseye-slim as provenance-arm64
ENV LOCALNET=1
ENV LD_LIBRARY_PATH="/usr/local/lib"

RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y curl jq libleveldb-dev && \
apt-get clean && \
rm -rf /var/lib/apt/lists/

# Requires a mounted volume with the config in it.
VOLUME [ "/provenance" ]
WORKDIR /provenance
EXPOSE 26656 26657 1317 9090

# Source binaries from the build above
COPY --from=build-arm64 /go/src/github.com/provenance-io/provenance/vendor/github.com/CosmWasm/wasmvm/internal/api/libwasmvm.aarch64.so /usr/local/lib/

COPY --from=build-arm64 /go/bin/provenanced /usr/bin/provenanced

COPY networks/ibc/blockchain-ibc/entrypoint.sh /usr/bin/entrypoint.sh

STOPSIGNAL SIGTERM

ENTRYPOINT ["/usr/bin/entrypoint.sh"]
CMD ["start"]
20 changes: 20 additions & 0 deletions networks/ibc/blockchain-ibc/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

##
## Input parameters
##
ID=${ID:-0}
export PIO_HOME="/provenance/ibc${ID}-0"

BINARY=/usr/bin/${BINARY:-provenanced}
LOG=${LOG:-provenance.log}

##
## Run binary with all parameters
##
if [ -d "$(dirname "${PIO_HOME}"/"${LOG}")" ]; then
"${BINARY}" -t --home "${PIO_HOME}" "$@" | tee "${PIO_HOME}/${LOG}"
else
"${BINARY}" -t --home "${PIO_HOME}" "$@"
fi

40 changes: 40 additions & 0 deletions networks/ibc/blockchain-relayer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
## Build provenance for ARM
FROM golang:1.18-bullseye as build
WORKDIR /
ARG VERSION
RUN apt-get update && apt-get upgrade -y && apt-get install -y libleveldb-dev && apt-get install -y git
RUN git clone https://github.com/cosmos/relayer.git /relayer && cd /relayer && git checkout "$VERSION" && make install && cd / && rm -rf /relayer

## Run provenance for ARM
FROM build as relayer
ARG MNEMONIC
ENV LD_LIBRARY_PATH="/usr/local/lib"

RUN apt-get update && \
apt-get upgrade -y && \
apt-get clean && \
rm -rf /var/lib/apt/lists/

# Requires a mounted volume with the config in it.
VOLUME [ "/relayer" ]
WORKDIR /relayer
EXPOSE 26656 26657 1317 9090

COPY --from=build /go/bin/rly /usr/bin/rly

# We need to setup the relayer
RUN rly config init --home "/relayer"

# Copy over the network config
COPY networks/ibc/blockchain-relayer/config.yaml /relayer/config/config.yaml

# Generate the keys
RUN rly keys restore local default "$MNEMONIC" --home "/relayer"
RUN rly keys restore local2 default "$MNEMONIC" --home "/relayer"

COPY networks/ibc/blockchain-relayer/entrypoint.sh /usr/bin/entrypoint.sh

STOPSIGNAL SIGTERM

ENTRYPOINT ["/usr/bin/entrypoint.sh"]
CMD ["start"]
44 changes: 44 additions & 0 deletions networks/ibc/blockchain-relayer/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
global:
api-listen-addr: :5183
timeout: 10s
memo: ""
light-cache-size: 20
chains:
local:
type: cosmos
value:
key: default
chain-id: testing
rpc-addr: http://192.168.20.2:26657
account-prefix: tp
keyring-backend: test
gas-adjustment: 1.5
gas-prices: 1905nhash
debug: false
timeout: 20s
output-format: json
sign-mode: direct
local2:
type: cosmos
value:
key: default
chain-id: testing2
rpc-addr: http://192.168.20.3:26657
account-prefix: tp
keyring-backend: test
gas-adjustment: 1.5
gas-prices: 1905nhash
debug: false
timeout: 20s
output-format: json
sign-mode: direct

paths:
local_local2:
src:
chain-id: testing
dst:
chain-id: testing2
src-channel-filter:
rule: ""
channel-list: []
14 changes: 14 additions & 0 deletions networks/ibc/blockchain-relayer/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

##
## Input parameters
##

export RELAYER_HOME="/relayer"
export RELAY_PATH="local_local2"

# Setup the connection, client, and channel
rly tx link "$RELAY_PATH" --home "$RELAYER_HOME"

# Start the relayer
rly start "$RELAY_PATH" -p events --home "$RELAYER_HOME"
Loading