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

Implement validator sessions pallets #233

Merged
merged 7 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
- arch: aarch64
target-tupl: aarch64-unknown-linux-gnu
dependencies: gcc-aarch64-linux-gnu protobuf-compiler libclang-dev g++-aarch64-linux-gnu
bindgenExtraClangArgs: "--sysroot=/usr/aarch64-linux-gnu -mfloat-abi=hard"
bindgenExtraClangArgs: "--sysroot=/usr/aarch64-linux-gnu"
mattdean-digicatapult marked this conversation as resolved.
Show resolved Hide resolved

steps:
- uses: actions/checkout@v4
Expand Down
43 changes: 33 additions & 10 deletions Cargo.lock

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

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ resolver = "2"

[workspace.package]
edition = "2021"
version = "12.0.0"
version = "12.1.0"

[workspace.dependencies]
##############################
Expand Down Expand Up @@ -49,6 +49,7 @@ pallet-scheduler = { version = "39.0.0", default-features = false }
pallet-balances = { version = "39.0.0", default-features = false }
pallet-babe = { version = "38.0.0", default-features = false }
pallet-grandpa = { version = "38.0.0", default-features = false }
pallet-session = { version = "38.0.0", default-features = false }
pallet-sudo = { version = "38.0.0", default-features = false }
pallet-timestamp = { version = "37.0.0", default-features = false }
pallet-transaction-payment-rpc-runtime-api = { version = "38.0.0", default-features = false }
Expand All @@ -61,10 +62,13 @@ sp-genesis-builder = { version = "0.15.1", default-features = false }
sp-inherents = { version = "34.0.0", default-features = false }
sp-offchain = { version = "34.0.0", default-features = false }
sp-session = { version = "36.0.0", default-features = false }
sp-staking = { version = "36.0.0", default-features = false }
sp-state-machine = { version = "0.43.0", default-features = false }
sp-statement-store = { version = "18.0.0", default-features = false }
sp-storage = { version = "21.0.0", default-features = false }
sp-transaction-pool = { version = "34.0.0", default-features = false }
sp-version = { version = "37.0.0", default-features = false }
sp-weights = { version = "31.0.0", default-features = false }
frame-try-runtime = { version = "0.44.0", default-features = false }
pallet-collective = { version = "38.0.0", default-features = false }
pallet-membership = { version = "38.0.0", default-features = false }
Expand Down
25 changes: 19 additions & 6 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use sp_consensus_babe::AuthorityId as BabeId;
use sp_consensus_grandpa::AuthorityId as GrandpaId;
use sp_core::{sr25519, Pair, Public};
use sp_runtime::traits::{IdentifyAccount, Verify};
use sqnc_runtime::WASM_BINARY;
use sqnc_runtime::{opaque::SessionKeys, SessionConfig, ValidatorSetConfig, WASM_BINARY};
use sqnc_runtime_types::{AccountId, RuntimeExpressionSymbol, RuntimeRestriction, Signature};

const DEFAULT_PROTOCOL_ID: &str = "sqnc";
Expand All @@ -29,8 +29,12 @@ where
}

/// Generate an authority key.
pub fn authority_keys_from_seed(s: &str) -> (BabeId, GrandpaId) {
(get_from_seed::<BabeId>(s), get_from_seed::<GrandpaId>(s))
pub fn authority_keys_from_seed(s: &str) -> (AccountId, BabeId, GrandpaId) {
(
get_account_id_from_seed::<sr25519::Public>(s),
get_from_seed::<BabeId>(s),
get_from_seed::<GrandpaId>(s),
)
}

pub fn development_config() -> Result<ChainSpec, String> {
Expand Down Expand Up @@ -141,7 +145,7 @@ pub fn local_testnet_config() -> Result<ChainSpec, String> {

/// Configure initial storage state for FRAME modules.
fn testnet_genesis(
initial_authorities: Vec<(BabeId, GrandpaId)>,
initial_authorities: Vec<(AccountId, BabeId, GrandpaId)>,
root_key: AccountId,
endowed_accounts: Vec<AccountId>,
technical_committee_accounts: Vec<AccountId>,
Expand All @@ -152,11 +156,20 @@ fn testnet_genesis(
"balances": endowed_accounts.iter().cloned().map(|k| (k, 1i64 << 60)).collect::<Vec<_>>(),
},
"babe": {
"authorities": initial_authorities.iter().map(|x| (x.0.clone(), 1)).collect::<Vec<_>>(),
"authorities": Vec::<BabeId>::new(),
"epochConfig": Some(sqnc_runtime::BABE_GENESIS_EPOCH_CONFIG),
},
"grandpa": {
"authorities": initial_authorities.iter().map(|x| (x.1.clone(), 1)).collect::<Vec<_>>(),
"authorities": Vec::<GrandpaId>::new(),
},
"validatorSet": ValidatorSetConfig {
initial_validators: initial_authorities.iter().map(|x| x.0.clone()).collect::<Vec<_>>(),
},
"session": SessionConfig {
keys: initial_authorities.iter().map(|x| {
(x.0.clone(), x.0.clone(), SessionKeys { babe: x.1.clone(), grandpa: x.2.clone() })
}).collect::<Vec<_>>(),
non_authority_keys: Vec::new()
},
"sudo": {
"key": Some(root_key),
Expand Down
44 changes: 44 additions & 0 deletions pallets/validator-set/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[package]
name = 'pallet-validator-set'
authors = ['Digital Catapult <https://www.digicatapult.org.uk>']
description = 'SessionManager implementation that allows a configured origin to manager the validators for future sessions'
edition = '2021'
license = 'Apache-2.0'
repository = 'https://github.com/digicatapult/sqnc-node/'
version = { workspace = true }

[dependencies]
sp-core = { workspace = true }
sp-io = { workspace = true }
sp-runtime = { workspace = true }
sp-std = { workspace = true }
sp-staking = { workspace = true }
frame-benchmarking = { workspace = true, optional = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
pallet-session = { workspace = true, features = ['historical'] }
sp-weights = { workspace = true }
scale-info = { workspace = true, features = ['derive', 'serde'] }
log = { workspace = true }
parity-scale-codec = { workspace = true, features = ["derive"] }

[dev-dependencies]
sp-state-machine = { workspace = true }
serde = { workspace = true, features = ['derive'] }

[features]
default = ['std']
runtime-benchmarks = ['frame-benchmarking/runtime-benchmarks']
std = [
'parity-scale-codec/std',
'frame-benchmarking/std',
'frame-support/std',
'frame-system/std',
'scale-info/std',
'sp-core/std',
'sp-io/std',
'sp-std/std',
'sp-runtime/std',
'pallet-session/std',
]
try-runtime = ['frame-support/try-runtime']
Loading
Loading