From 8c07a3d38ca15531ba805f36d48c833d3da920aa Mon Sep 17 00:00:00 2001 From: b-yap <2826165+b-yap@users.noreply.github.com> Date: Wed, 16 Oct 2024 19:43:05 +0800 Subject: [PATCH] https://github.com/pendulum-chain/spacewalk/pull/545#discussion_r1802855387, https://github.com/pendulum-chain/spacewalk/pull/545/files#r1794072004 --- clients/runtime/src/rpc.rs | 25 ++++++++++++---------- clients/stellar-relay-lib/src/tests/mod.rs | 19 +++++++--------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/clients/runtime/src/rpc.rs b/clients/runtime/src/rpc.rs index 6bb5e3328..b6eb9fd6e 100644 --- a/clients/runtime/src/rpc.rs +++ b/clients/runtime/src/rpc.rs @@ -272,7 +272,7 @@ impl SpacewalkParachain { let storage_key = metadata::storage().system().account(&self.account_id); let on_chain_nonce = self .get_latest_storage() - .await + .await? .fetch(&storage_key) .await .transpose() @@ -290,7 +290,7 @@ impl SpacewalkParachain { where Address: StorageAddress, { - Ok(self.get_latest_storage().await.fetch(&address).await?) + Ok(self.get_latest_storage().await?.fetch(&address).await?) } async fn query_finalized_or_error
( @@ -310,7 +310,7 @@ impl SpacewalkParachain { where Address: StorageAddress, { - Ok(self.get_latest_storage().await.fetch_or_default(&address).await?) + Ok(self.get_latest_storage().await?.fetch_or_default(&address).await?) } pub async fn get_finalized_block_hash(&self) -> Result, Error> { @@ -319,8 +319,11 @@ impl SpacewalkParachain { async fn get_latest_storage( &self, - ) -> Storage> { - self.api.storage().at_latest().await.expect("failed to get latest storage") + ) -> Result>, Error> { + self.api.storage().at_latest().await.map_err(|e| { + log::error!("Failed to get storage from the latest block hash"); + Error::SubxtRuntimeError(e) + }) } /// Subscribe to new parachain blocks. @@ -502,7 +505,7 @@ pub trait UtilFuncs { impl UtilFuncs for SpacewalkParachain { async fn get_current_chain_height(&self) -> Result { let height_query = metadata::storage().system().number(); - let height = self.get_latest_storage().await.fetch(&height_query).await?; + let height = self.get_latest_storage().await?.fetch(&height_query).await?; match height { Some(height) => Ok(height), None => Err(Error::BlockNotFound), @@ -597,7 +600,7 @@ impl VaultRegistryPallet for SpacewalkParachain { async fn get_all_vaults(&self) -> Result, Error> { let mut vaults = Vec::new(); let key_addr = metadata::storage().vault_registry().vaults_iter(); - let mut iter = self.get_latest_storage().await.iter(key_addr).await?; + let mut iter = self.get_latest_storage().await?.iter(key_addr).await?; while let Ok((_, account)) = iter.next().await.ok_or(Error::VaultNotFound)? { if let VaultStatus::Active(..) = account.status { vaults.push(account); @@ -782,7 +785,7 @@ impl CollateralBalancesPallet for SpacewalkParachain { async fn get_native_balance_for_id(&self, id: &AccountId) -> Result { let query = metadata::storage().system().account(id); - let result = self.get_latest_storage().await.fetch(&query).await?; + let result = self.get_latest_storage().await?.fetch(&query).await?; Ok(result.map(|x| x.data.free).unwrap_or_default()) } @@ -793,7 +796,7 @@ impl CollateralBalancesPallet for SpacewalkParachain { ) -> Result { let query = metadata::storage().tokens().accounts(&id, &Static(currency_id)); - let result = self.get_latest_storage().await.fetch(&query).await?; + let result = self.get_latest_storage().await?.fetch(&query).await?; Ok(result.map(|x| x.free).unwrap_or_default()) } @@ -808,7 +811,7 @@ impl CollateralBalancesPallet for SpacewalkParachain { ) -> Result { let query = metadata::storage().tokens().accounts(&id, &Static(currency_id)); - let result = self.get_latest_storage().await.fetch(&query).await?; + let result = self.get_latest_storage().await?.fetch(&query).await?; Ok(result.map(|x| x.reserved).unwrap_or_default()) } @@ -1077,7 +1080,7 @@ impl IssuePallet for SpacewalkParachain { let mut issue_requests = Vec::new(); let key_addr = metadata::storage().issue().issue_requests_iter(); - let mut iter = self.get_latest_storage().await.iter(key_addr).await?; + let mut iter = self.get_latest_storage().await?.iter(key_addr).await?; while let Some(result) = iter.next().await { let (issue_id, request) = result?; diff --git a/clients/stellar-relay-lib/src/tests/mod.rs b/clients/stellar-relay-lib/src/tests/mod.rs index e40b25407..b9402f54e 100644 --- a/clients/stellar-relay-lib/src/tests/mod.rs +++ b/clients/stellar-relay-lib/src/tests/mod.rs @@ -1,7 +1,7 @@ use crate::{ connection::ConnectionInfo, node::NodeInfo, StellarOverlayConfig, StellarOverlayConnection, }; -use async_std::{future::timeout, sync::Mutex}; +use async_std::sync::Mutex; use serial_test::serial; use std::{sync::Arc, thread::sleep, time::Duration}; use substrate_stellar_sdk::{ @@ -62,18 +62,15 @@ async fn stellar_overlay_should_receive_scp_messages() { } ov_conn_locked.stop(); - }); - - // wait for the spawned thread to finish - timeout(Duration::from_secs(200), async move { - let _ = receiver.await.expect("should receive a message"); - - //assert - //ensure that we receive some scp message from stellar node - assert!(!scps_vec.lock().await.is_empty()); }) .await - .expect("time has elapsed"); + .expect("should finish"); + + let _ = receiver.await.expect("should receive a message"); + + //assert + //ensure that we receive some scp message from stellar node + assert!(!scps_vec.lock().await.is_empty()); } #[tokio::test(flavor = "multi_thread")]