-
Notifications
You must be signed in to change notification settings - Fork 666
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Snowbridge Rococo deployment updates (#2792)
- Includes the introduction of the `fast-runtime` feature, which cleans up our features - Updates beacon client fork versions config to Sepolia's versions - Cleanup of AgentIdOf --------- Co-authored-by: Ron <yrong1997@gmail.com> Co-authored-by: claravanstaden <Cats 4 life!>
- Loading branch information
1 parent
69e2ae6
commit 3811629
Showing
26 changed files
with
3,544 additions
and
1,527 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,155 +1,127 @@ | ||
# Parachain modules | ||
# Snowbridge · | ||
[![codecov](https://codecov.io/gh/Snowfork/snowbridge/branch/main/graph/badge.svg?token=9hvgSws4rN)] | ||
(https://codecov.io/gh/Snowfork/snowbridge) | ||
![GitHub](https://img.shields.io/github/license/Snowfork/snowbridge) | ||
|
||
## Configuration | ||
Snowbridge is a trustless bridge between Polkadot and Ethereum. For documentation, visit https://docs.snowbridge.network. | ||
|
||
Note: This section is not necessary for local development, as there are scripts to auto-configure the parachain in the | ||
[test directory](https://github.com/Snowfork/snowbridge/blob/main/web/packages/test). | ||
## Components | ||
|
||
For a fully operational chain, further configuration of the initial chain spec is required. The specific configuration will | ||
depend heavily on your environment, so this guide will remain high-level. | ||
### Parachain | ||
|
||
After completing a release build of the parachain, build an initial spec for the snowbase runtime: | ||
Polkadot parachain and our pallets. See [parachain/README.md](https://github.com/Snowfork/snowbridge/blob/main/parachain/README.md). | ||
|
||
```bash | ||
target/release/snowbridge build-spec --chain snowbase --disable-default-bootnode > spec.json | ||
``` | ||
### Contracts | ||
|
||
Now edit the spec and configure the following: | ||
1. Recently finalized ethereum header and difficulty for the ethereum light client | ||
2. Contract addresses for the Ether, Erc20, and Dot apps. | ||
3. Authorized principal for the basic channel | ||
Ethereum contracts and unit tests. See [contracts/README.md](https://github.com/Snowfork/snowbridge/blob/main/contracts/README.md) | ||
|
||
For an example configuration, consult the [setup script](https://github.com/Snowfork/snowbridge/blob/main/web/packages/test/scripts/start-services.sh) | ||
for our local development stack. Specifically the `start_polkadot_launch` bash function. | ||
### Relayer | ||
|
||
## Tests | ||
Off-chain relayer services for relaying messages between Polkadot and Ethereum. See | ||
[relayer/README.md](https://github.com/Snowfork/snowbridge/blob/main/relayer/README.md) | ||
|
||
To run the parachain tests locally, use `cargo test --workspace`. For the full suite of tests, use | ||
`cargo test --workspace --features runtime-benchmarks`. | ||
### Local Testnet | ||
|
||
Optionally exclude the top-level and runtime crates: | ||
Scripts to provision a local testnet, running the above services to bridge between local deployments of Polkadot and | ||
Ethereum. See [web/packages/test/README.md](https://github.com/Snowfork/snowbridge/blob/main/web/packages/test/README.md). | ||
|
||
```bash | ||
cargo test --workspace \ | ||
--features runtime-benchmarks \ | ||
--exclude snowbridge \ | ||
--exclude snowbridge-runtime \ | ||
--exclude snowblink-runtime \ | ||
--exclude snowbase-runtime | ||
``` | ||
### Smoke Tests | ||
|
||
### Updating test data for inbound channel unit tests | ||
Integration tests for our local testnet. See [smoketest/README.md](https://github.com/Snowfork/snowbridge/blob/main/smoketest/README.md). | ||
|
||
To regenerate the test data, use a test with multiple `submit` calls in `ethereum/test/test_basic_outbound_channel.js`, eg. | ||
"should increment nonces correctly". | ||
## Development | ||
|
||
Add the following preamble: | ||
We use the Nix package manager to provide a reproducible and maintainable developer environment. | ||
|
||
```javascript | ||
const rlp = require("rlp"); | ||
const contract = BasicOutboundChannel; | ||
const signature = 'Message(address,address,uint64,uint64,bytes)'; | ||
``` | ||
After [installing nix](https://nixos.org/download.html) Nix, enable [flakes](https://nixos.wiki/wiki/Flakes): | ||
|
||
For each encoded log you want to create, find a transaction object `tx` returned from a `submit` call and run this: | ||
|
||
```javascript | ||
const rawLog = tx.receipt.rawLogs[0]; | ||
const encodedLog = rlp.encode([rawLog.address, rawLog.topics, rawLog.data]).toString("hex"); | ||
console.log(`encodedLog: ${encodedLog}`); | ||
const iface = new ethers.utils.Interface(contract.abi); | ||
const decodedEventLog = iface.decodeEventLog( | ||
signature, | ||
rawLog.data, | ||
rawLog.topics, | ||
); | ||
console.log(`decoded rawLog.data: ${JSON.stringify(decodedEventLog)}`); | ||
```sh | ||
mkdir -p ~/.config/nix | ||
echo 'experimental-features = nix-command flakes' >> ~/.config/nix/nix.conf | ||
``` | ||
|
||
Place the `encodedLog` string in the `message.data` field in the test data. Use the `decoded rawLog.data` field to | ||
update the comments with the decoded log data. | ||
|
||
## Generating pallet weights from benchmarks | ||
Then activate a developer shell in the root of our repo, where | ||
[`flake.nix`](https://github.com/Snowfork/snowbridge/blob/main/flake.nix) is located: | ||
|
||
Build the parachain with the runtime benchmark flags for the chosen runtime: | ||
```sh | ||
nix develop | ||
``` | ||
|
||
```bash | ||
runtime=snowbase | ||
cargo build \ | ||
--release \ | ||
--no-default-features \ | ||
--features "$runtime-native,rococo-native,runtime-benchmarks,$runtime-runtime-benchmarks" \ | ||
--bin snowbridge | ||
Also make sure to run this initialization script once: | ||
```sh | ||
scripts/init.sh | ||
``` | ||
|
||
List available pallets and their benchmarks: | ||
### Support for code editors | ||
|
||
```bash | ||
./target/release/snowbridge benchmark pallet --chain $runtime --list | ||
``` | ||
To ensure your code editor (such as VS Code) can execute tools in the nix shell, startup your editor within the | ||
interactive shell. | ||
|
||
Run a benchmark for a pallet, generating weights: | ||
|
||
```bash | ||
target/release/snowbridge benchmark pallet \ | ||
--chain=$runtime \ | ||
--execution=wasm \ | ||
--wasm-execution=compiled \ | ||
--pallet=basic_channel_inbound \ | ||
--extra \ | ||
--extrinsic=* \ | ||
--repeat=20 \ | ||
--steps=50 \ | ||
--output=pallets/basic-channel/src/inbound/weights.rs \ | ||
--template=templates/module-weight-template.hbs | ||
``` | ||
Example for VS Code: | ||
|
||
## Generating beacon test fixtures and benchmarking data | ||
```sh | ||
nix develop | ||
code . | ||
``` | ||
|
||
### Minimal Spec | ||
### Custom shells | ||
|
||
To generate `minimal` test data and benchmarking data, make sure to start the local E2E setup to spin up a local beacon | ||
node instance to connect to: | ||
The developer shell is bash by default. To preserve your existing shell: | ||
|
||
```bash | ||
cd web/packages/test | ||
./scripts/start-services.sh | ||
```sh | ||
nix develop --command $SHELL | ||
``` | ||
|
||
Wait for output `Testnet has been initialized`. | ||
### Automatic developer shells | ||
|
||
In a separate terminal, from the `snowbridge` directory, run: | ||
To automatically enter the developer shell whenever you open the project, install | ||
[`direnv`](https://direnv.net/docs/installation.html) and use the template `.envrc`: | ||
|
||
```bash | ||
mage -d relayer build && relayer/build/snowbridge-relay generate-beacon-data --spec "minimal" && cd parachain && | ||
cargo +nightly fmt -- --config-path rustfmt.toml && cd - | ||
```sh | ||
cp .envrc.example .envrc | ||
direnv allow | ||
``` | ||
|
||
### Mainnet Spec | ||
### Upgrading the Rust toolchain | ||
|
||
Sometimes we would like to upgrade rust toolchain. First update `parachain/rust-toolchain.toml` as required and then | ||
update `flake.lock` running | ||
```sh | ||
nix flake lock --update-input rust-overlay | ||
``` | ||
|
||
We only use the mainnet spec for generating fixtures for pallet weight benchmarks. | ||
## Troubleshooting | ||
|
||
To generate the data we can connect to the Lodestar Goerli public node. The script already connects to the Lodestar node, | ||
so no need to start up additional services. In the event of the Lodestar node not being available, you can start up your | ||
own stack with these commands: | ||
Check the contents of all `.envrc` files. | ||
|
||
```bash | ||
cd web/packages/test | ||
./scripts/start-goerli.sh | ||
Remove untracked files: | ||
```sh | ||
git clean -idx | ||
``` | ||
|
||
From the `snowbridge` directory, run: | ||
Ensure that the current Rust toolchain is the one selected in `scripts/init.sh`. | ||
|
||
```bash | ||
mage -d relayer build && relayer/build/snowbridge-relay generate-beacon-data --spec "mainnet" && cd parachain && | ||
cargo +nightly fmt -- --config-path rustfmt.toml && cd - | ||
Ensure submodules are up-to-date: | ||
```sh | ||
git submodule update | ||
``` | ||
|
||
### Benchmarking tests | ||
Check untracked files & directories: | ||
```sh | ||
git clean -ndx | awk '{print $3}' | ||
``` | ||
After removing `node_modules` directories (eg. with `git clean above`), clear the pnpm cache: | ||
```sh | ||
pnpm store prune | ||
``` | ||
|
||
To run the benchmark tests | ||
Check Nix config in `~/.config/nix/nix.conf`. | ||
|
||
```bash | ||
cd parachain/pallets/ethereum-beacon-client | ||
cargo test --release --features runtime-benchmarks | ||
Run a pure developer shell (note that this removes access to your local tools): | ||
```sh | ||
nix develop -i --pure-eval | ||
``` | ||
|
||
## Security | ||
|
||
The security policy and procedures can be found in SECURITY.md. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.