Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
2e22b79
dont use String for creating connections
krzysztofziobro Dec 27, 2022
20aafa6
do not wrap client
krzysztofziobro Dec 27, 2022
1f10b03
wip
krzysztofziobro Dec 28, 2022
2f5cda9
should work as old one
krzysztofziobro Dec 28, 2022
f5b769f
hide connection
krzysztofziobro Dec 28, 2022
44a4e9a
hide the rest
krzysztofziobro Dec 28, 2022
1472fd7
Don not hide clone
krzysztofziobro Dec 28, 2022
40225ca
Merge branch 'main' into A0-1613-improve-connection
krzysztofziobro Dec 29, 2022
168ce19
bump
krzysztofziobro Dec 29, 2022
0247e81
wip
krzysztofziobro Dec 30, 2022
4c1a6eb
wrap client
krzysztofziobro Dec 30, 2022
e41d124
rename client
krzysztofziobro Dec 30, 2022
7968aea
add Clone
krzysztofziobro Dec 30, 2022
9a979f6
Merge branch 'main' into A0-1613-improve-connection
krzysztofziobro Dec 30, 2022
50d7071
more general adder
krzysztofziobro Dec 30, 2022
dba9561
Add AsSigned
krzysztofziobro Dec 30, 2022
d700129
add impls for references
krzysztofziobro Dec 30, 2022
e45f361
wip
krzysztofziobro Jan 2, 2023
e6839b8
change TreasurySudoApi
krzysztofziobro Jan 2, 2023
8ec4625
Merge branch 'main' into A0-1613-improve-connection
krzysztofziobro Jan 2, 2023
3bf05d5
add methods to SignedConnectionApi
krzysztofziobro Jan 2, 2023
6b259b2
Merge branch 'A0-1613-improve-connection' of github.com:Cardinal-Cryp…
krzysztofziobro Jan 2, 2023
23d5a58
remove unnecessary casts
krzysztofziobro Jan 2, 2023
5600e11
Merge branch 'main' into A0-1613-improve-connection
krzysztofziobro Jan 2, 2023
b7ad771
review part 1
krzysztofziobro Jan 2, 2023
d156320
Merge branch 'A0-1613-improve-connection' of github.com:Cardinal-Cryp…
krzysztofziobro Jan 2, 2023
ef5625d
review part 2
krzysztofziobro Jan 2, 2023
af4d737
Make AsConnection visible only in crate
krzysztofziobro Jan 3, 2023
d15be1b
Merge branch 'main' into A0-1613-improve-connection
krzysztofziobro Jan 3, 2023
70db49a
Remove unnecessary dependencies on ConnectionApi
krzysztofziobro Jan 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make AsConnection visible only in crate
  • Loading branch information
krzysztofziobro committed Jan 3, 2023
commit af4d737c0b26449e43dfb24608dfa37f7f4c18b2
8 changes: 4 additions & 4 deletions aleph-client/src/connections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ pub struct RootConnection {
connection: SignedConnection,
}

pub trait AsConnection {
pub(crate) trait AsConnection {
fn as_connection(&self) -> &Connection;
}

pub trait AsSigned {
pub(crate) trait AsSigned {
fn as_signed(&self) -> &SignedConnection;
}

#[async_trait::async_trait]
pub trait ConnectionApi: AsConnection + Sync {
pub trait ConnectionApi: Sync {
async fn get_storage_entry<T: DecodeWithMetadata + Sync, Defaultable: Sync, Iterable: Sync>(
&self,
addrs: &StaticStorageAddress<T, Yes, Defaultable, Iterable>,
Expand All @@ -61,7 +61,7 @@ pub trait ConnectionApi: AsConnection + Sync {
}

#[async_trait::async_trait]
pub trait SignedConnectionApi: AsSigned + Sync {
pub trait SignedConnectionApi: ConnectionApi {
async fn send_tx<Call: TxPayload + Send + Sync>(
&self,
tx: Call,
Expand Down
4 changes: 2 additions & 2 deletions aleph-client/src/pallets/author.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use codec::Decode;

use crate::{aleph_runtime::SessionKeys, ConnectionApi};
use crate::{aleph_runtime::SessionKeys, connections::AsConnection, ConnectionApi};

#[async_trait::async_trait]
pub trait AuthorRpc {
async fn author_rotate_keys(&self) -> anyhow::Result<SessionKeys>;
}

#[async_trait::async_trait]
impl<C: ConnectionApi> AuthorRpc for C {
impl<C: ConnectionApi + AsConnection> AuthorRpc for C {
async fn author_rotate_keys(&self) -> anyhow::Result<SessionKeys> {
let bytes = self.as_connection().as_client().rpc().rotate_keys().await?;
SessionKeys::decode(&mut bytes.0.as_slice()).map_err(|e| e.into())
Expand Down
3 changes: 2 additions & 1 deletion aleph-client/src/pallets/elections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::{
pallet_elections::pallet::Call::set_ban_config,
primitives::{BanReason, CommitteeSeats, EraValidators},
},
connections::AsConnection,
pallet_elections::pallet::Call::{
ban_from_committee, change_validators, set_elections_openness,
},
Expand Down Expand Up @@ -78,7 +79,7 @@ pub trait ElectionsSudoApi {
}

#[async_trait::async_trait]
impl<C: ConnectionApi> ElectionsApi for C {
impl<C: ConnectionApi + AsConnection> ElectionsApi for C {
async fn get_ban_config(&self, at: Option<BlockHash>) -> BanConfig {
let addrs = api::storage().elections().ban_config();

Expand Down
5 changes: 3 additions & 2 deletions aleph-client/src/pallets/staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use subxt::{

use crate::{
api,
connections::AsConnection,
pallet_staking::{
pallet::pallet::{
Call::{bond, force_new_era, nominate, set_staking_configs},
Expand Down Expand Up @@ -123,7 +124,7 @@ pub trait StakingRawApi {
}

#[async_trait::async_trait]
impl<C: ConnectionApi> StakingApi for C {
impl<C: ConnectionApi + AsConnection> StakingApi for C {
async fn get_active_era(&self, at: Option<BlockHash>) -> EraIndex {
let addrs = api::storage().staking().active_era();

Expand Down Expand Up @@ -298,7 +299,7 @@ impl StakingSudoApi for RootConnection {
}

#[async_trait::async_trait]
impl<C: ConnectionApi> StakingRawApi for C {
impl<C: ConnectionApi + AsConnection> StakingRawApi for C {
async fn get_stakers_storage_keys(
&self,
era: EraIndex,
Expand Down
3 changes: 2 additions & 1 deletion aleph-client/src/pallets/treasury.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use subxt::ext::sp_runtime::MultiAddress;

use crate::{
api,
connections::AsConnection,
pallet_treasury::pallet::Call::{approve_proposal, reject_proposal},
pallets::{elections::ElectionsApi, staking::StakingApi},
AccountId, BlockHash,
Expand Down Expand Up @@ -105,7 +106,7 @@ impl TreasurySudoApi for RootConnection {
}

#[async_trait::async_trait]
impl<C: ConnectionApi> TreasureApiExt for C {
impl<C: ConnectionApi + AsConnection> TreasureApiExt for C {
async fn possible_treasury_payout(&self) -> anyhow::Result<Balance> {
let session_period = self.get_session_period().await?;
let sessions_per_era = self.get_session_per_era().await?;
Expand Down
5 changes: 3 additions & 2 deletions aleph-client/src/utility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use log::info;
use primitives::{BlockNumber, EraIndex, SessionIndex};

use crate::{
connections::AsConnection,
pallets::{elections::ElectionsApi, staking::StakingApi},
BlockHash, ConnectionApi,
};
Expand All @@ -28,7 +29,7 @@ pub trait SessionEraApi {
}

#[async_trait::async_trait]
impl<C: ConnectionApi> BlocksApi for C {
impl<C: ConnectionApi + AsConnection> BlocksApi for C {
async fn first_block_of_session(
&self,
session: SessionIndex,
Expand Down Expand Up @@ -81,7 +82,7 @@ impl<C: ConnectionApi> BlocksApi for C {
}

#[async_trait::async_trait]
impl<C: ConnectionApi> SessionEraApi for C {
impl<C: ConnectionApi + AsConnection> SessionEraApi for C {
async fn get_active_era_for_session(&self, session: SessionIndex) -> anyhow::Result<EraIndex> {
let block = self.first_block_of_session(session).await?;
Ok(self.get_active_era(block).await)
Expand Down
5 changes: 3 additions & 2 deletions aleph-client/src/waiting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use subxt::events::StaticEvent;
use crate::{
aleph_zero,
api::session::events::NewSession,
connections::AsConnection,
pallets::{session::SessionApi, staking::StakingApi},
ConnectionApi,
};
Expand Down Expand Up @@ -34,7 +35,7 @@ pub trait WaitingExt {
}

#[async_trait::async_trait]
impl<C: ConnectionApi> AlephWaiting for C {
impl<C: ConnectionApi + AsConnection> AlephWaiting for C {
async fn wait_for_block<P: Fn(u32) -> bool + Send>(&self, predicate: P, status: BlockStatus) {
let mut block_sub = match status {
BlockStatus::Best => self
Expand Down Expand Up @@ -126,7 +127,7 @@ impl<C: ConnectionApi> AlephWaiting for C {
}

#[async_trait::async_trait]
impl<C: ConnectionApi> WaitingExt for C {
impl<C: ConnectionApi + AsConnection> WaitingExt for C {
async fn wait_for_n_sessions(&self, n: SessionIndex, status: BlockStatus) {
let current_session = self.get_session(None).await;

Expand Down
2 changes: 1 addition & 1 deletion benches/payout-stakers/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ pub fn derive_user_account_from_numeric_seed(seed: u32) -> KeyPair {
}

/// For a given number of eras, in each era check whether stash balances of a validator are locked.
async fn wait_for_successive_eras<C: ConnectionApi>(
async fn wait_for_successive_eras<C: ConnectionApi + WaitingExt + StakingApi>(
address: &str,
connection: &C,
validators_and_nominator_stashes: Vec<(KeyPair, Vec<AccountId>)>,
Expand Down
14 changes: 7 additions & 7 deletions e2e-tests/src/ban.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use aleph_client::{
primitives::{BanConfig, BanInfo, CommitteeSeats, EraValidators},
utility::BlocksApi,
waiting::{AlephWaiting, BlockStatus, WaitingExt},
AccountId, ConnectionApi, RootConnection, TxStatus,
AccountId, RootConnection, TxStatus,
};
use codec::Encode;
use log::info;
Expand Down Expand Up @@ -68,7 +68,7 @@ pub fn check_validators(
era_validators
}

pub async fn check_ban_config<C: ConnectionApi>(
pub async fn check_ban_config<C: ElectionsApi>(
connection: &C,
expected_minimal_expected_performance: Perbill,
expected_session_count_threshold: SessionCount,
Expand All @@ -92,7 +92,7 @@ pub async fn check_ban_config<C: ConnectionApi>(
ban_config
}

pub async fn check_underperformed_validator_session_count<C: ConnectionApi>(
pub async fn check_underperformed_validator_session_count<C: ElectionsApi>(
connection: &C,
validator: &AccountId,
expected_session_count: SessionCount,
Expand All @@ -110,7 +110,7 @@ pub async fn check_underperformed_validator_session_count<C: ConnectionApi>(
underperformed_validator_session_count
}

pub async fn check_underperformed_validator_reason<C: ConnectionApi>(
pub async fn check_underperformed_validator_reason<C: ElectionsApi>(
connection: &C,
validator: &AccountId,
expected_info: Option<&BanInfo>,
Expand All @@ -123,7 +123,7 @@ pub async fn check_underperformed_validator_reason<C: ConnectionApi>(
validator_ban_info
}

pub async fn check_ban_info_for_validator<C: ConnectionApi>(
pub async fn check_ban_info_for_validator<C: ElectionsApi>(
connection: &C,
validator: &AccountId,
expected_info: Option<&BanInfo>,
Expand All @@ -137,7 +137,7 @@ pub async fn check_ban_info_for_validator<C: ConnectionApi>(
validator_ban_info
}

pub async fn check_ban_event<C: ConnectionApi>(
pub async fn check_ban_event<C: AlephWaiting>(
connection: &C,
expected_banned_validators: &[(AccountId, BanInfo)],
) -> anyhow::Result<BanValidators> {
Expand Down Expand Up @@ -174,7 +174,7 @@ pub fn get_members_for_session(
/// Checks whether underperformed counts for validators change predictably. Assumes: (a) that the
/// sessions checked are in the past, (b) that all the checked validators are underperforming in
/// those sessions (e.g. due to a prohibitively high performance threshold).
pub async fn check_underperformed_count_for_sessions<C: ConnectionApi>(
pub async fn check_underperformed_count_for_sessions<C: ElectionsApi + BlocksApi>(
connection: &C,
reserved_validators: &[AccountId],
non_reserved_validators: &[AccountId],
Expand Down
4 changes: 2 additions & 2 deletions e2e-tests/src/elections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ use aleph_client::{
pallets::session::SessionApi,
primitives::{CommitteeSeats, EraValidators},
utility::BlocksApi,
AccountId, ConnectionApi,
AccountId,
};
use log::debug;
use primitives::SessionIndex;

pub async fn get_and_test_members_for_session<C: ConnectionApi>(
pub async fn get_and_test_members_for_session<C: SessionApi + BlocksApi>(
connection: &C,
seats: CommitteeSeats,
era_validators: &EraValidators<AccountId>,
Expand Down
12 changes: 6 additions & 6 deletions e2e-tests/src/rewards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use aleph_client::{
primitives::{CommitteeSeats, EraValidators},
utility::BlocksApi,
waiting::{AlephWaiting, BlockStatus, WaitingExt},
AccountId, SignedConnection, SignedConnectionApi, TxStatus,
AccountId, SignedConnection, TxStatus,
};
use anyhow::anyhow;
use log::{debug, info};
Expand All @@ -33,7 +33,7 @@ type RewardPoint = u32;

/// Changes session_keys used by a given `controller` to some `zero`/invalid value,
/// making it impossible to create new legal blocks.
pub async fn set_invalid_keys_for_validator<S: SignedConnectionApi>(
pub async fn set_invalid_keys_for_validator<S: WaitingExt + SessionUserApi>(
controller_connection: &S,
) -> anyhow::Result<()> {
let zero_session_keys = [0; 64].to_vec().into();
Expand All @@ -51,7 +51,7 @@ pub async fn set_invalid_keys_for_validator<S: SignedConnectionApi>(
}

/// Rotates session_keys of a given `controller`, making it able to rejoin the `consensus`.
pub(super) async fn reset_validator_keys<S: SignedConnectionApi>(
pub(super) async fn reset_validator_keys<S: AuthorRpc + WaitingExt + SessionUserApi>(
controller_connection: &S,
) -> anyhow::Result<()> {
let validator_keys = controller_connection.author_rotate_keys().await?;
Expand All @@ -68,7 +68,7 @@ pub(super) async fn reset_validator_keys<S: SignedConnectionApi>(
Ok(())
}

pub async fn download_exposure<S: SignedConnectionApi>(
pub async fn download_exposure<S: StakingApi>(
connection: &S,
era: EraIndex,
account_id: &AccountId,
Expand Down Expand Up @@ -124,7 +124,7 @@ fn check_rewards(
Ok(())
}

async fn get_node_performance<S: SignedConnectionApi>(
async fn get_node_performance<S: ElectionsApi>(
connection: &S,
account_id: &AccountId,
before_end_of_session_block_hash: BlockHash,
Expand Down Expand Up @@ -152,7 +152,7 @@ async fn get_node_performance<S: SignedConnectionApi>(
lenient_performance
}

pub async fn check_points<S: SignedConnectionApi>(
pub async fn check_points<S: ElectionsApi + AlephWaiting + BlocksApi + StakingApi>(
connection: &S,
session: SessionIndex,
era: EraIndex,
Expand Down
4 changes: 2 additions & 2 deletions e2e-tests/src/test/electing_validators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::{
/// Verify that `pallet_staking::ErasStakers` contains all target validators.
///
/// We have to do it by comparing keys in storage trie.
async fn assert_validators_are_elected_stakers<C: ConnectionApi>(
async fn assert_validators_are_elected_stakers<C: StakingRawApi>(
connection: &C,
current_era: EraIndex,
expected_validators_as_keys: Vec<Vec<u8>>,
Expand Down Expand Up @@ -61,7 +61,7 @@ fn min_num_sessions_to_see_all_non_reserved_validators(

/// Verify that all target validators are included `pallet_session::Validators` across a few
/// consecutive sessions.
async fn assert_validators_are_used_as_authorities<C: ConnectionApi>(
async fn assert_validators_are_used_as_authorities<C: SessionApi + WaitingExt>(
connection: &C,
expected_authorities: &BTreeSet<AccountId>,
min_num_sessions: u32,
Expand Down
4 changes: 2 additions & 2 deletions e2e-tests/src/test/era_payout.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use aleph_client::{
pallets::staking::{StakingApi, StakingSudoApi},
waiting::{AlephWaiting, BlockStatus, WaitingExt},
ConnectionApi, TxStatus,
TxStatus,
};
use primitives::{
staking::era_payout, Balance, EraIndex, DEFAULT_SESSIONS_PER_ERA, DEFAULT_SESSION_PERIOD,
Expand Down Expand Up @@ -32,7 +32,7 @@ fn payout_within_two_block_delta(expected_payout: Balance, payout: Balance) {
);
}

async fn wait_to_second_era<C: ConnectionApi>(connection: &C) -> EraIndex {
async fn wait_to_second_era<C: StakingApi + WaitingExt>(connection: &C) -> EraIndex {
let active_era = connection.get_active_era(None).await;
if active_era < 2 {
connection.wait_for_n_eras(2, BlockStatus::Best).await;
Expand Down
6 changes: 3 additions & 3 deletions e2e-tests/src/test/era_validators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use aleph_client::{
primitives::CommitteeSeats,
utility::BlocksApi,
waiting::{AlephWaiting, BlockStatus, WaitingExt},
AccountId, ConnectionApi, KeyPair, TxStatus,
AccountId, KeyPair, TxStatus,
};
use anyhow::anyhow;

Expand Down Expand Up @@ -40,15 +40,15 @@ fn get_new_non_reserved_validators(config: &Config) -> Vec<KeyPair> {
.collect()
}

async fn get_current_and_next_era_reserved_validators<C: ConnectionApi>(
async fn get_current_and_next_era_reserved_validators<C: ElectionsApi>(
connection: &C,
) -> (Vec<AccountId>, Vec<AccountId>) {
let stored_reserved = connection.get_next_era_reserved_validators(None).await;
let current_reserved = connection.get_current_era_validators(None).await.reserved;
(current_reserved, stored_reserved)
}

async fn get_current_and_next_era_non_reserved_validators<C: ConnectionApi>(
async fn get_current_and_next_era_non_reserved_validators<C: ElectionsApi>(
connection: &C,
) -> (Vec<AccountId>, Vec<AccountId>) {
let stored_non_reserved = connection.get_next_era_non_reserved_validators(None).await;
Expand Down
8 changes: 4 additions & 4 deletions e2e-tests/src/test/fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use aleph_client::{
api::transaction_payment::events::TransactionFeePaid,
pallets::{balances::BalanceUserApi, fee::TransactionPaymentApi, system::SystemSudoApi},
waiting::{AlephWaiting, BlockStatus},
AccountId, RootConnection, SignedConnectionApi, TxStatus,
AccountId, RootConnection, SignedConnection, SignedConnectionApi, TxStatus,
};
use log::info;
use primitives::Balance;
Expand Down Expand Up @@ -99,15 +99,15 @@ async fn fill_blocks(target_ratio: u8, blocks: u32, connection: &RootConnection)
}
}

pub async fn current_fees<S: SignedConnectionApi>(
connection: &S,
pub async fn current_fees(
connection: &SignedConnection,
to: AccountId,
tip: Option<Balance>,
transfer_value: Balance,
) -> (Balance, u128) {
let actual_multiplier = connection.get_next_fee_multiplier(None).await;

let waiting_connection = connection.as_signed().clone();
let waiting_connection = connection.clone();
let signer = connection.account_id().clone();
let event_handle = tokio::spawn(async move {
waiting_connection
Expand Down
Loading