|
1 | | -# Parachain modules |
| 1 | +# Snowbridge · |
| 2 | +[] |
| 3 | +(https://codecov.io/gh/Snowfork/snowbridge) |
| 4 | + |
2 | 5 |
|
3 | | -## Configuration |
| 6 | +Snowbridge is a trustless bridge between Polkadot and Ethereum. For documentation, visit https://docs.snowbridge.network. |
4 | 7 |
|
5 | | -Note: This section is not necessary for local development, as there are scripts to auto-configure the parachain in the |
6 | | -[test directory](https://github.com/Snowfork/snowbridge/blob/main/web/packages/test). |
| 8 | +## Components |
7 | 9 |
|
8 | | -For a fully operational chain, further configuration of the initial chain spec is required. The specific configuration will |
9 | | -depend heavily on your environment, so this guide will remain high-level. |
| 10 | +### Parachain |
10 | 11 |
|
11 | | -After completing a release build of the parachain, build an initial spec for the snowbase runtime: |
| 12 | +Polkadot parachain and our pallets. See [parachain/README.md](https://github.com/Snowfork/snowbridge/blob/main/parachain/README.md). |
12 | 13 |
|
13 | | -```bash |
14 | | -target/release/snowbridge build-spec --chain snowbase --disable-default-bootnode > spec.json |
15 | | -``` |
| 14 | +### Contracts |
16 | 15 |
|
17 | | -Now edit the spec and configure the following: |
18 | | -1. Recently finalized ethereum header and difficulty for the ethereum light client |
19 | | -2. Contract addresses for the Ether, Erc20, and Dot apps. |
20 | | -3. Authorized principal for the basic channel |
| 16 | +Ethereum contracts and unit tests. See [contracts/README.md](https://github.com/Snowfork/snowbridge/blob/main/contracts/README.md) |
21 | 17 |
|
22 | | -For an example configuration, consult the [setup script](https://github.com/Snowfork/snowbridge/blob/main/web/packages/test/scripts/start-services.sh) |
23 | | -for our local development stack. Specifically the `start_polkadot_launch` bash function. |
| 18 | +### Relayer |
24 | 19 |
|
25 | | -## Tests |
| 20 | +Off-chain relayer services for relaying messages between Polkadot and Ethereum. See |
| 21 | +[relayer/README.md](https://github.com/Snowfork/snowbridge/blob/main/relayer/README.md) |
26 | 22 |
|
27 | | -To run the parachain tests locally, use `cargo test --workspace`. For the full suite of tests, use |
28 | | -`cargo test --workspace --features runtime-benchmarks`. |
| 23 | +### Local Testnet |
29 | 24 |
|
30 | | -Optionally exclude the top-level and runtime crates: |
| 25 | +Scripts to provision a local testnet, running the above services to bridge between local deployments of Polkadot and |
| 26 | +Ethereum. See [web/packages/test/README.md](https://github.com/Snowfork/snowbridge/blob/main/web/packages/test/README.md). |
31 | 27 |
|
32 | | -```bash |
33 | | -cargo test --workspace \ |
34 | | - --features runtime-benchmarks \ |
35 | | - --exclude snowbridge \ |
36 | | - --exclude snowbridge-runtime \ |
37 | | - --exclude snowblink-runtime \ |
38 | | - --exclude snowbase-runtime |
39 | | -``` |
| 28 | +### Smoke Tests |
40 | 29 |
|
41 | | -### Updating test data for inbound channel unit tests |
| 30 | +Integration tests for our local testnet. See [smoketest/README.md](https://github.com/Snowfork/snowbridge/blob/main/smoketest/README.md). |
42 | 31 |
|
43 | | -To regenerate the test data, use a test with multiple `submit` calls in `ethereum/test/test_basic_outbound_channel.js`, eg. |
44 | | -"should increment nonces correctly". |
| 32 | +## Development |
45 | 33 |
|
46 | | -Add the following preamble: |
| 34 | +We use the Nix package manager to provide a reproducible and maintainable developer environment. |
47 | 35 |
|
48 | | -```javascript |
49 | | -const rlp = require("rlp"); |
50 | | -const contract = BasicOutboundChannel; |
51 | | -const signature = 'Message(address,address,uint64,uint64,bytes)'; |
52 | | -``` |
| 36 | +After [installing nix](https://nixos.org/download.html) Nix, enable [flakes](https://nixos.wiki/wiki/Flakes): |
53 | 37 |
|
54 | | -For each encoded log you want to create, find a transaction object `tx` returned from a `submit` call and run this: |
55 | | - |
56 | | -```javascript |
57 | | -const rawLog = tx.receipt.rawLogs[0]; |
58 | | -const encodedLog = rlp.encode([rawLog.address, rawLog.topics, rawLog.data]).toString("hex"); |
59 | | -console.log(`encodedLog: ${encodedLog}`); |
60 | | -const iface = new ethers.utils.Interface(contract.abi); |
61 | | -const decodedEventLog = iface.decodeEventLog( |
62 | | - signature, |
63 | | - rawLog.data, |
64 | | - rawLog.topics, |
65 | | -); |
66 | | -console.log(`decoded rawLog.data: ${JSON.stringify(decodedEventLog)}`); |
| 38 | +```sh |
| 39 | +mkdir -p ~/.config/nix |
| 40 | +echo 'experimental-features = nix-command flakes' >> ~/.config/nix/nix.conf |
67 | 41 | ``` |
68 | 42 |
|
69 | | -Place the `encodedLog` string in the `message.data` field in the test data. Use the `decoded rawLog.data` field to |
70 | | -update the comments with the decoded log data. |
71 | | - |
72 | | -## Generating pallet weights from benchmarks |
| 43 | +Then activate a developer shell in the root of our repo, where |
| 44 | +[`flake.nix`](https://github.com/Snowfork/snowbridge/blob/main/flake.nix) is located: |
73 | 45 |
|
74 | | -Build the parachain with the runtime benchmark flags for the chosen runtime: |
| 46 | +```sh |
| 47 | +nix develop |
| 48 | +``` |
75 | 49 |
|
76 | | -```bash |
77 | | -runtime=snowbase |
78 | | -cargo build \ |
79 | | - --release \ |
80 | | - --no-default-features \ |
81 | | - --features "$runtime-native,rococo-native,runtime-benchmarks,$runtime-runtime-benchmarks" \ |
82 | | - --bin snowbridge |
| 50 | +Also make sure to run this initialization script once: |
| 51 | +```sh |
| 52 | +scripts/init.sh |
83 | 53 | ``` |
84 | 54 |
|
85 | | -List available pallets and their benchmarks: |
| 55 | +### Support for code editors |
86 | 56 |
|
87 | | -```bash |
88 | | -./target/release/snowbridge benchmark pallet --chain $runtime --list |
89 | | -``` |
| 57 | +To ensure your code editor (such as VS Code) can execute tools in the nix shell, startup your editor within the |
| 58 | +interactive shell. |
90 | 59 |
|
91 | | -Run a benchmark for a pallet, generating weights: |
92 | | - |
93 | | -```bash |
94 | | -target/release/snowbridge benchmark pallet \ |
95 | | - --chain=$runtime \ |
96 | | - --execution=wasm \ |
97 | | - --wasm-execution=compiled \ |
98 | | - --pallet=basic_channel_inbound \ |
99 | | - --extra \ |
100 | | - --extrinsic=* \ |
101 | | - --repeat=20 \ |
102 | | - --steps=50 \ |
103 | | - --output=pallets/basic-channel/src/inbound/weights.rs \ |
104 | | - --template=templates/module-weight-template.hbs |
105 | | -``` |
| 60 | +Example for VS Code: |
106 | 61 |
|
107 | | -## Generating beacon test fixtures and benchmarking data |
| 62 | +```sh |
| 63 | +nix develop |
| 64 | +code . |
| 65 | +``` |
108 | 66 |
|
109 | | -### Minimal Spec |
| 67 | +### Custom shells |
110 | 68 |
|
111 | | -To generate `minimal` test data and benchmarking data, make sure to start the local E2E setup to spin up a local beacon |
112 | | -node instance to connect to: |
| 69 | +The developer shell is bash by default. To preserve your existing shell: |
113 | 70 |
|
114 | | -```bash |
115 | | -cd web/packages/test |
116 | | -./scripts/start-services.sh |
| 71 | +```sh |
| 72 | +nix develop --command $SHELL |
117 | 73 | ``` |
118 | 74 |
|
119 | | -Wait for output `Testnet has been initialized`. |
| 75 | +### Automatic developer shells |
120 | 76 |
|
121 | | -In a separate terminal, from the `snowbridge` directory, run: |
| 77 | +To automatically enter the developer shell whenever you open the project, install |
| 78 | +[`direnv`](https://direnv.net/docs/installation.html) and use the template `.envrc`: |
122 | 79 |
|
123 | | -```bash |
124 | | -mage -d relayer build && relayer/build/snowbridge-relay generate-beacon-data --spec "minimal" && cd parachain && |
125 | | -cargo +nightly fmt -- --config-path rustfmt.toml && cd - |
| 80 | +```sh |
| 81 | +cp .envrc.example .envrc |
| 82 | +direnv allow |
126 | 83 | ``` |
127 | 84 |
|
128 | | -### Mainnet Spec |
| 85 | +### Upgrading the Rust toolchain |
| 86 | + |
| 87 | +Sometimes we would like to upgrade rust toolchain. First update `parachain/rust-toolchain.toml` as required and then |
| 88 | +update `flake.lock` running |
| 89 | +```sh |
| 90 | +nix flake lock --update-input rust-overlay |
| 91 | +``` |
129 | 92 |
|
130 | | -We only use the mainnet spec for generating fixtures for pallet weight benchmarks. |
| 93 | +## Troubleshooting |
131 | 94 |
|
132 | | -To generate the data we can connect to the Lodestar Goerli public node. The script already connects to the Lodestar node, |
133 | | -so no need to start up additional services. In the event of the Lodestar node not being available, you can start up your |
134 | | -own stack with these commands: |
| 95 | +Check the contents of all `.envrc` files. |
135 | 96 |
|
136 | | -```bash |
137 | | -cd web/packages/test |
138 | | -./scripts/start-goerli.sh |
| 97 | +Remove untracked files: |
| 98 | +```sh |
| 99 | +git clean -idx |
139 | 100 | ``` |
140 | 101 |
|
141 | | -From the `snowbridge` directory, run: |
| 102 | +Ensure that the current Rust toolchain is the one selected in `scripts/init.sh`. |
142 | 103 |
|
143 | | -```bash |
144 | | -mage -d relayer build && relayer/build/snowbridge-relay generate-beacon-data --spec "mainnet" && cd parachain && |
145 | | -cargo +nightly fmt -- --config-path rustfmt.toml && cd - |
| 104 | +Ensure submodules are up-to-date: |
| 105 | +```sh |
| 106 | +git submodule update |
146 | 107 | ``` |
147 | 108 |
|
148 | | -### Benchmarking tests |
| 109 | +Check untracked files & directories: |
| 110 | +```sh |
| 111 | +git clean -ndx | awk '{print $3}' |
| 112 | +``` |
| 113 | +After removing `node_modules` directories (eg. with `git clean above`), clear the pnpm cache: |
| 114 | +```sh |
| 115 | +pnpm store prune |
| 116 | +``` |
149 | 117 |
|
150 | | -To run the benchmark tests |
| 118 | +Check Nix config in `~/.config/nix/nix.conf`. |
151 | 119 |
|
152 | | -```bash |
153 | | -cd parachain/pallets/ethereum-beacon-client |
154 | | -cargo test --release --features runtime-benchmarks |
| 120 | +Run a pure developer shell (note that this removes access to your local tools): |
| 121 | +```sh |
| 122 | +nix develop -i --pure-eval |
155 | 123 | ``` |
| 124 | + |
| 125 | +## Security |
| 126 | + |
| 127 | +The security policy and procedures can be found in SECURITY.md. |
0 commit comments