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

Cleanup docs #87

Merged
merged 37 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
f0bdc1b
update READMEs
cam-schultz Oct 27, 2023
16ff0f7
move scripts
cam-schultz Oct 27, 2023
6897c9b
Merge branch 'main' into cleanup-docs
cam-schultz Oct 27, 2023
5de6c90
clean up comments
cam-schultz Oct 30, 2023
aeab864
Merge branch 'main' into cleanup-docs
cam-schultz Oct 30, 2023
a3e8bb7
update abi
cam-schultz Oct 30, 2023
67c607b
remove inaccurate comment
cam-schultz Oct 30, 2023
cadc142
Merge branch 'cleanup-docs' of github.com:ava-labs/teleporter into cl…
cam-schultz Oct 30, 2023
9811ffa
check in forge docs
cam-schultz Oct 31, 2023
439b8da
docs checker job
cam-schultz Oct 31, 2023
975ada1
cleanup comments
cam-schultz Oct 31, 2023
dde09fb
fix typo in job
cam-schultz Oct 31, 2023
4e46f28
update docs
cam-schultz Oct 31, 2023
8efe96f
remove forge docs from repo
cam-schultz Oct 31, 2023
180b629
Merge branch 'main' into cleanup-docs
cam-schultz Oct 31, 2023
d2a4aff
consistent naming
cam-schultz Nov 1, 2023
d03a697
Merge branch 'main' into cleanup-docs
cam-schultz Nov 3, 2023
e1b9cb0
remove generated docs
cam-schultz Nov 6, 2023
1bcb0a9
Merge branch 'cleanup-docs' of github.com:ava-labs/teleporter into cl…
cam-schultz Nov 6, 2023
5b0adf5
Update contracts/src/Teleporter/TeleporterMessenger.sol
cam-schultz Nov 6, 2023
5473492
Update README.md
cam-schultz Nov 6, 2023
298c6b3
Update README.md
cam-schultz Nov 6, 2023
72fbea7
Update README.md
cam-schultz Nov 6, 2023
50d23db
Update README.md
cam-schultz Nov 6, 2023
0e3157c
Update README.md
cam-schultz Nov 6, 2023
eec9825
Update README.md
cam-schultz Nov 6, 2023
ead9506
Update README.md
cam-schultz Nov 6, 2023
65a912c
Update README.md
cam-schultz Nov 6, 2023
80ca25e
Update README.md
cam-schultz Nov 6, 2023
5510d59
Update README.md
cam-schultz Nov 6, 2023
765b24d
Update README.md
cam-schultz Nov 6, 2023
5992f19
remove redundant usage
cam-schultz Nov 6, 2023
42fbae9
default behavior to tear down network
cam-schultz Nov 6, 2023
63c45d9
consistent usage punc
cam-schultz Nov 6, 2023
45fcabb
Merge branch 'cleanup-docs' of github.com:ava-labs/teleporter into cl…
cam-schultz Nov 6, 2023
24dbbca
correct container in readme
cam-schultz Nov 7, 2023
28ff12c
Merge branch 'main' into cleanup-docs
cam-schultz Nov 7, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ jobs:
# in subdirectories. The former only checks sol files in the current directory and directories one level down.
- name: Run Lint
run: |
./scripts/local/lint.sh
./scripts/lint.sh
86 changes: 55 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
# Overview
## Overview

Teleporter is an EVM compatible cross-subnet communication protocol built on top of [Avalanche Warp Messaging (AWM)](https://docs.avax.network/learn/avalanche/awm), and implemented as a Solidity smart contract. It provides a mechanism to asynchronously invoke smart contract functions on other EVM blockchains within Avalanche. Teleporter provides a handful of useful features on top of AWM, such as specifying relayer incentives for message delivery, replay protection, message delivery and execution retries, and a standard interface for sending and receiving messages within a dApp deployed across multiple subnets.

It's important to understand the distinction between Avalanche Warp Messaging and Teleporter. AWM allows subnets to communicate with each other via authenticated messages by providing signing and verification primitives in Avalanchego. These are used by the blockchain VMs to sign outgoing messages and verify incoming messages.

The Teleporter protocol, on the other hand, is implemented at the smart contract level, and is a user-friendly interface to AWM, aimed at dApp developers. All of the message signing and verification is abstracted away from developers. Instead, developers simply call `sendCrossChainMessage` on the `TeleporterMessenger` contract to send a message invoking a smart contract on another subnet, and implement the `ITeleporterReceiver` interface to receive messages on the destination subnet. Teleporter handles all of the message signing and verification, as well as the message delivery and execution.

**Note:** Teleporter and Avalanche Warp Messaging are under active development and may cease to function at any time. This repository is intended to be used for testing and development purposes only and should **not** be used in production.
The Teleporter protocol, on the other hand, is implemented at the smart contract level, and is a user-friendly interface to AWM, aimed at dApp developers. All of the message signing and verification is abstracted away from developers. Instead, developers simply call `sendCrossChainMessage` on the `TeleporterMessenger` contract to send a message invoking a smart contract on another subnet, and implement the `ITeleporterReceiver` interface to receive messages on the destination subnet. Teleporter handles all of the Warp message construction and sending, as well as the message delivery and execution.

- [Overview](#overview)
- [Setup](#setup)
- [Docker Setup](#docker-setup)
- [General Setup](#general-setup)
- [Structure](#structure)
- [Build + Run + Test](#build--run--test)
- [Run tests on Fuji Testnet](#run-tests-on-fuji-testnet)
- [E2E tests](#e2e-tests)
- [Docs](#docs)
- [Resources](#resources)
- [Setup](#setup)
- [Docker Setup](#docker-setup)
- [General Setup](#general-setup)
- [Structure](#structure)
- [Build + Run + Test](#build--run--test)
- [Run tests on Fuji Testnet](#run-tests-on-fuji-testnet)
- [E2E tests](#e2e-tests)
- [Docs](#docs)
- [Resources](#resources)

## Setup

### Docker Setup

- Install Docker:

```
Expand Down Expand Up @@ -57,28 +57,36 @@ docker run hello-world # This should work without sudo now
- Note that as you develop and continuously build Docker images, it will eat up continuously more disk space. Periodically you'll want to remedy this be removing everything Docker has built: `docker system prune --all --volumes --force`

### General Setup

The above steps are sufficient to run the included integration tests inside Docker containers. If you wish to run them outside docker, you'll need to install the following dependencies:
- [Foundry](https://book.getfoundry.sh/getting-started/installation)
- [Python3](https://www.python.org/downloads/)

## Structure

- `contracts/` is a [Foundry](https://github.com/foundry-rs/foundry) project that includes the implementation of the `TeleporterMessenger` contract and example dApps that demonstrate how to write contracts that interact with Teleporter.
- `abi-bindings/` includes Go ABI bindings for the contracts in `contracts/`.
- `tests/` includes integration tests for the contracts in `contracts/`, written using the [Ginkgo](https://onsi.github.io/ginkgo/) testing framework
cam-schultz marked this conversation as resolved.
Show resolved Hide resolved
- `utils/` includes Go utility functions for interacting with the contracts in `contracts/`. Included are Golang scripts to derive the expected EVM contract address deployed from a given EOA at a specific nonce, and also construct a transaction to deploy provided byte code to the same address on any EVM chain using [Nick's method](https://yamenmerhi.medium.com/nicks-method-ethereum-keyless-execution-168a6659479c#).
- `subnet-evm/` is the public subnet-evm repository (included as a submodule) checked out on the `warp-contract` branch with our changes.
- `contract-deployment/` includes Golang scripts to derive the expected EVM contract address deployed from a given EOA at a specific nonce, and also construct a transaction to deploy provided byte code to the same address on any EVM chain using [Nick's method](https://yamenmerhi.medium.com/nicks-method-ethereum-keyless-execution-168a6659479c#).
- `contracts/` is a [foundry](https://github.com/foundry-rs/foundry) project that includes the implementation of the `TeleporterMessenger` contract and other dApps that serve as examples for how to write contracts that interact with Teleporter.
- `scripts/` includes scripts to run Teleporter and integration tests.
- Note that all the scripts should be run from the root of the repository.
- `scripts/local/` includes scripts to run Teleporter in Docker containers and tests in the `scripts/local/integration-tests` locally.
- `scripts/` includes bash scripts for interacting with Teleporter in various environments, as well as utility scripts. All the scripts should be run from the root of the repository.
cam-schultz marked this conversation as resolved.
Show resolved Hide resolved
- `abi_bindings.sh` generates ABI bindings for the contracts in `contracts/` and outputs them to `abi-bindings/`
cam-schultz marked this conversation as resolved.
Show resolved Hide resolved
- `lint.sh` lints the contracts in `contracts/`
cam-schultz marked this conversation as resolved.
Show resolved Hide resolved
- `scripts/local/` includes scripts for running Teleporter in Docker containers and tests in the `scripts/local/integration-tests` locally.
cam-schultz marked this conversation as resolved.
Show resolved Hide resolved
- `scripts/local/integration-tests/` includes integration test scripts written in bash. The scripts use `foundry` to deploy smart contracts that use Teleporter, send transactions to interact with the contracts, and check that cross-chain messages have the expected effect on destination chains.
- `scripts/fuji/` includes scripts to interact with a live Teleporter deployment on Fuji subnets.
- `scripts/fuji/example-workflows/` includes example workflows that send transactions to interact with Teleporter contracts on Fuji subnets.
- `docker/` includes containerized setup for running a local setup of Teleporter, as well as a script to run each of the integration tests against the local network.
- *Note* These tests will be deprecated in favor of the end to end tests in `tests/`, written using the [Ginkgo](https://onsi.github.io/ginkgo/) testing framework
cam-schultz marked this conversation as resolved.
Show resolved Hide resolved
- `scripts/fuji/` includes scripts to interact with a live Teleporter deployment on Fuji subnets.
- `scripts/fuji/example-workflows/` includes example workflows that send transactions to interact with Teleporter contracts on Fuji subnets.
cam-schultz marked this conversation as resolved.
Show resolved Hide resolved
- `docker/` includes a containerized setup for running a local setup of Teleporter
cam-schultz marked this conversation as resolved.
Show resolved Hide resolved

## Build + Run + Test
## Run the Docker integration tests

- Get all submodules: `git submodule update --init --recursive`
- Install Docker as described in the setup section of the README in the root of this repository.
- If we are using a local version of the `awm-relayer` image, build it using `./scripts/build_local_image.sh` from the root of `awm-relayer` repository.
- If we are using a local version of the `awm-relayer` image, build it using `./scripts/build_local_image.sh` from the root of the `awm-relayer` repository.

### Start up the local testnet
feuGeneA marked this conversation as resolved.
Show resolved Hide resolved

- Run `./scripts/local/run.sh` to run the local testnet in Docker containers with the ability to interact with the nodes directly.
- `./scripts/local/run.sh` usage is as follows:
```
Expand All @@ -93,7 +101,7 @@ cast send --private-key 0x56289e99c94b6912bfc12adc093c9b51124f0dc54ac7a766b2bc5c
cast balance --rpc-url http://127.0.0.1:9652/ext/bc/C/rpc 0x333d17d3b42bf7930dbc6e852ca7bcf560a69003
```

- After calling `./scripts/local/run.sh`, you can directly send messages between the deployed subnets (in comparison, calling `./scripts/local/test.sh` runs the same setup steps, then runs the tests in `./scripts/integration-tests/` automatically). As an example, `./scripts/integration-tests/basic_send_receive.sh` can be run manually like so:
- After calling `./scripts/local/run.sh`, you can directly send messages between the deployed subnets . As an example, `./scripts/integration-tests/basic_send_receive.sh` can be run manually like so:
Copy link
Contributor

Choose a reason for hiding this comment

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

I wondered if the instructions just below could be simplified to just one command: docker exec -it relayer_run /bin/bash -c "set -a; source vars.sh; ./integration-tests/basic_send_receive.sh". But, when I tried, I found that those instructions don't work.

For one thing, when I try to run the script, I get:

gene@gene-dev:~/dev/teleporter$ docker exec -it relayer_run /bin/bash
root@gene-dev:/code# set -a
root@gene-dev:/code# source vars.sh
bash: BASHOPTS: readonly variable
bash: BASH_VERSINFO: readonly variable
bash: EUID: readonly variable
bash: PPID: readonly variable
bash: SHELLOPTS: readonly variable
bash: UID: readonly variable
root@gene-dev:/code# ./integration-tests/basic_send_receive.sh
bash: ./integration-tests/basic_send_receive.sh: No such file or directory

Because that script path needs to be prepended with scripts/local/.

But then when I run the command with the proper path, I get:

root@gene-dev:/code# scripts/local/integration-tests/basic_send_receive.sh 
scripts/local/integration-tests/basic_send_receive.sh: line 36: forge: command not found

While we've mounted the scripts from the teleporter repo into the relayer container, via the volume declaration in the docker compose file, foundry isn't available because the awm-relayer's Dockerfile doesn't install it.

After going into the container and installing foundry, via the same command as the RUN statement that does that in teleporter's Dockerfile, I can exit the container back to the host system and then successfully run that succinct command quoted at the beginning of this message.

I know this is a whole can of worms to open in this PR of doc changes, it did feel like it fell under the purview of "cleanup docs." :)

I discovered that the same command can be successfully run via the local_network_run container instead of the relayer_run one, and since that container already has forge installed, maybe we should use that instead?

Sorry to be so long winded haha, but I think this whole comment boils down to just one statement: Delete the code block below and accept the following suggestion.

Suggested change
- After calling `./scripts/local/run.sh`, you can directly send messages between the deployed subnets . As an example, `./scripts/integration-tests/basic_send_receive.sh` can be run manually like so:
- After calling `./scripts/local/run.sh`, you can directly send messages between the deployed subnets . As an example, `./scripts/integration-tests/basic_send_receive.sh` can be run manually like so: `docker exec -it local_network_run /bin/bash -c "set -a; source vars.sh; ./scripts/local/integration-tests/basic_send_receive.sh"`

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for digging into this. I'd actually prefer to keep the commands as is, that shell in the container persists after running basic_send_receive.sh, in case the user wants to run other tests or inspect the state of the chains manually. Providing a command via -c won't give the user an interactive shell, if I'm not mistaken.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree that that approach is better, so thank you for pushing back on my suggestion.

But, one remaining bit in this thread here: the relayer_run container does not have foundry installed, and I believe the easiest fix would be to change the command to reference the local_network_run container instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! Corrected now.

cam-schultz marked this conversation as resolved.
Show resolved Hide resolved

```
# Open a shell in the container
Expand Down Expand Up @@ -121,13 +129,29 @@ source vars.sh
./run_stop.sh # stop the running containers and preserve the network for subsequent runs
./run_stop.sh -c # stop the running containers and clean the network
```
- Additional Notes:
- Both the `./scripts/local/run.sh` and `./scripts/local/test.sh` scripts run local five node networks, with each of the nodes validating the primary network and three subnets (Subnet A, Subnet B, and Subnet C).
- Logs from the subnets on one of the five nodes are printed to stdout when run using either script.
- These logs can also be found at `~/.avalanche-cli/runs/network-runner-root-data_<DATE>_<TIMESTAMP>/node{1,5]/logs/<SUBNET_ID>.log`, or at `/var/lib/docker/overlay2/<CONTAINER_ID>/merged/root/.avalanche-cli/....` on your local machine. You will need to be the root user to access the logs under `/var/lib`.

### Run the integration tests in Docker containers

- Run `./scripts/local/test.sh` to run the integration tests in Docker containers.
- `./scripts/local/test.sh` usage is as follows:
```
-t, --test <test_name> Run a specific test. If empty, runs all tests in the ./scripts/local/integration-tests/
-t, --test "test1 test2" Run multiple tests. Test names must be space delimited and enclosed in quotes
-l, --local-relayer-image <tag> Use a local AWM Relayer image instead of pulling from dockerhub
-h, --help Print this help message
```
- Note that if `-l, --local` is not set, then the latest published `awm-relayer` image will be pulled from Dockerhub.
feuGeneA marked this conversation as resolved.
Show resolved Hide resolved
- This script performs the same setup steps as `scripts/local/run.sh` (described above), and then runs the tests in `./scripts/integration-tests/` automatically

### Additional notes

- Both the `./scripts/local/run.sh` and `./scripts/local/test.sh` scripts run local five node networks, with each of the nodes validating the primary network and three subnets (Subnet A, Subnet B, and Subnet C).
cam-schultz marked this conversation as resolved.
Show resolved Hide resolved
- Logs from the subnets on one of the five nodes are printed to stdout when run using either script.
- These logs can also be found at `~/.avalanche-cli/runs/network-runner-root-data_<DATE>_<TIMESTAMP>/node{1,5]/logs/<SUBNET_ID>.log`, or at `/var/lib/docker/overlay2/<CONTAINER_ID>/merged/root/.avalanche-cli/....` on your local machine. You will need to be the root user to access the logs under `/var/lib`.
cam-schultz marked this conversation as resolved.
Show resolved Hide resolved

### Run tests on Fuji Testnet
The following steps will allow you to run integration tests and example workflows against three Fuji subnets that have AWM enabled. These workflows send transaction on each of these subnets, so you will need to fund your account with some native tokens to pay for gas fees. The three subnets are called [Amplify](https://subnets-test.avax.network/amplify), [Bulletin](https://subnets-test.avax.network/bulletin), and [Conduit](https://subnets-test.avax.network/conduit).

The following steps will allow you to run the integration tests described above and example workflows against three Fuji subnets that have AWM enabled. These workflows send transaction on each of these subnets, so you will need to fund your account with some native tokens to pay for gas fees. The three subnets are called [Amplify](https://subnets-test.avax.network/amplify), [Bulletin](https://subnets-test.avax.network/bulletin), and [Conduit](https://subnets-test.avax.network/conduit).

The configuration for all the subnets is in `.env.testnet`. If needed, you can change the subnet IDs, the chain IDs, urls and teleporter contract address to match your setup.

Expand Down Expand Up @@ -160,7 +184,7 @@ source .env.testnet
source .env
```

### E2E tests
## E2E tests

E2E tests are ran as part of CI, but can also be ran locally with the `--local` flag. To run the E2E tests locally, you'll need to install Gingko following the intructions [here](https://onsi.github.io/ginkgo/#installing-ginkgo)
cam-schultz marked this conversation as resolved.
Show resolved Hide resolved

Expand All @@ -169,7 +193,7 @@ Next, provide the path to the `subnet-evm` repository and the path to a writeabl
./scripts/local/e2e_test.sh --local --subnet-evm ./subnet-evm --data-dir ~/tmp/e2e-test
```

### ABI Bindings
## ABI Bindings

To generate Golang ABI bindings for the Solidity smart contracts, run:
```bash
Expand Down
4 changes: 2 additions & 2 deletions contracts/src/CrossChainApplications/ERC20Bridge/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The generic ERC20 bridge is implemented using two primary contracts.
- Bridge contract that uses Teleporter to facilitate the bridging operations of adding new supported tokens and moving tokens between chains.
- The bridge contract tracks the balances of each token sent to other bridge instances, and only allows those bridge instances to redeem up to the amount of tokens that has been previously sent to them.
- Primary functions include:
- `submitCreateBridgeToken`: Called on the origin subnet to add support for an ERC20 native to the chain to a bridge instance on a different chain. Submits a Teleporter message that invokes `createBridgeToken` on the destination chain.
- `submitCreateBridgeToken`: Called on the origin chain to add support for an ERC20 native to the chain to a bridge instance on a different chain. Submits a Teleporter message that invokes `createBridgeToken` on the destination chain.
cam-schultz marked this conversation as resolved.
Show resolved Hide resolved
- `createBridgeToken`: Called by cross-chain messages to add support for a new bridge token from another chain. Assuming the token is not already supported, deploys a new `BridgeToken` contract instance to represent the tokens on this chain.
- `bridgeTokens`: Called to move supported tokens from one chain to another. This includes both "wrapping" of tokens native to the chain and also "unwrapping" of bridge tokens on the chain to other chains. In the case of unwrapping or moving of a bridge token, if the destination chain ID is the native chain for the given token, the original token is sent to the recipient on the destination. If the destination chain ID is another non-native chain for the underlying token, a Teleporter message is first sent to the native chain, which then subsequently updates its accounting of balances and sends a Teleporter message on the destination chain to re-wrap the given tokens. This multi-hop flow is illustrated below.
- `mintBridgeTokens`: Called by cross-chain messages in the event of new bridge transfers of tokens from their native chains.
Expand All @@ -25,7 +25,7 @@ The generic ERC20 bridge is implemented using two primary contracts.
</div>

## Integration Test
An integration test demostrating the use of the generic ERC20 token bridge contracts can be found from the root of this repository in `integration-tests/erc20_bridge_multihop.sh`. This test implements the following flow and checks that each step is successful:
An integration test demostrating the use of the generic ERC20 token bridge contracts can be found from the root of this repository in `scripts/local/integration-tests/erc20_bridge_multihop.sh`. This test implements the following flow and checks that each step is successful:
1. An example "native" ERC20 token is deployed on subnet A
1. The `ERC20Bridge` contract is deployed on subnets A, B, and C.
1. Teleporter messages are sent from subnet A to B and subnet A to C to add the example ERC20 deployed in step 1 to the bridge instances on the other chains.
Expand Down
Loading