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
hide connection
  • Loading branch information
krzysztofziobro committed Dec 28, 2022
commit f5b769ff4bea35c4f84bf45ee7f54cb70c0131df
4 changes: 2 additions & 2 deletions aleph-client/src/connections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ pub trait ConnectionExt: AsConnection {
}

pub struct SignedConnection {
pub connection: Connection,
connection: Connection,
pub signer: KeyPair,
}

pub struct RootConnection {
pub connection: Connection,
connection: Connection,
pub root: KeyPair,
}

Expand Down
2 changes: 0 additions & 2 deletions benches/payout-stakers/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,15 +340,13 @@ async fn payout_stakers_and_assert_locked_balance(
era: EraIndex,
) {
let locked_stash_balances_before_payout = stash_connection
.connection
.locks(accounts_to_check_balance, None)
.await;
stash_connection
.payout_stakers(stash_account.clone(), era - 1, TxStatus::Finalized)
.await
.unwrap();
let locked_stash_balances_after_payout = stash_connection
.connection
.locks(accounts_to_check_balance, None)
.await;
locked_stash_balances_before_payout.iter()
Expand Down
12 changes: 6 additions & 6 deletions bin/cliain/src/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use aleph_client::{
pallets::contract::{ContractsApi, ContractsUserApi},
sp_weights::weight_v2::Weight,
waiting::{AlephWaiting, BlockStatus},
AccountId, Connection, SignedConnection, TxStatus,
AccountId, AsConnection, Connection, SignedConnection, TxStatus,
};
use codec::{Compact, Decode};
use contract_metadata::ContractMetadata;
Expand Down Expand Up @@ -45,7 +45,7 @@ pub async fn upload_code(
let wasm = fs::read(wasm_path).expect("WASM artifact not found");
debug!(target: "contracts", "Found WASM contract code {:?}", wasm);

let connection = signed_connection.connection.clone();
let connection = signed_connection.as_connection();
let event_handler = tokio::spawn(async move {
connection
.wait_for_event(
Expand Down Expand Up @@ -94,7 +94,7 @@ pub async fn instantiate(

debug!("Encoded constructor data {:?}", data);

let connection = signed_connection.connection.clone();
let connection = signed_connection.as_connection();
let signer_id = signed_connection.signer.account_id().clone();

let event_handler = tokio::spawn(async move {
Expand Down Expand Up @@ -154,8 +154,8 @@ pub async fn instantiate_with_code(
debug!("Encoded constructor data {:?}", data);

let signer_id = signed_connection.signer.account_id().clone();
let connection_0 = signed_connection.connection.clone();
let connection_1 = signed_connection.connection.clone();
let connection_0 = signed_connection.as_connection();
let connection_1 = signed_connection.as_connection();

let event_handler_0 = tokio::spawn(async move {
connection_0
Expand Down Expand Up @@ -253,7 +253,7 @@ pub async fn remove_code(
) -> anyhow::Result<CodeRemoved> {
let ContractRemoveCode { code_hash } = command;

let connection = signed_connection.connection.clone();
let connection = signed_connection.as_connection();

let event_handler = tokio::spawn(async move {
connection
Expand Down
2 changes: 1 addition & 1 deletion bin/cliain/src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub async fn prepare_keys(connection: RootConnection, controller_account_id: Acc
)
.await
.unwrap();
let new_keys = connection.connection.author_rotate_keys().await;
let new_keys = connection.author_rotate_keys().await;
connection
.as_signed()
.set_keys(new_keys, TxStatus::Finalized)
Expand Down
56 changes: 13 additions & 43 deletions e2e-tests/src/rewards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ pub async fn set_invalid_keys_for_validator(
.await
.unwrap();
controller_connection
.connection
.wait_for_n_sessions(2, BlockStatus::Best)
.await;

Expand All @@ -54,15 +53,14 @@ 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.author_rotate_keys().await;
controller_connection
.set_keys(validator_keys, TxStatus::InBlock)
.await
.unwrap();

// wait until our node is forced to use new keys, i.e. current session + 2
controller_connection
.connection
.wait_for_n_sessions(2, BlockStatus::Best)
.await;

Expand All @@ -76,7 +74,6 @@ pub async fn download_exposure(
beginning_of_session_block_hash: BlockHash,
) -> Balance {
let exposure = connection
.connection
.get_exposure(era, account_id, Some(beginning_of_session_block_hash))
.await;
info!(
Expand Down Expand Up @@ -133,7 +130,6 @@ async fn get_node_performance(
blocks_to_produce_per_session: u32,
) -> f64 {
let block_count = connection
.connection
.get_validator_block_count(account_id.clone(), Some(before_end_of_session_block_hash))
.await
.unwrap_or_default();
Expand Down Expand Up @@ -164,30 +160,22 @@ 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.get_session_period().await;

info!("Era: {} | session: {}.", era, session);

let beginning_of_session_block = session * session_period;
let end_of_session_block = beginning_of_session_block + session_period;
info!("Waiting for block: {}.", end_of_session_block);
connection
.connection
.wait_for_block(|n| n >= end_of_session_block, BlockStatus::Finalized)
.await;

let beginning_of_session_block_hash = connection
.connection
.get_block_hash(beginning_of_session_block)
.await;
let end_of_session_block_hash = connection
.connection
.get_block_hash(end_of_session_block)
.await;
let before_end_of_session_block_hash = connection
.connection
.get_block_hash(end_of_session_block - 1)
.await;
let beginning_of_session_block_hash =
connection.get_block_hash(beginning_of_session_block).await;
let end_of_session_block_hash = connection.get_block_hash(end_of_session_block).await;
let before_end_of_session_block_hash =
connection.get_block_hash(end_of_session_block - 1).await;
info!(
"End-of-session block hash: {:?}.",
end_of_session_block_hash
Expand All @@ -203,15 +191,13 @@ pub async fn check_points(

// get points stored by the Staking pallet
let validator_reward_points_current_era = connection
.connection
.get_era_reward_points(era, end_of_session_block_hash)
.await
.unwrap_or_default()
.individual;

let validator_reward_points_previous_session = HashMap::<AccountId, u32>::from_iter(
connection
.connection
.get_era_reward_points(era, beginning_of_session_block_hash)
.await
.unwrap_or_default()
Expand Down Expand Up @@ -282,10 +268,7 @@ pub async fn setup_validators(
) -> anyhow::Result<(EraValidators<AccountId>, CommitteeSeats, SessionIndex)> {
let root_connection = config.create_root_connection().await;
// we need to wait for at least era 1 since some of the storage items are not available at era 0
root_connection
.connection
.wait_for_n_eras(1, BlockStatus::Best)
.await;
root_connection.wait_for_n_eras(1, BlockStatus::Best).await;

let seats = COMMITTEE_SEATS;
let members_seats = seats.reserved_seats + seats.non_reserved_seats;
Expand All @@ -305,18 +288,13 @@ pub async fn setup_validators(
let reserved_members = &members[0..reserved_size];
let non_reserved_members = &members[reserved_size..];

let session = root_connection.connection.get_session(None).await;
let network_validators = root_connection
.connection
.get_current_era_validators(None)
.await;
let session = root_connection.get_session(None).await;
let network_validators = root_connection.get_current_era_validators(None).await;
let first_block_in_session = root_connection
.connection
.first_block_of_session(session)
.await
.unwrap();
let network_seats = root_connection
.connection
.get_committee_seats(Some(first_block_in_session))
.await;

Expand All @@ -340,26 +318,18 @@ pub async fn setup_validators(
)
.await?;

root_connection
.connection
.wait_for_n_eras(1, BlockStatus::Best)
.await;
let session = root_connection.connection.get_session(None).await;
root_connection.wait_for_n_eras(1, BlockStatus::Best).await;
let session = root_connection.get_session(None).await;

let first_block_in_session = root_connection
.connection
.first_block_of_session(session)
.await;
let first_block_in_session = root_connection.first_block_of_session(session).await;
let network_validators = root_connection
.connection
.get_current_era_validators(first_block_in_session)
.await;
let reserved: HashSet<_> = era_validators.reserved.iter().cloned().collect();
let network_reserved: HashSet<_> = network_validators.reserved.into_iter().collect();
let non_reserved: HashSet<_> = era_validators.non_reserved.iter().cloned().collect();
let network_non_reserved: HashSet<_> = network_validators.non_reserved.into_iter().collect();
let network_seats = root_connection
.connection
.get_committee_seats(first_block_in_session)
.await;

Expand Down
Loading