Skip to content

Commit

Permalink
A0-1502: Finality version e2e test (#717)
Browse files Browse the repository at this point in the history
* Setting up AlephBFT version

* Changed handling to map from session to version

* Changed logic to handle serving last set AlephBFT version

* Changed logic to handle setting of version in future only

* Reworked storage and accessors to only store one version plus session to change it

* Treat version change as a delimiting flag

* Loose coupling between pallet_aleph and pallet_session to access current session index

* Fixed trait implementation for mock

* Added comment to trait

* Replaced panics with Results in AlephBFT version handling

* Changed logic to work with numbered versions

* Changed behavior on session start and end

* Fixed version change update

* Linked SessionManager in runtime

* Mock impl

* Reworked SessionManage link

* Linter

* Removed pallet_elections from mock

* Removed event

* linter

* Linter

* Reworked AlephBFT version history updates

* Reworked storage to use value instead of map

* Added unit test

* Added version change unscheduling and next session version

* Removed explicit version unscheduling; added version default

* Extended docs for pallet aleph

* Moved default AlephBFT version to const

* Renamed helper function

* Fixed test

* Changed naming

* Bumped spec version

* Bumped transaction version

* Finality version RPC and e2e test, first stab

* Added GenesisBuild to pallet_aleph

* Added finality version e2e test

* Reworked test logic

* Removed unused imports

* Dependency version fixes; prep work for test logic change

* Post factum checks

* Changed checks; changed finality version update session

* Added test description

* aleph-client and aleph-e2e-client version bumps

* spec_version and transaction_version bumps

* Changed comment about error code

* Added doc comment

* Cargo.lock

* Bumped runtime version

* Disabled runtime upgrade check in CI

* Revert "Disabled runtime upgrade check in CI"

This reverts commit e4cc57b.

* Disabled runtime upgrade check without removing it

* Post-merge cleanup

* Back to storage; handle connection refactor

* Codegen

* Bumped aleph-client version

* Back to rpc call; prelims

* Rpc interface

* Rpc

* Link with node

* Rpc request; cleanup

* Partial fix

* Fixed RPC params

* Versioning

* Linter

* Default version fix

* E2e test version bump

* Interface reorg

* Linter

* Connection fixes; pipelines

* Linter

* Finality version set in chain spec

* Subxt codegen

* E2e test fix

* Runtime metadata for aleph-client

* Hide doc warnings

* Removed hide docs

* Actually check the version change

* Subxt metadata

* Linter cleanup

* Const reorg

* Current finality version calculated based on the legacy one
  • Loading branch information
maciejzelaszczyk authored Jan 31, 2023
1 parent c3a93ab commit f82550c
Show file tree
Hide file tree
Showing 26 changed files with 421 additions and 192 deletions.
54 changes: 35 additions & 19 deletions .github/workflows/e2e-tests-main-devnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -466,23 +466,23 @@ jobs:
follow-up-finalization-check: true
timeout-minutes: 10

# run-e2e-authorities-are-staking:
# needs: [build-test-docker, build-test-client]
# name: Run authorities are staking 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: authorities_are_staking
# node-count: 6
# reserved-seats: 3
# non-reserved-seats: 3
# follow-up-finalization-check: false
# timeout-minutes: 15
run-e2e-authorities-are-staking:
needs: [build-test-docker, build-test-client]
name: Run authorities are staking 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: authorities_are_staking
node-count: 6
reserved-seats: 3
non-reserved-seats: 3
follow-up-finalization-check: true
timeout-minutes: 15

run-e2e-ban-automatic:
needs: [build-test-docker, build-test-client]
Expand Down Expand Up @@ -570,7 +570,7 @@ jobs:
- name: Run e2e test
uses: ./.github/actions/run-e2e-test
with:
test-case: version_upgrade::schedule_version_change
test-case: finality_version::schedule_version_change
env:
UPGRADE_VERSION: 1
UPGRADE_SESSION: 3
Expand Down Expand Up @@ -683,6 +683,21 @@ jobs:
# run: |
# ./scripts/catchup_version_upgrade_test.sh

run-e2e-finality-version-change:
needs: [build-test-docker, build-test-client]
name: Run finality version change 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: finality_version::finality_version_change
follow-up-finalization-check: true
timeout-minutes: 10

check-e2e-test-suite-completion:
needs: [
run-e2e-finalization-test,
Expand All @@ -702,7 +717,7 @@ jobs:
run-e2e-rewards-stake-change,
run-e2e-rewards-change-stake-force-new-era,
run-e2e-rewards-points-basic,
# run-e2e-authorities-are-staking,
run-e2e-authorities-are-staking,
run-e2e-ban-automatic,
run-e2e-ban-manual,
run-e2e-ban-counter-clearing,
Expand All @@ -712,6 +727,7 @@ jobs:
run-e2e-adder-contract-test,
# run-e2e-failing-version-upgrade,
# run-e2e-version-upgrade-catchup,
run-e2e-finality-version-change,
]
name: Check e2e test suite completion
runs-on: ubuntu-20.04
Expand Down
17 changes: 0 additions & 17 deletions .github/workflows/nightly-pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -158,22 +158,6 @@ jobs:
if-no-files-found: error
retention-days: 7

run-e2e-authorities-are-staking:
needs: [build-test-docker, build-test-client]
name: Run authorities are staking 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: authorities_are_staking
node-count: 6
follow-up-finalization-check: true
timeout-minutes: 60

run-e2e-high-out-latency:
needs: [build-synthetic-network-docker, build-test-client]
name: Run high out-latency test
Expand Down Expand Up @@ -210,7 +194,6 @@ jobs:

check-e2e-test-suite-completion:
needs: [
run-e2e-authorities-are-staking,
run-e2e-high-out-latency,
run-e2e-no-quorum-without-high-out-latency,
]
Expand Down
8 changes: 4 additions & 4 deletions 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/Cargo.lock

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

3 changes: 2 additions & 1 deletion aleph-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[package]
name = "aleph_client"
version = "2.12.0"
# TODO bump major version when API stablize
version = "2.13.0"
edition = "2021"
license = "Apache 2.0"

Expand Down
20 changes: 11 additions & 9 deletions aleph-client/src/aleph_zero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6353,9 +6353,10 @@ pub mod api {
"NextAuthorities",
vec![],
[
241u8, 145u8, 255u8, 235u8, 191u8, 220u8, 57u8, 89u8, 8u8, 134u8, 72u8,
193u8, 247u8, 37u8, 54u8, 201u8, 136u8, 32u8, 11u8, 199u8, 134u8,
207u8, 154u8, 107u8, 71u8, 121u8, 245u8, 153u8, 9u8, 33u8, 70u8, 3u8,
223u8, 196u8, 18u8, 234u8, 75u8, 169u8, 31u8, 25u8, 180u8, 189u8, 78u8,
192u8, 179u8, 27u8, 218u8, 254u8, 245u8, 211u8, 86u8, 33u8, 113u8,
114u8, 214u8, 133u8, 240u8, 211u8, 232u8, 163u8, 123u8, 98u8, 114u8,
26u8,
],
)
}
Expand Down Expand Up @@ -6430,9 +6431,10 @@ pub mod api {
"FinalityVersion",
vec![],
[
99u8, 158u8, 103u8, 180u8, 128u8, 32u8, 84u8, 110u8, 229u8, 2u8, 3u8,
114u8, 95u8, 125u8, 230u8, 210u8, 56u8, 85u8, 38u8, 136u8, 49u8, 206u8,
6u8, 136u8, 193u8, 164u8, 251u8, 60u8, 125u8, 91u8, 205u8, 144u8,
134u8, 19u8, 94u8, 247u8, 125u8, 18u8, 148u8, 160u8, 167u8, 235u8,
174u8, 4u8, 107u8, 69u8, 55u8, 187u8, 249u8, 13u8, 129u8, 99u8, 116u8,
158u8, 38u8, 29u8, 239u8, 112u8, 150u8, 92u8, 151u8, 197u8, 223u8,
30u8,
],
)
}
Expand Down Expand Up @@ -19553,9 +19555,9 @@ pub mod api {
let runtime_metadata_hash = client.metadata().metadata_hash(&PALLETS);
if runtime_metadata_hash
!= [
51u8, 153u8, 218u8, 203u8, 158u8, 62u8, 141u8, 96u8, 177u8, 177u8, 12u8, 204u8,
220u8, 53u8, 42u8, 155u8, 22u8, 96u8, 238u8, 212u8, 98u8, 225u8, 39u8, 241u8, 52u8,
28u8, 166u8, 99u8, 14u8, 192u8, 65u8, 67u8,
129u8, 53u8, 4u8, 85u8, 248u8, 69u8, 122u8, 6u8, 68u8, 150u8, 173u8, 133u8, 118u8,
19u8, 96u8, 223u8, 153u8, 160u8, 226u8, 156u8, 47u8, 53u8, 206u8, 110u8, 204u8,
37u8, 67u8, 45u8, 176u8, 126u8, 21u8, 133u8,
]
{
Err(::subxt::error::MetadataError::IncompatibleMetadata)
Expand Down
29 changes: 28 additions & 1 deletion aleph-client/src/pallets/aleph.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use codec::Encode;
use primitives::{BlockNumber, SessionIndex};
use primitives::{BlockNumber, SessionIndex, Version};
use subxt::rpc_params;

use crate::{
api,
api::runtime_types::{
pallet_aleph::pallet::Call::set_emergency_finalizer, primitives::app::Public,
sp_core::ed25519::Public as EdPublic,
Expand All @@ -15,6 +16,15 @@ use crate::{
};

// TODO replace docs with link to pallet aleph docs, once they are published
/// Pallet aleph API which does not require sudo.
#[async_trait::async_trait]
pub trait AlephApi {
/// Gets the current finality version.
async fn finality_version(&self, at: Option<BlockHash>) -> Version;
/// Gets the finality version for the next session.
async fn next_session_finality_version(&self, at: Option<BlockHash>) -> Version;
}

/// Pallet aleph API that requires sudo.
#[async_trait::async_trait]
pub trait AlephSudoApi {
Expand Down Expand Up @@ -57,6 +67,23 @@ pub trait AlephRpc {
) -> anyhow::Result<()>;
}

#[async_trait::async_trait]
impl<C: ConnectionApi> AlephApi for C {
async fn finality_version(&self, at: Option<BlockHash>) -> Version {
let addrs = api::storage().aleph().finality_version();

self.get_storage_entry(&addrs, at).await
}

async fn next_session_finality_version(&self, hash: Option<BlockHash>) -> Version {
let method = "state_call";
let api_method = "AlephSessionApi_next_session_finality_version";
let params = rpc_params![api_method, "0x", hash];

self.rpc_call(method.to_string(), params).await.unwrap()
}
}

#[async_trait::async_trait]
impl AlephSudoApi for RootConnection {
async fn set_emergency_finalizer(
Expand Down
4 changes: 2 additions & 2 deletions benches/payout-stakers/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 bin/cliain/Cargo.lock

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

25 changes: 21 additions & 4 deletions bin/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use std::{collections::HashSet, str::FromStr};
use std::{collections::HashSet, str::FromStr, string::ToString};

use aleph_primitives::{
staking::{MIN_NOMINATOR_BOND, MIN_VALIDATOR_BOND},
AuthorityId as AlephId, ADDRESSES_ENCODING, TOKEN, TOKEN_DECIMALS,
AuthorityId as AlephId, Version as FinalityVersion, ADDRESSES_ENCODING,
LEGACY_FINALITY_VERSION, TOKEN, TOKEN_DECIMALS,
};
use aleph_runtime::{
AccountId, AuraConfig, BalancesConfig, ElectionsConfig, GenesisConfig, Perbill, SessionConfig,
SessionKeys, StakingConfig, SudoConfig, SystemConfig, VestingConfig, WASM_BINARY,
AccountId, AlephConfig, AuraConfig, BalancesConfig, ElectionsConfig, GenesisConfig, Perbill,
SessionConfig, SessionKeys, StakingConfig, SudoConfig, SystemConfig, VestingConfig,
WASM_BINARY,
};
use libp2p::PeerId;
use pallet_staking::{Forcing, StakerStatus};
Expand Down Expand Up @@ -136,6 +138,10 @@ pub struct ChainParams {
/// Minimum number of stakers before chain enters emergency state.
#[arg(long, default_value = "4")]
min_validator_count: u32,

/// Finality version at chain inception.
#[arg(long, default_value = LEGACY_FINALITY_VERSION.to_string())]
finality_version: FinalityVersion,
}

impl ChainParams {
Expand Down Expand Up @@ -170,6 +176,10 @@ impl ChainParams {
pub fn min_validator_count(&self) -> u32 {
self.min_validator_count
}

pub fn finality_version(&self) -> FinalityVersion {
self.finality_version
}
}

fn system_properties(token_symbol: String) -> serde_json::map::Map<String, Value> {
Expand Down Expand Up @@ -218,6 +228,7 @@ fn generate_chain_spec_config(
let sudo_account = chain_params.sudo_account_id();
let faucet_account = chain_params.faucet_account_id();
let min_validator_count = chain_params.min_validator_count();
let finality_version = chain_params.finality_version();

Ok(ChainSpec::from_genesis(
// Name
Expand All @@ -233,6 +244,7 @@ fn generate_chain_spec_config(
faucet_account.clone(), // Pre-funded faucet account
controller_accounts.clone(), // Controller accounts for staking.
min_validator_count,
finality_version,
)
},
// Bootnodes
Expand Down Expand Up @@ -335,6 +347,7 @@ fn generate_genesis_config(
faucet_account: Option<AccountId>,
controller_accounts: Vec<AccountId>,
min_validator_count: u32,
finality_version: FinalityVersion,
) -> GenesisConfig {
let special_accounts = match faucet_account {
Some(faucet_id) => vec![sudo_account.clone(), faucet_id],
Expand Down Expand Up @@ -398,6 +411,10 @@ fn generate_genesis_config(
min_nominator_bond: MIN_NOMINATOR_BOND,
..Default::default()
},
aleph: AlephConfig {
finality_version,
..Default::default()
},
treasury: Default::default(),
vesting: VestingConfig { vesting: vec![] },
nomination_pools: Default::default(),
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.9.0"
version = "0.9.1"
authors = ["Cardinal Cryptography"]
edition = "2021"
homepage = "https://alephzero.org"
Expand Down
Loading

0 comments on commit f82550c

Please sign in to comment.