Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A0-1499: E2e ban test threshold #704

Merged
merged 55 commits into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
a858939
Checkpoint
maciejzelaszczyk Oct 19, 2022
f26695e
Partial attempt
maciejzelaszczyk Oct 21, 2022
d55e50c
Fixed index
maciejzelaszczyk Oct 21, 2022
d999199
Touch up
maciejzelaszczyk Oct 21, 2022
f26bf90
Merge branch 'main' into A0-1432-e2e-test-automatic
maciejzelaszczyk Oct 24, 2022
259f1e5
Reworked automatic test for greater modularity
maciejzelaszczyk Oct 24, 2022
b422aa0
Partial manual kick-out
maciejzelaszczyk Oct 25, 2022
5ffe7a6
Modularity; bumped crate versions
maciejzelaszczyk Oct 25, 2022
d3853dd
GH workflow
maciejzelaszczyk Oct 25, 2022
f760c49
Test case reordering
maciejzelaszczyk Oct 25, 2022
0be412c
Merge branch 'main' into A0-1432-e2e-test-automatic
maciejzelaszczyk Oct 25, 2022
969006d
Initial modules work
maciejzelaszczyk Oct 25, 2022
01ac2d2
Manual kickout case
maciejzelaszczyk Oct 25, 2022
a3d3d61
Consts
maciejzelaszczyk Oct 25, 2022
6261a56
Modules
maciejzelaszczyk Oct 25, 2022
51ce937
Checkpoint
maciejzelaszczyk Oct 26, 2022
cd0072a
Removed next era validators check
maciejzelaszczyk Oct 26, 2022
e1e7de5
Merge branch 'main' into A0-1432-e2e-test-automatic
maciejzelaszczyk Oct 26, 2022
136de14
Merge
maciejzelaszczyk Oct 26, 2022
c25a82d
Merge branch 'main' into A0-1432-e2e-test-automatic
maciejzelaszczyk Oct 26, 2022
d02f8fd
Checkpoint
maciejzelaszczyk Oct 26, 2022
81cb920
Semver consistent versioning
maciejzelaszczyk Oct 26, 2022
41d6ba2
Merge branch 'A0-1432-e2e-test-automatic' of github.com:Cardinal-Cryp…
maciejzelaszczyk Oct 26, 2022
6618683
Merge branch 'main' into A0-1432-e2e-test-automatic
maciejzelaszczyk Oct 26, 2022
ea4bcf8
Removed superfluous function and imports
maciejzelaszczyk Oct 26, 2022
0edbfaf
Merge branch 'A0-1432-e2e-test-automatic' into A0-1489-e2e-test-manual
maciejzelaszczyk Oct 26, 2022
502bef5
Checkpoint
maciejzelaszczyk Oct 26, 2022
2e2244f
Explicit params for bounded vec
maciejzelaszczyk Oct 26, 2022
23463ec
Merge branch 'main' into A0-1489-e2e-test-manual
maciejzelaszczyk Oct 26, 2022
16a89e9
Merge fixes
maciejzelaszczyk Oct 26, 2022
8275e1b
Changed bounded vec creation
maciejzelaszczyk Oct 27, 2022
4107329
Linter, version
maciejzelaszczyk Oct 27, 2022
2739d03
Fixed reason passed to extrinsic
maciejzelaszczyk Oct 28, 2022
08e183c
Session count tracking
maciejzelaszczyk Oct 28, 2022
2e9ba57
Merge branch 'main' into A0-1499-e2e-ban-test-threshold
maciejzelaszczyk Nov 2, 2022
f039773
Welcome to the ban world!
maciejzelaszczyk Nov 2, 2022
d1541a2
GH workflow
maciejzelaszczyk Nov 2, 2022
9f35a41
Changed params to refs; cases reorder
maciejzelaszczyk Nov 2, 2022
ae8465f
Merge branch 'main' into A0-1499-e2e-ban-test-threshold
maciejzelaszczyk Nov 2, 2022
8bcc43a
Housekeeping
maciejzelaszczyk Nov 2, 2022
d792c3a
Version bumps
maciejzelaszczyk Nov 2, 2022
c98e306
Changed option unwrapping
maciejzelaszczyk Nov 2, 2022
c857d6f
Removed needless borrow
maciejzelaszczyk Nov 2, 2022
71e731d
Added ban event call
maciejzelaszczyk Nov 3, 2022
d7cc270
Removed borrows
maciejzelaszczyk Nov 3, 2022
9507582
Removed ban event call from initial place
maciejzelaszczyk Nov 3, 2022
50857fe
Merge branch 'main' into A0-1499-e2e-ban-test-threshold
maciejzelaszczyk Nov 3, 2022
d4296ae
Changed test logic to post factum
maciejzelaszczyk Nov 3, 2022
2202e1a
Changed logic to test only sessions after ban config change comes in
maciejzelaszczyk Nov 4, 2022
49cae48
Test logic fix
maciejzelaszczyk Nov 4, 2022
a900ff3
Typo fix in rewards test
maciejzelaszczyk Nov 4, 2022
7454ce2
Removed unnecessary reference
maciejzelaszczyk Nov 4, 2022
86cad43
Rolled back pallet change
maciejzelaszczyk Nov 4, 2022
b5977a7
Merge branch 'main' into A0-1499-e2e-ban-test-threshold
maciejzelaszczyk Nov 8, 2022
53343d5
aleph-client version bump
maciejzelaszczyk Nov 8, 2022
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
48 changes: 32 additions & 16 deletions .github/workflows/e2e-tests-main-devnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,21 @@ jobs:
follow-up-finalization-check: true
timeout-minutes: 15

run-e2e-ban-manual:
needs: [build-test-docker, build-test-client]
name: Run ban manual test
runs-on: ubuntu-20.04
steps:
- name: Checkout source code
uses: actions/checkout@v2

- name: Run e2e test
uses: ./.github/actions/run-e2e-test
with:
test-case: ban_manual
follow-up-finalization-check: true
timeout-minutes: 15

run-e2e-ban-counter-clearing:
needs: [build-test-docker, build-test-client]
name: Run ban counter clearing test
Expand All @@ -472,6 +487,21 @@ jobs:
follow-up-finalization-check: true
timeout-minutes: 15

run-e2e-ban-threshold:
needs: [build-test-docker, build-test-client]
name: Run ban threshold test
runs-on: ubuntu-20.04
steps:
- name: Checkout source code
uses: actions/checkout@v2

- name: Run e2e test
uses: ./.github/actions/run-e2e-test
with:
test-case: ban_threshold
follow-up-finalization-check: true
timeout-minutes: 15

run-e2e-version-upgrade:
needs: [build-test-docker, build-test-client]
name: Run basic (positive) version-upgrade test
Expand Down Expand Up @@ -510,21 +540,6 @@ jobs:
ONLY_LEGACY: true
timeout-minutes: 10

run-e2e-ban-manual:
needs: [build-test-docker, build-test-client]
name: Run ban manual test
runs-on: ubuntu-20.04
steps:
- name: Checkout source code
uses: actions/checkout@v2

- name: Run e2e test
uses: ./.github/actions/run-e2e-test
with:
test-case: ban_manual
follow-up-finalization-check: true
timeout-minutes: 15

run-e2e-version-upgrade-catchup:
needs: [build-test-docker, build-cliain-image]
name: Run series of tests where some of the nodes need to do version-upgrade during catch-up
Expand Down Expand Up @@ -606,8 +621,9 @@ jobs:
run-e2e-rewards-points-basic,
run-e2e-authorities-are-staking,
run-e2e-ban-automatic,
run-e2e-ban-counter-clearing,
run-e2e-ban-manual,
run-e2e-ban-counter-clearing,
run-e2e-ban-threshold,
run-e2e-version-upgrade,
run-e2e-failing-version-upgrade,
run-e2e-version-upgrade-catchup,
Expand Down
2 changes: 1 addition & 1 deletion aleph-client/Cargo.lock

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

2 changes: 1 addition & 1 deletion aleph-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aleph_client"
version = "1.12.0"
version = "1.13.0"
edition = "2021"
license = "Apache 2.0"

Expand Down
15 changes: 11 additions & 4 deletions aleph-client/src/elections.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use log::info;
use primitives::{
BanConfig, BanInfo, CommitteeSeats, EraIndex, EraValidators, SessionCount, SessionIndex,
};
Expand Down Expand Up @@ -76,18 +77,19 @@ pub fn get_ban_config<C: ReadStorage>(connection: &C) -> BanConfig {
pub fn get_underperformed_validator_session_count<C: ReadStorage>(
connection: &C,
account_id: &AccountId,
block_hash: Option<H256>,
) -> SessionCount {
connection
.read_storage_map(
PALLET,
"UnderperformedValidatorSessionCount",
account_id,
None,
block_hash,
)
.unwrap_or(0)
}

pub fn get_ban_reason_for_validator<C: ReadStorage>(
pub fn get_ban_info_for_validator<C: ReadStorage>(
connection: &C,
account_id: &AccountId,
) -> Option<BanInfo> {
Expand Down Expand Up @@ -129,21 +131,26 @@ pub fn change_ban_config(
ban_period: Option<EraIndex>,
status: XtStatus,
) {
info!(target: "aleph-client", "Changing ban config");
let call_name = "set_ban_config";

let call = compose_call!(
sudo_connection.as_connection().metadata,
PALLET,
"set_ban_config",
call_name,
minimal_expected_performance,
underperformed_session_count_threshold,
clean_session_counter_delay,
ban_period
);

let xt = compose_extrinsic!(
sudo_connection.as_connection(),
"Sudo",
"sudo_unchecked_weight",
call,
0_u64
);
send_xt(sudo_connection, xt, Some("set_ban_config"), status);

send_xt(sudo_connection, xt, Some(call_name), status);
}
2 changes: 1 addition & 1 deletion aleph-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub use balances::total_issuance;
use codec::{Decode, Encode};
pub use debug::print_storages;
pub use elections::{
ban_from_committee, change_ban_config, get_ban_config, get_ban_reason_for_validator,
ban_from_committee, change_ban_config, get_ban_config, get_ban_info_for_validator,
get_committee_seats, get_current_era_non_reserved_validators,
get_current_era_reserved_validators, get_current_era_validators, get_era_validators,
get_next_era_committee_seats, get_next_era_non_reserved_validators,
Expand Down
2 changes: 1 addition & 1 deletion benches/payout-stakers/Cargo.lock

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

2 changes: 1 addition & 1 deletion bin/cliain/Cargo.lock

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

2 changes: 1 addition & 1 deletion e2e-tests/Cargo.lock

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

2 changes: 1 addition & 1 deletion e2e-tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aleph-e2e-client"
version = "0.7.0"
version = "0.8.0"
edition = "2021"
license = "Apache 2.0"

Expand Down
125 changes: 113 additions & 12 deletions e2e-tests/src/ban.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,39 @@
use aleph_client::{
change_validators, get_ban_config, get_ban_reason_for_validator,
get_underperformed_validator_session_count, wait_for_event, wait_for_full_era_completion,
AccountId, AnyConnection, RootConnection, XtStatus,
change_validators, get_ban_config, get_ban_info_for_validator, get_block_hash,
get_session_period, get_underperformed_validator_session_count, wait_for_event,
wait_for_full_era_completion, AccountId, AnyConnection, RootConnection, XtStatus,
};
use codec::Decode;
use log::info;
use primitives::{BanConfig, BanInfo, CommitteeSeats, EraValidators, SessionCount};
use primitives::{BanConfig, BanInfo, CommitteeSeats, EraValidators, SessionCount, SessionIndex};
use sp_core::H256;
use sp_runtime::Perbill;

use crate::{accounts::account_ids_from_keys, validators::get_test_validators, Config};
use crate::{
accounts::account_ids_from_keys, elections::get_members_subset_for_session,
validators::get_test_validators, Config,
};

const RESERVED_SEATS: u32 = 2;
const NON_RESERVED_SEATS: u32 = 2;

pub fn setup_test(
config: &Config,
) -> anyhow::Result<(RootConnection, Vec<AccountId>, Vec<AccountId>)> {
type BanTestSetup = (
RootConnection,
Vec<AccountId>,
Vec<AccountId>,
CommitteeSeats,
);

pub fn setup_test(config: &Config) -> anyhow::Result<BanTestSetup> {
let root_connection = config.create_root_connection();

let validator_keys = get_test_validators(config);
let reserved_validators = account_ids_from_keys(&validator_keys.reserved);
let non_reserved_validators = account_ids_from_keys(&validator_keys.non_reserved);

let seats = CommitteeSeats {
reserved_seats: 2,
non_reserved_seats: 2,
reserved_seats: RESERVED_SEATS,
non_reserved_seats: NON_RESERVED_SEATS,
};

change_validators(
Expand All @@ -38,6 +50,7 @@ pub fn setup_test(
root_connection,
reserved_validators,
non_reserved_validators,
seats,
))
}

Expand Down Expand Up @@ -83,9 +96,10 @@ pub fn check_underperformed_validator_session_count<C: AnyConnection>(
connection: &C,
validator: &AccountId,
expected_session_count: &SessionCount,
block_hash: Option<H256>,
) -> SessionCount {
let underperformed_validator_session_count =
get_underperformed_validator_session_count(connection, validator);
get_underperformed_validator_session_count(connection, validator, block_hash);

assert_eq!(
&underperformed_validator_session_count,
Expand All @@ -100,7 +114,7 @@ pub fn check_ban_info_for_validator<C: AnyConnection>(
validator: &AccountId,
expected_info: Option<&BanInfo>,
) -> Option<BanInfo> {
let validator_ban_info = get_ban_reason_for_validator(connection, validator);
let validator_ban_info = get_ban_info_for_validator(connection, validator);

assert_eq!(validator_ban_info.as_ref(), expected_info);

Expand All @@ -124,3 +138,90 @@ pub fn check_ban_event<C: AnyConnection>(

Ok(event)
}

pub fn get_members_for_session(
reserved_validators: &[AccountId],
non_reserved_validators: &[AccountId],
seats: &CommitteeSeats,
session: SessionIndex,
) -> Vec<AccountId> {
let reserved_members =
get_members_subset_for_session(seats.reserved_seats, reserved_validators, session);
let non_reserved_members =
get_members_subset_for_session(seats.non_reserved_seats, non_reserved_validators, session);
reserved_members
.into_iter()
.chain(non_reserved_members.into_iter())
.collect()
}

/// 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 fn check_underperformed_count_for_sessions<C: AnyConnection>(
connection: &C,
reserved_validators: &[AccountId],
non_reserved_validators: &[AccountId],
seats: &CommitteeSeats,
start_session: SessionIndex,
end_session: SessionIndex,
ban_session_threshold: SessionCount,
) -> anyhow::Result<()> {
let session_period = get_session_period(connection);

let validators: Vec<_> = reserved_validators
.iter()
.chain(non_reserved_validators.iter())
.collect();

for session in start_session..end_session {
let session_end_block = (session + 1) * session_period;
let session_end_block_hash = get_block_hash(connection, session_end_block);

let previous_session_end_block = session_end_block - session_period;
let previous_session_end_block_hash =
get_block_hash(connection, previous_session_end_block);

let members =
get_members_for_session(reserved_validators, non_reserved_validators, seats, session);

validators.iter().for_each(|&val| {
info!(
"Checking session count | session {} | validator {}",
session, val
);
let session_underperformed_count = get_underperformed_validator_session_count(
connection,
val,
Some(session_end_block_hash),
);
let previous_session_underperformed_count = get_underperformed_validator_session_count(
connection,
val,
Some(previous_session_end_block_hash),
);

let underperformed_diff =
session_underperformed_count.abs_diff(previous_session_underperformed_count);

if members.contains(val) {
// Counter for committee members legally incremented by 1 or reset to 0 (decremented
// by ban_session_threshold - 1).
if underperformed_diff != 1 && underperformed_diff != (ban_session_threshold - 1) {
panic!(
"Underperformed session count for committee validator {} for session {} changed from {} to {}.",
val, session, previous_session_underperformed_count, session_underperformed_count
);
}
} else if underperformed_diff != 0 {
// Counter for validators on the bench should stay the same.
panic!(
"Underperformed session count for non-committee validator {} for session {} changed from {} to {}.",
val, session, previous_session_underperformed_count, session_underperformed_count
);
}
});
}

Ok(())
}
3 changes: 2 additions & 1 deletion e2e-tests/src/cases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
test::{
authorities_are_staking as test_authorities_are_staking,
ban_automatic as test_ban_automatic, ban_manual as test_ban_manual,
batch_transactions as test_batch_transactions,
ban_threshold as test_ban_threshold, batch_transactions as test_batch_transactions,
change_stake_and_force_new_era as test_change_stake_and_force_new_era,
change_validators as test_change_validators,
channeling_fee_and_tip as test_channeling_fee_and_tip,
Expand Down Expand Up @@ -70,5 +70,6 @@ pub fn possible_test_cases() -> PossibleTestCases {
"clearing_session_count",
test_clearing_session_count as TestCase,
),
("ban_threshold", test_ban_threshold as TestCase),
]
}
Loading