-
Notifications
You must be signed in to change notification settings - Fork 2
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
Update pallet-relayer
to use Contraints V2
#433
Changes from all commits
d6212ad
2f451c4
2c35d89
f5e39a5
c7076ce
067a5d4
4eb1842
8a7ebe3
cf0ace9
b4a0c49
6d17b7a
9f4d82f
444eef8
996c34d
4f941aa
1822952
272b24e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,24 @@ | ||
//! # Relayer Pallet | ||
//! | ||
//! | ||
//! ## Overview | ||
//! | ||
//! Allows a user to ask to sign, register with the network and allows a node to confirm | ||
//! signing was completed properly. | ||
//! Entrypoint into the Entropy network. | ||
//! | ||
//! It allows a user to submit a registration request to the network initiating the distributed key | ||
//! generation (DKG) process. | ||
//! | ||
//! After this process validator nodes on the network can confirm that they have received a | ||
//! key-share from the registering user. Once enough validators have signaled that they have the | ||
//! user's key-share (right now this is one validator per partition) the user can be considered as | ||
//! registered. | ||
//! | ||
//! ### Public Functions | ||
//! | ||
//! prep_transaction - declares intent to sign, this gets relayed to thereshold network | ||
//! register - register's a user and that they have created and distributed entropy shards | ||
//! confirm_done - allows a node to confirm signing has happened and if a failure occured | ||
//! `register` - Allows a user to signal their intent to register onto the Entropy network. | ||
//! `confirm_register` - Allows validator nodes to confirm that they have recieved a user's | ||
//! key-share. After enough succesful confirmations from validators that user will be succesfully | ||
//! registered. | ||
|
||
#![cfg_attr(not(feature = "std"), no_std)] | ||
#![allow(clippy::new_without_default)] | ||
#![allow(clippy::or_fun_call)] | ||
|
@@ -30,7 +38,7 @@ pub mod weights; | |
|
||
#[frame_support::pallet] | ||
pub mod pallet { | ||
use entropy_shared::{Constraints, KeyVisibility, SIGNING_PARTY_SIZE}; | ||
use entropy_shared::{KeyVisibility, SIGNING_PARTY_SIZE}; | ||
use frame_support::{ | ||
dispatch::{DispatchResult, DispatchResultWithPostInfo, Pays}, | ||
inherent::Vec, | ||
|
@@ -66,9 +74,9 @@ pub mod pallet { | |
#[scale_info(skip_type_params(T))] | ||
pub struct RegisteringDetails<T: Config> { | ||
pub is_registering: bool, | ||
pub constraint_account: T::AccountId, | ||
pub program_modification_account: T::AccountId, | ||
pub confirmations: Vec<u8>, | ||
pub constraints: Option<Constraints>, | ||
pub program: Vec<u8>, | ||
pub key_visibility: KeyVisibility, | ||
} | ||
|
||
|
@@ -162,54 +170,58 @@ pub mod pallet { | |
IpAddressError, | ||
SigningGroupError, | ||
NoSyncedValidators, | ||
MaxProgramLengthExceeded, | ||
} | ||
|
||
/// Allows a user to kick off signing process | ||
/// `sig_request`: signature request for user | ||
#[pallet::call] | ||
impl<T: Config> Pallet<T> { | ||
/// Signals that a user wants to register an account with Entropy. | ||
/// Allows a user to signal that they want to register an account with the Entropy network. | ||
/// | ||
/// This should be called by the signature-request account, and specify the initial | ||
/// constraint-modification `AccountId` that can set constraints. | ||
/// The caller provides an initial program, if any, an account which is able to modify a | ||
/// the program, and the program's permission level on the network. | ||
/// | ||
/// Note that a user needs to be confirmed by validators through the | ||
/// [`Self::confirm_register`] extrinsic before they can be considered as registered on the | ||
/// network. | ||
#[pallet::call_index(0)] | ||
#[pallet::weight({ | ||
let (mut evm_acl_len, mut btc_acl_len) = (0, 0); | ||
if let Some(constraints) = &initial_constraints { | ||
(evm_acl_len, btc_acl_len) = ConstraintsPallet::<T>::constraint_weight_values(constraints); | ||
} | ||
<T as Config>::WeightInfo::register(evm_acl_len, btc_acl_len) | ||
<T as Config>::WeightInfo::register(initial_program.len() as u32) | ||
})] | ||
pub fn register( | ||
origin: OriginFor<T>, | ||
constraint_account: T::AccountId, | ||
program_modification_account: T::AccountId, | ||
key_visibility: KeyVisibility, | ||
initial_constraints: Option<Constraints>, | ||
initial_program: Vec<u8>, | ||
) -> DispatchResult { | ||
let sig_req_account = ensure_signed(origin)?; | ||
|
||
// ensure account isn't already registered or has existing constraints | ||
// Ensure account isn't already registered or has existing constraints | ||
ensure!(!Registered::<T>::contains_key(&sig_req_account), Error::<T>::AlreadySubmitted); | ||
ensure!( | ||
!Registering::<T>::contains_key(&sig_req_account), | ||
Error::<T>::AlreadySubmitted | ||
); | ||
if let Some(constraints) = &initial_constraints { | ||
ConstraintsPallet::<T>::validate_constraints(constraints)?; | ||
} | ||
|
||
ensure!( | ||
initial_program.len() as u32 | ||
<= <T as pallet_constraints::Config>::MaxV2BytecodeLength::get(), | ||
Error::<T>::MaxProgramLengthExceeded, | ||
); | ||
|
||
let block_number = <frame_system::Pallet<T>>::block_number(); | ||
Dkg::<T>::try_mutate(block_number, |messages| -> Result<_, DispatchError> { | ||
messages.push(sig_req_account.clone().encode()); | ||
Ok(()) | ||
})?; | ||
// put account into a registering state | ||
|
||
// Put account into a registering state | ||
Registering::<T>::insert( | ||
&sig_req_account, | ||
RegisteringDetails::<T> { | ||
is_registering: true, | ||
constraint_account: constraint_account.clone(), | ||
program_modification_account, | ||
confirmations: vec![], | ||
constraints: initial_constraints, | ||
program: initial_program, | ||
key_visibility, | ||
}, | ||
); | ||
|
@@ -222,9 +234,11 @@ pub mod pallet { | |
Ok(()) | ||
} | ||
|
||
/// Used by validators to confirm they have received a key-share from a user that is | ||
/// registering. After a validator from each partition confirms they have a | ||
/// keyshare, this should get the user to a `Registered` state | ||
/// Allows validators to confirm that they have received a key-share from a user that is | ||
/// in the process of registering. | ||
/// | ||
/// After a validator from each partition confirms they have a keyshare the user will be | ||
/// considered as registered on the network. | ||
#[pallet::call_index(2)] | ||
#[pallet::weight({ | ||
let weight = | ||
|
@@ -271,17 +285,15 @@ pub mod pallet { | |
Registering::<T>::remove(&sig_req_account); | ||
|
||
AllowedToModifyConstraints::<T>::insert( | ||
®istering_info.constraint_account, | ||
®istering_info.program_modification_account, | ||
sig_req_account.clone(), | ||
(), | ||
); | ||
|
||
if let Some(constraints) = registering_info.constraints { | ||
ConstraintsPallet::<T>::set_constraints_unchecked( | ||
&sig_req_account, | ||
&constraints, | ||
); | ||
} | ||
ConstraintsPallet::<T>::set_program_unchecked( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't like using set unchecked, as in set program we charge a deposit for length of program, here I believe people can post an arbitrary sized program for free There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From what I can tell this doesn't change the previous deposit/weight behaviour for this extrinsic. So the user calling the The validators never got charged this deposit since If we do want to charge for this some questions come up:
And technically the wouldn't be arbitrarily length program, they can only go up to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmmmm ya that does need to be solved, but we can charge them the deposit in the register extrinsic and then ya do set unchecked later on |
||
&sig_req_account, | ||
registering_info.program, | ||
)?; | ||
|
||
let weight = | ||
<T as Config>::WeightInfo::confirm_register_registered(confirmation_length); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI @frankiebee @jawndiego
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this requires we pass an initial program at registration?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe (pending the discussion below), but mostly that there's a change in field names and the type of a program (
Option
vs.Vec<u8>
).