diff --git a/aleph-client/Cargo.lock b/aleph-client/Cargo.lock index ab6cf0e29a..33dfcb4bbf 100644 --- a/aleph-client/Cargo.lock +++ b/aleph-client/Cargo.lock @@ -49,7 +49,7 @@ dependencies = [ [[package]] name = "aleph_client" -version = "2.4.0" +version = "2.5.0" dependencies = [ "anyhow", "async-trait", diff --git a/aleph-client/Cargo.toml b/aleph-client/Cargo.toml index b412e30552..e37a066193 100644 --- a/aleph-client/Cargo.toml +++ b/aleph-client/Cargo.toml @@ -1,6 +1,7 @@ [package] name = "aleph_client" -version = "2.4.0" +# TODO bump major version when API stablize +version = "2.5.0" edition = "2021" license = "Apache 2.0" diff --git a/aleph-client/src/pallets/author.rs b/aleph-client/src/pallets/author.rs index f614e9e545..6edae050b0 100644 --- a/aleph-client/src/pallets/author.rs +++ b/aleph-client/src/pallets/author.rs @@ -4,14 +4,14 @@ use crate::{aleph_runtime::SessionKeys, Connection}; #[async_trait::async_trait] pub trait AuthorRpc { - async fn author_rotate_keys(&self) -> SessionKeys; + async fn author_rotate_keys(&self) -> anyhow::Result; } #[async_trait::async_trait] impl AuthorRpc for Connection { - async fn author_rotate_keys(&self) -> SessionKeys { - let bytes = self.client.rpc().rotate_keys().await.unwrap(); + async fn author_rotate_keys(&self) -> anyhow::Result { + let bytes = self.client.rpc().rotate_keys().await?; - SessionKeys::decode(&mut bytes.0.as_slice()).unwrap() + SessionKeys::decode(&mut bytes.0.as_slice()).map_err(|e| e.into()) } } diff --git a/aleph-client/src/pallets/contract.rs b/aleph-client/src/pallets/contract.rs index e1cb81fd47..0612114b4b 100644 --- a/aleph-client/src/pallets/contract.rs +++ b/aleph-client/src/pallets/contract.rs @@ -188,7 +188,13 @@ impl ContractRpc for Connection { let res: ContractExecResult = self.rpc_call("state_call".to_string(), params).await?; - let res = T::decode(&mut (res.result.unwrap().data.as_slice()))?; + let res = T::decode( + &mut (res + .result + .expect("Failed to decode execution result of the wasm code!") + .data + .as_slice()), + )?; Ok(res) } diff --git a/aleph-client/src/pallets/elections.rs b/aleph-client/src/pallets/elections.rs index cb9f1ef5bd..b29789f084 100644 --- a/aleph-client/src/pallets/elections.rs +++ b/aleph-client/src/pallets/elections.rs @@ -43,7 +43,7 @@ pub trait ElectionsApi { validator: AccountId, at: Option, ) -> Option; - async fn get_session_period(&self) -> u32; + async fn get_session_period(&self) -> anyhow::Result; } #[async_trait::async_trait] @@ -164,10 +164,10 @@ impl ElectionsApi for Connection { self.get_storage_entry_maybe(&addrs, at).await } - async fn get_session_period(&self) -> u32 { + async fn get_session_period(&self) -> anyhow::Result { let addrs = api::constants().elections().session_period(); - self.client.constants().at(&addrs).unwrap() + self.client.constants().at(&addrs).map_err(|e| e.into()) } } diff --git a/aleph-client/src/pallets/staking.rs b/aleph-client/src/pallets/staking.rs index 81031abb95..7d10ec7201 100644 --- a/aleph-client/src/pallets/staking.rs +++ b/aleph-client/src/pallets/staking.rs @@ -44,7 +44,7 @@ pub trait StakingApi { at: Option, ) -> Option>; async fn get_minimum_validator_count(&self, at: Option) -> u32; - async fn get_session_per_era(&self) -> u32; + async fn get_session_per_era(&self) -> anyhow::Result; } #[async_trait::async_trait] @@ -113,7 +113,7 @@ pub trait StakingRawApi { &self, era: EraIndex, at: Option, - ) -> Vec; + ) -> anyhow::Result>; async fn get_stakers_storage_keys_from_accounts( &self, era: EraIndex, @@ -181,10 +181,10 @@ impl StakingApi for Connection { self.get_storage_entry(&addrs, at).await } - async fn get_session_per_era(&self) -> u32 { + async fn get_session_per_era(&self) -> anyhow::Result { let addrs = api::constants().staking().sessions_per_era(); - self.client.constants().at(&addrs).unwrap() + self.client.constants().at(&addrs).map_err(|e| e.into()) } } @@ -300,7 +300,7 @@ impl StakingRawApi for Connection { &self, era: EraIndex, at: Option, - ) -> Vec { + ) -> anyhow::Result> { let key_addrs = api::storage().staking().eras_stakers_root(); let mut key = key_addrs.to_root_bytes(); StorageMapKey::new(era, StorageHasher::Twox64Concat).to_bytes(&mut key); @@ -308,7 +308,7 @@ impl StakingRawApi for Connection { .storage() .fetch_keys(&key, 10, None, at) .await - .unwrap() + .map_err(|e| e.into()) } async fn get_stakers_storage_keys_from_accounts( diff --git a/aleph-client/src/pallets/treasury.rs b/aleph-client/src/pallets/treasury.rs index c47eb75643..1b1bb3773a 100644 --- a/aleph-client/src/pallets/treasury.rs +++ b/aleph-client/src/pallets/treasury.rs @@ -33,7 +33,7 @@ pub trait TreasuryUserApi { #[async_trait::async_trait] pub trait TreasureApiExt { - async fn possible_treasury_payout(&self) -> Balance; + async fn possible_treasury_payout(&self) -> anyhow::Result; } #[async_trait::async_trait] @@ -106,12 +106,12 @@ impl TreasurySudoApi for RootConnection { #[async_trait::async_trait] impl TreasureApiExt for Connection { - async fn possible_treasury_payout(&self) -> Balance { - let session_period = self.get_session_period().await; - let sessions_per_era = self.get_session_per_era().await; + async fn possible_treasury_payout(&self) -> anyhow::Result { + let session_period = self.get_session_period().await?; + let sessions_per_era = self.get_session_per_era().await?; let millisecs_per_era = MILLISECS_PER_BLOCK * session_period as u64 * sessions_per_era as u64; - primitives::staking::era_payout(millisecs_per_era).1 + Ok(primitives::staking::era_payout(millisecs_per_era).1) } } diff --git a/aleph-client/src/runtime_types.rs b/aleph-client/src/runtime_types.rs index 866487b5a8..2c1eceddbe 100644 --- a/aleph-client/src/runtime_types.rs +++ b/aleph-client/src/runtime_types.rs @@ -24,8 +24,16 @@ impl From> for SessionKeys { fn from(bytes: Vec) -> Self { assert_eq!(bytes.len(), 64); Self { - aura: AuraPublic(SrPublic(bytes[..32].try_into().unwrap())), - aleph: AlephPublic(EdPublic(bytes[32..64].try_into().unwrap())), + aura: AuraPublic(SrPublic( + bytes[..32] + .try_into() + .expect("Failed to convert bytes slice to an Aura key!"), + )), + aleph: AlephPublic(EdPublic( + bytes[32..64] + .try_into() + .expect("Failed to convert bytes slice to an Aleph key!"), + )), } } } diff --git a/aleph-client/src/utility.rs b/aleph-client/src/utility.rs index eb59983f03..bdb195a1dc 100644 --- a/aleph-client/src/utility.rs +++ b/aleph-client/src/utility.rs @@ -8,64 +8,77 @@ use crate::{ #[async_trait::async_trait] pub trait BlocksApi { - async fn first_block_of_session(&self, session: SessionIndex) -> Option; - async fn get_block_hash(&self, block: BlockNumber) -> Option; - async fn get_best_block(&self) -> BlockNumber; - async fn get_finalized_block_hash(&self) -> BlockHash; - async fn get_block_number(&self, block: BlockHash) -> Option; + async fn first_block_of_session( + &self, + session: SessionIndex, + ) -> anyhow::Result>; + async fn get_block_hash(&self, block: BlockNumber) -> anyhow::Result>; + async fn get_best_block(&self) -> anyhow::Result>; + async fn get_finalized_block_hash(&self) -> anyhow::Result; + async fn get_block_number(&self, block: BlockHash) -> anyhow::Result>; } #[async_trait::async_trait] pub trait SessionEraApi { - async fn get_active_era_for_session(&self, session: SessionIndex) -> EraIndex; + async fn get_active_era_for_session(&self, session: SessionIndex) -> anyhow::Result; +} + +impl Connection { + async fn get_block_number_inner( + &self, + block: Option, + ) -> anyhow::Result> { + self.client + .rpc() + .header(block) + .await + .map(|maybe_header| maybe_header.map(|header| header.number)) + .map_err(|e| e.into()) + } } #[async_trait::async_trait] impl BlocksApi for Connection { - async fn first_block_of_session(&self, session: SessionIndex) -> Option { - let period = self.get_session_period().await; + async fn first_block_of_session( + &self, + session: SessionIndex, + ) -> anyhow::Result> { + let period = self.get_session_period().await?; let block_num = period * session; self.get_block_hash(block_num).await } - async fn get_block_hash(&self, block: BlockNumber) -> Option { + async fn get_block_hash(&self, block: BlockNumber) -> anyhow::Result> { info!(target: "aleph-client", "querying block hash for number #{}", block); self.client .rpc() .block_hash(Some(block.into())) .await - .unwrap() + .map_err(|e| e.into()) } - async fn get_best_block(&self) -> BlockNumber { - self.client - .rpc() - .header(None) - .await - .unwrap() - .unwrap() - .number - } - - async fn get_finalized_block_hash(&self) -> BlockHash { - self.client.rpc().finalized_head().await.unwrap() + async fn get_best_block(&self) -> anyhow::Result> { + self.get_block_number_inner(None).await } - async fn get_block_number(&self, block: BlockHash) -> Option { + async fn get_finalized_block_hash(&self) -> anyhow::Result { self.client .rpc() - .header(Some(block)) + .finalized_head() .await - .unwrap() - .map(|h| h.number) + .map_err(|e| e.into()) + } + + async fn get_block_number(&self, block: BlockHash) -> anyhow::Result> { + self.get_block_number_inner(Some(block)).await } } #[async_trait::async_trait] impl SessionEraApi for Connection { - async fn get_active_era_for_session(&self, session: SessionIndex) -> EraIndex { - let block = self.first_block_of_session(session).await; - self.get_active_era(block).await + async fn get_active_era_for_session(&self, session: SessionIndex) -> anyhow::Result { + let block = self.first_block_of_session(session).await?; + Ok(self.get_active_era(block).await) } } diff --git a/aleph-client/src/waiting.rs b/aleph-client/src/waiting.rs index dcb8b355ef..74d7cc5ca9 100644 --- a/aleph-client/src/waiting.rs +++ b/aleph-client/src/waiting.rs @@ -37,8 +37,18 @@ pub trait WaitingExt { impl AlephWaiting for Connection { async fn wait_for_block bool + Send>(&self, predicate: P, status: BlockStatus) { let mut block_sub = match status { - BlockStatus::Best => self.client.blocks().subscribe_best().await.unwrap(), - BlockStatus::Finalized => self.client.blocks().subscribe_finalized().await.unwrap(), + BlockStatus::Best => self + .client + .blocks() + .subscribe_best() + .await + .expect("Failed to subscribe to the best block stream!"), + BlockStatus::Finalized => self + .client + .blocks() + .subscribe_finalized() + .await + .expect("Failed to subscribe to the finalized block stream!"), }; while let Some(Ok(block)) = block_sub.next().await { @@ -54,8 +64,18 @@ impl AlephWaiting for Connection { status: BlockStatus, ) -> T { let mut block_sub = match status { - BlockStatus::Best => self.client.blocks().subscribe_best().await.unwrap(), - BlockStatus::Finalized => self.client.blocks().subscribe_finalized().await.unwrap(), + BlockStatus::Best => self + .client + .blocks() + .subscribe_best() + .await + .expect("Failed to subscribe to the best block stream!"), + BlockStatus::Finalized => self + .client + .blocks() + .subscribe_finalized() + .await + .expect("Failed to subscribe to the finalized block stream!"), }; info!(target: "aleph-client", "waiting for event {}.{}", T::PALLET, T::EVENT); @@ -67,7 +87,7 @@ impl AlephWaiting for Connection { }; for event in events.iter() { - let event = event.unwrap(); + let event = event.expect("Failed to obtain event from the block!"); if let Ok(Some(ev)) = event.as_event::() { if predicate(&ev) { return ev; @@ -81,7 +101,11 @@ impl AlephWaiting for Connection { async fn wait_for_era(&self, era: EraIndex, status: BlockStatus) { let addrs = aleph_zero::api::constants().staking().sessions_per_era(); - let sessions_per_era = self.client.constants().at(&addrs).unwrap(); + let sessions_per_era = self + .client + .constants() + .at(&addrs) + .expect("Failed to obtain sessions_per_era const!"); let first_session_in_era = era * sessions_per_era; self.wait_for_session(first_session_in_era, status).await; diff --git a/benches/payout-stakers/Cargo.lock b/benches/payout-stakers/Cargo.lock index 416a39b5c9..2749a90e7b 100644 --- a/benches/payout-stakers/Cargo.lock +++ b/benches/payout-stakers/Cargo.lock @@ -49,7 +49,7 @@ dependencies = [ [[package]] name = "aleph_client" -version = "2.4.0" +version = "2.5.0" dependencies = [ "anyhow", "async-trait", diff --git a/bin/cliain/Cargo.lock b/bin/cliain/Cargo.lock index f2358ff658..346655da73 100644 --- a/bin/cliain/Cargo.lock +++ b/bin/cliain/Cargo.lock @@ -49,7 +49,7 @@ dependencies = [ [[package]] name = "aleph_client" -version = "2.4.0" +version = "2.5.0" dependencies = [ "anyhow", "async-trait", @@ -393,7 +393,7 @@ dependencies = [ [[package]] name = "cliain" -version = "0.10.0" +version = "0.11.0" dependencies = [ "aleph_client", "anyhow", diff --git a/bin/cliain/Cargo.toml b/bin/cliain/Cargo.toml index 4f36298741..0d04e9b332 100644 --- a/bin/cliain/Cargo.toml +++ b/bin/cliain/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cliain" -version = "0.10.0" +version = "0.11.0" edition = "2021" license = "GPL-3.0-or-later" diff --git a/bin/cliain/src/keys.rs b/bin/cliain/src/keys.rs index a75ff66cda..7cd1827ebc 100644 --- a/bin/cliain/src/keys.rs +++ b/bin/cliain/src/keys.rs @@ -13,7 +13,10 @@ use primitives::staking::MIN_VALIDATOR_BOND; use serde_json::json; use subxt::ext::sp_core::crypto::Ss58Codec; -pub async fn prepare_keys(connection: RootConnection, controller_account_id: AccountId) { +pub async fn prepare_keys( + connection: RootConnection, + controller_account_id: AccountId, +) -> anyhow::Result<()> { connection .as_signed() .bond( @@ -23,12 +26,12 @@ pub async fn prepare_keys(connection: RootConnection, controller_account_id: Acc ) .await .unwrap(); - let new_keys = connection.connection.author_rotate_keys().await; - connection + let new_keys = connection.connection.author_rotate_keys().await?; + let _ = connection .as_signed() .set_keys(new_keys, TxStatus::Finalized) - .await - .unwrap(); + .await?; + Ok(()) } pub async fn set_keys(connection: SignedConnection, new_keys: String) { diff --git a/bin/cliain/src/main.rs b/bin/cliain/src/main.rs index bd89b9f464..ff06959770 100644 --- a/bin/cliain/src/main.rs +++ b/bin/cliain/src/main.rs @@ -58,7 +58,7 @@ fn read_secret(secret: Option, message: &str) -> String { } #[tokio::main] -async fn main() { +async fn main() -> anyhow::Result<()> { init_env(); let Config { @@ -76,7 +76,7 @@ async fn main() { Command::PrepareKeys => { let key = keypair_from_string(&seed); let controller_account_id = account_from_keypair(key.signer()); - prepare_keys(cfg.get_root_connection().await, controller_account_id).await; + prepare_keys(cfg.get_root_connection().await, controller_account_id).await? } Command::Bond { controller_account, @@ -245,6 +245,7 @@ async fn main() { Err(why) => error!("Unable to schedule an upgrade {:?}", why), }, } + Ok(()) } fn init_env() { diff --git a/e2e-tests/Cargo.lock b/e2e-tests/Cargo.lock index 33330c590a..e379e2513c 100644 --- a/e2e-tests/Cargo.lock +++ b/e2e-tests/Cargo.lock @@ -49,7 +49,7 @@ dependencies = [ [[package]] name = "aleph-e2e-client" -version = "0.9.4" +version = "0.10.0" dependencies = [ "aleph_client", "anyhow", @@ -75,7 +75,7 @@ dependencies = [ [[package]] name = "aleph_client" -version = "2.4.0" +version = "2.5.0" dependencies = [ "anyhow", "async-trait", diff --git a/e2e-tests/Cargo.toml b/e2e-tests/Cargo.toml index 48166153be..851f5f1e1e 100644 --- a/e2e-tests/Cargo.toml +++ b/e2e-tests/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "aleph-e2e-client" -version = "0.9.4" +version = "0.10.0" edition = "2021" license = "Apache 2.0" diff --git a/e2e-tests/src/ban.rs b/e2e-tests/src/ban.rs index 3972508623..8d54b229d0 100644 --- a/e2e-tests/src/ban.rs +++ b/e2e-tests/src/ban.rs @@ -186,7 +186,7 @@ pub async fn check_underperformed_count_for_sessions( end_session: SessionIndex, ban_session_threshold: SessionCount, ) -> anyhow::Result<()> { - let session_period = connection.get_session_period().await; + let session_period = connection.get_session_period().await?; let validators: Vec<_> = reserved_validators .iter() @@ -195,11 +195,12 @@ pub async fn check_underperformed_count_for_sessions( for session in start_session..end_session { let session_end_block = (session + 1) * session_period; - let session_end_block_hash = connection.get_block_hash(session_end_block).await; + let session_end_block_hash = connection.get_block_hash(session_end_block).await?; let previous_session_end_block = session_end_block - session_period; - let previous_session_end_block_hash = - connection.get_block_hash(previous_session_end_block).await; + let previous_session_end_block_hash = connection + .get_block_hash(previous_session_end_block) + .await?; let members = get_members_for_session(reserved_validators, non_reserved_validators, seats, session); diff --git a/e2e-tests/src/elections.rs b/e2e-tests/src/elections.rs index fcc9f19edf..72c42f2545 100644 --- a/e2e-tests/src/elections.rs +++ b/e2e-tests/src/elections.rs @@ -14,7 +14,7 @@ pub async fn get_and_test_members_for_session( seats: CommitteeSeats, era_validators: &EraValidators, session: SessionIndex, -) -> (Vec, Vec) { +) -> anyhow::Result<(Vec, Vec)> { let reserved_members_for_session = get_members_subset_for_session(seats.reserved_seats, &era_validators.reserved, session); let non_reserved_members_for_session = get_members_subset_for_session( @@ -40,7 +40,7 @@ pub async fn get_and_test_members_for_session( .collect(); let members_active_set: HashSet<_> = members_active.iter().cloned().collect(); - let block = connection.first_block_of_session(session).await; + let block = connection.first_block_of_session(session).await?; let network_members: HashSet<_> = connection.get_validators(block).await.into_iter().collect(); debug!( @@ -55,7 +55,7 @@ pub async fn get_and_test_members_for_session( assert_eq!(members_active_set, network_members); - (members_active, members_bench) + Ok((members_active, members_bench)) } /// Computes a list of validators that should be elected for a given session, based on description in our elections pallet. diff --git a/e2e-tests/src/rewards.rs b/e2e-tests/src/rewards.rs index 69c7b3d257..d081a4272e 100644 --- a/e2e-tests/src/rewards.rs +++ b/e2e-tests/src/rewards.rs @@ -14,6 +14,7 @@ use aleph_client::{ waiting::{AlephWaiting, BlockStatus, WaitingExt}, AccountId, SignedConnection, TxStatus, }; +use anyhow::anyhow; use log::{debug, info}; use pallet_elections::LENIENT_THRESHOLD; use primitives::{Balance, BlockHash, EraIndex, SessionIndex, TOKEN}; @@ -54,7 +55,10 @@ pub async fn set_invalid_keys_for_validator( pub(super) async fn reset_validator_keys( controller_connection: &SignedConnection, ) -> anyhow::Result<()> { - let validator_keys = controller_connection.connection.author_rotate_keys().await; + let validator_keys = controller_connection + .connection + .author_rotate_keys() + .await?; controller_connection .set_keys(validator_keys, TxStatus::InBlock) .await @@ -164,7 +168,7 @@ pub async fn check_points( members_per_session: u32, max_relative_difference: f64, ) -> anyhow::Result<()> { - let session_period = connection.connection.get_session_period().await; + let session_period = connection.connection.get_session_period().await?; info!("Era: {} | session: {}.", era, session); @@ -179,15 +183,15 @@ pub async fn check_points( let beginning_of_session_block_hash = connection .connection .get_block_hash(beginning_of_session_block) - .await; + .await?; let end_of_session_block_hash = connection .connection .get_block_hash(end_of_session_block) - .await; + .await?; let before_end_of_session_block_hash = connection .connection .get_block_hash(end_of_session_block - 1) - .await; + .await?; info!( "End-of-session block hash: {:?}.", end_of_session_block_hash @@ -313,8 +317,8 @@ pub async fn setup_validators( let first_block_in_session = root_connection .connection .first_block_of_session(session) - .await - .unwrap(); + .await? + .ok_or(anyhow!("First block of session {} is None!", session))?; let network_seats = root_connection .connection .get_committee_seats(Some(first_block_in_session)) @@ -349,7 +353,7 @@ pub async fn setup_validators( let first_block_in_session = root_connection .connection .first_block_of_session(session) - .await; + .await?; let network_validators = root_connection .connection .get_current_era_validators(first_block_in_session) diff --git a/e2e-tests/src/test/electing_validators.rs b/e2e-tests/src/test/electing_validators.rs index 31994843b3..b099bde3b6 100644 --- a/e2e-tests/src/test/electing_validators.rs +++ b/e2e-tests/src/test/electing_validators.rs @@ -25,10 +25,10 @@ async fn assert_validators_are_elected_stakers( connection: &Connection, current_era: EraIndex, expected_validators_as_keys: Vec>, -) { +) -> anyhow::Result<()> { let stakers = connection .get_stakers_storage_keys(current_era, None) - .await + .await? .into_iter() .map(|key| key.0); let stakers_tree = BTreeSet::from_iter(stakers); @@ -39,6 +39,8 @@ async fn assert_validators_are_elected_stakers( "Expected another set of staking validators.\n\tExpected: {:?}\n\tActual: {:?}", expected_validators_as_keys, stakers_tree ); + + Ok(()) } // There are v non-reserved validators and s non-reserved seats. We will have seen all @@ -180,7 +182,7 @@ pub async fn authorities_are_staking() -> anyhow::Result<()> { let desired_validator_count = reserved_seats + non_reserved_seats; let accounts = setup_accounts(desired_validator_count); - prepare_validators(&root_connection.as_signed(), node, &accounts).await; + prepare_validators(&root_connection.as_signed(), node, &accounts).await?; info!("New validators are set up"); let reserved_validators = accounts.get_stash_accounts()[..reserved_seats as usize].to_vec(); @@ -249,7 +251,7 @@ pub async fn authorities_are_staking() -> anyhow::Result<()> { .map(|k| k.0) .collect(), ) - .await; + .await?; let min_num_sessions = min_num_sessions_to_see_all_non_reserved_validators(non_reserved_count, non_reserved_seats); @@ -288,7 +290,7 @@ pub async fn authorities_are_staking() -> anyhow::Result<()> { .map(|k| k.0) .collect(), ) - .await; + .await?; assert_validators_are_used_as_authorities( &connection.connection, &BTreeSet::from_iter(left_stashes.into_iter()), diff --git a/e2e-tests/src/test/era_validators.rs b/e2e-tests/src/test/era_validators.rs index 81c2570116..4eee186fb9 100644 --- a/e2e-tests/src/test/era_validators.rs +++ b/e2e-tests/src/test/era_validators.rs @@ -5,6 +5,7 @@ use aleph_client::{ waiting::{AlephWaiting, BlockStatus, WaitingExt}, AccountId, Connection, KeyPair, TxStatus, }; +use anyhow::anyhow; use crate::{ accounts::{account_ids_from_keys, get_validators_raw_keys}, @@ -160,7 +161,11 @@ pub async fn era_validators() -> anyhow::Result<()> { "Non-reserved validators set is not properly updated in the next era." ); - let block_number = connection.connection.get_best_block().await; + let block_number = connection + .connection + .get_best_block() + .await? + .ok_or(anyhow!("Failed to retrieve best block number!"))?; connection .connection .wait_for_block(|n| n >= block_number, BlockStatus::Finalized) diff --git a/e2e-tests/src/test/finalization.rs b/e2e-tests/src/test/finalization.rs index 2c28b5d32f..3d53c3a562 100644 --- a/e2e-tests/src/test/finalization.rs +++ b/e2e-tests/src/test/finalization.rs @@ -2,6 +2,7 @@ use aleph_client::{ utility::BlocksApi, waiting::{AlephWaiting, BlockStatus}, }; +use anyhow::anyhow; use crate::config::setup_test; @@ -10,12 +11,14 @@ pub async fn finalization() -> anyhow::Result<()> { let config = setup_test(); let connection = config.create_root_connection().await; - let finalized = connection.connection.get_finalized_block_hash().await; + let finalized = connection.connection.get_finalized_block_hash().await?; let finalized_number = connection .connection .get_block_number(finalized) - .await - .unwrap(); + .await? + .ok_or(anyhow!( + "Failed to retrieve block number for hash {finalized:?}" + ))?; connection .connection .wait_for_block(|n| n > finalized_number, BlockStatus::Finalized) diff --git a/e2e-tests/src/test/rewards.rs b/e2e-tests/src/test/rewards.rs index 9ca7ff4e16..fd4652ef57 100644 --- a/e2e-tests/src/test/rewards.rs +++ b/e2e-tests/src/test/rewards.rs @@ -48,14 +48,14 @@ pub async fn points_basic() -> anyhow::Result<()> { let era = connection .connection .get_active_era_for_session(session) - .await; + .await?; let (members_active, members_bench) = get_and_test_members_for_session( &connection.connection, committee_size.clone(), &era_validators, session, ) - .await; + .await?; check_points( &connection, @@ -109,14 +109,14 @@ pub async fn points_stake_change() -> anyhow::Result<()> { let era = connection .connection .get_active_era_for_session(session) - .await; + .await?; let (members_active, members_bench) = get_and_test_members_for_session( &connection.connection, committee_size.clone(), &era_validators, session, ) - .await; + .await?; check_points( &connection, @@ -165,14 +165,14 @@ pub async fn disable_node() -> anyhow::Result<()> { let era = root_connection .connection .get_active_era_for_session(session) - .await; + .await?; let (members_active, members_bench) = get_and_test_members_for_session( &controller_connection.connection, committee_size.clone(), &era_validators, session, ) - .await; + .await?; check_points( &controller_connection, @@ -203,7 +203,7 @@ pub async fn force_new_era() -> anyhow::Result<()> { let start_era = connection .connection .get_active_era_for_session(start_session) - .await; + .await?; info!("Start | era: {}, session: {}", start_era, start_session); @@ -248,7 +248,7 @@ pub async fn change_stake_and_force_new_era() -> anyhow::Result<()> { let start_era = connection .connection .get_active_era_for_session(start_session) - .await; + .await?; info!("Start | era: {}, session: {}", start_era, start_session); validators_bond_extra_stakes( @@ -316,7 +316,7 @@ async fn check_points_after_force_new_era( era_validators, session_to_check, ) - .await; + .await?; check_points( connection, diff --git a/e2e-tests/src/test/staking.rs b/e2e-tests/src/test/staking.rs index 1ce9f7638f..766c0a1971 100644 --- a/e2e-tests/src/test/staking.rs +++ b/e2e-tests/src/test/staking.rs @@ -178,7 +178,7 @@ pub async fn staking_new_validator() -> anyhow::Result<()> { &stash_account, &controller_account, &bonded_controller_account ); - let validator_keys = root_connection.connection.author_rotate_keys().await; + let validator_keys = root_connection.connection.author_rotate_keys().await?; let controller_connection = SignedConnection::new(node.to_string(), KeyPair::new(controller.signer().clone())).await; controller_connection diff --git a/e2e-tests/src/test/treasury.rs b/e2e-tests/src/test/treasury.rs index 50df832815..940d0779af 100644 --- a/e2e-tests/src/test/treasury.rs +++ b/e2e-tests/src/test/treasury.rs @@ -41,7 +41,7 @@ pub async fn channeling_fee_and_tip() -> anyhow::Result<()> { let (treasury_balance_before, issuance_before) = balance_info(&connection.connection).await; let possible_treasury_gain_from_staking = - connection.connection.possible_treasury_payout().await; + connection.connection.possible_treasury_payout().await?; let (fee, _) = current_fees(&connection, to, Some(tip), transfer_amount).await; let (treasury_balance_after, issuance_after) = balance_info(&connection.connection).await; diff --git a/e2e-tests/src/test/validators_change.rs b/e2e-tests/src/test/validators_change.rs index e1e0e8cb4a..f906f980f1 100644 --- a/e2e-tests/src/test/validators_change.rs +++ b/e2e-tests/src/test/validators_change.rs @@ -6,6 +6,7 @@ use aleph_client::{ waiting::{AlephWaiting, BlockStatus}, AccountId, Pair, TxStatus, }; +use anyhow::anyhow; use log::info; use crate::{accounts::get_validators_keys, config::setup_test}; @@ -90,7 +91,11 @@ pub async fn change_validators() -> anyhow::Result<()> { }, committee_size_after ); - let block_number = connection.connection.get_best_block().await; + let block_number = connection + .connection + .get_best_block() + .await? + .ok_or(anyhow!("Failed to retrieve best block!"))?; connection .connection .wait_for_block(|n| n >= block_number, BlockStatus::Finalized) diff --git a/e2e-tests/src/test/validators_rotate.rs b/e2e-tests/src/test/validators_rotate.rs index 56d222346c..f206865a20 100644 --- a/e2e-tests/src/test/validators_rotate.rs +++ b/e2e-tests/src/test/validators_rotate.rs @@ -7,6 +7,7 @@ use aleph_client::{ waiting::{AlephWaiting, BlockStatus, WaitingExt}, TxStatus, }; +use anyhow::anyhow; use crate::{ accounts::account_ids_from_keys, config::setup_test, elections::get_members_subset_for_session, @@ -54,7 +55,12 @@ pub async fn validators_rotate() -> anyhow::Result<()> { for session in current_session..current_session + TEST_LENGTH { let elected = connection .connection - .get_validators(connection.connection.first_block_of_session(session).await) + .get_validators( + connection + .connection + .first_block_of_session(session) + .await?, + ) .await; let non_reserved = get_members_subset_for_session( @@ -101,7 +107,11 @@ pub async fn validators_rotate() -> anyhow::Result<()> { let min_elected = non_reserved_count.values().min().unwrap(); assert!(max_elected - min_elected <= 1); - let block_number = connection.connection.get_best_block().await; + let block_number = connection + .connection + .get_best_block() + .await? + .ok_or(anyhow!("Failed to retrieve best block number!"))?; connection .connection .wait_for_block(|n| n >= block_number, BlockStatus::Finalized) diff --git a/e2e-tests/src/test/version_upgrade.rs b/e2e-tests/src/test/version_upgrade.rs index 8f718335b3..8d0846e78e 100644 --- a/e2e-tests/src/test/version_upgrade.rs +++ b/e2e-tests/src/test/version_upgrade.rs @@ -4,6 +4,7 @@ use aleph_client::{ waiting::{AlephWaiting, BlockStatus}, TxStatus, }; +use anyhow::anyhow; use primitives::SessionIndex; use crate::config::setup_test; @@ -44,7 +45,11 @@ pub async fn schedule_version_change() -> anyhow::Result<()> { .wait_for_session(session_after_upgrade + 1, BlockStatus::Finalized) .await; - let block_number = connection.connection.get_best_block().await; + let block_number = connection + .connection + .get_best_block() + .await? + .ok_or(anyhow!("Failed to retrieve best block number!"))?; connection .connection .wait_for_block(|n| n >= block_number, BlockStatus::Finalized) @@ -86,11 +91,11 @@ pub async fn schedule_doomed_version_change_and_verify_finalization_stopped() -> .await; let last_finalized_block = - session_for_upgrade * connection.connection.get_session_period().await - 1; + session_for_upgrade * connection.connection.get_session_period().await? - 1; let connection = connection.connection; - let finalized_block_head = connection.get_finalized_block_hash().await; - let finalized_block = connection.get_block_number(finalized_block_head).await; + let finalized_block_head = connection.get_finalized_block_hash().await?; + let finalized_block = connection.get_block_number(finalized_block_head).await?; let finalized_block = match finalized_block { Some(block) => block, diff --git a/e2e-tests/src/validators.rs b/e2e-tests/src/validators.rs index a4567e429c..31833885b2 100644 --- a/e2e-tests/src/validators.rs +++ b/e2e-tests/src/validators.rs @@ -103,7 +103,11 @@ pub fn setup_accounts(desired_validator_count: u32) -> Accounts { /// Endow validators (stashes and controllers), bond and rotate keys. /// /// Signer of `connection` should have enough balance to endow new accounts. -pub async fn prepare_validators(connection: &SignedConnection, node: &str, accounts: &Accounts) { +pub async fn prepare_validators( + connection: &SignedConnection, + node: &str, + accounts: &Accounts, +) -> anyhow::Result<()> { connection .batch_transfer( &accounts.stash_accounts, @@ -134,7 +138,7 @@ pub async fn prepare_validators(connection: &SignedConnection, node: &str, accou } for controller in accounts.controller_raw_keys.iter() { - let keys = connection.connection.author_rotate_keys().await; + let keys = connection.connection.author_rotate_keys().await?; let connection = SignedConnection::new(node.to_string(), KeyPair::new(controller.clone())).await; handles.push(tokio::spawn(async move { @@ -147,4 +151,5 @@ pub async fn prepare_validators(connection: &SignedConnection, node: &str, accou } join_all(handles).await; + Ok(()) } diff --git a/flooder/Cargo.lock b/flooder/Cargo.lock index bbd519f9f1..fef7c2c125 100644 --- a/flooder/Cargo.lock +++ b/flooder/Cargo.lock @@ -49,7 +49,7 @@ dependencies = [ [[package]] name = "aleph_client" -version = "2.4.0" +version = "2.5.0" dependencies = [ "anyhow", "async-trait",