Skip to content

Commit

Permalink
Set inital signers (#971)
Browse files Browse the repository at this point in the history
* Set inital signers

* Set init signers in jumpstart

* fix benches

* fix timing

* changelog

* clean
  • Loading branch information
JesseAbram authored Aug 1, 2024
1 parent 5c69d8b commit 704ada4
Show file tree
Hide file tree
Showing 18 changed files with 70 additions and 66 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ At the moment this project **does not** adhere to
- Add Signer groups and rotation ([#938](https://github.com/entropyxyz/entropy-core/pull/938))
- Split jumpstart and register flows ([#952](https://github.com/entropyxyz/entropy-core/pull/952))
- Reshare confirmation ([#965](https://github.com/entropyxyz/entropy-core/pull/965))
- Set inital signers ([#971](https://github.com/entropyxyz/entropy-core/pull/971))

## [0.2.0](https://github.com/entropyxyz/entropy-core/compare/release/v0.1.0...release/v0.2.0) - 2024-07-11

Expand Down
2 changes: 0 additions & 2 deletions crates/shared/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ 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;

// 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_SIGNERS,
};
use futures::{
channel::mpsc,
Expand Down
2 changes: 1 addition & 1 deletion crates/threshold-signature-server/src/user/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ async fn test_jumpstart_network() {

// wait for jump start event check that key exists in kvdb
let mut got_jumpstart_event = false;
for _ in 0..45 {
for _ in 0..75 {
std::thread::sleep(std::time::Duration::from_millis(1000));
let block_hash = rpc.chain_get_block_hash(None).await.unwrap();
let events = EventsClient::new(api.clone()).at(block_hash.unwrap()).await.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion crates/threshold-signature-server/src/validator/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ pub async fn new_reshare(
) -> Result<StatusCode, ValidatorErr> {
let data = OcwMessageReshare::decode(&mut encoded_data.as_ref())?;
// TODO: validate message came from chain (check reshare block # against current block number) see #941

let api = get_api(&app_state.configuration.endpoint).await?;
let rpc = get_rpc(&app_state.configuration.endpoint).await?;
validate_new_reshare(&api, &rpc, &data, &app_state.kv_store).await?;
Expand All @@ -79,6 +78,7 @@ pub async fn new_reshare(
let validators_info = get_validators_info(&api, &rpc, next_signers)
.await
.map_err(|e| ValidatorErr::UserError(e.to_string()))?;

let (signer, x25519_secret_key) = get_signer_and_x25519_secret(&app_state.kv_store)
.await
.map_err(|e| ValidatorErr::UserError(e.to_string()))?;
Expand Down
2 changes: 1 addition & 1 deletion crates/threshold-signature-server/src/validator/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ async fn setup_for_reshare(
let jump_start_request = entropy::tx().registry().jump_start_network();
let _result = submit_transaction(api, rpc, &signer, &jump_start_request, None).await.unwrap();

let validators_names = vec![ValidatorName::Alice, ValidatorName::Bob];
let validators_names = vec![ValidatorName::Alice, ValidatorName::Bob, ValidatorName::Charlie];
for validator_name in validators_names {
let mnemonic = development_mnemonic(&Some(validator_name));
let (tss_signer, _static_secret) =
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![], 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<_>>(), vec![get_account_id_from_seed::<sr25519::Public>("Alice")],),
},
"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![], 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![], vec![]),
};

pallet_staking_extension.assimilate_storage(&mut t).unwrap();
Expand Down
22 changes: 11 additions & 11 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_SIGNERS, 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,26 +79,26 @@ benchmarks! {
}

confirm_jump_start_done {
let c in 0 .. SIGNING_PARTY_SIZE as u32;
let c in 0 .. TOTAL_SIGNERS 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_SIGNERS {
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_SIGNERS as u32, 0);
<Validators<T>>::set(validators.clone());

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

<JumpStartProgress<T>>::put(JumpStartDetails {
jump_start_status: JumpStartStatus::InProgress(0),
confirmations: vec![validators[0].clone()],
confirmations: vec![validators[0].clone(), validators[0].clone()],
verifying_key: None
});

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

confirm_jump_start_confirm {
let c in 0 .. SIGNING_PARTY_SIZE as u32;
let c in 0 .. TOTAL_SIGNERS 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_SIGNERS {
let validators = add_non_syncing_validators::<T>(TOTAL_SIGNERS as u32, 0);
<Validators<T>>::set(validators.clone());
<ThresholdToStash<T>>::insert(&threshold_account, &validators[i]);
<ThresholdToStash<T>>::insert(&threshold_account, &validators[i as usize]);
}
<JumpStartProgress<T>>::put(JumpStartDetails {
jump_start_status: JumpStartStatus::InProgress(0),
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_SIGNERS, 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_SIGNERS as u32)
.max(<T as Config>::WeightInfo::confirm_jump_start_done(TOTAL_SIGNERS 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_SIGNERS as usize - 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
5 changes: 2 additions & 3 deletions pallets/registry/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,13 +365,12 @@ 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![], vec![]),
};

pallet_staking_extension.assimilate_storage(&mut t).unwrap();

let stakers = vec![1, 2];
let stakers = vec![1, 2, 5];
let keys: Vec<_> = stakers.iter().cloned().map(|i| (i, i, UintAuthorityId(i).into())).collect();

pallet_session::GenesisConfig::<Test> { keys }.assimilate_storage(&mut t).unwrap();
Expand Down
24 changes: 21 additions & 3 deletions pallets/registry/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ fn it_tests_get_validators_info() {
ServerInfo { tss_account: 3, x25519_public_key: NULL_ARR, endpoint: vec![10] };
let server_info_2 =
ServerInfo { tss_account: 4, x25519_public_key: NULL_ARR, endpoint: vec![11] };
let server_info_3 =
ServerInfo { tss_account: 7, x25519_public_key: NULL_ARR, endpoint: vec![20] };

assert_eq!(result_1, vec![server_info_1, server_info_2]);
assert_eq!(result_1, vec![server_info_1, server_info_2, server_info_3]);
});
}

Expand Down Expand Up @@ -184,10 +186,15 @@ fn it_tests_jump_start_result() {
);

pallet_staking_extension::ThresholdToStash::<Test>::insert(2, 2);
pallet_staking_extension::ThresholdToStash::<Test>::insert(5, 5);
assert_ok!(Registry::confirm_jump_start(
RuntimeOrigin::signed(2),
expected_verifying_key.clone()
));
assert_ok!(Registry::confirm_jump_start(
RuntimeOrigin::signed(5),
expected_verifying_key.clone()
));
assert_eq!(
Registry::jump_start_progress(),
JumpStartDetails {
Expand All @@ -197,6 +204,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, 5],
"Jumpstart sets inital signers"
);
});
}

Expand Down Expand Up @@ -258,7 +270,7 @@ fn it_confirms_registers_a_user() {
);

assert_noop!(
Registry::confirm_register(RuntimeOrigin::signed(7), 1, expected_verifying_key.clone()),
Registry::confirm_register(RuntimeOrigin::signed(8), 1, expected_verifying_key.clone()),
Error::<Test>::NotValidator
);

Expand All @@ -278,6 +290,12 @@ fn it_confirms_registers_a_user() {
expected_verifying_key.clone()
));

assert_ok!(Registry::confirm_register(
RuntimeOrigin::signed(7),
1,
expected_verifying_key.clone()
));

assert_eq!(Registry::registering(1), None);
assert_eq!(
Registry::registered(expected_verifying_key.clone()).unwrap(),
Expand Down Expand Up @@ -794,7 +812,7 @@ fn it_provides_free_txs_confirm_done_fails_4() {
});
let di = c.get_dispatch_info();
assert_eq!(di.pays_fee, Pays::No);
let r = p.validate(&7, &c, &di, 20);
let r = p.validate(&8, &c, &di, 20);
assert_eq!(r, TransactionValidity::Ok(ValidTransaction::default()));
});
}
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_SIGNERS;
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_SIGNERS 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_SIGNERS - 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_SIGNERS as usize - 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
Loading

0 comments on commit 704ada4

Please sign in to comment.