Skip to content

Commit

Permalink
Add PCK to server info
Browse files Browse the repository at this point in the history
  • Loading branch information
ameba23 committed Sep 13, 2024
1 parent 815c356 commit eb39792
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 23 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions pallets/staking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ scale-info ={ version="2.11", default-features=false, features=["derive"] }
log ={ version="0.4.22", default-features=false }
serde ={ version="1.0.210", default-features=false }
rand_chacha={ version="0.3", default-features=false }
p256 ={ version="0.13.2", default-features=false, features=["ecdsa", "alloc"] }

frame-benchmarking={ version="29.0.0", default-features=false, optional=true }
frame-support ={ version="29.0.0", default-features=false }
Expand Down
4 changes: 3 additions & 1 deletion pallets/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ pub mod pallet {
pub tss_account: AccountId,
pub x25519_public_key: X25519PublicKey,
pub endpoint: TssServerURL,
pub provisioning_certification_key: VerifyingKey,
}
/// Info that is requiered to do a proactive refresh
#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, Default)]
Expand Down Expand Up @@ -238,7 +239,7 @@ pub mod pallet {
/// 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),
(<T as frame_system::Config>::AccountId, X25519PublicKey, TssServerURL, VerifyingKey),
);

#[pallet::genesis_config]
Expand All @@ -265,6 +266,7 @@ pub mod pallet {
tss_account: server_info_tuple.0.clone(),
x25519_public_key: server_info_tuple.1,
endpoint: server_info_tuple.2.clone(),
provisioning_certification_key: server_info_tuple.3.clone(),
};

ThresholdServers::<T>::insert(validator_stash, server_info.clone());
Expand Down
7 changes: 5 additions & 2 deletions pallets/staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,11 @@ 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> {
// (ValidatorID, (AccountId, X25519PublicKey, TssServerURL))
threshold_servers: vec![(5, (7, NULL_ARR, vec![20])), (6, (8, NULL_ARR, vec![40]))],
// (ValidatorID, (AccountId, X25519PublicKey, TssServerURL, VerifyingKey))
threshold_servers: vec![
(5, (7, NULL_ARR, vec![20], BoundedVec::with_max_capacity())),
(6, (8, NULL_ARR, vec![40], BoundedVec::with_max_capacity())),
],
proactive_refresh_data: (vec![], vec![]),
mock_signer_rotate: (false, vec![], vec![]),
};
Expand Down
88 changes: 68 additions & 20 deletions pallets/staking/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,29 @@ use frame_support::{assert_noop, assert_ok};
use frame_system::{EventRecord, Phase};
use pallet_parameters::SignersSize;
use pallet_session::SessionManager;
use sp_runtime::BoundedVec;
const NULL_ARR: [u8; 32] = [0; 32];

#[test]
fn basic_setup_works() {
new_test_ext().execute_with(|| {
assert_eq!(
Staking::threshold_server(5).unwrap(),
ServerInfo { tss_account: 7, x25519_public_key: NULL_ARR, endpoint: vec![20] }
ServerInfo {
tss_account: 7,
x25519_public_key: NULL_ARR,
endpoint: vec![20],
provisioning_certification_key: BoundedVec::with_max_capacity()
}
);
assert_eq!(
Staking::threshold_server(6).unwrap(),
ServerInfo { tss_account: 8, x25519_public_key: NULL_ARR, endpoint: vec![40] }
ServerInfo {
tss_account: 8,
x25519_public_key: NULL_ARR,
endpoint: vec![40],
provisioning_certification_key: BoundedVec::with_max_capacity()
}
);
assert_eq!(Staking::threshold_to_stash(7).unwrap(), 5);
assert_eq!(Staking::threshold_to_stash(8).unwrap(), 6);
Expand All @@ -51,8 +62,12 @@ fn it_takes_in_an_endpoint() {
pallet_staking::RewardDestination::Account(1),
));

let server_info =
ServerInfo { tss_account: 3, x25519_public_key: NULL_ARR, endpoint: vec![20] };
let server_info = ServerInfo {
tss_account: 3,
x25519_public_key: NULL_ARR,
endpoint: vec![20],
provisioning_certification_key: BoundedVec::with_max_capacity(),
};
assert_ok!(Staking::validate(
RuntimeOrigin::signed(1),
pallet_staking::ValidatorPrefs::default(),
Expand All @@ -68,6 +83,7 @@ fn it_takes_in_an_endpoint() {
tss_account: 3,
x25519_public_key: NULL_ARR,
endpoint: vec![20, 20, 20, 20],
provisioning_certification_key: BoundedVec::with_max_capacity(),
};
assert_noop!(
Staking::validate(
Expand All @@ -78,8 +94,12 @@ fn it_takes_in_an_endpoint() {
Error::<Test>::EndpointTooLong
);

let server_info =
ServerInfo { tss_account: 5, x25519_public_key: NULL_ARR, endpoint: vec![20, 20] };
let server_info = ServerInfo {
tss_account: 5,
x25519_public_key: NULL_ARR,
endpoint: vec![20, 20],
provisioning_certification_key: BoundedVec::with_max_capacity(),
};
assert_noop!(
Staking::validate(
RuntimeOrigin::signed(4),
Expand All @@ -100,8 +120,12 @@ fn it_will_not_allow_validator_to_use_existing_tss_account() {
pallet_staking::RewardDestination::Account(1),
));

let server_info =
ServerInfo { tss_account: 3, x25519_public_key: NULL_ARR, endpoint: vec![20] };
let server_info = ServerInfo {
tss_account: 3,
x25519_public_key: NULL_ARR,
endpoint: vec![20],
provisioning_certification_key: BoundedVec::with_max_capacity(),
};
assert_ok!(Staking::validate(
RuntimeOrigin::signed(1),
pallet_staking::ValidatorPrefs::default(),
Expand Down Expand Up @@ -134,8 +158,12 @@ fn it_changes_endpoint() {
pallet_staking::RewardDestination::Account(1),
));

let server_info =
ServerInfo { tss_account: 3, x25519_public_key: NULL_ARR, endpoint: vec![20] };
let server_info = ServerInfo {
tss_account: 3,
x25519_public_key: NULL_ARR,
endpoint: vec![20],
provisioning_certification_key: BoundedVec::with_max_capacity(),
};
assert_ok!(Staking::validate(
RuntimeOrigin::signed(1),
pallet_staking::ValidatorPrefs::default(),
Expand All @@ -161,8 +189,12 @@ fn it_changes_threshold_account() {
pallet_staking::RewardDestination::Account(1),
));

let server_info =
ServerInfo { tss_account: 3, x25519_public_key: NULL_ARR, endpoint: vec![20] };
let server_info = ServerInfo {
tss_account: 3,
x25519_public_key: NULL_ARR,
endpoint: vec![20],
provisioning_certification_key: BoundedVec::with_max_capacity(),
};
assert_ok!(Staking::validate(
RuntimeOrigin::signed(1),
pallet_staking::ValidatorPrefs::default(),
Expand All @@ -185,8 +217,12 @@ fn it_changes_threshold_account() {
pallet_staking::RewardDestination::Account(2),
));

let server_info =
ServerInfo { tss_account: 5, x25519_public_key: NULL_ARR, endpoint: vec![20] };
let server_info = ServerInfo {
tss_account: 5,
x25519_public_key: NULL_ARR,
endpoint: vec![20],
provisioning_certification_key: BoundedVec::with_max_capacity(),
};
assert_ok!(Staking::validate(
RuntimeOrigin::signed(2),
pallet_staking::ValidatorPrefs::default(),
Expand All @@ -209,8 +245,12 @@ fn it_will_not_allow_existing_tss_account_when_changing_threshold_account() {
pallet_staking::RewardDestination::Account(1),
));

let server_info =
ServerInfo { tss_account: 3, x25519_public_key: NULL_ARR, endpoint: vec![20] };
let server_info = ServerInfo {
tss_account: 3,
x25519_public_key: NULL_ARR,
endpoint: vec![20],
provisioning_certification_key: BoundedVec::with_max_capacity(),
};
assert_ok!(Staking::validate(
RuntimeOrigin::signed(1),
pallet_staking::ValidatorPrefs::default(),
Expand All @@ -224,8 +264,12 @@ fn it_will_not_allow_existing_tss_account_when_changing_threshold_account() {
pallet_staking::RewardDestination::Account(2),
));

let server_info =
ServerInfo { tss_account: 5, x25519_public_key: NULL_ARR, endpoint: vec![20] };
let server_info = ServerInfo {
tss_account: 5,
x25519_public_key: NULL_ARR,
endpoint: vec![20],
provisioning_certification_key: BoundedVec::with_max_capacity(),
};
assert_ok!(Staking::validate(
RuntimeOrigin::signed(2),
pallet_staking::ValidatorPrefs::default(),
Expand All @@ -250,8 +294,12 @@ fn it_deletes_when_no_bond_left() {
pallet_staking::RewardDestination::Account(1),
));

let server_info =
ServerInfo { tss_account: 3, x25519_public_key: NULL_ARR, endpoint: vec![20] };
let server_info = ServerInfo {
tss_account: 3,
x25519_public_key: NULL_ARR,
endpoint: vec![20],
provisioning_certification_key: BoundedVec::with_max_capacity(),
};
assert_ok!(Staking::validate(
RuntimeOrigin::signed(2),
pallet_staking::ValidatorPrefs::default(),
Expand Down

0 comments on commit eb39792

Please sign in to comment.