-
Notifications
You must be signed in to change notification settings - Fork 1.2k
migrate pallet-mixnet to umbrella crate #6986
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
Changes from all commits
03c0254
de7d2f1
fedc90f
d7d411e
c27a6e3
0266ff3
59a9402
1474e43
268da64
5a0638f
d329f1a
3cca750
845d618
e3edd3d
178976d
e786607
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0 | ||
| # See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json | ||
|
|
||
| title: '[pallet-mixnet] Migrate to using frame umbrella crate' | ||
|
|
||
| doc: | ||
| - audience: Runtime Dev | ||
| description: This PR migrates the pallet-mixnet to use the frame umbrella crate. This | ||
| is part of the ongoing effort to migrate all pallets to use the frame umbrella crate. | ||
| The effort is tracked [here](https://github.com/paritytech/polkadot-sdk/issues/6504). | ||
|
|
||
| crates: | ||
| - name: pallet-mixnet | ||
| bump: minor | ||
| - name: polkadot-sdk-frame | ||
| bump: minor | ||
| - name: polkadot-sdk | ||
| bump: none |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,28 +23,23 @@ | |
|
|
||
| extern crate alloc; | ||
|
|
||
| pub use pallet::*; | ||
|
|
||
| use alloc::vec::Vec; | ||
| use codec::{Decode, Encode, MaxEncodedLen}; | ||
| use core::cmp::Ordering; | ||
| use frame_support::{ | ||
| traits::{EstimateNextSessionRotation, Get, OneSessionHandler}, | ||
| BoundedVec, | ||
| use frame::{ | ||
| deps::{ | ||
| sp_io::{self, MultiRemovalResults}, | ||
| sp_runtime, | ||
| }, | ||
| prelude::*, | ||
| }; | ||
| use frame_system::{ | ||
| offchain::{CreateInherent, SubmitTransaction}, | ||
| pallet_prelude::BlockNumberFor, | ||
| }; | ||
| pub use pallet::*; | ||
| use scale_info::TypeInfo; | ||
| use serde::{Deserialize, Serialize}; | ||
| use sp_application_crypto::RuntimeAppPublic; | ||
| use sp_arithmetic::traits::{CheckedSub, Saturating, UniqueSaturatedInto, Zero}; | ||
| use sp_io::MultiRemovalResults; | ||
| use sp_mixnet::types::{ | ||
| AuthorityId, AuthoritySignature, KxPublic, Mixnode, MixnodesErr, PeerId, SessionIndex, | ||
| SessionPhase, SessionStatus, KX_PUBLIC_SIZE, | ||
| }; | ||
| use sp_runtime::RuntimeDebug; | ||
|
|
||
| const LOG_TARGET: &str = "runtime::mixnet"; | ||
|
|
||
|
|
@@ -168,12 +163,9 @@ fn twox<BlockNumber: UniqueSaturatedInto<u64>>( | |
| // The pallet | ||
| //////////////////////////////////////////////////////////////////////////////// | ||
|
|
||
| #[frame_support::pallet(dev_mode)] | ||
| #[frame::pallet(dev_mode)] | ||
|
Contributor
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. This
Member
Author
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 see, will have to dig in the code to understand why but we could create an issue for it if there's isn't one already.
Contributor
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. Think this is just because I never got around to adding weights. |
||
| pub mod pallet { | ||
| use super::*; | ||
| use frame_support::pallet_prelude::*; | ||
| use frame_system::pallet_prelude::*; | ||
|
|
||
| #[pallet::pallet] | ||
| pub struct Pallet<T>(_); | ||
|
|
||
|
|
@@ -254,7 +246,7 @@ pub mod pallet { | |
| StorageDoubleMap<_, Identity, SessionIndex, Identity, AuthorityIndex, BoundedMixnodeFor<T>>; | ||
|
|
||
| #[pallet::genesis_config] | ||
| #[derive(frame_support::DefaultNoBound)] | ||
| #[derive(DefaultNoBound)] | ||
| pub struct GenesisConfig<T: Config> { | ||
| /// The mixnode set for the very first session. | ||
| pub mixnodes: BoundedVec<BoundedMixnodeFor<T>, T::MaxAuthorities>, | ||
|
|
@@ -308,7 +300,7 @@ pub mod pallet { | |
|
|
||
| fn validate_unsigned(_source: TransactionSource, call: &Self::Call) -> TransactionValidity { | ||
| let Self::Call::register { registration, signature } = call else { | ||
| return InvalidTransaction::Call.into() | ||
| return InvalidTransaction::Call.into(); | ||
| }; | ||
|
|
||
| // Check session index matches | ||
|
|
@@ -320,16 +312,16 @@ pub mod pallet { | |
|
|
||
| // Check authority index is valid | ||
| if registration.authority_index >= T::MaxAuthorities::get() { | ||
| return InvalidTransaction::BadProof.into() | ||
| return InvalidTransaction::BadProof.into(); | ||
| } | ||
| let Some(authority_id) = NextAuthorityIds::<T>::get(registration.authority_index) | ||
| else { | ||
| return InvalidTransaction::BadProof.into() | ||
| return InvalidTransaction::BadProof.into(); | ||
| }; | ||
|
|
||
| // Check the authority hasn't registered a mixnode yet | ||
| if Self::already_registered(registration.session_index, registration.authority_index) { | ||
| return InvalidTransaction::Stale.into() | ||
| return InvalidTransaction::Stale.into(); | ||
| } | ||
|
|
||
| // Check signature. Note that we don't use regular signed transactions for registration | ||
|
|
@@ -339,7 +331,7 @@ pub mod pallet { | |
| authority_id.verify(&encoded_registration, signature) | ||
| }); | ||
| if !signature_ok { | ||
| return InvalidTransaction::BadProof.into() | ||
| return InvalidTransaction::BadProof.into(); | ||
| } | ||
|
|
||
| ValidTransaction::with_tag_prefix("MixnetRegistration") | ||
|
|
@@ -368,12 +360,12 @@ impl<T: Config> Pallet<T> { | |
| .saturating_sub(CurrentSessionStartBlock::<T>::get()); | ||
| let Some(block_in_phase) = block_in_phase.checked_sub(&T::NumCoverToCurrentBlocks::get()) | ||
| else { | ||
| return SessionPhase::CoverToCurrent | ||
| return SessionPhase::CoverToCurrent; | ||
| }; | ||
| let Some(block_in_phase) = | ||
| block_in_phase.checked_sub(&T::NumRequestsToCurrentBlocks::get()) | ||
| else { | ||
| return SessionPhase::RequestsToCurrent | ||
| return SessionPhase::RequestsToCurrent; | ||
|
kianenigma marked this conversation as resolved.
|
||
| }; | ||
| if block_in_phase < T::NumCoverToPrevBlocks::get() { | ||
| SessionPhase::CoverToPrev | ||
|
|
@@ -411,7 +403,7 @@ impl<T: Config> Pallet<T> { | |
| return Err(MixnodesErr::InsufficientRegistrations { | ||
| num: 0, | ||
| min: T::MinMixnodes::get(), | ||
| }) | ||
| }); | ||
| }; | ||
| Self::mixnodes(prev_session_index) | ||
| } | ||
|
|
@@ -430,15 +422,15 @@ impl<T: Config> Pallet<T> { | |
| // registering | ||
| let block_in_session = block_number.saturating_sub(CurrentSessionStartBlock::<T>::get()); | ||
| if block_in_session < T::NumRegisterStartSlackBlocks::get() { | ||
| return false | ||
| return false; | ||
|
UtkarshBhardwaj007 marked this conversation as resolved.
|
||
| } | ||
|
|
||
| let (Some(end_block), _weight) = | ||
| T::NextSessionRotation::estimate_next_session_rotation(block_number) | ||
| else { | ||
| // Things aren't going to work terribly well in this case as all the authorities will | ||
| // just pile in after the slack period... | ||
| return true | ||
| return true; | ||
| }; | ||
|
|
||
| let remaining_blocks = end_block | ||
|
|
@@ -447,7 +439,7 @@ impl<T: Config> Pallet<T> { | |
| if remaining_blocks.is_zero() { | ||
| // Into the slack time at the end of the session. Not necessarily too late; | ||
| // registrations are accepted right up until the session ends. | ||
| return true | ||
| return true; | ||
| } | ||
|
|
||
| // Want uniform distribution over the remaining blocks, so pick this block with probability | ||
|
|
@@ -496,7 +488,7 @@ impl<T: Config> Pallet<T> { | |
| "Session {session_index} registration attempted, \ | ||
| but current session is {current_session_index}", | ||
| ); | ||
| return false | ||
| return false; | ||
| } | ||
|
|
||
| let block_number = frame_system::Pallet::<T>::block_number(); | ||
|
|
@@ -505,30 +497,30 @@ impl<T: Config> Pallet<T> { | |
| target: LOG_TARGET, | ||
| "Waiting for the session to progress further before registering", | ||
| ); | ||
| return false | ||
| return false; | ||
| } | ||
|
|
||
| let Some((authority_index, authority_id)) = Self::next_local_authority() else { | ||
| log::trace!( | ||
| target: LOG_TARGET, | ||
| "Not an authority in the next session; cannot register a mixnode", | ||
| ); | ||
| return false | ||
| return false; | ||
| }; | ||
|
|
||
| if Self::already_registered(session_index, authority_index) { | ||
| log::trace!( | ||
| target: LOG_TARGET, | ||
| "Already registered a mixnode for the next session", | ||
| ); | ||
| return false | ||
| return false; | ||
| } | ||
|
|
||
| let registration = | ||
| Registration { block_number, session_index, authority_index, mixnode: mixnode.into() }; | ||
| let Some(signature) = authority_id.sign(®istration.encode()) else { | ||
| log::debug!(target: LOG_TARGET, "Failed to sign registration"); | ||
| return false | ||
| return false; | ||
| }; | ||
| let call = Call::register { registration, signature }; | ||
| let xt = T::create_inherent(call.into()); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.