Crates.io | webb-relayer |
lib.rs | webb-relayer |
version | 0.4.1 |
source | src |
created_at | 2022-08-15 12:18:14.767702 |
updated_at | 2022-08-15 16:44:21.366714 |
description | The Webb Relayer toolkit |
homepage | https://webb.tools |
repository | https://github.com/webb-tools/relayer |
max_upload_size | |
id | 645896 |
size | 504,294 |
π The Webb Relayer π§ββοΈ
β οΈ Beta Software β οΈ
In the Webb Protocol, the relayer plays a variety of roles. This repo contains code for an Anchor Protcol oracle, transaction and data relayer, and protocol governance participant. The aim is that these can all be run exclusive to one another to ensure maximum flexibility of external participants to the Webb Protocol.
The relayer system is composed of three main components. Each of these components should be thought of as entirely separate because they could be handled by different entities entirely.
Relayers who fulfill the role of a transaction relayer are responsible with exposing an API for clients who wish to relay their zero-knowledge transactions through and with submitting them. Relayers of this role must possess enough balance on the blockchains in which they will relay these transactions, since, after all, they must possess the native balance to pay the fees for these transactions. Relayers can be configured for any number of chains and protocols from mixers to variable anchors and run for individual chains or all of them that exist for a given bridged set of anchors.
Relayers who fulfill this role do so in conjunction with the transaction relaying role although it is not required to possess both. Namely, this role is concerned with listening to the events occurring within an Anchor Protocol instance and storing the data for clients who wish to quickly access it through traditional HTTP methods. This role is actively maintained and sees regular updates to how we hope to store and serve data in the future.
Relayers who fulfill the role of an oracle listen to the Anchor Protocol instances on the various chains the anchors exist on. When they hear of insertions into the anchors' merkle trees they handle them accordingly (as is implemented in the event watchers). Those playing this role then relay the anchor update information to other connected Anchors, the DKG governance system, and any other integration that gets implemented in this repo. Oracle relayers help keep the state of an Anchor Protocol instance up to date by ensuring that all anchors within an instance know about the latest state of their neighboring anchors.
For additional information, please refer to the Webb Relayer Rust Docs π. Have feedback on how to improve the relayer network? Or have a specific question to ask? Checkout the Relayer Feedback Discussion π¬.
This repo uses Rust so it is required to have a Rust developer environment set up. First install and configure rustup:
# Install
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# Configure
source ~/.cargo/env
Configure the Rust toolchain to default to the latest stable version, add nightly:
rustup default stable
rustup update
rustup update nightly
Great! Now your Rust environment is ready! ππ
git clone https://github.com/webb-tools/relayer.git
cargo build --release --features cli
Eager to try out the Webb Relayer and see it in action? Run a relayer with our preset EVM Local Network configuration to get up and running immediately. You can follow this guide to use the relayer for the EVM bridge! You will have to configure an .env
file in the root directory as well. See below configuration section for more details.
# Update your local env file
cp ./config/development/evm-localnet/.env.example .env
cargo run -- -c ./config/development/evm-localnet -vvv
Hot Tip πΆοΈ: To increase the logger verbosity add additional
-vvvv
during start up command. You will now seeTRACE
logs. Happy debugging!
To use the relayer for our Substrate mixer, you will first need to start a local substrate node that integrates with our pallets webb-standalone-node. Once the Substrate node is started locally you can proceed to start the relayer. You can follow this guide to use the relayer for the Substrate mixer!
cargo run -- -c ./config/development/local-substrate -vvv
Webb Relayer is easy to run and with flexible config π. The first step is to create a config file.
Example:
.env
file with the following values for the networks you wish to support.WEBB_EVM_<network>_ENABLED=true
WEBB_EVM_<network>_PRIVATE_KEY=<0X_PREFIXED_PRIVATE_KEY>
WEBB_EVM_<network>_BENEFICIARY=<0X_PREFIXED_ADDRESS>
Checkout config for useful default configurations for many networks. These config files can be changed to your preferences, and are enabled with the .env configuration listed above.
Then run:
webb-relayer -vv -c ./config
Hot Tip πΆοΈ: you could also use the
json
format for the config files if you prefer that!
Note: You can also review the different chain configurations for EVM and Substrate.
Field | Description | Optionality |
---|---|---|
http-endpoint |
Http(s) Endpoint for quick Req/Res | Required |
ws-endpoint |
Websocket Endpoint for long living connections | Required |
name |
The Chain/Node name | Required |
explorer |
Block explorer, used for generating clickable links for transactions that happens on this chain. | Optional |
chain-id |
Chain specific id. | Required |
private-key |
The Private Key of this account on this network. See PrivateKey Docs for secure setup | Required |
beneficiary |
The address of the account that will receive relayer fees. | Optional |
runtime |
Indicates Substrate runtime to use | Required for Substrate |
suri |
Interprets a string in order to generate a key Pair. In the case that the pair can be expressed as a direct derivation from a seed | Required for Substrate |
pallets |
Supported pallets for a particular Substrate node | Optional |
Field | Description | Optionality |
---|---|---|
contract |
Chain contract. Must be either: - VAnchor - SignatureBridge | Required |
address |
The address of this contract on this chain. | Required |
deployed-at |
The block number where this contract got deployed at. | Required |
events-watcher |
Control the events watcher for this contract. | Optional |
withdraw-config |
Config the fees and gas limits of your private transaction relayer. | Optional |
proposal-signing-backend |
a value of ProposalSigingBackend (for example { type = "DKGNode", node = "dkg-node" } ) |
Optional |
To use Docker to run the relayer, you will need to specify a config file and provide an .env
file as described above. Then proceed to save it into the config
directory.
To run docker image:
docker run --rm -v "<ABSOLUTE_PATH_TO_CONFIGS_DIRECTORY>:/config" --env-file .env -p 9955:9955 ghcr.io/webb-tools/relayer:edge
Note: this uses the latest and pre-released version deployed from
main
branch, changeedge
to the latest stable release version.
This will mount a configuration files at the /config
directory inside the container so it would allow it to read the configuration you added.
The relayer has 3 endpoints available to query from. They are outlined below for your convenience.
Retrieving nodes IP address:
/api/v1/ip
{
"ip": "127.0.0.1"
}
Retrieve relayer configuration
/api/v1/info
{
"evm": {
"rinkeby": {
"enabled": true,
"chainId": 4,
"beneficiary": "0x58fcd47ece3ed24ace88fee06efd90dcb38f541f",
"contracts": [{
"contract": "Anchor",
"address": "0x626fec5ffa7bf1ee8ced7dabde545630473e3abb",
"deployedAt": 8896800,
"eventsWatcher": {
"enabled": true,
"pollingInterval": 15000
},
"size": 0.1,
"proposalSigningBackend": { "type": "DKGNode", "node": "dkg-local" },
"withdrawFeePercentage": 0.05
}]
}
},
"substrate": {},
"experimental": {
"smart-anchor-updates": false,
"smart-anchor-updates-retries": 0
}
}
Retrieve historical leaves cache
target_system
(Could be evm
or substrate
).chain_id
contract_address
/api/v1/leaves/evm/4/0x626fec5ffa7bf1ee8ced7dabde545630473e3abb
Note: Since substrate dosent have contract address we use
tree_id
/api/v1/leaves/substrate/4/9
{
"leaves": ["0x2e5c62af48845c095bfa9b90b8ec9f6b7bd98fb3ac2dd3039050a64b919951dd", "0x0f89f0ef52120b8db99f5bdbbdd4019b5ea4bcfef14b0c19d261268da8afdc24", "0x3007c62f678a503e568534487bc5b0bc651f37bbe1f34668b4c8a360f15ba3c3"],
"lastQueriedBlock": "0x9f30a8"
}
The following instructions outlines how to run the relayer base test suite and E2E test suite.
cargo test
First you will need protocol-substrate
node, compiled locally (in release mode) and both the protocol-substrate
and relayer
project must be next to each other. The relayer must be compiled using --features integration-tests
.
Here is the basic setup you will need:
git clone https://github.com/webb-tools/relayer.git
https://github.com/webb-tools/protocol-substrate.git
cd protocol-substrate && git submodule update --init
cargo build --release -p webb-standalone-node
cd ../relayer
cargo build --features integration-tests
cd tests && git submodule update --init --recursive
yarn install
(in tests
dir)yarn test
yarn test -fgrep <UNIQUE_PART_OF_TEST_NAME>
.yarn test --bail
.yarn test --parallel=false
.yarn test --retries=0
.For the Substrate Mixer test, you can connect to your local chain manually by:
const aliceManualPorts = { ws: 9944, http: 9933, p2p: 30333 };
const bobManualPorts = { ws: 9945, http: 9934, p2p: 30334 };
ports
property value be the aliceManualPorts
and bobManualPorts
respectively in the LocalNodeOpts
config which is the parameter in LocalProtocolSubstrate.start()
method.isManual
flag to true
in the LocalNodeOpts
config which is the parameter in LocalProtocolSubstrate.start()
method.Interested in contributing to the Webb Relayer Network? Thank you so much for your interest! We are always appreciative for contributions from the open-source community!
If you have a contribution in mind, please check out our Contribution Guide for information on how to do so. We are excited for your first contribution!
Licensed under Apache 2.0 license.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache 2.0 license, shall be licensed as above, without any additional terms or conditions.