From 7efd2b92ee4445b07003104a5dcc04e359b54a43 Mon Sep 17 00:00:00 2001 From: salman01zp Date: Thu, 25 May 2023 19:25:26 +0530 Subject: [PATCH 1/5] create new client if connection drops --- Cargo.lock | 85 +++++++++++++++++-- crates/event-watcher-traits/Cargo.toml | 2 +- .../src/substrate/bridge_watcher.rs | 11 ++- .../src/substrate/event_watcher.rs | 28 ++++-- .../event-watcher-traits/src/substrate/mod.rs | 6 +- crates/event-watcher-traits/src/tests.rs | 5 +- crates/relayer-context/Cargo.toml | 2 +- crates/relayer-context/src/lib.rs | 10 +++ .../src/substrate/substrate_tx_queue.rs | 21 +++-- event-watchers/dkg/src/lib.rs | 6 +- event-watchers/substrate/src/lib.rs | 4 +- .../substrate/src/signature_bridge_watcher.rs | 7 +- services/webb-relayer/src/main.rs | 10 ++- services/webb-relayer/src/service/mod.rs | 6 +- .../webb-relayer/src/service/substrate.rs | 47 +++++----- 15 files changed, 174 insertions(+), 76 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f024a6e33..e2d0d0782 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4032,10 +4032,10 @@ version = "0.16.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7d291e3a5818a2384645fd9756362e6d89cf0541b0b916fa7702ea4a9833608e" dependencies = [ - "jsonrpsee-client-transport", - "jsonrpsee-core", + "jsonrpsee-client-transport 0.16.2", + "jsonrpsee-core 0.16.2", "jsonrpsee-http-client", - "jsonrpsee-types", + "jsonrpsee-types 0.16.2", ] [[package]] @@ -4046,8 +4046,8 @@ checksum = "965de52763f2004bc91ac5bcec504192440f0b568a5d621c59d9dbd6f886c3fb" dependencies = [ "futures-util", "http", - "jsonrpsee-core", - "jsonrpsee-types", + "jsonrpsee-core 0.16.2", + "jsonrpsee-types 0.16.2", "pin-project 1.0.12", "rustls-native-certs", "soketto", @@ -4059,6 +4059,25 @@ dependencies = [ "webpki-roots", ] +[[package]] +name = "jsonrpsee-client-transport" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11aa5766d5c430b89cb26a99b88f3245eb91534be8126102cea9e45ee3891b22" +dependencies = [ + "futures-util", + "http", + "jsonrpsee-core 0.18.2", + "pin-project 1.0.12", + "rustls-native-certs", + "soketto", + "thiserror", + "tokio 1.28.1", + "tokio-rustls 0.24.0", + "tokio-util 0.7.7", + "tracing", +] + [[package]] name = "jsonrpsee-core" version = "0.16.2" @@ -4073,7 +4092,7 @@ dependencies = [ "futures-timer", "futures-util", "hyper 0.14.25", - "jsonrpsee-types", + "jsonrpsee-types 0.16.2", "rustc-hash", "serde", "serde_json", @@ -4082,6 +4101,28 @@ dependencies = [ "tracing", ] +[[package]] +name = "jsonrpsee-core" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64c6832a55f662b5a6ecc844db24b8b9c387453f923de863062c60ce33d62b81" +dependencies = [ + "anyhow", + "async-lock", + "async-trait", + "beef", + "futures-timer", + "futures-util", + "jsonrpsee-types 0.18.2", + "rustc-hash", + "serde", + "serde_json", + "thiserror", + "tokio 1.28.1", + "tokio-stream", + "tracing", +] + [[package]] name = "jsonrpsee-http-client" version = "0.16.2" @@ -4091,8 +4132,8 @@ dependencies = [ "async-trait", "hyper 0.14.25", "hyper-rustls 0.23.2", - "jsonrpsee-core", - "jsonrpsee-types", + "jsonrpsee-core 0.16.2", + "jsonrpsee-types 0.16.2", "rustc-hash", "serde", "serde_json", @@ -4115,6 +4156,32 @@ dependencies = [ "tracing", ] +[[package]] +name = "jsonrpsee-types" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e5bf6c75ce2a4217421154adfc65a24d2b46e77286e59bba5d9fa6544ccc8f4" +dependencies = [ + "anyhow", + "beef", + "serde", + "serde_json", + "thiserror", + "tracing", +] + +[[package]] +name = "jsonrpsee-ws-client" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a64b2589680ba1ad7863f279cd2d5083c1dc0a7c0ea959d22924553050f8ab9f" +dependencies = [ + "http", + "jsonrpsee-client-transport 0.18.2", + "jsonrpsee-core 0.18.2", + "jsonrpsee-types 0.18.2", +] + [[package]] name = "k256" version = "0.11.6" @@ -9017,6 +9084,7 @@ dependencies = [ "async-trait", "backoff", "futures", + "jsonrpsee-ws-client", "native-tls", "sled", "sp-core", @@ -9292,6 +9360,7 @@ name = "webb-relayer-context" version = "0.1.0" dependencies = [ "http", + "jsonrpsee-ws-client", "native-tls", "regex", "serde", diff --git a/crates/event-watcher-traits/Cargo.toml b/crates/event-watcher-traits/Cargo.toml index cdcd06cab..b9a5862b8 100644 --- a/crates/event-watcher-traits/Cargo.toml +++ b/crates/event-watcher-traits/Cargo.toml @@ -28,7 +28,7 @@ webb-proposals = { workspace = true } tracing-test = "0.2" sled = { version = "^0.34" } sp-core = { workspace = true } - +jsonrpsee-ws-client = "0.18.1" [features] default = ["std", "evm", "substrate"] std = [] diff --git a/crates/event-watcher-traits/src/substrate/bridge_watcher.rs b/crates/event-watcher-traits/src/substrate/bridge_watcher.rs index 119e80e05..83f017639 100644 --- a/crates/event-watcher-traits/src/substrate/bridge_watcher.rs +++ b/crates/event-watcher-traits/src/substrate/bridge_watcher.rs @@ -14,6 +14,8 @@ use super::{event_watcher::SubstrateEventWatcher, *}; use sp_core::sr25519::Pair as Sr25519Pair; +use webb::substrate::subxt::OnlineClient; +use webb_relayer_context::RelayerContext; // A Substrate Bridge Watcher is a trait for Signature Bridge Pallet that is not specific for watching events from that pallet, /// instead it watches for commands sent from other event watchers or services, it helps decouple the event watchers /// from the actual action that should be taken depending on the event. @@ -30,7 +32,7 @@ where &self, chain_id: u32, store: Arc, - client: Arc, + client: Arc>, pair: Sr25519Pair, cmd: BridgeCommand, ) -> webb_relayer_utils::Result<()>; @@ -47,7 +49,7 @@ where async fn run( &self, chain_id: u32, - client: Arc, + ctx: RelayerContext, pair: Sr25519Pair, store: Arc, ) -> webb_relayer_utils::Result<()> { @@ -58,6 +60,11 @@ where webb_proposals::TypedChainId::Substrate(chain_id); let bridge_key = BridgeKey::new(typed_chain_id); let key = SledQueueKey::from_bridge_key(bridge_key); + let client = ctx + .substrate_provider::(&chain_id.to_string()) + .await?; + let client = Arc::new(client); + loop { let result = match store.dequeue_item(key)? { Some(cmd) => { diff --git a/crates/event-watcher-traits/src/substrate/event_watcher.rs b/crates/event-watcher-traits/src/substrate/event_watcher.rs index bc6a94f26..388b8716b 100644 --- a/crates/event-watcher-traits/src/substrate/event_watcher.rs +++ b/crates/event-watcher-traits/src/substrate/event_watcher.rs @@ -13,8 +13,9 @@ // limitations under the License. use tokio::sync::Mutex; -use webb::substrate::subxt::config::Header; +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}; use super::*; @@ -23,7 +24,7 @@ use super::*; pub type EventHandlerFor = Box< dyn EventHandler< RuntimeConfig, - Client = >::Client, + Client = OnlineClient, Store = >::Store, > + Send + Sync, @@ -125,8 +126,6 @@ where /// The name of the pallet that this event watcher is watching. const PALLET_NAME: &'static str; - /// The Runtime Client that can be used to perform API calls. - type Client: OnlineClientT + Send + Sync; /// The Storage backend, used by the event watcher to store its state. type Store: HistoryStore; @@ -143,7 +142,7 @@ where async fn run( &self, chain_id: u32, - client: Arc, + ctx: RelayerContext, store: Arc, event_watcher_config: EventsWatcherConfig, handlers: Vec>, @@ -151,9 +150,26 @@ where ) -> webb_relayer_utils::Result<()> { const MAX_RETRY_COUNT: usize = 5; - let backoff = backoff::backoff::Constant::new(Duration::from_secs(1)); + let backoff = backoff::ExponentialBackoff { + max_elapsed_time: None, + ..Default::default() + }; let metrics_clone = metrics.clone(); let task = || async { + let maybe_client = ctx + .substrate_provider::(&chain_id.to_string()) + .await; + let client = match maybe_client { + Ok(client) => client, + Err(err) => { + tracing::error!( + "Failed to connect with substrate 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(); diff --git a/crates/event-watcher-traits/src/substrate/mod.rs b/crates/event-watcher-traits/src/substrate/mod.rs index e907e13c9..1468f334a 100644 --- a/crates/event-watcher-traits/src/substrate/mod.rs +++ b/crates/event-watcher-traits/src/substrate/mod.rs @@ -18,11 +18,7 @@ use futures::prelude::*; use std::cmp; use std::sync::Arc; use std::time::Duration; -use webb::substrate::subxt::{ - self, - client::{OfflineClientT, OnlineClientT}, - config::Header, -}; +use webb::substrate::subxt::{self, client::OnlineClientT, config::Header}; use webb_proposals::{ ResourceId, SubstrateTargetSystem, TargetSystem, TypedChainId, }; diff --git a/crates/event-watcher-traits/src/tests.rs b/crates/event-watcher-traits/src/tests.rs index 9c5191e6a..2003b4b7d 100644 --- a/crates/event-watcher-traits/src/tests.rs +++ b/crates/event-watcher-traits/src/tests.rs @@ -33,8 +33,6 @@ impl SubstrateEventWatcher for TestEventsWatcher { const PALLET_NAME: &'static str = "System"; - type Client = OnlineClient; - type Store = SledStore; } @@ -83,7 +81,6 @@ async fn substrate_event_watcher_should_work() -> webb_relayer_utils::Result<()> { let chain_id = 5u32; let store = SledStore::temporary()?; - let client = OnlineClient::::new().await?; let watcher = TestEventsWatcher::default(); let config = webb_relayer_config::WebbRelayerConfig::default(); let ctx = RelayerContext::new(config, store.clone())?; @@ -92,7 +89,7 @@ async fn substrate_event_watcher_should_work() -> webb_relayer_utils::Result<()> watcher .run( chain_id, - client.into(), + ctx, Arc::new(store), event_watcher_config, vec![Box::::default()], diff --git a/crates/relayer-context/Cargo.toml b/crates/relayer-context/Cargo.toml index 9fd3962f9..2f3d4fa8c 100644 --- a/crates/relayer-context/Cargo.toml +++ b/crates/relayer-context/Cargo.toml @@ -26,7 +26,7 @@ serde = { workspace = true } serde_json = { workspace = true } http = "0.2.9" regex = { version = "1" } - +jsonrpsee-ws-client = "0.18.1" [features] default = ["std", "evm", "substrate"] std = [] diff --git a/crates/relayer-context/src/lib.rs b/crates/relayer-context/src/lib.rs index 72d42cfa3..ba0b61836 100644 --- a/crates/relayer-context/src/lib.rs +++ b/crates/relayer-context/src/lib.rs @@ -216,6 +216,16 @@ impl RelayerContext { node_config.ws_endpoint.to_string(), ) .await?; + // let ws_client = jsonrpsee_ws_client::WsClientBuilder::default() + // .build(node_config.ws_endpoint.to_string()) + // .await + // .unwrap(); + // // wait for ws_client to be connected + // loop { + // ws_client.is_connected(); + // } + // let client = subxt::OnlineClient::::from(ws_client); + Ok(client) } /// Sets up and returns a Substrate wallet for the relayer. diff --git a/crates/tx-queue/src/substrate/substrate_tx_queue.rs b/crates/tx-queue/src/substrate/substrate_tx_queue.rs index 80ba2b4bf..a8afa4ddd 100644 --- a/crates/tx-queue/src/substrate/substrate_tx_queue.rs +++ b/crates/tx-queue/src/substrate/substrate_tx_queue.rs @@ -18,6 +18,7 @@ use rand::Rng; use webb::substrate::subxt; use webb::substrate::subxt::config::ExtrinsicParams; use webb::substrate::subxt::tx::SubmittableExtrinsic; +use webb::substrate::subxt::PolkadotConfig; use webb_relayer_context::RelayerContext; use webb_relayer_store::sled::SledQueueKey; use webb_relayer_store::QueueStore; @@ -87,11 +88,6 @@ where max_elapsed_time: None, ..Default::default() }; - // protocol-substrate client - let client = self - .ctx - .substrate_provider::(&chain_id.to_string()) - .await?; tracing::event!( target: webb_relayer_utils::probe::TARGET, @@ -104,6 +100,21 @@ where let metrics_clone = self.ctx.metrics.clone(); let task = || async { + // protocol-substrate client + let maybe_client = self + .ctx + .substrate_provider::(&chain_id.to_string()) + .await; + let client = match maybe_client { + Ok(client) => client, + Err(err) => { + tracing::error!( + "Failed to connect with substrate client for chain_id: {}, retrying...!", + chain_id + ); + return Err(backoff::Error::transient(err)); + } + }; loop { tracing::trace!("Checking for any txs in the queue ..."); // dequeue signed transaction diff --git a/event-watchers/dkg/src/lib.rs b/event-watchers/dkg/src/lib.rs index e516768b6..08635e3a5 100644 --- a/event-watchers/dkg/src/lib.rs +++ b/event-watchers/dkg/src/lib.rs @@ -21,7 +21,7 @@ mod public_key_changed_handler; #[doc(hidden)] pub use public_key_changed_handler::*; use webb::substrate::subxt::events::StaticEvent; -use webb::substrate::subxt::{self, PolkadotConfig}; +use webb::substrate::subxt::PolkadotConfig; use webb::substrate::tangle_runtime::api::{ dkg::events::PublicKeySignatureChanged, dkg_proposal_handler::events::ProposalSigned, @@ -38,8 +38,6 @@ impl SubstrateEventWatcher for DKGMetadataWatcher { const PALLET_NAME: &'static str = PublicKeySignatureChanged::PALLET; - type Client = subxt::OnlineClient; - type Store = webb_relayer_store::SledStore; } @@ -53,7 +51,5 @@ impl SubstrateEventWatcher for DKGProposalHandlerWatcher { const PALLET_NAME: &'static str = ProposalSigned::PALLET; - type Client = subxt::OnlineClient; - type Store = webb_relayer_store::SledStore; } diff --git a/event-watchers/substrate/src/lib.rs b/event-watchers/substrate/src/lib.rs index 038f1146a..9aa95f951 100644 --- a/event-watchers/substrate/src/lib.rs +++ b/event-watchers/substrate/src/lib.rs @@ -27,7 +27,7 @@ pub use vanchor_encrypted_output_handler::*; pub use vanchor_leaves_handler::*; use webb::substrate::subxt::events::StaticEvent; use webb::substrate::{ - subxt::{OnlineClient, PolkadotConfig}, + subxt::PolkadotConfig, tangle_runtime::api::v_anchor_bn254::events::Transaction, }; use webb_event_watcher_traits::SubstrateEventWatcher; @@ -42,7 +42,5 @@ impl SubstrateEventWatcher for SubstrateVAnchorEventWatcher { const PALLET_NAME: &'static str = Transaction::PALLET; - type Client = OnlineClient; - type Store = SledStore; } diff --git a/event-watchers/substrate/src/signature_bridge_watcher.rs b/event-watchers/substrate/src/signature_bridge_watcher.rs index 433f73be6..d707564f2 100644 --- a/event-watchers/substrate/src/signature_bridge_watcher.rs +++ b/event-watchers/substrate/src/signature_bridge_watcher.rs @@ -98,7 +98,6 @@ pub struct SubstrateBridgeEventWatcher; impl SubstrateEventWatcher for SubstrateBridgeEventWatcher { const TAG: &'static str = "Substrate bridge pallet Watcher"; const PALLET_NAME: &'static str = MaintainerSet::PALLET; - type Client = OnlineClient; type Store = SledStore; } @@ -109,7 +108,7 @@ impl SubstrateBridgeWatcher for SubstrateBridgeEventWatcher { &self, chain_id: u32, store: Arc, - client: Arc, + client: Arc>, pair: Sr25519Pair, cmd: BridgeCommand, ) -> webb_relayer_utils::Result<()> { @@ -154,7 +153,7 @@ where &self, chain_id: u32, store: Arc<>::Store>, - api: Arc<>::Client>, + api: Arc>, pair: Sr25519Pair, (proposal_data, signature): (Vec, Vec), ) -> webb_relayer_utils::Result<()> { @@ -252,7 +251,7 @@ where &self, chain_id: u32, store: Arc<>::Store>, - api: Arc<>::Client>, + api: Arc>, pair: Sr25519Pair, (public_key, nonce, signature): (Vec, u32, Vec), ) -> webb_relayer_utils::Result<()> { diff --git a/services/webb-relayer/src/main.rs b/services/webb-relayer/src/main.rs index 457bbafe1..ebe89dc02 100644 --- a/services/webb-relayer/src/main.rs +++ b/services/webb-relayer/src/main.rs @@ -76,7 +76,15 @@ async fn main(args: Opts) -> anyhow::Result<()> { let server_handle = tokio::spawn(build_web_services(ctx.clone())); // start all background services. // this does not block, will fire the services on background tasks. - webb_relayer::service::ignite(&ctx, Arc::new(store)).await?; + let res = webb_relayer::service::ignite(ctx.clone(), Arc::new(store)).await; + match res { + Ok(_) => { + tracing::info!("Relayer started successfully"); + } + Err(e) => { + tracing::error!("Failed to start relayer: {}", e); + } + } tracing::event!( target: webb_relayer_utils::probe::TARGET, tracing::Level::DEBUG, diff --git a/services/webb-relayer/src/service/mod.rs b/services/webb-relayer/src/service/mod.rs index e273683c7..383cd8db8 100644 --- a/services/webb-relayer/src/service/mod.rs +++ b/services/webb-relayer/src/service/mod.rs @@ -86,15 +86,15 @@ pub async fn build_web_services(ctx: RelayerContext) -> crate::Result<()> { /// * `ctx` - RelayContext reference that holds the configuration /// * `store` -[Sled](https://sled.rs)-based database store pub async fn ignite( - ctx: &RelayerContext, + ctx: RelayerContext, store: Arc, ) -> crate::Result<()> { tracing::trace!( "Relayer configuration: {}", serde_json::to_string_pretty(&ctx.config)? ); - evm::ignite(ctx, store.clone()).await?; - substrate::ignite(ctx, store.clone()).await?; + evm::ignite(&ctx, store.clone()).await?; + substrate::ignite(ctx.clone(), store.clone()).await?; Ok(()) } diff --git a/services/webb-relayer/src/service/substrate.rs b/services/webb-relayer/src/service/substrate.rs index b47c56507..f695381a0 100644 --- a/services/webb-relayer/src/service/substrate.rs +++ b/services/webb-relayer/src/service/substrate.rs @@ -59,43 +59,38 @@ pub fn build_web_services() -> Router> { /// * `ctx` - RelayContext reference that holds the configuration /// * `store` -[Sled](https://sled.rs)-based database store pub async fn ignite( - ctx: &RelayerContext, + ctx: RelayerContext, store: Arc, ) -> crate::Result<()> { - for (node_name, node_config) in &ctx.config.substrate { + for (_, node_config) in ctx.clone().config.substrate { if !node_config.enabled { continue; } - ignite_tangle_runtime(ctx, store.clone(), node_name, node_config) - .await?; + ignite_tangle_runtime(ctx.clone(), store.clone(), &node_config).await?; } Ok(()) } async fn ignite_tangle_runtime( - ctx: &RelayerContext, + ctx: RelayerContext, store: Arc, - node_name: &str, node_config: &SubstrateConfig, ) -> crate::Result<()> { - let client = ctx.substrate_provider::(node_name).await?; let chain_id = node_config.chain_id; for pallet in &node_config.pallets { match pallet { Pallet::DKGProposalHandler(config) => { start_dkg_proposal_handler( - ctx, + ctx.clone(), config, - client.clone(), chain_id, store.clone(), )?; } Pallet::Dkg(config) => { start_dkg_pallet_watcher( - ctx, + ctx.clone(), config, - client.clone(), chain_id, store.clone(), )?; @@ -107,7 +102,6 @@ async fn ignite_tangle_runtime( start_substrate_signature_bridge_events_watcher( ctx.clone(), config, - client.clone(), chain_id, store.clone(), ) @@ -115,9 +109,8 @@ async fn ignite_tangle_runtime( } Pallet::VAnchorBn254(config) => { start_substrate_vanchor_event_watcher( - ctx, + ctx.clone(), config, - client.clone(), chain_id, store.clone(), )?; @@ -141,9 +134,8 @@ async fn ignite_tangle_runtime( /// * `chain_id` - An u32 representing the chain id of the chain /// * `store` -[Sled](https://sled.rs)-based database store pub fn start_dkg_proposal_handler( - ctx: &RelayerContext, + ctx: RelayerContext, config: &DKGProposalHandlerPalletConfig, - client: TangleClient, chain_id: u32, store: Arc, ) -> crate::Result<()> { @@ -167,7 +159,7 @@ pub fn start_dkg_proposal_handler( let proposal_signed_handler = ProposalSignedHandler::default(); let proposal_handler_watcher_task = proposal_handler_watcher.run( chain_id, - client.into(), + ctx.clone(), store, my_config.events_watcher, vec![Box::new(proposal_signed_handler)], @@ -205,9 +197,8 @@ pub fn start_dkg_proposal_handler( /// * `chain_id` - An u32 representing the chain id of the chain /// * `store` -[Sled](https://sled.rs)-based database store pub fn start_dkg_pallet_watcher( - ctx: &RelayerContext, + ctx: RelayerContext, config: &DKGPalletConfig, - client: TangleClient, chain_id: u32, store: Arc, ) -> crate::Result<()> { @@ -231,7 +222,7 @@ pub fn start_dkg_pallet_watcher( let dkg_event_watcher_task = dkg_event_watcher.run( chain_id, - client.into(), + ctx.clone(), store, my_config.events_watcher, vec![Box::new(public_key_changed_handler)], @@ -269,9 +260,8 @@ pub fn start_dkg_pallet_watcher( /// * `chain_id` - An u32 representing the chain id of the chain /// * `store` -[Sled](https://sled.rs)-based database store pub fn start_substrate_vanchor_event_watcher( - ctx: &RelayerContext, + ctx: RelayerContext, config: &VAnchorBn254PalletConfig, - client: TangleClient, chain_id: u32, store: Arc, ) -> crate::Result<()> { @@ -316,7 +306,7 @@ pub fn start_substrate_vanchor_event_watcher( let watcher = SubstrateVAnchorEventWatcher::default(); let substrate_vanchor_watcher_task = watcher.run( chain_id, - client.clone().into(), + ctx.clone(), store.clone(), my_config.events_watcher, vec![ @@ -359,7 +349,7 @@ pub fn start_substrate_vanchor_event_watcher( let watcher = SubstrateVAnchorEventWatcher::default(); let substrate_vanchor_watcher_task = watcher.run( chain_id, - client.clone().into(), + ctx.clone(), store.clone(), my_config.events_watcher, vec![ @@ -392,7 +382,7 @@ pub fn start_substrate_vanchor_event_watcher( let watcher = SubstrateVAnchorEventWatcher::default(); let substrate_vanchor_watcher_task = watcher.run( chain_id, - client.clone().into(), + ctx.clone(), store.clone(), my_config.events_watcher, vec![ @@ -417,6 +407,8 @@ pub fn start_substrate_vanchor_event_watcher( } } }; + + tracing::debug!("Task resturned"); crate::Result::Ok(()) }; // kick off the watcher. @@ -428,7 +420,6 @@ pub fn start_substrate_vanchor_event_watcher( pub async fn start_substrate_signature_bridge_events_watcher( ctx: RelayerContext, config: &SignatureBridgePalletConfig, - client: TangleClient, chain_id: u32, store: Arc, ) -> crate::Result<()> { @@ -452,7 +443,7 @@ pub async fn start_substrate_signature_bridge_events_watcher( let events_watcher_task = SubstrateEventWatcher::run( &substrate_bridge_watcher, chain_id, - client.clone().into(), + ctx.clone(), store.clone(), my_config.events_watcher, vec![Box::new(bridge_event_handler)], @@ -461,7 +452,7 @@ pub async fn start_substrate_signature_bridge_events_watcher( let cmd_handler_task = SubstrateBridgeWatcher::run( &substrate_bridge_watcher, chain_id, - client.into(), + ctx.clone(), pair.clone(), store.clone(), ); From 37fbcba3ed846b20a1a2a0f9819db6b139358afa Mon Sep 17 00:00:00 2001 From: salman01zp Date: Thu, 25 May 2023 19:37:10 +0530 Subject: [PATCH 2/5] remove logs --- crates/relayer-context/src/lib.rs | 10 ---------- crates/tx-queue/src/substrate/substrate_tx_queue.rs | 2 +- services/webb-relayer/src/main.rs | 11 ++--------- 3 files changed, 3 insertions(+), 20 deletions(-) diff --git a/crates/relayer-context/src/lib.rs b/crates/relayer-context/src/lib.rs index ba0b61836..72d42cfa3 100644 --- a/crates/relayer-context/src/lib.rs +++ b/crates/relayer-context/src/lib.rs @@ -216,16 +216,6 @@ impl RelayerContext { node_config.ws_endpoint.to_string(), ) .await?; - // let ws_client = jsonrpsee_ws_client::WsClientBuilder::default() - // .build(node_config.ws_endpoint.to_string()) - // .await - // .unwrap(); - // // wait for ws_client to be connected - // loop { - // ws_client.is_connected(); - // } - // let client = subxt::OnlineClient::::from(ws_client); - Ok(client) } /// Sets up and returns a Substrate wallet for the relayer. diff --git a/crates/tx-queue/src/substrate/substrate_tx_queue.rs b/crates/tx-queue/src/substrate/substrate_tx_queue.rs index a8afa4ddd..2bd991e5e 100644 --- a/crates/tx-queue/src/substrate/substrate_tx_queue.rs +++ b/crates/tx-queue/src/substrate/substrate_tx_queue.rs @@ -100,7 +100,7 @@ where let metrics_clone = self.ctx.metrics.clone(); let task = || async { - // protocol-substrate client + // Tangle node connection let maybe_client = self .ctx .substrate_provider::(&chain_id.to_string()) diff --git a/services/webb-relayer/src/main.rs b/services/webb-relayer/src/main.rs index ebe89dc02..9f27a9b9a 100644 --- a/services/webb-relayer/src/main.rs +++ b/services/webb-relayer/src/main.rs @@ -76,15 +76,8 @@ async fn main(args: Opts) -> anyhow::Result<()> { let server_handle = tokio::spawn(build_web_services(ctx.clone())); // start all background services. // this does not block, will fire the services on background tasks. - let res = webb_relayer::service::ignite(ctx.clone(), Arc::new(store)).await; - match res { - Ok(_) => { - tracing::info!("Relayer started successfully"); - } - Err(e) => { - tracing::error!("Failed to start relayer: {}", e); - } - } + webb_relayer::service::ignite(ctx.clone(), Arc::new(store)).await?; + tracing::event!( target: webb_relayer_utils::probe::TARGET, tracing::Level::DEBUG, From 4a3f8b7f234978ffb7e5cf085239e9b442157a9b Mon Sep 17 00:00:00 2001 From: salman01zp Date: Thu, 25 May 2023 19:38:53 +0530 Subject: [PATCH 3/5] remove unused dependency --- Cargo.lock | 1 - crates/relayer-context/Cargo.toml | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e2d0d0782..aebd317c3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9360,7 +9360,6 @@ name = "webb-relayer-context" version = "0.1.0" dependencies = [ "http", - "jsonrpsee-ws-client", "native-tls", "regex", "serde", diff --git a/crates/relayer-context/Cargo.toml b/crates/relayer-context/Cargo.toml index 2f3d4fa8c..9fd3962f9 100644 --- a/crates/relayer-context/Cargo.toml +++ b/crates/relayer-context/Cargo.toml @@ -26,7 +26,7 @@ serde = { workspace = true } serde_json = { workspace = true } http = "0.2.9" regex = { version = "1" } -jsonrpsee-ws-client = "0.18.1" + [features] default = ["std", "evm", "substrate"] std = [] From 3e0d8b213d801ba46a67bb9bfcd9effb7b0ab96d Mon Sep 17 00:00:00 2001 From: salman01zp Date: Thu, 25 May 2023 19:54:07 +0530 Subject: [PATCH 4/5] clippy fix --- examples/in_depth.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/in_depth.rs b/examples/in_depth.rs index 239eadf97..24460d876 100644 --- a/examples/in_depth.rs +++ b/examples/in_depth.rs @@ -136,6 +136,6 @@ async fn main() -> anyhow::Result<()> { service::build_web_services(ctx.clone()).await?; // and also the background services: // this does not block, will fire the services on background tasks. - service::ignite(&ctx, Arc::new(store)).await?; + service::ignite(ctx, Arc::new(store)).await?; Ok(()) } From c16cccfaca5c59250c69868d66d2b14a7121fada Mon Sep 17 00:00:00 2001 From: salman01zp Date: Fri, 26 May 2023 09:11:58 +0530 Subject: [PATCH 5/5] remove unused deps --- Cargo.lock | 84 +++----------------------- crates/event-watcher-traits/Cargo.toml | 2 +- 2 files changed, 9 insertions(+), 77 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index aebd317c3..f024a6e33 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4032,10 +4032,10 @@ version = "0.16.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7d291e3a5818a2384645fd9756362e6d89cf0541b0b916fa7702ea4a9833608e" dependencies = [ - "jsonrpsee-client-transport 0.16.2", - "jsonrpsee-core 0.16.2", + "jsonrpsee-client-transport", + "jsonrpsee-core", "jsonrpsee-http-client", - "jsonrpsee-types 0.16.2", + "jsonrpsee-types", ] [[package]] @@ -4046,8 +4046,8 @@ checksum = "965de52763f2004bc91ac5bcec504192440f0b568a5d621c59d9dbd6f886c3fb" dependencies = [ "futures-util", "http", - "jsonrpsee-core 0.16.2", - "jsonrpsee-types 0.16.2", + "jsonrpsee-core", + "jsonrpsee-types", "pin-project 1.0.12", "rustls-native-certs", "soketto", @@ -4059,25 +4059,6 @@ dependencies = [ "webpki-roots", ] -[[package]] -name = "jsonrpsee-client-transport" -version = "0.18.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11aa5766d5c430b89cb26a99b88f3245eb91534be8126102cea9e45ee3891b22" -dependencies = [ - "futures-util", - "http", - "jsonrpsee-core 0.18.2", - "pin-project 1.0.12", - "rustls-native-certs", - "soketto", - "thiserror", - "tokio 1.28.1", - "tokio-rustls 0.24.0", - "tokio-util 0.7.7", - "tracing", -] - [[package]] name = "jsonrpsee-core" version = "0.16.2" @@ -4092,7 +4073,7 @@ dependencies = [ "futures-timer", "futures-util", "hyper 0.14.25", - "jsonrpsee-types 0.16.2", + "jsonrpsee-types", "rustc-hash", "serde", "serde_json", @@ -4101,28 +4082,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "jsonrpsee-core" -version = "0.18.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64c6832a55f662b5a6ecc844db24b8b9c387453f923de863062c60ce33d62b81" -dependencies = [ - "anyhow", - "async-lock", - "async-trait", - "beef", - "futures-timer", - "futures-util", - "jsonrpsee-types 0.18.2", - "rustc-hash", - "serde", - "serde_json", - "thiserror", - "tokio 1.28.1", - "tokio-stream", - "tracing", -] - [[package]] name = "jsonrpsee-http-client" version = "0.16.2" @@ -4132,8 +4091,8 @@ dependencies = [ "async-trait", "hyper 0.14.25", "hyper-rustls 0.23.2", - "jsonrpsee-core 0.16.2", - "jsonrpsee-types 0.16.2", + "jsonrpsee-core", + "jsonrpsee-types", "rustc-hash", "serde", "serde_json", @@ -4156,32 +4115,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "jsonrpsee-types" -version = "0.18.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e5bf6c75ce2a4217421154adfc65a24d2b46e77286e59bba5d9fa6544ccc8f4" -dependencies = [ - "anyhow", - "beef", - "serde", - "serde_json", - "thiserror", - "tracing", -] - -[[package]] -name = "jsonrpsee-ws-client" -version = "0.18.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a64b2589680ba1ad7863f279cd2d5083c1dc0a7c0ea959d22924553050f8ab9f" -dependencies = [ - "http", - "jsonrpsee-client-transport 0.18.2", - "jsonrpsee-core 0.18.2", - "jsonrpsee-types 0.18.2", -] - [[package]] name = "k256" version = "0.11.6" @@ -9084,7 +9017,6 @@ dependencies = [ "async-trait", "backoff", "futures", - "jsonrpsee-ws-client", "native-tls", "sled", "sp-core", diff --git a/crates/event-watcher-traits/Cargo.toml b/crates/event-watcher-traits/Cargo.toml index b9a5862b8..cdcd06cab 100644 --- a/crates/event-watcher-traits/Cargo.toml +++ b/crates/event-watcher-traits/Cargo.toml @@ -28,7 +28,7 @@ webb-proposals = { workspace = true } tracing-test = "0.2" sled = { version = "^0.34" } sp-core = { workspace = true } -jsonrpsee-ws-client = "0.18.1" + [features] default = ["std", "evm", "substrate"] std = []