Skip to content

Commit

Permalink
wip: bridge-registry-backend
Browse files Browse the repository at this point in the history
  • Loading branch information
Nutomic committed Mar 13, 2023
1 parent 347bff2 commit babb63d
Show file tree
Hide file tree
Showing 16 changed files with 206 additions and 57 deletions.
76 changes: 50 additions & 26 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ members = [
webb = { git = "https://github.com/webb-tools/webb-rs.git" }

[workspace.dependencies]
webb-bridge-registry-backends = { path = "crates/bridge-registry-backends" }
webb-proposal-signing-backends = { path = "crates/proposal-signing-backends" }
webb-relayer-tx-queue = { path = "crates/tx-queue" }
webb-relayer-handlers = { path = "crates/relayer-handlers" }
Expand All @@ -41,7 +42,7 @@ tokio = { version = "^1", features = ["full"] }
config = { version = "0.13", default-features = false, features = ["toml", "json"] }
serde_json = { version = "^1", default-features = false }
paw = { version = "^1.0" }
webb = { version = "0.5.17", default-features = false }
webb = { version = "0.5.18", default-features = false }
sp-core = { version = "16.0.0", default-features = false }
sp-runtime = { version = "18.0.0", default-features = false }
# Used by ethers (but we need it to be vendored with the lib).
Expand Down
2 changes: 2 additions & 0 deletions config/development/evm-localdkg/athena.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ enabled = true
# - VAnchor (Variable Anchor)
# - SignatureBridge
contract = "VAnchor"
type = "VAnchor"
# The address of the contract
address = "0x91eB86019FD8D7c5a9E31143D422850A13F670A3"
# The deployed block number of the contract. When a relayer does not have information for
Expand All @@ -63,6 +64,7 @@ proposal-signing-backend = { type = "DKGNode", node = "5" }

[[evm.athena.contracts]]
contract = "SignatureBridge"
type = "SignatureBridge"
address = "0x51a240271AB8AB9f9a21C82d9a85396b704E164d"
deployed-at = 1
events-watcher = { enabled = true, polling-interval = 1000, print-progress-interval = 60000 }
2 changes: 2 additions & 0 deletions config/development/evm-localdkg/demeter.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ enabled = true
# - VAnchor (Variable Anchor)
# - SignatureBridge
contract = "VAnchor"
type = "VAnchor"
# The address of the contract
address = "0x6595b34ED0a270B10a586FC1EA22030A95386f1e"
# The deployed block number of the contract. When a relayer does not have information for
Expand All @@ -61,6 +62,7 @@ proposal-signing-backend = { type = "DKGNode", node = "5" }

[[evm.demeter.contracts]]
contract = "SignatureBridge"
type = "SignatureBridge"
address = "0x2946259E0334f33A064106302415aD3391BeD384"
deployed-at = 1
events-watcher = { enabled = true, polling-interval = 10000, print-progress-interval = 0 }
2 changes: 2 additions & 0 deletions config/development/evm-localdkg/hermes.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ enabled = true
# - VAnchor (Variable Anchor)
# - SignatureBridge
contract = "VAnchor"
type = "VAnchor"
# The address of the contract
address = "0xc705034ded85e817b9E56C977E61A2098362898B"
# The deployed block number of the contract. When a relayer does not have information for
Expand All @@ -61,6 +62,7 @@ proposal-signing-backend = { type = "DKGNode", node = "5" }

[[evm.hermes.contracts]]
contract = "SignatureBridge"
type = "SignatureBridge"
address = "0xDe09E74d4888Bc4e65F589e8c13Bce9F71DdF4c7"
deployed-at = 1
events-watcher = { enabled = true, polling-interval = 1000, print-progress-interval = 60000 }
1 change: 1 addition & 0 deletions config/development/local-substrate/substrate.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ http-endpoint = "http://localhost:9933"
ws-endpoint = "ws://localhost:9944"
runtime = "WebbProtocol"
suri = "//Alice//stash"
chain-id = 5002
[[substrate.localnode.pallets]]
pallet = "VAnchorBn254"
events-watcher = { enabled = true, polling-interval = 10000, print-progress-interval = 0 }
33 changes: 33 additions & 0 deletions crates/bridge-registry-backends/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[package]
name = "webb-bridge-registry-backends"
version = "0.1.0"
authors = { workspace = true }
edition = { workspace = true }
license = { workspace = true }
documentation = { workspace = true }
homepage = { workspace = true }
repository = { workspace = true }

[dependencies]
webb-relayer-types = { path = "../relayer-types" }
webb-relayer-store = { path = "../relayer-store" }
webb-relayer-utils = { path = "../relayer-utils" }

async-trait = { workspace = true }
tracing = { workspace = true }
sled = { workspace = true }
futures = { workspace = true }
tokio = { workspace = true }
hex = { workspace = true }
webb = { workspace = true }
# Used by ethers (but we need it to be vendored with the lib).
native-tls = { workspace = true, optional = true }
webb-proposals = { workspace = true }
ethereum-types = { workspace = true }
sp-core = { workspace = true }

typed-builder = "0.12.0"

[features]
default = ["std"]
std = []
41 changes: 41 additions & 0 deletions crates/bridge-registry-backends/src/dkg.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use webb::substrate::subxt::{OnlineClient, PolkadotConfig};
use webb::substrate::dkg_runtime::api as RuntimeApi;
use webb::substrate::dkg_runtime::api::runtime_types::pallet_bridge_registry::types::BridgeMetadata;

pub struct DkgBridgeRegistryBackend {
client: OnlineClient<PolkadotConfig>,
}

impl DkgBridgeRegistryBackend {
pub fn new(
client: OnlineClient<PolkadotConfig>,
) -> Self {
Self {
client,
}
}
}

#[async_trait::async_trait]
impl super::BridgeRegistryBackend for DkgBridgeRegistryBackend {
async fn next_bridge_index(&self) -> webb_relayer_utils::Result<u32> {
// retrieve resource ids from bridge registry
let storage = RuntimeApi::storage().bridge_registry();
let next_bridge_index = storage.next_bridge_index();
Ok(self.client.storage()
.at(None)
.await?
.fetch(&next_bridge_index)
.await?
.unwrap())
}

async fn bridges(&self, index: u32) -> webb_relayer_utils::Result<BridgeMetadata> {
let storage = RuntimeApi::storage().bridge_registry();
let bridges = storage.bridges(index);
Ok(self.client.storage()
.at(None)
.await?
.fetch(&bridges).await?.unwrap())
}
}
18 changes: 18 additions & 0 deletions crates/bridge-registry-backends/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use webb::substrate::dkg_runtime::api::runtime_types::pallet_bridge_registry::types::BridgeMetadata;

#[doc(hidden)]
pub mod dkg;

#[doc(hidden)]
pub mod mocked;

#[async_trait::async_trait]
pub trait BridgeRegistryBackend {
async fn next_bridge_index(
&self,
) -> webb_relayer_utils::Result<u32>;
async fn bridges(
&self,
index: u32
) -> webb_relayer_utils::Result<BridgeMetadata>;
}
Loading

0 comments on commit babb63d

Please sign in to comment.