Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
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
16 changes: 16 additions & 0 deletions .github/workflows/e2e-tests-main-devnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,21 @@ jobs:
follow-up-finalization-check: true
timeout-minutes: 15

run-e2e-permissionless-ban:
needs: [build-test-docker, build-test-client]
name: Run permissionless ban 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: permissionless_ban
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 @@ -489,6 +504,7 @@ jobs:
run-e2e-ban-counter-clearing,
run-e2e-ban-manual,
run-e2e-version-upgrade,
run-e2e-permissionless-ban,
]
name: Check e2e test suite completion
runs-on: ubuntu-20.04
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

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

24 changes: 23 additions & 1 deletion aleph-client/src/elections.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use primitives::{
BanConfig, BanInfo, CommitteeSeats, EraIndex, EraValidators, SessionCount, SessionIndex,
BanConfig, BanInfo, CommitteeSeats, ElectionOpenness, EraIndex, EraValidators, SessionCount,
SessionIndex,
};
use sp_core::H256;
use substrate_api_client::{compose_call, compose_extrinsic};
Expand Down Expand Up @@ -147,3 +148,24 @@ pub fn change_ban_config(
);
send_xt(sudo_connection, xt, Some("set_ban_config"), status);
}

pub fn set_elections_openness(
sudo_connection: &RootConnection,
mode: ElectionOpenness,
status: XtStatus,
) {
let call = compose_call!(
sudo_connection.as_connection().metadata,
PALLET,
"set_elections_openness",
mode
);
let xt = compose_extrinsic!(
sudo_connection.as_connection(),
"Sudo",
"sudo_unchecked_weight",
call,
0_u64
);
send_xt(sudo_connection, xt, Some("set_elections_openness"), status);
}
2 changes: 1 addition & 1 deletion aleph-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub use elections::{
get_current_era_reserved_validators, get_current_era_validators, get_era_validators,
get_next_era_committee_seats, get_next_era_non_reserved_validators,
get_next_era_reserved_validators, get_next_era_validators,
get_underperformed_validator_session_count, get_validator_block_count,
get_underperformed_validator_session_count, get_validator_block_count, set_elections_openness,
};
pub use fee::get_next_fee_multiplier;
pub use finalization::set_emergency_finalizer as finalization_set_emergency_finalizer;
Expand Down
2 changes: 1 addition & 1 deletion bin/runtime/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aleph-runtime"
version = "0.8.0"
version = "0.8.1"
authors = ["Cardinal Cryptography"]
edition = "2021"
homepage = "https://alephzero.org"
Expand Down
2 changes: 1 addition & 1 deletion bin/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("aleph-node"),
impl_name: create_runtime_str!("aleph-node"),
authoring_version: 1,
spec_version: 38,
spec_version: 39,
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 13,
Expand Down
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.

5 changes: 3 additions & 2 deletions e2e-tests/src/cases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use crate::{
clearing_session_count as test_clearing_session_count, disable_node as test_disable_node,
era_payouts_calculated_correctly as test_era_payout, era_validators as test_era_validators,
fee_calculation as test_fee_calculation, finalization as test_finalization,
force_new_era as test_force_new_era, points_basic as test_points_basic,
points_stake_change as test_points_stake_change,
force_new_era as test_force_new_era, permissionless_ban as test_permissionless_ban,
points_basic as test_points_basic, points_stake_change as test_points_stake_change,
schedule_version_change as test_schedule_version_change,
staking_era_payouts as test_staking_era_payouts,
staking_new_validator as test_staking_new_validator, token_transfer as test_token_transfer,
Expand Down Expand Up @@ -65,5 +65,6 @@ pub fn possible_test_cases() -> PossibleTestCases {
"clearing_session_count",
test_clearing_session_count as TestCase,
),
("permissionless_ban", test_permissionless_ban as TestCase),
]
}
84 changes: 77 additions & 7 deletions e2e-tests/src/test/ban.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
use std::collections::HashSet;

use aleph_client::{
ban_from_committee, change_ban_config, get_current_era, get_current_era_validators,
get_current_session, get_next_era_non_reserved_validators, get_next_era_reserved_validators,
get_underperformed_validator_session_count, wait_for_at_least_session, SignedConnection,
XtStatus,
ban_from_committee, change_ban_config, change_validators, get_current_era,
get_current_era_non_reserved_validators, get_current_era_validators, get_current_session,
get_next_era_non_reserved_validators, get_next_era_reserved_validators,
get_underperformed_validator_session_count, set_elections_openness, wait_for_at_least_session,
wait_for_full_era_completion, wait_for_next_era, SignedConnection, XtStatus,
};
use log::info;
use primitives::{
BanInfo, BanReason, BoundedVec, SessionCount, DEFAULT_BAN_MINIMAL_EXPECTED_PERFORMANCE,
DEFAULT_BAN_SESSION_COUNT_THRESHOLD, DEFAULT_CLEAN_SESSION_COUNTER_DELAY,
BanInfo, BanReason, BoundedVec, CommitteeSeats, ElectionOpenness, SessionCount,
DEFAULT_BAN_MINIMAL_EXPECTED_PERFORMANCE, DEFAULT_BAN_SESSION_COUNT_THRESHOLD,
DEFAULT_CLEAN_SESSION_COUNTER_DELAY,
};

use crate::{
accounts::{get_validator_seed, NodeKeys},
accounts::{account_ids_from_keys, get_validator_seed, NodeKeys},
ban::{
check_ban_config, check_ban_event, check_ban_info_for_validator,
check_underperformed_validator_session_count, check_validators, setup_test,
},
rewards::set_invalid_keys_for_validator,
validators::get_test_validators,
Config,
};

Expand Down Expand Up @@ -223,3 +228,68 @@ pub fn clearing_session_count(config: &Config) -> anyhow::Result<()> {

Ok(())
}

/// Setup reserved validators, non_reserved are set to empty vec. Set ban config ban_period to 2.
/// Set Openness to Permissionless.
/// Ban manually one validator. Check if the banned validator is out of the non_reserved and is back
/// after ban period.
pub fn permissionless_ban(config: &Config) -> anyhow::Result<()> {
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,
};

let validator_to_ban =
&non_reserved_validators[VALIDATOR_TO_DISABLE_NON_RESERVED_INDEX as usize];
let mut non_reserved_without_banned = non_reserved_validators.to_vec();
non_reserved_without_banned.remove(VALIDATOR_TO_DISABLE_NON_RESERVED_INDEX as usize);

let ban_period = 2;
let test_non_reserved_validators = vec![];
set_elections_openness(
&root_connection,
ElectionOpenness::Permissionless,
XtStatus::InBlock,
);
change_ban_config(
&root_connection,
None,
None,
None,
Some(ban_period),
XtStatus::InBlock,
);
change_validators(
&root_connection,
Some(reserved_validators),
Some(test_non_reserved_validators),
Some(seats),
XtStatus::InBlock,
);
ban_from_committee(
&root_connection,
validator_to_ban,
&vec![],
XtStatus::InBlock,
);
wait_for_full_era_completion(&root_connection)?;
let without_banned = HashSet::<_>::from_iter(non_reserved_without_banned);
let non_reserved =
HashSet::<_>::from_iter(get_current_era_non_reserved_validators(&root_connection));
assert_eq!(without_banned, non_reserved);

wait_for_next_era(&root_connection)?;
let expected_non_reserved = HashSet::<_>::from_iter(non_reserved_validators);
let non_reserved =
HashSet::<_>::from_iter(get_current_era_non_reserved_validators(&root_connection));

assert_eq!(expected_non_reserved, non_reserved);

Ok(())
}
2 changes: 1 addition & 1 deletion e2e-tests/src/test/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub use ban::{ban_automatic, ban_manual, clearing_session_count};
pub use ban::{ban_automatic, ban_manual, clearing_session_count, permissionless_ban};
pub use electing_validators::authorities_are_staking;
pub use era_payout::era_payouts_calculated_correctly;
pub use era_validators::era_validators;
Expand Down
2 changes: 1 addition & 1 deletion pallets/elections/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pallet-elections"
version = "0.5.0"
version = "0.5.1"
edition = "2021"
license = "Apache 2.0"

Expand Down
8 changes: 5 additions & 3 deletions pallets/elections/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,10 @@ pub mod pallet {

let committee_size_all = reserved + non_reserved;

let mode = Openness::<T>::get();

ensure!(
committee_size_all <= validators_size,
committee_size_all <= validators_size || mode == ElectionOpenness::Permissionless,
Error::<T>::NotEnoughValidators
);

Expand All @@ -410,8 +412,8 @@ pub mod pallet {
);

ensure!(
non_reserved <= non_reserved_len,
Error::<T>::NotEnoughReservedValidators,
non_reserved <= non_reserved_len || mode == ElectionOpenness::Permissionless,
Error::<T>::NotEnoughNonReservedValidators,
);

let member_set: BTreeSet<_> = reserved_validators
Expand Down