Skip to content

Commit

Permalink
Merge branch 'main' into benjamin
Browse files Browse the repository at this point in the history
  • Loading branch information
fbielejec authored Aug 12, 2022
2 parents 0a3a6d9 + 3694550 commit 8b5b1b3
Show file tree
Hide file tree
Showing 64 changed files with 1,668 additions and 705 deletions.
8 changes: 1 addition & 7 deletions .github/workflows/deploy-to-devnet.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
name: Deploy to Devnet

on:
workflow_run:
workflows: ["e2e-tests-main-devnet"]
branches:
- main
types:
- completed
workflow_dispatch:

concurrency:
group: ${{ github.ref }}-${{ github.workflow }}

jobs:
deploy-devnet:
if: github.event.workflow_run.conclusion == 'success'
name: Deploy new aleph-node image to EKS
environment:
name: devnet
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e-tests-main-devnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ jobs:
with:
test-case: rewards_disable_node
follow-up-finalization-check: true
timeout-minutes: 10
timeout-minutes: 15


run-e2e-token-transfer-test:
Expand Down
3 changes: 2 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion aleph-client/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions aleph-client/src/balances.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use primitives::Balance;

use crate::AnyConnection;
use crate::AnyConnectionExt;

/// Reads from the storage how much balance is currently on chain.
///
/// Performs a single storage read.
pub fn total_issuance<C: AnyConnection>(connection: &C) -> Balance {
pub fn total_issuance<C: AnyConnectionExt>(connection: &C) -> Balance {
connection.read_storage_value("Balances", "TotalIssuance")
}
4 changes: 2 additions & 2 deletions aleph-client/src/debug/aleph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use primitives::AuthorityId;

use crate::{
debug::{element_prompt, entry_prompt, pallet_prompt},
AnyConnection,
AnyConnectionExt,
};

pub fn print_storage<C: AnyConnection>(connection: &C) {
pub fn print_storage<C: AnyConnectionExt>(connection: &C) {
let authorities: Vec<AuthorityId> = connection.read_storage_value("Aleph", "Authorities");

println!("{}", pallet_prompt("Aleph"));
Expand Down
4 changes: 2 additions & 2 deletions aleph-client/src/debug/elections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use primitives::AuthorityId;

use crate::{
debug::{element_prompt, entry_prompt, pallet_prompt},
AnyConnection,
AnyConnectionExt,
};

pub fn print_storage<C: AnyConnection>(connection: &C) {
pub fn print_storage<C: AnyConnectionExt>(connection: &C) {
let members: Vec<AuthorityId> = connection.read_storage_value("Elections", "Members");

println!("{}", pallet_prompt("Elections"));
Expand Down
15 changes: 8 additions & 7 deletions aleph-client/src/debug/treasury.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ use substrate_api_client::Balance;

use crate::{
debug::{element_prompt, entry_prompt, pallet_prompt},
AnyConnection,
AnyConnectionExt,
};

pub fn print_storage<C: AnyConnection>(connection: &C) {
let connection = connection.as_connection();
let proposal_count: u32 = connection.read_storage_value_or_default("Treasury", "ProposalCount");
const PALLET: &str = "Treasury";

pub fn print_storage<C: AnyConnectionExt>(connection: &C) {
let proposal_count: u32 = connection.read_storage_value_or_default(PALLET, "ProposalCount");
let approvals: Vec<ProposalIndex> =
connection.read_storage_value_or_default("Treasury", "Approvals");
connection.read_storage_value_or_default(PALLET, "Approvals");

println!("{}", pallet_prompt("Treasury"));
println!("{}", pallet_prompt(PALLET));
println!("{}: {}", entry_prompt("ProposalCount"), proposal_count);
println!();
println!("{}", entry_prompt("Approvals"));
Expand All @@ -28,7 +29,7 @@ pub fn print_storage<C: AnyConnection>(connection: &C) {
println!("{}", entry_prompt("Proposals"));
for x in 0..=proposal_count {
let p: Option<Proposal<AccountId32, Balance>> = connection
.get_storage_map("Treasury", "Proposals", x, None)
.read_storage_map(PALLET, "Proposals", x, None)
.unwrap();

if let Some(p) = p {
Expand Down
52 changes: 25 additions & 27 deletions aleph-client/src/elections.rs
Original file line number Diff line number Diff line change
@@ -1,59 +1,57 @@
use pallet_elections::EraValidators;
use primitives::CommitteeSeats;
use primitives::SessionIndex;
pub use primitives::{CommitteeSeats, EraValidators};
use sp_core::H256;
use substrate_api_client::AccountId;

use crate::AnyConnection;
use crate::{get_session_first_block, AnyConnectionExt};

const PALLET: &str = "Elections";

pub fn get_committee_seats<C: AnyConnection>(
pub fn get_committee_seats<C: AnyConnectionExt>(
connection: &C,
block_hash: Option<H256>,
) -> CommitteeSeats {
connection
.as_connection()
.get_storage_value(PALLET, "CommitteeSize", block_hash)
.expect("Failed to obtain CommitteeSize extrinsic!")
.unwrap_or_else(|| {
panic!(
"Failed to decode CommitteeSize for block hash: {:?}.",
block_hash
)
})
}

pub fn get_next_era_committee_seats<C: AnyConnection>(connection: &C) -> CommitteeSeats {
connection.read_storage_value_at_block(PALLET, "CommitteeSize", block_hash)
}

pub fn get_next_era_committee_seats<C: AnyConnectionExt>(connection: &C) -> CommitteeSeats {
connection.read_storage_value(PALLET, "NextEraCommitteeSize")
}

pub fn get_validator_block_count<C: AnyConnection>(
pub fn get_validator_block_count<C: AnyConnectionExt>(
connection: &C,
account_id: &AccountId,
block_hash: Option<H256>,
) -> Option<u32> {
connection
.as_connection()
.get_storage_map(PALLET, "SessionValidatorBlockCount", account_id, block_hash)
.expect("Failed to obtain SessionValidatorBlockCount extrinsic!")
connection.read_storage_map(PALLET, "SessionValidatorBlockCount", account_id, block_hash)
}

pub fn get_current_era_validators<C: AnyConnection>(connection: &C) -> EraValidators<AccountId> {
pub fn get_current_era_validators<C: AnyConnectionExt>(connection: &C) -> EraValidators<AccountId> {
connection.read_storage_value(PALLET, "CurrentEraValidators")
}

pub fn get_current_era_reserved_validators<C: AnyConnection>(connection: &C) -> Vec<AccountId> {
pub fn get_current_era_reserved_validators<C: AnyConnectionExt>(connection: &C) -> Vec<AccountId> {
get_current_era_validators(connection).reserved
}

pub fn get_current_era_non_reserved_validators<C: AnyConnection>(connection: &C) -> Vec<AccountId> {
pub fn get_current_era_non_reserved_validators<C: AnyConnectionExt>(
connection: &C,
) -> Vec<AccountId> {
get_current_era_validators(connection).non_reserved
}

pub fn get_next_era_reserved_validators<C: AnyConnection>(connection: &C) -> Vec<AccountId> {
pub fn get_next_era_reserved_validators<C: AnyConnectionExt>(connection: &C) -> Vec<AccountId> {
connection.read_storage_value(PALLET, "NextEraReservedValidators")
}

pub fn get_next_era_non_reserved_validators<C: AnyConnection>(connection: &C) -> Vec<AccountId> {
pub fn get_next_era_non_reserved_validators<C: AnyConnectionExt>(connection: &C) -> Vec<AccountId> {
connection.read_storage_value(PALLET, "NextEraNonReservedValidators")
}

pub fn get_era_validators<C: AnyConnectionExt>(
connection: &C,
session: SessionIndex,
) -> EraValidators<AccountId> {
let block_hash = get_session_first_block(connection, session);
connection.read_storage_value_at_block(PALLET, "CurrentEraValidators", Some(block_hash))
}
6 changes: 3 additions & 3 deletions aleph-client/src/fee.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use codec::Encode;
use substrate_api_client::Balance;

use crate::{AnyConnection, Extrinsic};
use crate::{AnyConnectionExt, Extrinsic};

#[derive(Debug)]
pub struct FeeInfo {
Expand All @@ -10,7 +10,7 @@ pub struct FeeInfo {
pub adjusted_weight: Balance,
}

pub fn get_tx_fee_info<C: AnyConnection, Call: Encode>(
pub fn get_tx_fee_info<C: AnyConnectionExt, Call: Encode>(
connection: &C,
tx: &Extrinsic<Call>,
) -> FeeInfo {
Expand All @@ -35,6 +35,6 @@ pub fn get_tx_fee_info<C: AnyConnection, Call: Encode>(
}
}

pub fn get_next_fee_multiplier<C: AnyConnection>(connection: &C) -> u128 {
pub fn get_next_fee_multiplier<C: AnyConnectionExt>(connection: &C) -> u128 {
connection.read_storage_value("TransactionPayment", "NextFeeMultiplier")
}
69 changes: 56 additions & 13 deletions aleph-client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{default::Default, thread::sleep, time::Duration};
use std::{default::Default, fmt::Debug, thread::sleep, time::Duration};

use ac_primitives::SubstrateDefaultSignedExtra;
pub use account::{get_free_balance, locks};
Expand All @@ -7,7 +7,7 @@ use codec::{Decode, Encode};
pub use debug::print_storages;
pub use elections::{
get_committee_seats, get_current_era_non_reserved_validators,
get_current_era_reserved_validators, get_next_era_committee_seats,
get_current_era_reserved_validators, get_era_validators, get_next_era_committee_seats,
get_next_era_non_reserved_validators, get_next_era_reserved_validators,
get_validator_block_count,
};
Expand All @@ -22,9 +22,9 @@ pub use primitives::{BlockHash, BlockNumber, Header};
pub use rpc::{emergency_finalize, rotate_keys, rotate_keys_raw_result, state_query_storage_at};
pub use session::{
change_next_era_reserved_validators, change_validators, get_current_session,
get_current_validators, get_session, get_session_period, get_validators_for_session, set_keys,
wait_for as wait_for_session, wait_for_at_least as wait_for_at_least_session,
Keys as SessionKeys,
get_current_validators, get_session, get_session_first_block, get_session_period,
get_validators_for_session, set_keys, wait_for as wait_for_session,
wait_for_at_least as wait_for_at_least_session, Keys as SessionKeys,
};
use sp_core::{ed25519, sr25519, storage::StorageKey, Pair, H256};
pub use staking::{
Expand All @@ -37,13 +37,13 @@ pub use staking::{
get_stakers_as_storage_keys_from_storage_key, ledger as staking_ledger,
multi_bond as staking_multi_bond, nominate as staking_nominate, payout_stakers,
payout_stakers_and_assert_locked_balance, set_staking_limits as staking_set_staking_limits,
validate as staking_validate, wait_for_full_era_completion, wait_for_next_era, RewardPoint,
StakingLedger,
validate as staking_validate, wait_for_at_least_era, wait_for_era_completion,
wait_for_full_era_completion, wait_for_next_era, RewardPoint, StakingLedger,
};
pub use substrate_api_client;
pub use substrate_api_client::{self, AccountId, Balance, XtStatus};
use substrate_api_client::{
rpc::ws_client::WsRpcClient, std::error::Error, AccountId, Api, ApiResult,
PlainTipExtrinsicParams, RpcClient, UncheckedExtrinsicV4, XtStatus,
rpc::ws_client::WsRpcClient, std::error::Error, Api, ApiResult, PlainTipExtrinsicParams,
RpcClient, UncheckedExtrinsicV4,
};
pub use system::set_code;
pub use transfer::{
Expand Down Expand Up @@ -103,28 +103,59 @@ pub trait AnyConnection: Clone + Send {
/// objects are often passed to some macro like `compose_extrinsic!` and thus there is not
/// enough information for type inferring required for `Into<Connection>`.
fn as_connection(&self) -> Connection;
}

impl<C: AnyConnection> AnyConnectionExt for C {}

pub trait AnyConnectionExt: AnyConnection {
/// Reads value from storage. Panics if it couldn't be read.
fn read_storage_value<T: Decode>(&self, pallet: &'static str, key: &'static str) -> T {
self.read_storage_value_or_else(pallet, key, || {
panic!("Value is `None` or couldn't have been decoded")
})
}

/// Reads value from storage at given block (empty means `best known`). Panics if it couldn't be read.
fn read_storage_value_at_block<T: Decode>(
&self,
pallet: &'static str,
key: &'static str,
block_hash: Option<H256>,
) -> T {
self.read_storage_value_at_block_or_else(pallet, key, block_hash, || {
panic!(
"Retrieved storage value ({}/{}) was equal `null`",
pallet, key
)
})
}

/// Reads value from storage. In case value is `None` or couldn't have been decoded, result of
/// `fallback` is returned.
fn read_storage_value_or_else<F: FnOnce() -> T, T: Decode>(
&self,
pallet: &'static str,
key: &'static str,
fallback: F,
) -> T {
self.read_storage_value_at_block_or_else(pallet, key, None, fallback)
}

/// Reads value from storage from a given block. In case value is `None` or couldn't have been decoded, result of
/// `fallback` is returned.
fn read_storage_value_at_block_or_else<F: FnOnce() -> T, T: Decode>(
&self,
pallet: &'static str,
key: &'static str,
block_hash: Option<H256>,
fallback: F,
) -> T {
self.as_connection()
.get_storage_value(pallet, key, None)
.get_storage_value(pallet, key, block_hash)
.unwrap_or_else(|e| {
panic!(
"Key `{}::{}` should be present in storage, error {:?}",
pallet, key, e
"Unable to retrieve a storage value {}/{} at block {:#?}: {}",
pallet, key, block_hash, e
)
})
.unwrap_or_else(fallback)
Expand Down Expand Up @@ -172,6 +203,18 @@ pub trait AnyConnection: Clone + Send {
) -> T {
self.read_constant_or_else(pallet, constant, Default::default)
}

fn read_storage_map<K: Encode + Debug + Clone, T: Decode + Clone>(
&self,
pallet: &'static str,
map_name: &'static str,
map_key: K,
block_hash: Option<H256>,
) -> Option<T> {
self.as_connection()
.get_storage_map(pallet, map_name, map_key.clone(), block_hash)
.unwrap_or_else(|e| panic!("Unable to retrieve a storage map for pallet={} map_name={} map_key={:#?} block_hash={:#?}: {}", pallet, map_name, &map_key, block_hash, e))
}
}

impl AnyConnection for Connection {
Expand Down
Loading

0 comments on commit 8b5b1b3

Please sign in to comment.