diff --git a/Cargo.lock b/Cargo.lock index a37c85978..897467cf4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -143,6 +143,16 @@ dependencies = [ "subtle", ] +[[package]] +name = "again" +version = "0.1.2" +source = "git+https://github.com/softprops/again?branch=develop#6db8c5e56bf93b1177ed35a926f8ff7d4adbf93b" +dependencies = [ + "log", + "rand 0.8.5", + "wasm-timer", +] + [[package]] name = "ahash" version = "0.7.7" @@ -5977,7 +5987,18 @@ checksum = "9579d0ca9fb30da026bac2f0f7d9576ec93489aeb7cd4971dd5b4617d82c79b2" dependencies = [ "jsonrpsee-core 0.21.0", "jsonrpsee-types 0.21.0", - "jsonrpsee-ws-client", + "jsonrpsee-ws-client 0.21.0", +] + +[[package]] +name = "jsonrpsee" +version = "0.22.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f3ae45a64cfc0882934f963be9431b2a165d667f53140358181f262aca0702" +dependencies = [ + "jsonrpsee-core 0.22.2", + "jsonrpsee-types 0.22.2", + "jsonrpsee-ws-client 0.22.2", ] [[package]] @@ -6022,6 +6043,27 @@ dependencies = [ "url", ] +[[package]] +name = "jsonrpsee-client-transport" +version = "0.22.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "455fc882e56f58228df2aee36b88a1340eafd707c76af2fa68cf94b37d461131" +dependencies = [ + "futures-util", + "http 0.2.11", + "jsonrpsee-core 0.22.2", + "pin-project", + "rustls-native-certs 0.7.0", + "rustls-pki-types", + "soketto", + "thiserror", + "tokio", + "tokio-rustls 0.25.0", + "tokio-util 0.7.10", + "tracing", + "url", +] + [[package]] name = "jsonrpsee-core" version = "0.16.3" @@ -6073,6 +6115,29 @@ dependencies = [ "tracing", ] +[[package]] +name = "jsonrpsee-core" +version = "0.22.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b75568f4f9696e3a47426e1985b548e1a9fcb13372a5e320372acaf04aca30d1" +dependencies = [ + "anyhow", + "async-lock 3.3.0", + "async-trait", + "beef", + "futures-timer", + "futures-util", + "jsonrpsee-types 0.22.2", + "pin-project", + "rustc-hash", + "serde", + "serde_json", + "thiserror", + "tokio", + "tokio-stream", + "tracing", +] + [[package]] name = "jsonrpsee-http-client" version = "0.16.3" @@ -6154,6 +6219,19 @@ dependencies = [ "thiserror", ] +[[package]] +name = "jsonrpsee-types" +version = "0.22.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3467fd35feeee179f71ab294516bdf3a81139e7aeebdd860e46897c12e1a3368" +dependencies = [ + "anyhow", + "beef", + "serde", + "serde_json", + "thiserror", +] + [[package]] name = "jsonrpsee-ws-client" version = "0.21.0" @@ -6167,6 +6245,19 @@ dependencies = [ "url", ] +[[package]] +name = "jsonrpsee-ws-client" +version = "0.22.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68ca71e74983f624c0cb67828e480a981586074da8ad3a2f214c6a3f884edab9" +dependencies = [ + "http 0.2.11", + "jsonrpsee-client-transport 0.22.2", + "jsonrpsee-core 0.22.2", + "jsonrpsee-types 0.22.2", + "url", +] + [[package]] name = "k256" version = "0.11.6" @@ -9249,16 +9340,16 @@ dependencies = [ [[package]] name = "reconnecting-jsonrpsee-ws-client" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7265f5d33f189e19e7242325ff6874e540aa9c46ae8f44a52412fb59faafbe00" +version = "0.3.0" +source = "git+https://github.com/polytope-labs/reconnecting-jsonrpsee-ws-client?rev=7c0817478c2741cc0889e7c75c645aad9f3cbb55#7c0817478c2741cc0889e7c75c645aad9f3cbb55" dependencies = [ + "again", "futures", - "jsonrpsee 0.21.0", + "getrandom 0.2.12", + "jsonrpsee 0.22.2", "serde_json", "thiserror", "tokio", - "tokio-retry", "tokio-stream", "tracing", ] @@ -14390,17 +14481,6 @@ dependencies = [ "tokio-util 0.7.10", ] -[[package]] -name = "tokio-retry" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f57eb36ecbe0fc510036adff84824dd3c24bb781e21bfa67b69d556aa85214f" -dependencies = [ - "pin-project", - "rand 0.8.5", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.22.0" diff --git a/Cargo.toml b/Cargo.toml index cff6e72f4..d99358e13 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -128,7 +128,7 @@ ethers = { git = "https://github.com/polytope-labs/ethers-rs", rev = "f8ab49e1ca ethers-contract-abigen = { git = "https://github.com/polytope-labs/ethers-rs", rev = "f8ab49e1ca2d68e8bf1113e705ade38e5f30b850" } merkle-mountain-range = { package = "ckb-merkle-mountain-range", version = "0.5.2" } -reconnecting-jsonrpsee-ws-client = "0.2.0" +reconnecting-jsonrpsee-ws-client = { git = "https://github.com/polytope-labs/reconnecting-jsonrpsee-ws-client", rev = "7c0817478c2741cc0889e7c75c645aad9f3cbb55" } # hyperbridge beefy-verifier-primitives = { git = "https://github.com/polytope-labs/hyperbridge", rev = "dffb69a0aeae8588fe4971fe2a2a3a8f87d4420f" } diff --git a/evm/common/src/mock.rs b/evm/common/src/mock.rs index 0773fadd2..48635260d 100644 --- a/evm/common/src/mock.rs +++ b/evm/common/src/mock.rs @@ -249,34 +249,20 @@ mod tests { "https://clean-capable-dew.bsc-testnet.quiknode.pro/bed456956996abb801b7ab44fdb3f6f63cd1a4ec/".into(), ); + let ping_addr = H160(hex!("d4812d6A3b9fB46feA314260Cbb61D57EBc71D7F")); + let chains = vec![ - ( - StateMachine::Ethereum(Ethereum::ExecutionLayer), - H160(hex!("d4812d6A3b9fB46feA314260Cbb61D57EBc71D7F")), - geth_url, - ), - ( - StateMachine::Ethereum(Ethereum::Arbitrum), - H160(hex!("d4812d6A3b9fB46feA314260Cbb61D57EBc71D7F")), - arb_url, - ), - ( - StateMachine::Ethereum(Ethereum::Optimism), - H160(hex!("d4812d6A3b9fB46feA314260Cbb61D57EBc71D7F")), - op_url, - ), - ( - StateMachine::Ethereum(Ethereum::Base), - H160(hex!("d4812d6A3b9fB46feA314260Cbb61D57EBc71D7F")), - base_url, - ), - (StateMachine::Bsc, H160(hex!("d4812d6A3b9fB46feA314260Cbb61D57EBc71D7F")), bsc_url), + (StateMachine::Ethereum(Ethereum::ExecutionLayer), geth_url), + (StateMachine::Ethereum(Ethereum::Arbitrum), arb_url), + (StateMachine::Ethereum(Ethereum::Optimism), op_url), + (StateMachine::Ethereum(Ethereum::Base), base_url), + (StateMachine::Bsc, bsc_url), ]; let stream = futures::stream::iter(chains.clone().into_iter().map(Ok::<_, anyhow::Error>)); stream - .try_for_each_concurrent(None, |(chain, ping, url)| { + .try_for_each_concurrent(None, |(chain, url)| { let chains_clone = chains.clone(); async move { let signer = sp_core::ecdsa::Pair::from_seed_slice(&hex!( @@ -287,10 +273,11 @@ mod tests { LocalWallet::from(SecretKey::from_slice(signer.seed().as_slice())?) .with_chain_id(provider.get_chainid().await?.low_u64()); let client = Arc::new(provider.with_signer(signer)); - let ping = PingModule::new(ping.clone(), client.clone()); + let ping = PingModule::new(ping_addr.clone(), client.clone()); let host_addr = ping.host().await.context(format!("Error in {chain:?}"))?; - dbg!(&host_addr); + dbg!((&chain, &host_addr)); + let host = EvmHost::new(host_addr, client.clone()); let erc_20 = Erc20::new( host.dai().await.context(format!("Error in {chain:?}"))?, @@ -301,29 +288,30 @@ mod tests { call.gas(gas) .send() .await - .context(format!("Error in {chain:?}"))? + .context(format!("Failed to send approval for {host_addr} in {chain:?}"))? .await - .context(format!("Error in {chain:?}"))?; + .context(format!("Failed to approve {host_addr} in {chain:?}"))?; - for (chain, ping_addr, _) in chains_clone.iter().filter(|(c, _, _)| chain != *c) - { + for (chain, _) in chains_clone.iter().filter(|(c, _)| chain != *c) { for _ in 0..1 { let call = ping.ping(PingMessage { dest: chain.to_string().as_bytes().to_vec().into(), module: ping_addr.clone().into(), timeout: 10 * 60 * 60, fee: U256::from(9_000_000_000_000_000_000u128), - count: U256::from(100), + count: U256::from(10), }); - let gas = - call.estimate_gas().await.context(format!("Error in {chain:?}"))?; + let gas = call + .estimate_gas() + .await + .context(format!("Failed to estimate gas in {chain:?}"))?; let receipt = call .gas(gas) .send() .await - .context(format!("Error in {chain:?}"))? + .context(format!("Failed to send ping tx to {chain:?}"))? .await - .context(format!("Error in {chain:?}"))?; + .context(format!("Failed to execute ping message on {chain:?}"))?; assert!(receipt.is_some()); } diff --git a/substrate/common/src/lib.rs b/substrate/common/src/lib.rs index 75ba30c33..5db51ac60 100644 --- a/substrate/common/src/lib.rs +++ b/substrate/common/src/lib.rs @@ -19,7 +19,7 @@ use anyhow::Context; use ismp::{consensus::ConsensusStateId, host::StateMachine}; use pallet_ismp::primitives::HashAlgorithm; use primitives::{config::Chain, IsmpHost, IsmpProvider}; -use reconnecting_jsonrpsee_ws_client::{Client, FixedInterval, PingConfig}; +use reconnecting_jsonrpsee_ws_client::{Client, PingConfig, RetryPolicy}; use serde::{Deserialize, Serialize}; use sp_core::{bytes::from_hex, sr25519, Pair, H256}; use std::{sync::Arc, time::Duration}; @@ -102,7 +102,7 @@ where let max_rpc_payload_size = config.max_rpc_payload_size.unwrap_or(15 * 1024 * 1024); let raw_client = Client::builder() // retry every second - .retry_policy(FixedInterval::from_millis(1000)) + .retry_policy(RetryPolicy::fixed(Duration::from_millis(1000))) .max_request_size(max_rpc_payload_size) .max_response_size(max_rpc_payload_size) .enable_ws_ping(