Skip to content

Commit

Permalink
Serialize threshold_server field into chain spec (#587)
Browse files Browse the repository at this point in the history
* fix chainspec ignore threshold_servers

* fmt

* Add comments around seed phrases used in chain_spec

* Add a typedef for the threshold_servers genesis config

* Update tests to use tuple instead of structs

* Bump lockfile

* Add a couple more comments around seeds

---------

Co-authored-by: Hernando Castano <[email protected]>
  • Loading branch information
JesseAbram and HCastano authored Jan 11, 2024
1 parent ae6fdd3 commit ad8b636
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 98 deletions.
7 changes: 0 additions & 7 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions node/cli/src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ use sp_consensus_babe::AuthorityId as BabeId;
use sp_core::{crypto::UncheckedInto, sr25519};

use crate::chain_spec::{
authority_keys_from_seed, devnet_genesis, get_account_id_from_seed, local_devnet_genesis,
testing, testnet_genesis,
authority_keys_from_seed, get_account_id_from_seed, local_devnet_genesis, testing,
testnet_genesis,
};

pub fn testnet_config_genesis() -> RuntimeGenesisConfig {
Expand Down Expand Up @@ -144,7 +144,7 @@ pub fn testnet_config_genesis() -> RuntimeGenesisConfig {
let root_key: AccountId =
hex!["6a16ded05ff7a50716e1ca943f0467c60b4b71c2a7fd7f75b6333b8af80b6e6f"].into();

devnet_genesis(initial_authorities, vec![], root_key)
testnet_genesis(initial_authorities, vec![], root_key)
}

pub fn staging_testnet_config_genesis() -> RuntimeGenesisConfig {
Expand Down
120 changes: 55 additions & 65 deletions node/cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ use grandpa_primitives::AuthorityId as GrandpaId;
use hex_literal::hex;
pub use node_primitives::{AccountId, Balance, Signature};
use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
use pallet_staking_extension::ServerInfo;
use sc_chain_spec::{ChainSpecExtension, Properties};
use sc_service::ChainType;
use sc_telemetry::TelemetryEndpoints;
Expand Down Expand Up @@ -223,33 +222,31 @@ pub fn testnet_genesis(
threshold_servers: vec![
(
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
ServerInfo {
tss_account: hex![
"e0543c102def9f6ef0e8b8ffa31aa259167a9391566929fd718a1ccdaabdb876"
]
.into(),
endpoint: "127.0.0.1:3001".as_bytes().to_vec(),
x25519_public_key: [
(
// Seed phrase: "alarm mutual concert decrease hurry invest culture survey diagram crash snap click"
hex!["e0543c102def9f6ef0e8b8ffa31aa259167a9391566929fd718a1ccdaabdb876"]
.into(),
[
10, 192, 41, 240, 184, 83, 178, 59, 237, 101, 45, 109, 13, 230, 155,
124, 195, 141, 148, 249, 55, 50, 238, 252, 133, 181, 134, 30, 144, 247,
58, 34,
],
},
"127.0.0.1:3001".as_bytes().to_vec(),
),
),
(
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
ServerInfo {
tss_account: hex![
"2a8200850770290c7ea3b50a8ff64c6761c882ff8393dc95fccb5d1475eff17f"
]
.into(),
endpoint: "127.0.0.1:3002".as_bytes().to_vec(),
x25519_public_key: [
(
// Seed phrase: "where sight patient orphan general short empower hope party hurt month voice"
hex!["2a8200850770290c7ea3b50a8ff64c6761c882ff8393dc95fccb5d1475eff17f"]
.into(),
[
225, 48, 135, 211, 227, 213, 170, 21, 1, 189, 118, 158, 255, 87, 245,
89, 36, 170, 169, 181, 68, 201, 210, 178, 237, 247, 101, 80, 153, 136,
102, 10,
],
},
"127.0.0.1:3002".as_bytes().to_vec(),
),
),
],
signing_groups: vec![
Expand Down Expand Up @@ -396,33 +393,31 @@ pub fn local_devnet_genesis(
threshold_servers: vec![
(
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
ServerInfo {
tss_account: hex![
"e0543c102def9f6ef0e8b8ffa31aa259167a9391566929fd718a1ccdaabdb876"
]
.into(),
endpoint: "alice-tss-server:3001".as_bytes().to_vec(),
x25519_public_key: [
(
// Seed phrase: "alarm mutual concert decrease hurry invest culture survey diagram crash snap click"
hex!["e0543c102def9f6ef0e8b8ffa31aa259167a9391566929fd718a1ccdaabdb876"]
.into(),
[
10, 192, 41, 240, 184, 83, 178, 59, 237, 101, 45, 109, 13, 230, 155,
124, 195, 141, 148, 249, 55, 50, 238, 252, 133, 181, 134, 30, 144, 247,
58, 34,
],
},
"alice-tss-server:3001".as_bytes().to_vec(),
),
),
(
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
ServerInfo {
tss_account: hex![
"2a8200850770290c7ea3b50a8ff64c6761c882ff8393dc95fccb5d1475eff17f"
]
.into(),
endpoint: "bob-tss-server:3002".as_bytes().to_vec(),
x25519_public_key: [
(
// Seed phrase: "where sight patient orphan general short empower hope party hurt month voice"
hex!["2a8200850770290c7ea3b50a8ff64c6761c882ff8393dc95fccb5d1475eff17f"]
.into(),
[
225, 48, 135, 211, 227, 213, 170, 21, 1, 189, 118, 158, 255, 87, 245,
89, 36, 170, 169, 181, 68, 201, 210, 178, 237, 247, 101, 80, 153, 136,
102, 10,
],
},
"bob-tss-server:3002".as_bytes().to_vec(),
),
),
],
signing_groups: vec![
Expand Down Expand Up @@ -669,63 +664,58 @@ pub fn testing(
threshold_servers: vec![
(
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
ServerInfo {
tss_account: hex![
"e0543c102def9f6ef0e8b8ffa31aa259167a9391566929fd718a1ccdaabdb876"
]
.into(),
endpoint: "127.0.0.1:3001".as_bytes().to_vec(),
x25519_public_key: [
(
// Seed phrase: "alarm mutual concert decrease hurry invest culture survey diagram crash snap click"
hex!["e0543c102def9f6ef0e8b8ffa31aa259167a9391566929fd718a1ccdaabdb876"]
.into(),
[
10, 192, 41, 240, 184, 83, 178, 59, 237, 101, 45, 109, 13, 230, 155,
124, 195, 141, 148, 249, 55, 50, 238, 252, 133, 181, 134, 30, 144, 247,
58, 34,
],
},
"127.0.0.1:3001".as_bytes().to_vec(),
),
),
(
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
ServerInfo {
tss_account: hex![
"2a8200850770290c7ea3b50a8ff64c6761c882ff8393dc95fccb5d1475eff17f"
]
.into(),
endpoint: "127.0.0.1:3002".as_bytes().to_vec(),
x25519_public_key: [
(
// Seed phrase: "where sight patient orphan general short empower hope party hurt month voice"
hex!["2a8200850770290c7ea3b50a8ff64c6761c882ff8393dc95fccb5d1475eff17f"]
.into(),
[
225, 48, 135, 211, 227, 213, 170, 21, 1, 189, 118, 158, 255, 87, 245,
89, 36, 170, 169, 181, 68, 201, 210, 178, 237, 247, 101, 80, 153, 136,
102, 10,
],
},
"127.0.0.1:3002".as_bytes().to_vec(),
),
),
(
// Seed phrase: "lake carry still awful point mention bike category tornado plate brass lock"
get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),
ServerInfo {
tss_account: hex![
"14d223daeec68671f07298c66c9458980a48bb89fb8a85d5df31131acad8d611"
]
.into(),
endpoint: "127.0.0.1:3002".as_bytes().to_vec(),
x25519_public_key: [
(
hex!["14d223daeec68671f07298c66c9458980a48bb89fb8a85d5df31131acad8d611"]
.into(),
[
225, 48, 135, 211, 227, 213, 170, 21, 1, 189, 118, 158, 255, 87, 245,
89, 36, 170, 169, 181, 68, 201, 210, 178, 237, 247, 101, 80, 153, 136,
102, 10,
],
},
"127.0.0.1:3002".as_bytes().to_vec(),
),
),
(
get_account_id_from_seed::<sr25519::Public>("Dave//stash"),
ServerInfo {
tss_account: hex![
"5212c5f562f4a43b89caadfeb9f5896dd4084700afa72aa55ca306d689523f3a"
]
.into(),
endpoint: "127.0.0.1:3002".as_bytes().to_vec(),
x25519_public_key: [
(
hex!["5212c5f562f4a43b89caadfeb9f5896dd4084700afa72aa55ca306d689523f3a"]
.into(),
[
225, 48, 135, 211, 227, 213, 170, 21, 1, 189, 118, 158, 255, 87, 245,
89, 36, 170, 169, 181, 68, 201, 210, 178, 237, 247, 101, 80, 153, 136,
102, 10,
],
},
"127.0.0.1:3002".as_bytes().to_vec(),
),
),
],
signing_groups: vec![
Expand Down
10 changes: 5 additions & 5 deletions pallets/propagation/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use frame_support::{
};
use frame_system as system;
use pallet_session::historical as pallet_session_historical;
use pallet_staking_extension::ServerInfo;
use sp_core::H256;
use sp_runtime::{
curve::PiecewiseLinear,
Expand Down Expand Up @@ -338,10 +337,11 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
let mut t = system::GenesisConfig::<Test>::default().build_storage().unwrap();
let pallet_staking_extension = pallet_staking_extension::GenesisConfig::<Test> {
threshold_servers: vec![
(5, ServerInfo { tss_account: 7, x25519_public_key: NULL_ARR, endpoint: vec![20] }),
(6, ServerInfo { tss_account: 8, x25519_public_key: NULL_ARR, endpoint: vec![40] }),
(1, ServerInfo { tss_account: 3, x25519_public_key: NULL_ARR, endpoint: vec![10] }),
(2, ServerInfo { tss_account: 4, x25519_public_key: NULL_ARR, endpoint: vec![11] }),
// (ValidatorID, (AccountId, X25519PublicKey, TssServerURL))
(5, (7, NULL_ARR, vec![20])),
(6, (8, NULL_ARR, vec![40])),
(1, (3, NULL_ARR, vec![10])),
(2, (4, NULL_ARR, vec![11])),
],
// Alice, Bob are represented by 1, 2 in the following tuples, respectively.
signing_groups: vec![(0, vec![1, 5]), (1, vec![2, 6])],
Expand Down
12 changes: 6 additions & 6 deletions pallets/relayer/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use frame_support::{
};
use frame_system as system;
use pallet_session::historical as pallet_session_historical;
use pallet_staking_extension::ServerInfo;
use sp_core::H256;
use sp_runtime::{
curve::PiecewiseLinear,
Expand Down Expand Up @@ -332,11 +331,12 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
let mut t = system::GenesisConfig::<Test>::default().build_storage().unwrap();
let pallet_staking_extension = pallet_staking_extension::GenesisConfig::<Test> {
threshold_servers: vec![
(5, ServerInfo { tss_account: 7, x25519_public_key: NULL_ARR, endpoint: vec![20] }),
(6, ServerInfo { tss_account: 8, x25519_public_key: NULL_ARR, endpoint: vec![40] }),
(1, ServerInfo { tss_account: 3, x25519_public_key: NULL_ARR, endpoint: vec![10] }),
(2, ServerInfo { tss_account: 4, x25519_public_key: NULL_ARR, endpoint: vec![11] }),
(7, ServerInfo { tss_account: 4, x25519_public_key: NULL_ARR, endpoint: vec![50] }),
// (ValidatorID, (AccountId, X25519PublicKey, TssServerURL))
(5, (7, NULL_ARR, vec![20])),
(6, (8, NULL_ARR, vec![40])),
(1, (3, NULL_ARR, vec![10])),
(2, (4, NULL_ARR, vec![11])),
(7, (4, NULL_ARR, vec![50])),
],
// Alice, Bob are represented by 1, 2 in the following tuples, respectively.
signing_groups: vec![(0, vec![1, 5]), (1, vec![2, 6, 7])],
Expand Down
21 changes: 15 additions & 6 deletions pallets/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,16 @@ pub mod pallet {
#[pallet::getter(fn proactive_refresh)]
pub type ProactiveRefresh<T: Config> = StorageValue<_, RefreshInfo, ValueQuery>;

/// A type used to simplify the genesis configuration definition.
pub type ThresholdServersConfig<T> = (
<T as pallet_session::Config>::ValidatorId,
(<T as frame_system::Config>::AccountId, X25519PublicKey, TssServerURL),
);

#[pallet::genesis_config]
#[derive(DefaultNoBound)]
pub struct GenesisConfig<T: Config> {
#[allow(clippy::type_complexity)]
#[serde(skip)]
pub threshold_servers:
Vec<(<T as pallet_session::Config>::ValidatorId, ServerInfo<T::AccountId>)>,
pub threshold_servers: Vec<ThresholdServersConfig<T>>,
pub signing_groups: Vec<(u8, Vec<<T as pallet_session::Config>::ValidatorId>)>,
pub proactive_refresh_validators: Vec<ValidatorInfo>,
}
Expand All @@ -184,9 +187,15 @@ pub mod pallet {
.threshold_servers
.clone()
.into_iter()
.map(|x| assert!(x.1.endpoint.len() as u32 <= T::MaxEndpointLength::get()));
.map(|x| assert!(x.1 .2.len() as u32 <= T::MaxEndpointLength::get()));

for (validator_stash, server_info_tuple) in &self.threshold_servers {
let server_info = ServerInfo {
tss_account: server_info_tuple.0.clone(),
x25519_public_key: server_info_tuple.1,
endpoint: server_info_tuple.2.clone(),
};

for (validator_stash, server_info) in &self.threshold_servers {
ThresholdServers::<T>::insert(validator_stash, server_info.clone());
ThresholdToStash::<T>::insert(&server_info.tss_account, validator_stash);
}
Expand Down
8 changes: 2 additions & 6 deletions pallets/staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ use frame_support::{
};
use frame_system as system;
use pallet_session::{historical as pallet_session_historical, ShouldEndSession};
// use pallet_session::historical as pallet_session_historical;
use pallet_staking_extension::ServerInfo;
use sp_core::H256;
use sp_runtime::{
curve::PiecewiseLinear,
Expand Down Expand Up @@ -369,10 +367,8 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
balances: vec![(1, 100), (2, 100), (3, 100), (4, 100)],
};
let pallet_staking_extension = pallet_staking_extension::GenesisConfig::<Test> {
threshold_servers: vec![
(5, ServerInfo { tss_account: 7, x25519_public_key: NULL_ARR, endpoint: vec![20] }),
(6, ServerInfo { tss_account: 8, x25519_public_key: NULL_ARR, endpoint: vec![40] }),
],
// (ValidatorID, (AccountId, X25519PublicKey, TssServerURL))
threshold_servers: vec![(5, (7, NULL_ARR, vec![20])), (6, (8, NULL_ARR, vec![40]))],
// Alice, Bob are represented by 1, 2 in the following tuples, respectively.
signing_groups: vec![(0, vec![1]), (1, vec![2])],
proactive_refresh_validators: vec![],
Expand Down

0 comments on commit ad8b636

Please sign in to comment.