Skip to content

Commit

Permalink
Relayer using signing rules as backend (#608)
Browse files Browse the repository at this point in the history
* rename dkg event crate watcher to tangle

* Update backend name form Dkg to Contract

* signal signature brige to update AUP proposals

* update reayer with latest subxt changes

* update SigningRulesBackendConfig

* get eth adrress from compressed public key

* AUP works using signing rules contract as backend

* update webb-rs

* cleaup

* fix clippy

* clippy fix

* some more fixes
  • Loading branch information
salman01zp authored May 6, 2024
1 parent 757b422 commit e307a31
Show file tree
Hide file tree
Showing 36 changed files with 1,121 additions and 2,765 deletions.
3,131 changes: 697 additions & 2,434 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ webb-relayer-context = { path = "crates/relayer-context" }
webb-relayer-utils = { path = "crates/relayer-utils" }
webb-chains-info = { path = "crates/chains-info" }
webb-event-watcher-traits = { path = "crates/event-watcher-traits" }
webb-ew-dkg = { path = "event-watchers/dkg" }
webb-ew-tangle = { path = "event-watchers/tangle" }
webb-ew-evm = { path = "event-watchers/evm" }

webb-relayer-handler-utils = { path = "crates/relayer-handler-utils" }
Expand All @@ -31,6 +31,8 @@ webb-relayer = { path = "services/webb-relayer" }
webb-proof-generation = { path = "crates/proof-generation" }
webb-circom-proving = { path = "crates/circom-proving" }

tangle-subxt = { git = "https://github.com/webb-tools/tangle", default-features = false, branch = "main" }

thiserror = "^1"
anyhow = "^1"
tracing = { version = "^0.1", features = ["log"] }
Expand All @@ -39,10 +41,10 @@ url = { version = "^2.3", features = ["serde"] }
sled = "^0.34"
tokio = { version = "^1", features = ["full"] }
config = { version = "0.13", default-features = false, features = ["toml", "json"] }
serde_json = { version = "^1", default-features = false }
serde_json = { version = "^1", default-features = false, features = ["raw_value"] }
paw = { version = "^1.0" }
webb = { version = "0.8.4", default-features = false }
subxt-signer = { version = "0.31", features = ["subxt"] }
webb = { version = "0.8.5", default-features = false }
subxt-signer = { version = "0.34", features = ["subxt"] }
# Used by ethers (but we need it to be vendored with the lib).
native-tls = { version = "^0.2", features = ["vendored"] }
webb-proposals = { git = "https://github.com/webb-tools/webb-rs", features = ["scale"] }
Expand All @@ -64,7 +66,7 @@ serde = { version = "^1", default-features = false, features = ["derive"] }
glob = "^0.3"
serde_path_to_error = "0.1.9"
serde_bytes = "0.11"
jsonrpsee = { version = "0.16.2" }
jsonrpsee = { version = "0.20.3" }

[profile.release]
strip = "symbols"
Expand Down
1 change: 1 addition & 0 deletions crates/event-watcher-traits/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ native-tls = { workspace = true }
webb-proposals = { workspace = true }
sled = { version = "^0.34" }
subxt-signer = { workspace = true }
tangle-subxt = { workspace = true }

[dev-dependencies]
tracing-test = "0.2"
Expand Down
33 changes: 25 additions & 8 deletions crates/event-watcher-traits/src/substrate/event_watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use tangle_subxt::subxt::{
backend::{legacy::LegacyRpcMethods, rpc::RpcClient},
config::Header,
OnlineClient,
};
use tokio::sync::Mutex;
use webb::substrate::subxt::{config::Header, OnlineClient};
use webb_relayer_config::event_watcher::EventsWatcherConfig;
use webb_relayer_context::RelayerContext;
use webb_relayer_utils::{metric, retry};
Expand Down Expand Up @@ -168,10 +172,24 @@ where
return Err(backoff::Error::transient(err));
}
};

let maybe_rpc_client = ctx.get_ws_client::<_>(chain_id).await;
let rpc = match maybe_rpc_client {
Ok(ws_client) => {
let rpc_client = RpcClient::new(ws_client);
LegacyRpcMethods::<RuntimeConfig>::new(rpc_client.clone())
}
Err(err) => {
tracing::error!(
"Failed to connect with substrate rpc client for chain_id: {}, retrying...!",
chain_id
);
return Err(backoff::Error::transient(err));
}
};
let client = Arc::new(client);
let mut instant = std::time::Instant::now();
let step = 1u64;
let rpc = client.rpc();
// get pallet index
let pallet_index = {
let metadata = client.metadata();
Expand All @@ -196,13 +214,13 @@ where
// now we start polling for new events.
// get the current latest block number.
let latest_head = rpc
.finalized_head()
.chain_get_finalized_head()
.map_err(Into::into)
.map_err(backoff::Error::transient)
.await?;

let maybe_latest_header = rpc
.header(Some(latest_head))
.chain_get_header(Some(latest_head))
.map_err(Into::into)
.map_err(backoff::Error::transient)
.await?;
Expand All @@ -219,9 +237,8 @@ where
"Latest block number: #{}",
current_block_number
);
let sync_blocks_from: u64 = event_watcher_config
.sync_blocks_from
.unwrap_or(current_block_number);
let sync_blocks_from: u64 =
event_watcher_config.sync_blocks_from.unwrap_or(0);
// get latest saved block number
let block = store
.get_last_block_number(history_store_key, sync_blocks_from)
Expand All @@ -243,7 +260,7 @@ where
// range [block, dest_block].
// so first we get the hash of the block we want to start from.
let maybe_from = rpc
.block_hash(Some(dest_block.into()))
.chain_get_block_hash(Some(dest_block.into()))
.map_err(Into::into)
.map_err(backoff::Error::transient)
.await?;
Expand Down
2 changes: 1 addition & 1 deletion crates/event-watcher-traits/src/substrate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use futures::prelude::*;
use std::cmp;
use std::sync::Arc;
use std::time::Duration;
use webb::substrate::subxt::{self, client::OnlineClientT, config::Header};
use tangle_subxt::subxt::{self, client::OnlineClientT, config::Header};
use webb_proposals::{
ResourceId, SubstrateTargetSystem, TargetSystem, TypedChainId,
};
Expand Down
6 changes: 3 additions & 3 deletions crates/event-watcher-traits/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
// limitations under the License.

use std::sync::Arc;
use tangle_subxt::subxt::{self, Config, OnlineClient};
use tangle_subxt::tangle_testnet_runtime::api::system;
use tokio::sync::Mutex;
use webb::substrate::subxt::{self, Config, OnlineClient};
use webb::substrate::tangle_runtime::api::system;
use webb_relayer_config::event_watcher::EventsWatcherConfig;
use webb_relayer_context::RelayerContext;
use webb_relayer_store::sled::SledStore;
Expand Down Expand Up @@ -84,7 +84,7 @@ async fn substrate_event_watcher_should_work() -> webb_relayer_utils::Result<()>
{
let chain_id = 5u32;
let store = SledStore::temporary()?;
let watcher = TestEventsWatcher::default();
let watcher = TestEventsWatcher;
let config = webb_relayer_config::WebbRelayerConfig::default();
let ctx = RelayerContext::new(config, store.clone()).await?;
let metrics = ctx.metrics.clone();
Expand Down
2 changes: 1 addition & 1 deletion crates/proof-generation/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub enum ProofGenerationError {
JsonDecodeError,
}

///
/// Proof inputs for Masp proof delegation.
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct MaspDelegatedProofInputsJson {
Expand Down
1 change: 1 addition & 0 deletions crates/proposal-signing-backends/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ webb-relayer-types = { workspace = true }
webb-relayer-store = { workspace = true }
webb-relayer-utils = { workspace = true }
webb-relayer-config = { workspace = true }
webb-relayer-context = { workspace = true }

async-trait = { workspace = true }
tracing = { workspace = true }
Expand Down
94 changes: 0 additions & 94 deletions crates/proposal-signing-backends/src/dkg.rs

This file was deleted.

19 changes: 8 additions & 11 deletions crates/proposal-signing-backends/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
//! Proposal signing backends are used to sign the proposals that are generated by the relayer.
//! There are two types of proposal signing backends:
//! - `MockedProposalSigningBackend`: This is a mocked proposal signing backend that is used for testing purposes.
//! - `DkgProposalSigningRulesBackend`: This is the actual proposal signing backend that is used in production.
//! - `SigningRulesBackend`: This is the actual proposal signing backend that is used in production.
//!
//! This crate also contains the proposal queue that is used to queue the proposals that are generated by the relayer.

use std::{ops, sync::Arc};
use tokio::sync::Mutex;
use webb::evm::ethers::contract::Contract;
use webb::evm::{
contract::protocol_dkg::signing_rules::SigningRulesContract,
contract::tangle::votable_signing_rules::SigningRulesContract,
ethers::providers::Middleware,
};
use webb_proposals::ProposalTrait;
Expand All @@ -37,19 +37,19 @@ use webb_proposals::ProposalTrait;
pub mod proposal_handler;

#[doc(hidden)]
pub mod dkg;
pub mod tangle;

#[doc(hidden)]
pub mod mocked;

/// A module to handle the queue of proposals
pub mod queue;

/// A module that Implements the DKG Proposal Signing Backend.
pub use dkg::*;
/// A module that Implements the Mocked Proposal Signing Backend.
pub use mocked::*;
use webb_relayer_config::signing_backend::DkgProposalSigningBackendConfig;
/// A module that Implements the DKG Proposal Signing Backend.
pub use tangle::*;
use webb_relayer_config::signing_backend::SigningRulesBackendConfig;
use webb_relayer_utils::metric;

/// A Proposal Signing Backend is responsible for signing proposal `P` where `P` is anything really depending on the
Expand Down Expand Up @@ -81,7 +81,7 @@ where
M: Middleware,
{
/// Signing rules contract config.
pub config: DkgProposalSigningBackendConfig,
pub config: SigningRulesBackendConfig,
/// Contratc
pub contract: SigningRulesContract<M>,
}
Expand All @@ -91,10 +91,7 @@ where
M: Middleware,
{
/// Creates wrapper around SigningRulesContract.
pub fn new(
config: DkgProposalSigningBackendConfig,
client: Arc<M>,
) -> Self {
pub fn new(config: SigningRulesBackendConfig, client: Arc<M>) -> Self {
Self {
contract: SigningRulesContract::new(config.address, client),
config,
Expand Down
Loading

0 comments on commit e307a31

Please sign in to comment.