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

Select validators for jumpstart DKG #1053

Merged
merged 32 commits into from
Sep 19, 2024
Merged

Conversation

ameba23
Copy link
Contributor

@ameba23 ameba23 commented Sep 13, 2024

Closes #1052

This selects n validators for initial jumpstart DKG when handling the jumpstart extrinsic, using on-chain randomness.

I've also removed the signature request account field from some types relating to DKG, since DKG is now only used for network jumpstart.

@ameba23 ameba23 marked this pull request as draft September 13, 2024 19:11
@ameba23 ameba23 changed the title Select validators for jumpstart DKG based on block number Select validators for jumpstart DKG Sep 16, 2024
for validator_name in validators_names {
let mnemonic = development_mnemonic(&Some(validator_name));
let (tss_signer, _static_secret) =
get_signer_and_x25519_secret_from_mnemonic(&mnemonic.to_string()).unwrap();
let jump_start_confirm_request =
entropy::tx().registry().confirm_jump_start(BoundedVec(EVE_VERIFYING_KEY.to_vec()));

submit_transaction(api, rpc, &tss_signer, &jump_start_confirm_request, None).await.unwrap();
// Ignore the error as one confirmation will fail
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we don't know which validators are going to be picked, but we want all those who are picked to send confirmations. Since nothing bad happens if the wrong one confirms, we just have them all send confirmations here.

@ameba23 ameba23 marked this pull request as ready for review September 17, 2024 10:37
Copy link
Collaborator

@HCastano HCastano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only thing I'm worried about here is the order when reading from a storage map, but otherwise looks good

pallets/registry/src/benchmarking.rs Outdated Show resolved Hide resolved
Comment on lines 276 to 279
// Check that the confirmation is coming from one of the selected validators
let (_block_number, selected_validators) =
JumpstartDkg::<T>::iter().last().ok_or(Error::<T>::JumpStartNotInProgress)?;
let selected_validators: Vec<_> =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this is consistently giving you the entry with the latest block? From the docs it says that iterating on a map doesn't guarantee any order

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the docs of the iter() function from IterableStorageMap which is a trait that StorageMap implements:

'Enumerate all elements in the map in lexicographical order of the encoded key'
https://paritytech.github.io/polkadot-sdk/master/frame_support/storage/trait.IterableStorageMap.html#tymethod.iter

So the question is whether lexicographically sorting scale encoded block numbers is the same as sorting them numerically. I think block numbers become a U256, but not sure about the encoding of a U256. I could try to write a test to figure it out.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@HCastano so in the end - good catch!

I wrote a test and iterating over block numbers in a StorageMap gives them in what appears to be arbitrary order despite them being sorted after being encoded, so no idea what encoding is being used. So i've changed this to use a comparison on the decoded key. I've left the test in, not sure if we really need it.

pallets/registry/src/tests.rs Show resolved Hide resolved
Comment on lines 108 to 113
<JumpstartDkg<T>>::set(block_number, vec![
ValidatorInfo {
x25519_public_key: [0; 32],
ip_address: vec![20],
tss_account: accounts[1].encode(),
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the size of this list can vary depending on the number of validators, we should probably take this into account during the benches

Copy link
Contributor Author

@ameba23 ameba23 Sep 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok - i have changed these to add MAX_SIGNERS validators. I am not totally sure the way i have done it makes sense, but the benches seem to run successfully.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense in the context of the benches, but I think the benches are actually parameterized wrong.

@JesseAbram doesn't look like we're using c in these benches, only the MAX_SIGNERS. Maybe something to follow up on?

pallets/registry/src/benchmarking.rs Outdated Show resolved Hide resolved
@ameba23 ameba23 requested a review from HCastano September 18, 2024 10:08
pallets/registry/src/lib.rs Show resolved Hide resolved
pallets/registry/src/tests.rs Show resolved Hide resolved
pallets/registry/src/benchmarking.rs Outdated Show resolved Hide resolved
Comment on lines 108 to 113
<JumpstartDkg<T>>::set(block_number, vec![
ValidatorInfo {
x25519_public_key: [0; 32],
ip_address: vec![20],
tss_account: accounts[1].encode(),
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense in the context of the benches, but I think the benches are actually parameterized wrong.

@JesseAbram doesn't look like we're using c in these benches, only the MAX_SIGNERS. Maybe something to follow up on?

Copy link
Collaborator

@HCastano HCastano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fixes!

@@ -117,12 +126,22 @@ benchmarks! {
let threshold_account: T::AccountId = whitelisted_caller();
let expected_verifying_key = BoundedVec::default();

// add validators and a registering user
// add validators
for i in 0..MAX_SIGNERS {
let validators = add_non_syncing_validators::<T>(MAX_SIGNERS as u32, 0);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not relevant to this PR, but while we are on the topic of whether stuff in this benchmark makes sense:
I am wondering why this line is inside the for loop and not before it.
Why do we need to call add_non_syncing_validators 15 times?

…/entropy-core into peg/select-initial-validators

* 'peg/select-initial-validators' of github.com:entropyxyz/entropy-core:
  Update pallets/registry/src/benchmarking.rs
@ameba23 ameba23 merged commit 959ce98 into master Sep 19, 2024
8 checks passed
@ameba23 ameba23 deleted the peg/select-initial-validators branch September 19, 2024 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Selecting initial validators for jumpstart DKG
2 participants