Skip to content

Commit

Permalink
Set inital signers
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseAbram committed Jul 31, 2024
1 parent c29e49a commit 425c4dc
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 46 deletions.
2 changes: 1 addition & 1 deletion crates/shared/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ lazy_static! {
pub static ref DEVICE_KEY_AUX_DATA_TYPE: Vec<u8> = vec![123, 34, 36, 115, 99, 104, 101, 109, 97, 34, 58, 34, 104, 116, 116, 112, 58, 47, 47, 106, 115, 111, 110, 45, 115, 99, 104, 101, 109, 97, 46, 111, 114, 103, 47, 100, 114, 97, 102, 116, 45, 48, 55, 47, 115, 99, 104, 101, 109, 97, 35, 34, 44, 34, 116, 105, 116, 108, 101, 34, 58, 34, 65, 117, 120, 68, 97, 116, 97, 34, 44, 34, 100, 101, 115, 99, 114, 105, 112, 116, 105, 111, 110, 34, 58, 34, 74, 83, 79, 78, 32, 114, 101, 112, 114, 101, 115, 101, 110, 116, 97, 116, 105, 111, 110, 32, 111, 102, 32, 116, 104, 101, 32, 97, 117, 120, 105, 108, 105, 97, 114, 121, 32, 100, 97, 116, 97, 34, 44, 34, 116, 121, 112, 101, 34, 58, 34, 111, 98, 106, 101, 99, 116, 34, 44, 34, 114, 101, 113, 117, 105, 114, 101, 100, 34, 58, 91, 34, 99, 111, 110, 116, 101, 120, 116, 34, 44, 34, 112, 117, 98, 108, 105, 99, 95, 107, 101, 121, 34, 44, 34, 112, 117, 98, 108, 105, 99, 95, 107, 101, 121, 95, 116, 121, 112, 101, 34, 44, 34, 115, 105, 103, 110, 97, 116, 117, 114, 101, 34, 93, 44, 34, 112, 114, 111, 112, 101, 114, 116, 105, 101, 115, 34, 58, 123, 34, 99, 111, 110, 116, 101, 120, 116, 34, 58, 123, 34, 100, 101, 115, 99, 114, 105, 112, 116, 105, 111, 110, 34, 58, 34, 84, 104, 101, 32, 99, 111, 110, 116, 101, 120, 116, 32, 102, 111, 114, 32, 116, 104, 101, 32, 115, 105, 103, 110, 97, 116, 117, 114, 101, 32, 111, 110, 108, 121, 32, 110, 101, 101, 100, 101, 100, 32, 105, 110, 32, 115, 114, 50, 53, 53, 49, 57, 32, 115, 105, 103, 110, 97, 116, 117, 114, 101, 32, 116, 121, 112, 101, 34, 44, 34, 116, 121, 112, 101, 34, 58, 34, 115, 116, 114, 105, 110, 103, 34, 125, 44, 34, 112, 117, 98, 108, 105, 99, 95, 107, 101, 121, 34, 58, 123, 34, 100, 101, 115, 99, 114, 105, 112, 116, 105, 111, 110, 34, 58, 34, 98, 97, 115, 101, 54, 52, 45, 101, 110, 99, 111, 100, 101, 100, 32, 112, 117, 98, 108, 105, 99, 32, 107, 101, 121, 34, 44, 34, 116, 121, 112, 101, 34, 58, 34, 115, 116, 114, 105, 110, 103, 34, 125, 44, 34, 112, 117, 98, 108, 105, 99, 95, 107, 101, 121, 95, 116, 121, 112, 101, 34, 58, 123, 34, 100, 101, 115, 99, 114, 105, 112, 116, 105, 111, 110, 34, 58, 34, 92, 34, 101, 99, 100, 115, 97, 92, 34, 44, 32, 92, 34, 101, 100, 50, 53, 53, 49, 57, 92, 34, 44, 32, 92, 34, 115, 114, 50, 53, 53, 49, 57, 92, 34, 34, 44, 34, 116, 121, 112, 101, 34, 58, 34, 115, 116, 114, 105, 110, 103, 34, 125, 44, 34, 115, 105, 103, 110, 97, 116, 117, 114, 101, 34, 58, 123, 34, 100, 101, 115, 99, 114, 105, 112, 116, 105, 111, 110, 34, 58, 34, 98, 97, 115, 101, 54, 52, 45, 101, 110, 99, 111, 100, 101, 100, 32, 115, 105, 103, 110, 97, 116, 117, 114, 101, 34, 44, 34, 116, 121, 112, 101, 34, 58, 34, 115, 116, 114, 105, 110, 103, 34, 125, 125, 125];
}

pub const SIGNING_PARTY_SIZE: usize = 2;
pub const TOTAL_SIGNERSZE: usize = 2;

// min balance 10 decimal chain = 1
pub const MIN_BALANCE: u128 = 10_000_000_000;
Expand Down
2 changes: 1 addition & 1 deletion crates/threshold-signature-server/src/user/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use entropy_kvdb::kv_manager::{
use entropy_programs_runtime::{Config as ProgramConfig, Runtime, SignatureRequest};
use entropy_protocol::{KeyParams, PartyId, SigningSessionInfo, ValidatorInfo};
use entropy_shared::{
HashingAlgorithm, OcwMessageDkg, X25519PublicKey, NETWORK_PARENT_KEY, SIGNING_PARTY_SIZE,
HashingAlgorithm, OcwMessageDkg, X25519PublicKey, NETWORK_PARENT_KEY, TOTAL_SIGNERSZE,
};
use futures::{
channel::mpsc,
Expand Down
6 changes: 1 addition & 5 deletions node/cli/src/chain_spec/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,7 @@ pub fn development_genesis_config(
})
.collect::<Vec<_>>(),
proactive_refresh_data: (vec![], vec![]),
mock_signer_rotate: false,
inital_signers: initial_authorities.iter().map(|auth| {
auth.0.clone()
})
.collect::<Vec<_>>(),
mock_signer_rotate: (false, vec![]),
},
"elections": ElectionsConfig {
members: endowed_accounts
Expand Down
6 changes: 2 additions & 4 deletions node/cli/src/chain_spec/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,9 @@ pub fn integration_tests_genesis_config(
],
vec![EVE_VERIFYING_KEY.to_vec(), DAVE_VERIFYING_KEY.to_vec()],
),
mock_signer_rotate: true,
inital_signers: initial_authorities.iter().map(|auth| {
mock_signer_rotate: (true, initial_authorities.iter().map(|auth| {
auth.0.clone()
})
.collect::<Vec<_>>(),
}).collect::<Vec<_>>()),
},
"elections": ElectionsConfig {
members: endowed_accounts
Expand Down
6 changes: 1 addition & 5 deletions node/cli/src/chain_spec/testnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,11 +414,7 @@ pub fn testnet_genesis_config(
})
.collect::<Vec<_>>(),
proactive_refresh_data: (vec![], vec![]),
mock_signer_rotate: false,
inital_signers: initial_authorities.iter().map(|auth| {
auth.0.clone()
})
.collect::<Vec<_>>(),
mock_signer_rotate: (false, vec![]),
},
"elections": ElectionsConfig {
members: endowed_accounts
Expand Down
3 changes: 1 addition & 2 deletions pallets/propagation/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
(2, (4, NULL_ARR, vec![11])),
],
proactive_refresh_data: (vec![], vec![]),
mock_signer_rotate: false,
inital_signers: vec![5, 6],
mock_signer_rotate: (false, vec![]),
};

pallet_staking_extension.assimilate_storage(&mut t).unwrap();
Expand Down
16 changes: 8 additions & 8 deletions pallets/registry/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

//! Benchmarking setup for pallet-propgation
use entropy_shared::{SIGNING_PARTY_SIZE, VERIFICATION_KEY_LENGTH};
use entropy_shared::{TOTAL_SIGNERSZE, VERIFICATION_KEY_LENGTH};
use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite, whitelisted_caller};
use frame_support::{
traits::{Currency, Get},
Expand Down Expand Up @@ -79,20 +79,20 @@ benchmarks! {
}

confirm_jump_start_done {
let c in 0 .. SIGNING_PARTY_SIZE as u32;
let c in 0 .. TOTAL_SIGNERSZE as u32;
let sig_req_account: T::AccountId = whitelisted_caller();
let validator_account: T::AccountId = whitelisted_caller();
let expected_verifying_key = BoundedVec::default();

let mut accounts = vec![];
for i in 0..SIGNING_PARTY_SIZE {
for i in 0..TOTAL_SIGNERSZE {
accounts.push(account::<T::AccountId>("ts_account", i as u32, SEED));
}

let validators = add_non_syncing_validators::<T>(SIGNING_PARTY_SIZE as u32, 0);
let validators = add_non_syncing_validators::<T>(TOTAL_SIGNERSZE as u32, 0);
<Validators<T>>::set(validators.clone());

for i in 0..SIGNING_PARTY_SIZE {
for i in 0..TOTAL_SIGNERSZE {
<ThresholdToStash<T>>::insert(accounts[i].clone(), &validators[i]);
}

Expand All @@ -111,15 +111,15 @@ benchmarks! {
}

confirm_jump_start_confirm {
let c in 0 .. SIGNING_PARTY_SIZE as u32;
let c in 0 .. TOTAL_SIGNERSZE as u32;
let sig_req_account: T::AccountId = whitelisted_caller();
let validator_account: T::AccountId = whitelisted_caller();
let threshold_account: T::AccountId = whitelisted_caller();
let expected_verifying_key = BoundedVec::default();

// add validators and a registering user
for i in 0..SIGNING_PARTY_SIZE {
let validators = add_non_syncing_validators::<T>(SIGNING_PARTY_SIZE as u32, 0);
for i in 0..TOTAL_SIGNERSZE {
let validators = add_non_syncing_validators::<T>(TOTAL_SIGNERSZE as u32, 0);
<Validators<T>>::set(validators.clone());
<ThresholdToStash<T>>::insert(&threshold_account, &validators[i]);
}
Expand Down
11 changes: 6 additions & 5 deletions pallets/registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub mod weights;

#[frame_support::pallet]
pub mod pallet {
use entropy_shared::{NETWORK_PARENT_KEY, SIGNING_PARTY_SIZE, VERIFICATION_KEY_LENGTH};
use entropy_shared::{NETWORK_PARENT_KEY, TOTAL_SIGNERSZE, VERIFICATION_KEY_LENGTH};
use frame_support::{
dispatch::{DispatchResultWithPostInfo, Pays},
pallet_prelude::*,
Expand Down Expand Up @@ -316,8 +316,8 @@ pub mod pallet {
/// Allows validators to signal a successful network jumpstart
#[pallet::call_index(1)]
#[pallet::weight({
<T as Config>::WeightInfo::confirm_jump_start_confirm(SIGNING_PARTY_SIZE as u32)
.max(<T as Config>::WeightInfo::confirm_jump_start_done(SIGNING_PARTY_SIZE as u32))
<T as Config>::WeightInfo::confirm_jump_start_confirm(TOTAL_SIGNERSZE as u32)
.max(<T as Config>::WeightInfo::confirm_jump_start_done(TOTAL_SIGNERSZE as u32))
})]
pub fn confirm_jump_start(
origin: OriginFor<T>,
Expand Down Expand Up @@ -357,7 +357,7 @@ pub mod pallet {
// ensure that registration was indeed successful.
//
// If it fails we'll need to allow another jumpstart.
if jump_start_info.confirmations.len() == (SIGNING_PARTY_SIZE - 1) {
if jump_start_info.confirmations.len() == (TOTAL_SIGNERSZE - 1) {
// registration finished, lock call
jump_start_info.confirmations.push(validator_stash);
let confirmations = jump_start_info.confirmations.len();
Expand All @@ -367,7 +367,8 @@ pub mod pallet {
confirmations: vec![],
verifying_key: jump_start_info.verifying_key,
});

// Jumpstart participants become first network signers
pallet_staking_extension::Signers::<T>::put(jump_start_info.confirmations);
Self::deposit_event(Event::FinishedNetworkJumpStart());

return Ok(Some(<T as Config>::WeightInfo::confirm_jump_start_done(
Expand Down
3 changes: 1 addition & 2 deletions pallets/registry/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
(7, (4, NULL_ARR, vec![50])),
],
proactive_refresh_data: (vec![], vec![]),
mock_signer_rotate: false,
inital_signers: vec![5, 6],
mock_signer_rotate: (false, vec![]),
};

pallet_staking_extension.assimilate_storage(&mut t).unwrap();
Expand Down
5 changes: 5 additions & 0 deletions pallets/registry/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ fn it_tests_jump_start_result() {
},
"Jump start in done status after all confirmations"
);
assert_eq!(
pallet_staking_extension::Signers::<Test>::get(),
vec![1, 2],
"Jumpstart sets inital signers"
);
});
}

Expand Down
8 changes: 4 additions & 4 deletions pallets/staking/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

//! Benchmarking setup for pallet-propgation
#![allow(unused_imports)]
use entropy_shared::SIGNING_PARTY_SIZE;
use entropy_shared::TOTAL_SIGNERSZE;
use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite, whitelisted_caller};
use frame_support::{
assert_ok, ensure,
Expand Down Expand Up @@ -178,10 +178,10 @@ benchmarks! {
}

confirm_key_reshare_confirmed {
let c in 0 .. SIGNING_PARTY_SIZE as u32;
let c in 0 .. TOTAL_SIGNERSZE as u32;
// leave a space for two as not to rotate and only confirm rotation
let confirmation_num = c.checked_sub(2).unwrap_or(0);
let signer_num = SIGNING_PARTY_SIZE - 1;
let signer_num = TOTAL_SIGNERSZE - 1;
let caller: T::AccountId = whitelisted_caller();
let validator_id_res = <T as pallet_session::Config>::ValidatorId::try_from(caller.clone()).or(Err(Error::<T>::InvalidValidatorId)).unwrap();
let second_signer: T::AccountId = account("second_signer", 0, SEED);
Expand All @@ -205,7 +205,7 @@ benchmarks! {

confirm_key_reshare_completed {
// once less confirmation to always flip to rotate
let confirmation_num = SIGNING_PARTY_SIZE - 1;
let confirmation_num = TOTAL_SIGNERSZE - 1;

let caller: T::AccountId = whitelisted_caller();
let validator_id_res = <T as pallet_session::Config>::ValidatorId::try_from(caller.clone()).or(Err(Error::<T>::InvalidValidatorId)).unwrap();
Expand Down
12 changes: 5 additions & 7 deletions pallets/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ use sp_staking::SessionIndex;
#[frame_support::pallet]
pub mod pallet {
use entropy_shared::{
ValidatorInfo, X25519PublicKey, SIGNING_PARTY_SIZE, TEST_RESHARE_BLOCK_NUMBER,
ValidatorInfo, X25519PublicKey, TOTAL_SIGNERSZE, TEST_RESHARE_BLOCK_NUMBER,
};
use frame_support::{
dispatch::{DispatchResult, DispatchResultWithPostInfo},
Expand Down Expand Up @@ -199,11 +199,10 @@ pub mod pallet {
#[derive(DefaultNoBound)]
pub struct GenesisConfig<T: Config> {
pub threshold_servers: Vec<ThresholdServersConfig<T>>,
pub inital_signers: Vec<T::ValidatorId>,
/// validator info and accounts to take part in proactive refresh
pub proactive_refresh_data: (Vec<ValidatorInfo>, Vec<Vec<u8>>),
/// validator info and account to take part in a reshare
pub mock_signer_rotate: bool,
pub mock_signer_rotate: (bool, Vec<T::ValidatorId>),
}

#[pallet::genesis_build]
Expand All @@ -225,7 +224,6 @@ pub mod pallet {
ThresholdServers::<T>::insert(validator_stash, server_info.clone());
ThresholdToStash::<T>::insert(&server_info.tss_account, validator_stash);
IsValidatorSynced::<T>::insert(validator_stash, true);
Signers::<T>::put(&self.inital_signers);
}

let refresh_info = RefreshInfo {
Expand All @@ -234,9 +232,9 @@ pub mod pallet {
};
ProactiveRefresh::<T>::put(refresh_info);
// mocks a signer rotation for tss new_reshare tests
if self.mock_signer_rotate {
if self.mock_signer_rotate.0 {
NextSigners::<T>::put(NextSignerInfo {
next_signers: self.inital_signers.clone(),
next_signers: self.mock_signer_rotate.clone().1,
confirmations: vec![],
});

Expand Down Expand Up @@ -441,7 +439,7 @@ pub mod pallet {

#[pallet::call_index(5)]
#[pallet::weight(({
<T as Config>::WeightInfo::confirm_key_reshare_confirmed(SIGNING_PARTY_SIZE as u32)
<T as Config>::WeightInfo::confirm_key_reshare_confirmed(TOTAL_SIGNERSZE as u32)
.max(<T as Config>::WeightInfo::confirm_key_reshare_completed())
}, DispatchClass::Operational))]
pub fn confirm_key_reshare(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
Expand Down
3 changes: 1 addition & 2 deletions pallets/staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,8 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
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]))],
inital_signers: vec![5, 6],
proactive_refresh_data: (vec![], vec![]),
mock_signer_rotate: false,
mock_signer_rotate: (false, vec![]),
};

pallet_balances.assimilate_storage(&mut t).unwrap();
Expand Down

0 comments on commit 425c4dc

Please sign in to comment.