From b3e99496a4968ee9d8b03e1706894ffc7a00ece9 Mon Sep 17 00:00:00 2001 From: Dustin Brickwood Date: Mon, 28 Mar 2022 15:47:25 -0500 Subject: [PATCH] wip: initial walkthrough of documentation --- .github/workflows/publish-rust-docs.yml | 37 +++++++++ .licenserc.yaml | 49 ++++++++++++ Dockerfile | 14 ++++ src/config.rs | 44 +++++++---- src/context.rs | 29 +++++-- src/events_watcher/anchor_watcher_over_dkg.rs | 20 ++++- src/events_watcher/mod.rs | 19 ++++- .../proposal_handler_watcher.rs | 14 ++++ src/events_watcher/tornado_leaves_watcher.rs | 17 ++++- src/handler.rs | 75 ++++++++++++++++++- src/main.rs | 14 ++++ src/probe.rs | 14 ++++ src/service.rs | 29 ++++++- src/store/mem.rs | 16 +++- src/store/mod.rs | 22 +++++- src/store/sled.rs | 26 +++++-- src/tx_queue.rs | 52 ++++++++++++- src/utils.rs | 14 ++++ tests/evmTransactionRelayer.test.ts | 16 ++++ tests/lib/MerkleTree.js | 16 ++++ tests/lib/MiMC.js | 16 ++++ tests/lib/Storage.js | 16 ++++ tests/lib/localDkg.ts | 16 ++++ tests/lib/localTestnet.ts | 16 ++++ tests/lib/webbRelayer.ts | 16 ++++ 25 files changed, 577 insertions(+), 40 deletions(-) create mode 100644 .github/workflows/publish-rust-docs.yml create mode 100644 .licenserc.yaml diff --git a/.github/workflows/publish-rust-docs.yml b/.github/workflows/publish-rust-docs.yml new file mode 100644 index 000000000..28e1a9dd7 --- /dev/null +++ b/.github/workflows/publish-rust-docs.yml @@ -0,0 +1,37 @@ +name: Publish Docs + +on: + push: + branches: + - master + pull_request: + branches: + - master + +jobs: + publish_docs: + if: github.event_name == 'push' && github.event.ref == 'refs/heads/master' + name: Publish Documentation + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + + - name: Install toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: nightly + + - name: Update apt repositories + run: sudo apt update + + - name: Build documentation + run: cargo doc --no-deps + - name: Publish documentation + run: | + cd target/doc + git init + echo '' > index.html + git add . + git -c user.name='ci' -c user.email='ci' commit -m 'Deploy documentation 🚀' + git push -f -q https://git:${{ secrets.github_token }}@github.com/${{ github.repository }} HEAD:gh-pages \ No newline at end of file diff --git a/.licenserc.yaml b/.licenserc.yaml new file mode 100644 index 000000000..a55e9902e --- /dev/null +++ b/.licenserc.yaml @@ -0,0 +1,49 @@ +# Copyright 2022 Webb Technologies Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +header: + license: + spdx-id: Apache-2.0 + copyright-owner: Webb Technologies Inc. + + paths-ignore: + - 'store/*' + - '**/*.env' + - '**/*.bash' + - 'target/*' + - 'rust-toolchain' + - '**/*.conf' + - '.env-example' + - 'tests/protocol-solidity-fixtures/*' + - '.eslintignore' + - 'licenses' + - '**/*.md' + - 'LICENSE' + - 'NOTICE' + - '.gitignore' + - '.dockerignore' + - '.editorconfig' + - '.gitmodules' + - '**/*.yml' + - '**/*.json' + - '**/*.lock' + - '**/*.toml' + - '**/*.yaml' + - '.nvmrc' + - 'jest.config.js' + - '*/**.mjs' + - '**/*.sh' + - 'node_modules/*' + + comment: on-failure \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 375204514..7cf54b076 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,17 @@ +# Copyright 2022 Webb Technologies Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# FROM scratch LABEL APP ="Webb Relayer" LABEL AUTHOR="Webb Developers " diff --git a/src/config.rs b/src/config.rs index f7b9be334..931a295d6 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,3 +1,17 @@ +// Copyright 2022 Webb Technologies Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// use std::collections::HashMap; use std::path::Path; use std::str::FromStr; @@ -22,7 +36,7 @@ const fn max_events_per_step_default() -> u64 { const fn print_progress_interval_default() -> u64 { 7_000 } - +/// WebbRelayerConfig is the configuration for the webb relayer. #[derive(Debug, Clone, Deserialize, Serialize, Default)] #[serde(rename_all = "kebab-case")] pub struct WebbRelayerConfig { @@ -45,7 +59,7 @@ pub struct WebbRelayerConfig { #[serde(default)] pub experimental: ExperimentalConfig, } - +/// EvmChainConfig is the configuration for the EVM based networks. #[derive(Debug, Clone, Deserialize, Serialize)] #[serde(rename_all = "kebab-case")] pub struct EvmChainConfig { @@ -92,7 +106,7 @@ pub struct EvmChainConfig { #[serde(skip_serializing, default)] pub tx_queue: TxQueueConfig, } - +/// SubstrateConfig is the configuration for the Substrate based networks. #[derive(Debug, Clone, Deserialize, Serialize)] #[serde(rename_all = "kebab-case")] pub struct SubstrateConfig { @@ -157,7 +171,7 @@ pub struct ExperimentalConfig { pub smart_anchor_updates: bool, pub smart_anchor_updates_retries: u32, } - +/// TxQueueConfig is the configuration for the TxQueue. #[derive(Debug, Clone, Deserialize, Serialize)] #[serde(rename_all = "kebab-case")] pub struct TxQueueConfig { @@ -173,6 +187,7 @@ impl Default for TxQueueConfig { } } } +/// EventsWatchConfig is the configuration for the events watch. #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(rename_all = "kebab-case")] pub struct EventsWatcherConfig { @@ -202,7 +217,7 @@ pub struct AnchorWithdrawConfig { #[serde(skip_serializing)] pub withdraw_gaslimit: U256, } - +/// LinkedAnchorConfig is the configuration for the linked anchor. #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(rename_all = "kebab-case")] pub struct LinkedAnchorConfig { @@ -212,7 +227,7 @@ pub struct LinkedAnchorConfig { /// The Anchor Contract Address. pub address: Address, } - +/// Enumerates the supported contract configurations. #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(tag = "contract")] pub enum Contract { @@ -220,21 +235,21 @@ pub enum Contract { AnchorOverDKG(AnchorContractOverDKGConfig), GovernanceBravoDelegate(GovernanceBravoDelegateContractConfig), } - +/// Enumerates the supported pallets configurations. #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(tag = "pallet")] pub enum Pallet { DKGProposals(DKGProposalsPalletConfig), DKGProposalHandler(DKGProposalHandlerPalletConfig), } - +/// Enumerates the supported Substrate runtimes. #[derive(Debug, Clone, Serialize, Deserialize)] pub enum SubstrateRuntime { #[serde(rename = "DKG")] Dkg, WebbProtocol, } - +/// CommonContractConfig represents the common configuration for contracts. #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(rename_all = "kebab-case")] pub struct CommonContractConfig { @@ -244,7 +259,7 @@ pub struct CommonContractConfig { #[serde(rename(serialize = "deployedAt"))] pub deployed_at: u64, } - +/// TornadoContractConfig represents the configuration for the Tornado contract. #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(rename_all = "kebab-case")] pub struct TornadoContractConfig { @@ -259,7 +274,7 @@ pub struct TornadoContractConfig { #[serde(flatten)] pub withdraw_config: AnchorWithdrawConfig, } - +/// AnchorContractOverDKGConfig represents the configuration for the Anchor contract over DKG. #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(rename_all = "kebab-case")] pub struct AnchorContractOverDKGConfig { @@ -281,7 +296,7 @@ pub struct AnchorContractOverDKGConfig { #[serde(rename(serialize = "linkedAnchors"))] pub linked_anchors: Vec, } - +/// GovernanceBravoDelegateContractConfig represents the configuration for the GovernanceBravoDelegate contract. #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(rename_all = "kebab-case")] pub struct GovernanceBravoDelegateContractConfig { @@ -289,7 +304,7 @@ pub struct GovernanceBravoDelegateContractConfig { pub common: CommonContractConfig, // TODO(@shekohex): add more fields here... } - +/// DKGProposalsPalletConfig represents the configuration for the DKGProposals pallet. #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(rename_all = "kebab-case")] pub struct DKGProposalsPalletConfig { @@ -297,7 +312,7 @@ pub struct DKGProposalsPalletConfig { #[serde(rename(serialize = "eventsWatcher"))] pub events_watcher: EventsWatcherConfig, } - +/// DKGProposalHandlerPalletConfig represents the configuration for the DKGProposalHandler pallet. #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(rename_all = "kebab-case")] pub struct DKGProposalHandlerPalletConfig { @@ -455,6 +470,7 @@ impl<'de> Deserialize<'de> for Suri { Ok(Self(secret)) } } +/// load the private key from the environment variable pub fn load>(path: P) -> anyhow::Result { let mut cfg = config::Config::new(); // A pattern that covers all toml or json files in the config directory and subdirectories. diff --git a/src/context.rs b/src/context.rs index 18c912536..4ff00c32d 100644 --- a/src/context.rs +++ b/src/context.rs @@ -1,3 +1,17 @@ +// Copyright 2022 Webb Technologies Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// use std::convert::TryFrom; use std::time::Duration; @@ -9,7 +23,7 @@ use webb::substrate::subxt; use webb::substrate::subxt::sp_core::sr25519::Pair as Sr25519Pair; use crate::config; - +/// RelayerContext contains Relayer's configuration and shutdown signal. #[derive(Clone)] pub struct RelayerContext { pub config: config::WebbRelayerConfig, @@ -25,6 +39,7 @@ pub struct RelayerContext { } impl RelayerContext { + /// Creates a new RelayerContext. pub fn new(config: config::WebbRelayerConfig) -> Self { let (notify_shutdown, _) = broadcast::channel(2); Self { @@ -32,15 +47,15 @@ impl RelayerContext { notify_shutdown, } } - + /// Returns a broadcast receiver handle for the shutdown signal. pub fn shutdown_signal(&self) -> Shutdown { Shutdown::new(self.notify_shutdown.subscribe()) } - + /// Sends a shutdown signal to all active connections. pub fn shutdown(&self) { let _ = self.notify_shutdown.send(()); } - + /// evm_provider returns an Ethers provider for the configured EVM chain. pub async fn evm_provider( &self, chain_name: &str, @@ -53,7 +68,7 @@ impl RelayerContext { .interval(Duration::from_millis(5u64)); Ok(provider) } - + /// evm_wallet returns an Ethers wallet for the configured EVM chain. pub async fn evm_wallet( &self, chain_name: &str, @@ -67,7 +82,7 @@ impl RelayerContext { let wallet = LocalWallet::from(key).with_chain_id(chain_id); Ok(wallet) } - + /// substrate_provider returns a Substrate provider for the configured pub async fn substrate_provider( &self, node_name: &str, @@ -87,7 +102,7 @@ impl RelayerContext { ))?; Ok(client) } - + /// substrate_wallet returns a Substrate wallet for the configured Substrate chain. pub async fn substrate_wallet( &self, node_name: &str, diff --git a/src/events_watcher/anchor_watcher_over_dkg.rs b/src/events_watcher/anchor_watcher_over_dkg.rs index 70a013bd2..7d2fcfa25 100644 --- a/src/events_watcher/anchor_watcher_over_dkg.rs +++ b/src/events_watcher/anchor_watcher_over_dkg.rs @@ -1,3 +1,17 @@ +// Copyright 2022 Webb Technologies Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// use std::ops; use std::sync::Arc; use std::time::Duration; @@ -17,7 +31,7 @@ use crate::config; use crate::store::sled::SledStore; type HttpProvider = providers::Provider; - +/// Represents a Substrate specific watcher for Anchor events. pub struct AnchorWatcherWithSubstrate where R: From>, @@ -32,6 +46,7 @@ where R: From>, C: subxt::Config, { + /// Creates a new AnchorWatcherWithSubstrate. pub fn new( client: subxt::Client, pair: subxt::PairSigner, Sr25519Pair>, @@ -46,9 +61,11 @@ where type DKGConfig = subxt::DefaultConfig; type DKGRuntimeApi = dkg_runtime::api::RuntimeApi>; +/// Type alias for the AnchorWatcherWithSubstrate. pub type AnchorWatcherOverDKG = AnchorWatcherWithSubstrate; +/// AnchorContractOverDKGWrapper contains FixedDepositAnchorContract contract along with configurations for Anchor contract over DKG, and Relayer. #[derive(Clone, Debug)] pub struct AnchorContractOverDKGWrapper where @@ -63,6 +80,7 @@ impl AnchorContractOverDKGWrapper where M: Middleware, { + /// Creates a new AnchorContractOverDKGWrapper. pub fn new( config: config::AnchorContractOverDKGConfig, webb_config: config::WebbRelayerConfig, diff --git a/src/events_watcher/mod.rs b/src/events_watcher/mod.rs index 476c8ee3b..aec2a8958 100644 --- a/src/events_watcher/mod.rs +++ b/src/events_watcher/mod.rs @@ -1,3 +1,17 @@ +// Copyright 2022 Webb Technologies Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// use std::cmp; use std::ops::Deref; use std::sync::Arc; @@ -48,6 +62,7 @@ pub trait WatchableContract: Send + Sync { fn print_progress_interval(&self) -> Duration; } +/// A trait for watching events from a watchable contract. #[async_trait::async_trait] pub trait EventWatcher { const TAG: &'static str; @@ -203,10 +218,10 @@ pub trait EventWatcher { Ok(()) } } - +/// Type alias for Substrate block number. pub type BlockNumberOf = <::RuntimeConfig as subxt::Config>::BlockNumber; - +/// Represents a Substrate event watcher. #[async_trait::async_trait] pub trait SubstrateEventWatcher { const TAG: &'static str; diff --git a/src/events_watcher/proposal_handler_watcher.rs b/src/events_watcher/proposal_handler_watcher.rs index 9e35c6b59..946b6c537 100644 --- a/src/events_watcher/proposal_handler_watcher.rs +++ b/src/events_watcher/proposal_handler_watcher.rs @@ -1,3 +1,17 @@ +// Copyright 2022 Webb Technologies Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// use std::sync::Arc; use webb::substrate::dkg_runtime::api::dkg_proposal_handler; diff --git a/src/events_watcher/tornado_leaves_watcher.rs b/src/events_watcher/tornado_leaves_watcher.rs index e35ac820a..4d3bb7e89 100644 --- a/src/events_watcher/tornado_leaves_watcher.rs +++ b/src/events_watcher/tornado_leaves_watcher.rs @@ -1,3 +1,17 @@ +// Copyright 2022 Webb Technologies Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// use std::ops; use std::sync::Arc; use std::time::Duration; @@ -15,7 +29,7 @@ use crate::store::LeafCacheStore; #[derive(Copy, Clone, Debug)] pub struct TornadoLeavesWatcher; - +/// Represents a Tornado leaves watcher. #[derive(Clone, Debug)] pub struct TornadoContractWrapper { config: config::TornadoContractConfig, @@ -23,6 +37,7 @@ pub struct TornadoContractWrapper { } impl TornadoContractWrapper { + /// Creates a new TornadoContractWrapper. pub fn new(config: config::TornadoContractConfig, client: Arc) -> Self { Self { contract: TornadoContract::new(config.common.address, client), diff --git a/src/handler.rs b/src/handler.rs index b7da12e69..f680fc5fb 100644 --- a/src/handler.rs +++ b/src/handler.rs @@ -1,3 +1,17 @@ +// Copyright 2022 Webb Technologies Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// #![allow(clippy::large_enum_variant)] use std::collections::HashMap; @@ -39,6 +53,20 @@ use webb::substrate::subxt::{self, PairSigner, TransactionStatus}; type CommandStream = mpsc::Sender; +/// Sets up a websocket connection. +/// +/// Returns `Ok(())` on success +/// +/// # Arguments +/// +/// * `ctx` - RelayContext reference that holds the configuration +/// * `stream` - Websocket stream +/// +/// # Examples +/// +/// ``` +/// let _ = handler::accept_connection(ctx.as_ref(), socket).await; +/// ``` pub async fn accept_connection( ctx: &RelayerContext, stream: warp::ws::WebSocket, @@ -51,7 +79,21 @@ pub async fn accept_connection( } Ok(()) } - +/// Sets u websocket channels for message sending. +/// +/// Returns `Ok(())` on success +/// +/// # Arguments +/// +/// * `ctx` - RelayContext reference that holds the configuration +/// * `v` - A vector of bytes +/// * `tx` - A mutable Trait implementation of the `warp::ws::Sender` trait +/// +/// # Examples +/// +/// ``` +/// let _ = handle_text(ctx, text, &mut tx).await?;; +/// ``` pub async fn handle_text( ctx: &RelayerContext, v: &str, @@ -87,12 +129,25 @@ where Ok(()) } +/// Representation for IP address response #[derive(Debug, Serialize)] #[serde(rename_all = "camelCase")] pub struct IpInformationResponse { ip: String, } - +/// Handles the `ip` address response +/// +/// Returns a Result with the `IpInformationResponse` on success +/// +/// # Arguments +/// +/// * `ip` - Option containing the IP address +/// +/// # Examples +/// +/// ``` +/// let _ = handler::handle_ip_info +/// ``` pub async fn handle_ip_info( ip: Option, ) -> Result { @@ -100,7 +155,19 @@ pub async fn handle_ip_info( ip: ip.unwrap().to_string(), })) } - +/// Handles the socket address response +/// +/// Returns a Result with the `IpInformationResponse` on success +/// +/// # Arguments +/// +/// * `ip` - Option containing the socket address +/// +/// # Examples +/// +/// ``` +/// let _ = handler::handle_ip_info +/// ``` pub async fn handle_socket_info( ip: Option, ) -> Result { @@ -190,7 +257,7 @@ pub struct MixerRelayTransaction { pub root: [u8; 32], /// The nullifier_hash for the proof pub nullifier_hash: [u8; 32], - /// The receipient of the transaction + /// The recipient of the transaction pub recipient: subxt::sp_core::crypto::AccountId32, /// The relayer of the transaction pub relayer: subxt::sp_core::crypto::AccountId32, diff --git a/src/main.rs b/src/main.rs index 5c4aed844..3ee2eed81 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,17 @@ +// Copyright 2022 Webb Technologies Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// #![deny(unsafe_code)] use std::path::{Path, PathBuf}; diff --git a/src/probe.rs b/src/probe.rs index 2777303ec..b4d1d184c 100644 --- a/src/probe.rs +++ b/src/probe.rs @@ -1,3 +1,17 @@ +// Copyright 2022 Webb Technologies Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// use derive_more::Display; pub const TARGET: &str = "webb_probe"; diff --git a/src/service.rs b/src/service.rs index 926fef6d4..f8428c70a 100644 --- a/src/service.rs +++ b/src/service.rs @@ -1,3 +1,17 @@ +// Copyright 2022 Webb Technologies Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// use std::sync::Arc; use ethereum_types::U256; @@ -19,7 +33,20 @@ type DkgRuntime = DkgRuntimeApi< subxt::DefaultExtra, >; type Store = crate::store::sled::SledStore; - +/// Starts all background services for all chains configured in the config file. +/// +/// Returns a future that resolves when all services are started successfully. +/// +/// # Arguments +/// +/// * `ctx` - RelayContext reference that holds the configuration +/// * `store` - Store reference that holds the database +/// +/// # Examples +/// +/// ``` +/// let _ = service::ignite(&ctx, Arc::new(store)).await?; +/// ``` pub async fn ignite( ctx: &RelayerContext, store: Arc, diff --git a/src/store/mem.rs b/src/store/mem.rs index bfe373571..e3010a08e 100644 --- a/src/store/mem.rs +++ b/src/store/mem.rs @@ -1,3 +1,17 @@ +// Copyright 2022 Webb Technologies Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// use std::collections::HashMap; use std::fmt::Debug; use std::sync::Arc; @@ -8,7 +22,7 @@ use webb::evm::ethers::types; use super::{HistoryStore, HistoryStoreKey, LeafCacheStore}; type MemStore = HashMap>; - +/// InMemoryStore is a store that stores the history of events in memory. #[derive(Clone, Default)] pub struct InMemoryStore { store: Arc>, diff --git a/src/store/mod.rs b/src/store/mod.rs index fedab8b42..7fdb09983 100644 --- a/src/store/mod.rs +++ b/src/store/mod.rs @@ -1,3 +1,17 @@ +// Copyright 2022 Webb Technologies Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// use std::fmt::{Debug, Display}; use std::sync::Arc; @@ -7,7 +21,7 @@ use webb::evm::ethers::types; pub mod mem; pub mod sled; - +/// HistoryStoreKey contains the keys used to store the history of events. #[derive(Eq, PartialEq, Hash)] pub enum HistoryStoreKey { Evm { @@ -25,13 +39,14 @@ pub enum HistoryStoreKey { pub struct BridgeKey; impl HistoryStoreKey { + /// Returns the chain id of the chain this key is for. pub fn chain_id(&self) -> types::U256 { match self { HistoryStoreKey::Evm { chain_id, .. } => *chain_id, HistoryStoreKey::Substrate { chain_id, .. } => *chain_id, } } - + /// Returns the address of the chain this key is for. pub fn address(&self) -> types::H160 { match self { HistoryStoreKey::Evm { address, .. } => *address, @@ -45,6 +60,7 @@ impl HistoryStoreKey { } } } + /// to_bytes returns the bytes of the key. pub fn to_bytes(&self) -> Vec { let mut vec = vec![]; match self { @@ -216,7 +232,7 @@ where S::remove_item(self, key) } } - +/// ProposalStore is a simple trait for inserting and removing proposals. pub trait ProposalStore { type Proposal: Serialize + DeserializeOwned; fn insert_proposal(&self, proposal: Self::Proposal) -> anyhow::Result<()>; diff --git a/src/store/sled.rs b/src/store/sled.rs index ca1bbeb43..34342bc12 100644 --- a/src/store/sled.rs +++ b/src/store/sled.rs @@ -1,3 +1,17 @@ +// Copyright 2022 Webb Technologies Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// use core::fmt; use serde::de::DeserializeOwned; use serde::Serialize; @@ -9,7 +23,7 @@ use crate::store::{BridgeKey, QueueKey}; use super::HistoryStoreKey; use super::{HistoryStore, LeafCacheStore, ProposalStore, QueueStore}; - +/// SledStore is a store that stores the history of events in Sled. #[derive(Clone)] pub struct SledStore { db: sled::Db, @@ -22,6 +36,7 @@ impl std::fmt::Debug for SledStore { } impl SledStore { + /// Create a new SledStore. pub fn open>(path: P) -> anyhow::Result { let db = sled::Config::new() .path(path) @@ -31,7 +46,7 @@ impl SledStore { .open()?; Ok(Self { db }) } - + /// Creates a temporary SledStore. pub fn temporary() -> anyhow::Result { let dir = tempfile::tempdir()?; Self::open(dir.path()) @@ -143,7 +158,7 @@ impl LeafCacheStore for SledStore { } } } - +/// SledQueueKey is a key for a queue in Sled. #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)] pub enum SledQueueKey { EvmTx { @@ -155,13 +170,14 @@ pub enum SledQueueKey { } impl SledQueueKey { + /// Create a new SledQueueKey from an evm chain id. pub fn from_evm_chain_id(chain_id: types::U256) -> Self { Self::EvmTx { chain_id, optional_key: None, } } - + /// from_evm_with_custom_key returns an EVM specific SledQueueKey. #[allow(dead_code)] pub fn from_evm_with_custom_key( chain_id: types::U256, @@ -172,7 +188,7 @@ impl SledQueueKey { optional_key: Some(key), } } - + /// from_bridge_key returns a Bridge specific SledQueueKey. #[allow(dead_code)] pub fn from_bridge_key(bridge_key: BridgeKey) -> Self { Self::BridgeCmd { bridge_key } diff --git a/src/tx_queue.rs b/src/tx_queue.rs index c03811cb3..ba0b95757 100644 --- a/src/tx_queue.rs +++ b/src/tx_queue.rs @@ -1,3 +1,17 @@ +// Copyright 2022 Webb Technologies Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// use std::sync::Arc; use std::time::Duration; @@ -14,6 +28,7 @@ use crate::store::sled::SledQueueKey; use crate::store::QueueStore; use crate::utils::ClickableLink; +/// Represents the transactions that are waiting to be processed. #[derive(Clone)] pub struct TxQueue> { ctx: RelayerContext, @@ -25,6 +40,22 @@ impl TxQueue where S: QueueStore, { + /// Creates a new TxQueue instance. + /// + /// Returns a TxQueue instance. + /// + /// # Arguments + /// + /// * `ctx` - RelayContext reference that holds the configuration + /// * `chain_name` - The name of the chain that this queue is for + /// * `store` - Store reference that holds the database + /// + /// # Examples + /// + /// ``` + /// use crate::tx_queue::TxQueue; + /// let tx_queue = TxQueue::new(ctx, chain_name.clone(), store); + /// ``` pub fn new(ctx: RelayerContext, chain_name: String, store: Arc) -> Self { Self { ctx, @@ -32,7 +63,26 @@ where store, } } - + /// Starts the TxQueue service. + /// + /// Returns a future that resolves `Ok(())` on success, otherwise returns an error. + /// + /// # Examples + /// + /// ``` + /// use crate::tx_queue::TxQueue; + /// let tx_queue = TxQueue::new(ctx, chain_name.clone(), store); + /// let task = async move { + /// tokio::select! { + /// _ = tx_queue.run() => { + /// // do something + /// }, + /// _ = shutdown_signal.recv() => { + /// // do something + /// }, + /// } + /// }; + /// ``` #[tracing::instrument(skip_all, fields(chain = %self.chain_name))] pub async fn run(self) -> Result<(), anyhow::Error> { let provider = self.ctx.evm_provider(&self.chain_name).await?; diff --git a/src/utils.rs b/src/utils.rs index 3306bf149..6bfb50c54 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,3 +1,17 @@ +// Copyright 2022 Webb Technologies Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// use std::fmt; use webb::substrate::subxt; diff --git a/tests/evmTransactionRelayer.test.ts b/tests/evmTransactionRelayer.test.ts index a19f6570b..f33769481 100644 --- a/tests/evmTransactionRelayer.test.ts +++ b/tests/evmTransactionRelayer.test.ts @@ -1,3 +1,19 @@ +/* + * Copyright 2022 Webb Technologies Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ // This our basic EVM Transaction Relayer Tests. // These are for testing the basic relayer functionality. which is just relay transactions for us. diff --git a/tests/lib/MerkleTree.js b/tests/lib/MerkleTree.js index d8457a19b..2827326bd 100644 --- a/tests/lib/MerkleTree.js +++ b/tests/lib/MerkleTree.js @@ -1,3 +1,19 @@ +/* + * Copyright 2022 Webb Technologies Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ import jsStorage from './Storage'; import hasherImpl from './MiMC'; diff --git a/tests/lib/MiMC.js b/tests/lib/MiMC.js index d070373dc..a66e9a210 100644 --- a/tests/lib/MiMC.js +++ b/tests/lib/MiMC.js @@ -1,3 +1,19 @@ +/* + * Copyright 2022 Webb Technologies Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ const circomlib = require('circomlib') const mimcsponge = circomlib.mimcsponge const snarkjs = require('snarkjs') diff --git a/tests/lib/Storage.js b/tests/lib/Storage.js index bc5fd8426..5f6751ff1 100644 --- a/tests/lib/Storage.js +++ b/tests/lib/Storage.js @@ -1,3 +1,19 @@ +/* + * Copyright 2022 Webb Technologies Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ class JsStorage { constructor() { this.db = {}; diff --git a/tests/lib/localDkg.ts b/tests/lib/localDkg.ts index e129801d1..904811ddb 100644 --- a/tests/lib/localDkg.ts +++ b/tests/lib/localDkg.ts @@ -1,3 +1,19 @@ +/* + * Copyright 2022 Webb Technologies Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ /// A Helper Class to Start and Manage a Local DKG Node. /// This Could be through a Docker Container or a Local Compiled node. diff --git a/tests/lib/localTestnet.ts b/tests/lib/localTestnet.ts index e5f8cc9b2..cb74bd3f8 100644 --- a/tests/lib/localTestnet.ts +++ b/tests/lib/localTestnet.ts @@ -1,3 +1,19 @@ +/* + * Copyright 2022 Webb Technologies Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ import fs from 'fs'; import ganache from 'ganache'; import { ethers } from 'ethers'; diff --git a/tests/lib/webbRelayer.ts b/tests/lib/webbRelayer.ts index 9b206943a..4876ce88e 100644 --- a/tests/lib/webbRelayer.ts +++ b/tests/lib/webbRelayer.ts @@ -1,3 +1,19 @@ +/* + * Copyright 2022 Webb Technologies Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ import WebSocket from 'ws'; import fetch from 'node-fetch'; import { IFixedAnchorPublicInputs } from '@webb-tools/interfaces';