From 7874beae1c22138ab3e43768ce2633590d2804e3 Mon Sep 17 00:00:00 2001 From: 1xstj <106580853+1xstj@users.noreply.github.com> Date: Wed, 14 Feb 2024 12:37:52 +0000 Subject: [PATCH] fix: Roles pallet - rename validators to restakers (#472) * rename all validators to restakers * set submission len to 32 --- pallets/dkg/src/mock.rs | 2 +- pallets/jobs/src/lib.rs | 4 +- pallets/jobs/src/mock.rs | 4 +- pallets/roles/src/benchmarking.rs | 4 +- pallets/roles/src/impls.rs | 35 +++++----- pallets/roles/src/lib.rs | 109 ++++++++++++++++-------------- pallets/roles/src/mock.rs | 4 +- pallets/roles/src/tests.rs | 4 +- precompiles/jobs/src/mock.rs | 6 +- precompiles/staking/src/lib.rs | 8 +-- precompiles/staking/src/tests.rs | 2 +- primitives/src/jobs/mod.rs | 2 +- primitives/src/roles/traits.rs | 6 +- runtime/mainnet/src/lib.rs | 4 +- runtime/testnet/src/lib.rs | 4 +- types/src/interfaces/lookup.ts | 2 +- 16 files changed, 110 insertions(+), 90 deletions(-) diff --git a/pallets/dkg/src/mock.rs b/pallets/dkg/src/mock.rs index 76671f4ac..2cd0774d4 100644 --- a/pallets/dkg/src/mock.rs +++ b/pallets/dkg/src/mock.rs @@ -80,7 +80,7 @@ parameter_types! { #[derive(Clone, Debug, Eq, PartialEq, TypeInfo)] pub const MaxParticipants: u32 = 10; #[derive(Clone, Debug, Eq, PartialEq, TypeInfo)] - pub const MaxSubmissionLen: u32 = 256; + pub const MaxSubmissionLen: u32 = 32; #[derive(Clone, Debug, Eq, PartialEq, TypeInfo)] pub const MaxKeyLen: u32 = 256; #[derive(Clone, Debug, Eq, PartialEq, TypeInfo)] diff --git a/pallets/jobs/src/lib.rs b/pallets/jobs/src/lib.rs index 7bedb8b3f..33a149e71 100644 --- a/pallets/jobs/src/lib.rs +++ b/pallets/jobs/src/lib.rs @@ -272,7 +272,7 @@ pub mod module { for participant in participants { ensure!( - T::RolesHandler::is_validator(participant.clone(), role_type), + T::RolesHandler::is_restaker(participant.clone(), role_type), Error::::InvalidValidator ); @@ -299,7 +299,7 @@ pub mod module { let participants = result.participants().ok_or(Error::::InvalidJobPhase)?; for participant in participants { ensure!( - T::RolesHandler::is_validator(participant.clone(), role_type), + T::RolesHandler::is_restaker(participant.clone(), role_type), Error::::InvalidValidator ); diff --git a/pallets/jobs/src/mock.rs b/pallets/jobs/src/mock.rs index 400c4a45e..b4a7a0464 100644 --- a/pallets/jobs/src/mock.rs +++ b/pallets/jobs/src/mock.rs @@ -322,6 +322,7 @@ impl pallet_staking::Config for Runtime { parameter_types! { pub InflationRewardPerSession: Balance = 10_000; + pub MaxRestake : Percent = Percent::from_percent(50); pub Reward : ValidatorRewardDistribution = ValidatorRewardDistribution::try_new(Percent::from_rational(1_u32,2_u32), Percent::from_rational(1_u32,2_u32)).unwrap(); } @@ -335,6 +336,7 @@ impl pallet_roles::Config for Runtime { type ValidatorSet = Historical; type ReportOffences = OffenceHandler; type MaxKeyLen = MaxKeyLen; + type MaxRestake = MaxRestake; type MaxRolesPerValidator = MaxActiveJobsPerValidator; type WeightInfo = (); } @@ -344,7 +346,7 @@ parameter_types! { #[derive(Clone, Debug, Eq, PartialEq, TypeInfo)] pub const MaxParticipants: u32 = 10; #[derive(Clone, Debug, Eq, PartialEq, TypeInfo)] - pub const MaxSubmissionLen: u32 = 256; + pub const MaxSubmissionLen: u32 = 32; #[derive(Clone, Debug, Eq, PartialEq, TypeInfo)] pub const MaxKeyLen: u32 = 256; #[derive(Clone, Debug, Eq, PartialEq, TypeInfo)] diff --git a/pallets/roles/src/benchmarking.rs b/pallets/roles/src/benchmarking.rs index 802ec1621..013600a38 100644 --- a/pallets/roles/src/benchmarking.rs +++ b/pallets/roles/src/benchmarking.rs @@ -112,7 +112,7 @@ mod benchmarks { fn update_profile() { let caller: T::AccountId = create_validator_account::("Alice"); let shared_profile = shared_profile::(); - let ledger = RoleStakingLedger::::new(caller.clone(), shared_profile.clone(), vec![]); + let ledger = RestakingLedger::::new(caller.clone(), shared_profile.clone(), vec![]); Ledger::::insert(caller.clone(), ledger); // Updating shared stake from 3000 to 5000 tokens let updated_profile = updated_profile::(); @@ -129,7 +129,7 @@ mod benchmarks { fn delete_profile() { let caller: T::AccountId = create_validator_account::("Alice"); let shared_profile = shared_profile::(); - let ledger = RoleStakingLedger::::new(caller.clone(), shared_profile.clone(), vec![]); + let ledger = RestakingLedger::::new(caller.clone(), shared_profile.clone(), vec![]); Ledger::::insert(caller.clone(), ledger); #[extrinsic_call] diff --git a/pallets/roles/src/impls.rs b/pallets/roles/src/impls.rs index 02d1ebcd3..714783916 100644 --- a/pallets/roles/src/impls.rs +++ b/pallets/roles/src/impls.rs @@ -23,12 +23,12 @@ use frame_support::{ }; use sp_runtime::{ traits::{CheckedDiv, Convert}, - Perbill, Percent, + Perbill, }; use sp_staking::offence::Offence; use tangle_primitives::{ - jobs::{traits::JobsHandler, JobId, ReportValidatorOffence}, + jobs::{traits::JobsHandler, JobId, ReportRestakerOffence}, roles::traits::RolesHandler, }; @@ -42,7 +42,7 @@ impl RolesHandler for Pallet { /// /// # Returns /// Returns `true` if the validator is permitted to work with this job type, otherwise `false`. - fn is_validator(address: T::AccountId, role_type: RoleType) -> bool { + fn is_restaker(address: T::AccountId, role_type: RoleType) -> bool { let assigned_roles = AccountRolesMapping::::get(address); assigned_roles.contains(&role_type) } @@ -57,7 +57,7 @@ impl RolesHandler for Pallet { /// /// Returns Ok() if validator offence report is submitted successfully. fn report_offence( - offence_report: ReportValidatorOffence, + offence_report: ReportRestakerOffence, ) -> sp_runtime::DispatchResult { Self::report_offence(offence_report) } @@ -192,7 +192,7 @@ impl Pallet { /// Check if account can chill, unbond and withdraw funds. /// /// # Parameters - /// - `account`: The account ID of the validator. + /// - `account`: The account ID of the restaker. /// /// # Returns /// Returns boolean value. @@ -208,14 +208,15 @@ impl Pallet { /// Calculate max restake amount for the given account. /// /// # Parameters - /// - `total_stake`: Total stake of the validator + /// - `total_stake`: Total stake of the restaker /// /// # Returns /// Returns the max restake amount. pub(crate) fn calculate_max_restake_amount(total_stake: BalanceOf) -> BalanceOf { // User can restake max 50% of the total stake - Percent::from_percent(50) * total_stake + T::MaxRestake::get() * total_stake } + /// Calculate slash value for restaked amount /// /// # Parameters @@ -232,17 +233,17 @@ impl Pallet { slash_fraction * total_stake } - /// Report offence for the given validator. - /// This function will report validators for committing offence. + /// Report offence for the given restaker. + /// This function will report restakers for committing offence. /// /// # Parameters /// - `offence_report`: The offence report. /// /// # Returns /// - /// Returns Ok() if validator offence report is submitted successfully. + /// Returns Ok() if restaker offence report is submitted successfully. pub(crate) fn report_offence( - offence_report: ReportValidatorOffence, + offence_report: ReportRestakerOffence, ) -> sp_runtime::DispatchResult { let offenders = offence_report .clone() @@ -288,10 +289,10 @@ impl Pallet { /// Update the ledger for the given stash account. /// /// # Parameters - /// - `staker`: The stash account ID. + /// - `restaker`: The stash account ID. /// - `ledger`: The new ledger. - pub(crate) fn update_ledger(staker: &T::AccountId, ledger: &RoleStakingLedger) { - >::insert(staker, ledger); + pub(crate) fn update_ledger(restaker: &T::AccountId, ledger: &RestakingLedger) { + >::insert(restaker, ledger); } pub fn distribute_rewards() -> DispatchResult { @@ -348,12 +349,12 @@ impl Pallet { Ok(()) } - pub fn update_ledger_role_key(staker: &T::AccountId, role_key: Vec) -> DispatchResult { - let mut ledger = Ledger::::get(staker).ok_or(Error::::NoProfileFound)?; + pub fn update_ledger_role_key(restaker: &T::AccountId, role_key: Vec) -> DispatchResult { + let mut ledger = Ledger::::get(restaker).ok_or(Error::::NoProfileFound)?; let bounded_role_key: BoundedVec = role_key.try_into().map_err(|_| Error::::KeySizeExceeded)?; ledger.role_key = bounded_role_key; - Self::update_ledger(staker, &ledger); + Self::update_ledger(restaker, &ledger); Ok(()) } } diff --git a/pallets/roles/src/lib.rs b/pallets/roles/src/lib.rs index a301739df..bc60a539e 100644 --- a/pallets/roles/src/lib.rs +++ b/pallets/roles/src/lib.rs @@ -24,6 +24,7 @@ use frame_support::{ BoundedBTreeMap, CloneNoBound, EqNoBound, PartialEqNoBound, RuntimeDebugNoBound, }; use parity_scale_codec::MaxEncodedLen; +use sp_runtime::Percent; use tangle_primitives::roles::ValidatorRewardDistribution; use frame_support::BoundedVec; @@ -70,7 +71,7 @@ use sp_runtime::RuntimeAppPublic; MaxEncodedLen, )] #[scale_info(skip_type_params(T))] -pub struct RoleStakingLedger { +pub struct RestakingLedger { /// The stash account whose balance is actually locked and at stake. pub stash: T::AccountId, /// The total amount of the stash's balance that is restaked for all selected roles. @@ -85,7 +86,7 @@ pub struct RoleStakingLedger { pub role_key: BoundedVec, } -impl RoleStakingLedger { +impl RestakingLedger { /// New staking ledger for a stash account. pub fn try_new( stash: T::AccountId, @@ -191,6 +192,9 @@ pub mod pallet { ValidatorOffence>, >; + /// The max permitted restake for a restaker + type MaxRestake: Get; + type WeightInfo: WeightInfo; } @@ -257,8 +261,7 @@ pub mod pallet { /// Map from all "controller" accounts to the info regarding the staking. #[pallet::storage] #[pallet::getter(fn ledger)] - pub type Ledger = - StorageMap<_, Blake2_128Concat, T::AccountId, RoleStakingLedger>; + pub type Ledger = StorageMap<_, Blake2_128Concat, T::AccountId, RestakingLedger>; #[pallet::storage] #[pallet::getter(fn account_roles)] @@ -276,9 +279,9 @@ pub mod pallet { #[pallet::getter(fn min_active_bond)] pub(super) type MinRestakingBond = StorageValue<_, BalanceOf, ValueQuery>; - /// Create profile for the validator. - /// Validator can choose roles he is interested to opt-in and restake tokens for it. - /// Staking can be done shared or independently for each role. + /// Create profile for the restaker. + /// Restaker can choose roles he is interested to opt-in and restake tokens for it. + /// ReStaking can be done shared or independently for each role. /// /// # Parameters /// @@ -295,17 +298,17 @@ pub mod pallet { #[pallet::weight(::WeightInfo::create_profile())] #[pallet::call_index(0)] pub fn create_profile(origin: OriginFor, profile: Profile) -> DispatchResult { - let stash_account = ensure_signed(origin)?; + let restaker_account = ensure_signed(origin)?; // Ensure stash account is a validator. ensure!( - pallet_staking::Validators::::contains_key(&stash_account), + pallet_staking::Validators::::contains_key(&restaker_account), Error::::NotValidator ); // Get Role key of validator. let validator_id = - ::ValidatorIdOf::convert(stash_account.clone()) + ::ValidatorIdOf::convert(restaker_account.clone()) .ok_or(Error::::NotValidator)?; let session_keys = pallet_session::NextKeys::::get(validator_id) @@ -313,9 +316,12 @@ pub mod pallet { let role_key = OpaqueKeys::get_raw(&session_keys, ROLE_KEY_TYPE); // Ensure no profile is assigned to the validator. - ensure!(!Ledger::::contains_key(&stash_account), Error::::ProfileAlreadyExists); - let ledger = RoleStakingLedger::::try_new( - stash_account.clone(), + ensure!( + !Ledger::::contains_key(&restaker_account), + Error::::ProfileAlreadyExists + ); + let ledger = RestakingLedger::::try_new( + restaker_account.clone(), profile.clone(), role_key.to_vec(), )?; @@ -329,15 +335,15 @@ pub mod pallet { ); // Total restaking amount should not exceed max_restaking_amount. - let staking_ledger = - pallet_staking::Ledger::::get(&stash_account).ok_or(Error::::NotValidator)?; + let staking_ledger = pallet_staking::Ledger::::get(&restaker_account) + .ok_or(Error::::NotValidator)?; let max_restaking_bond = Self::calculate_max_restake_amount(staking_ledger.active); ensure!( total_profile_restake <= max_restaking_bond, Error::::ExceedsMaxRestakeValue ); - // Validate role staking records. + // Validate role re-staking records. let records = profile.get_records(); for record in records { if profile.is_independent() { @@ -353,11 +359,11 @@ pub mod pallet { let profile_roles: BoundedVec = BoundedVec::try_from(profile.get_roles()).map_err(|_| Error::::MaxRoles)?; - AccountRolesMapping::::insert(&stash_account, profile_roles); + AccountRolesMapping::::insert(&restaker_account, profile_roles); - Self::update_ledger(&stash_account, &ledger); + Self::update_ledger(&restaker_account, &ledger); Self::deposit_event(Event::::ProfileCreated { - account: stash_account.clone(), + account: restaker_account.clone(), total_profile_restake, roles: profile.get_roles(), }); @@ -365,8 +371,8 @@ pub mod pallet { Ok(()) } - /// Update profile of the validator. - /// This function will update the profile of the validator. + /// Update profile of the restaker. + /// This function will update the profile of the restaker. /// If user wants to remove any role, please ensure that all the jobs associated with the /// role are completed else this tx will fail. /// If user wants to add any role, please ensure that the Restaking amount is greater than @@ -385,13 +391,14 @@ pub mod pallet { #[pallet::weight(::WeightInfo::update_profile())] #[pallet::call_index(1)] pub fn update_profile(origin: OriginFor, updated_profile: Profile) -> DispatchResult { - let stash_account = ensure_signed(origin)?; + let restaker_account = ensure_signed(origin)?; // Ensure stash account is a validator. ensure!( - pallet_staking::Validators::::contains_key(&stash_account), + pallet_staking::Validators::::contains_key(&restaker_account), Error::::NotValidator ); - let mut ledger = Ledger::::get(&stash_account).ok_or(Error::::NoProfileFound)?; + let mut ledger = + Ledger::::get(&restaker_account).ok_or(Error::::NoProfileFound)?; // Restaking amount of record should meet min restaking amount requirement. match updated_profile.clone() { Profile::Shared(profile) => { @@ -411,15 +418,15 @@ pub mod pallet { }; // Total restaking amount should not exceed `max_restaking_amount`. - let staking_ledger = - pallet_staking::Ledger::::get(&stash_account).ok_or(Error::::NotValidator)?; + let staking_ledger = pallet_staking::Ledger::::get(&restaker_account) + .ok_or(Error::::NotValidator)?; let max_restaking_bond = Self::calculate_max_restake_amount(staking_ledger.active); ensure!( updated_profile.get_total_profile_restake() <= max_restaking_bond, Error::::ExceedsMaxRestakeValue ); // Validate additional rules for profile update. - Self::validate_updated_profile(stash_account.clone(), updated_profile.clone())?; + Self::validate_updated_profile(restaker_account.clone(), updated_profile.clone())?; ledger.profile = updated_profile.clone(); ledger.total = updated_profile.get_total_profile_restake().into(); @@ -427,11 +434,11 @@ pub mod pallet { BoundedVec::try_from(updated_profile.get_roles()) .map_err(|_| Error::::MaxRoles)?; - AccountRolesMapping::::insert(&stash_account, profile_roles); - Self::update_ledger(&stash_account, &ledger); + AccountRolesMapping::::insert(&restaker_account, profile_roles); + Self::update_ledger(&restaker_account, &ledger); Self::deposit_event(Event::::ProfileUpdated { - account: stash_account.clone(), + account: restaker_account.clone(), total_profile_restake: updated_profile.get_total_profile_restake().into(), roles: updated_profile.get_roles(), }); @@ -439,7 +446,7 @@ pub mod pallet { Ok(()) } - /// Delete profile of the validator. + /// Delete profile of the restaker. /// This function will submit the request to exit from all the services and will fails if /// all the job are not completed. /// @@ -449,21 +456,21 @@ pub mod pallet { /// /// This function will return error if /// - Account is not a validator account. - /// - Profile is not assigned to the validator. + /// - Profile is not assigned to the restaker. /// - All the jobs are not completed. #[pallet::weight(::WeightInfo::delete_profile())] #[pallet::call_index(2)] pub fn delete_profile(origin: OriginFor) -> DispatchResult { - let stash_account = ensure_signed(origin)?; + let restaker_account = ensure_signed(origin)?; // Ensure stash account is a validator. ensure!( - pallet_staking::Validators::::contains_key(&stash_account), + pallet_staking::Validators::::contains_key(&restaker_account), Error::::NotValidator ); - let ledger = Ledger::::get(&stash_account).ok_or(Error::::NoProfileFound)?; + let ledger = Ledger::::get(&restaker_account).ok_or(Error::::NoProfileFound)?; // Submit request to exit from all the services. - let active_jobs = T::JobsHandler::get_active_jobs(stash_account.clone()); + let active_jobs = T::JobsHandler::get_active_jobs(restaker_account.clone()); let mut pending_jobs = Vec::new(); for job in active_jobs { let role_type = job.0; @@ -476,7 +483,7 @@ pub mod pallet { BoundedVec::try_from(ledger.profile.get_roles()) .map_err(|_| Error::::MaxRoles)?; - AccountRolesMapping::::insert(&stash_account, profile_roles); + AccountRolesMapping::::insert(&restaker_account, profile_roles); // Profile delete request failed due to pending jobs, which can't be opted out at // the moment. @@ -484,12 +491,12 @@ pub mod pallet { return Err(Error::::ProfileDeleteRequestFailed.into()) } - Self::deposit_event(Event::::ProfileDeleted { account: stash_account.clone() }); + Self::deposit_event(Event::::ProfileDeleted { account: restaker_account.clone() }); // Remove entry from ledger. - Ledger::::remove(&stash_account); + Ledger::::remove(&restaker_account); // Remove entry from account roles mapping. - AccountRolesMapping::::remove(&stash_account); + AccountRolesMapping::::remove(&restaker_account); Ok(()) } @@ -509,9 +516,9 @@ pub mod pallet { #[pallet::weight(::WeightInfo::chill())] #[pallet::call_index(3)] pub fn chill(origin: OriginFor) -> DispatchResult { - let account = ensure_signed(origin.clone())?; - // Ensure no role is assigned to the account before chilling. - ensure!(Self::can_exit(account), Error::::HasRoleAssigned); + let restaker_account = ensure_signed(origin.clone())?; + // Ensure no role is assigned to the restaker_account before chilling. + ensure!(Self::can_exit(restaker_account), Error::::HasRoleAssigned); // chill pallet_staking::Pallet::::chill(origin) @@ -531,15 +538,17 @@ pub mod pallet { /// This function will return error if /// - If there is any active role assigned to the user. /// + /// NOTE : This call wraps pallet_staking.unbond, so the pallet_staking.unbond call should + /// be blocked in runtime #[pallet::weight(::WeightInfo::unbond_funds())] #[pallet::call_index(4)] pub fn unbond_funds( origin: OriginFor, #[pallet::compact] amount: BalanceOf, ) -> DispatchResult { - let account = ensure_signed(origin.clone())?; - // Ensure no role is assigned to the account and is eligible to unbond. - ensure!(Self::can_exit(account), Error::::HasRoleAssigned); + let restaker_account = ensure_signed(origin.clone())?; + // Ensure no role is assigned to the restaker_account and is eligible to unbond. + ensure!(Self::can_exit(restaker_account), Error::::HasRoleAssigned); // Unbond funds. let res = pallet_staking::Pallet::::unbond(origin, amount); @@ -557,12 +566,14 @@ pub mod pallet { /// /// This function will return error if /// - If there is any active role assigned to the user. + /// NOTE : This call wraps pallet_staking.withdraw_unbonded, so the + /// pallet_staking.withdraw_unbonded call should be blocked in runtime #[pallet::weight(::WeightInfo::withdraw_unbonded())] #[pallet::call_index(5)] pub fn withdraw_unbonded(origin: OriginFor) -> DispatchResult { - let account = ensure_signed(origin.clone())?; - // Ensure no role is assigned to the account and is eligible to withdraw. - ensure!(Self::can_exit(account), Error::::HasRoleAssigned); + let restaker_account = ensure_signed(origin.clone())?; + // Ensure no role is assigned to the restaker_account and is eligible to withdraw. + ensure!(Self::can_exit(restaker_account), Error::::HasRoleAssigned); // Withdraw unbond funds. let res = pallet_staking::Pallet::::withdraw_unbonded(origin, 0); diff --git a/pallets/roles/src/mock.rs b/pallets/roles/src/mock.rs index 6dc320273..5d4ff35e3 100644 --- a/pallets/roles/src/mock.rs +++ b/pallets/roles/src/mock.rs @@ -312,7 +312,7 @@ parameter_types! { #[derive(Clone, Debug, Eq, PartialEq, TypeInfo)] pub const MaxParticipants: u32 = 10; #[derive(Clone, Debug, Eq, PartialEq, TypeInfo)] - pub const MaxSubmissionLen: u32 = 256; + pub const MaxSubmissionLen: u32 = 32; #[derive(Clone, Debug, Eq, PartialEq, TypeInfo)] pub const MaxKeyLen: u32 = 256; #[derive(Clone, Debug, Eq, PartialEq, TypeInfo)] @@ -348,6 +348,7 @@ impl pallet_jobs::Config for Runtime { parameter_types! { pub InflationRewardPerSession: Balance = 10_000; + pub MaxRestake: Percent = Percent::from_percent(50); pub Reward : ValidatorRewardDistribution = ValidatorRewardDistribution::try_new(Percent::from_rational(1_u32,2_u32), Percent::from_rational(1_u32,2_u32)).unwrap(); } @@ -362,6 +363,7 @@ impl Config for Runtime { type ReportOffences = OffenceHandler; type MaxRolesPerValidator = MaxRolesPerValidator; type MaxKeyLen = MaxKeyLen; + type MaxRestake = MaxRestake; type WeightInfo = (); } diff --git a/pallets/roles/src/tests.rs b/pallets/roles/src/tests.rs index 499e82ec1..b8972e6d0 100644 --- a/pallets/roles/src/tests.rs +++ b/pallets/roles/src/tests.rs @@ -21,7 +21,7 @@ use mock::*; use profile::{IndependentRestakeProfile, Record, SharedRestakeProfile}; use sp_std::{default::Default, vec}; use tangle_primitives::{ - jobs::ReportValidatorOffence, + jobs::ReportRestakerOffence, roles::{ThresholdSignatureRoleType, ZeroKnowledgeRoleType}, }; @@ -350,7 +350,7 @@ fn test_report_offence_should_work() { let session_index = pallet_session::CurrentIndex::::get(); // Create offence report. - let offence_report = ReportValidatorOffence { + let offence_report = ReportRestakerOffence { session_index, validator_set_count: 4, role_type: RoleType::Tss(Default::default()), diff --git a/precompiles/jobs/src/mock.rs b/precompiles/jobs/src/mock.rs index be20acaaa..5bd73603e 100644 --- a/precompiles/jobs/src/mock.rs +++ b/precompiles/jobs/src/mock.rs @@ -202,7 +202,7 @@ impl JobToFee for Moc pub struct MockRolesHandler; impl RolesHandler for MockRolesHandler { - fn is_validator(address: AccountId, _role_type: RoleType) -> bool { + fn is_restaker(address: AccountId, _role_type: RoleType) -> bool { let validators = [ AccountId::from_u64(1u64), AccountId::from_u64(2u64), @@ -217,7 +217,7 @@ impl RolesHandler for MockRolesHandler { None } - fn report_offence(_offence_report: ReportValidatorOffence) -> DispatchResult { + fn report_offence(_offence_report: ReportRestakerOffence) -> DispatchResult { Ok(()) } } @@ -277,7 +277,7 @@ parameter_types! { #[derive(Clone, Debug, Eq, PartialEq, TypeInfo)] pub const MaxParticipants: u32 = 10; #[derive(Clone, Debug, Eq, PartialEq, TypeInfo)] - pub const MaxSubmissionLen: u32 = 256; + pub const MaxSubmissionLen: u32 = 32; #[derive(Clone, Debug, Eq, PartialEq, TypeInfo)] pub const MaxKeyLen: u32 = 256; #[derive(Clone, Debug, Eq, PartialEq, TypeInfo)] diff --git a/precompiles/staking/src/lib.rs b/precompiles/staking/src/lib.rs index e4e9a597e..7c50cd8dd 100644 --- a/precompiles/staking/src/lib.rs +++ b/precompiles/staking/src/lib.rs @@ -189,13 +189,13 @@ where } #[precompile::public("isValidator(address)")] - #[precompile::public("is_validator(address)")] + #[precompile::public("is_restaker(address)")] #[precompile::view] - fn is_validator(handle: &mut impl PrecompileHandle, validator: Address) -> EvmResult { + fn is_restaker(handle: &mut impl PrecompileHandle, validator: Address) -> EvmResult { let validator_account = Runtime::AddressMapping::into_account_id(validator.0); handle.record_cost(RuntimeHelper::::db_read_gas_cost())?; - let is_validator = pallet_staking::Validators::::contains_key(validator_account); - Ok(is_validator) + let is_restaker = pallet_staking::Validators::::contains_key(validator_account); + Ok(is_restaker) } #[precompile::public("maxNominatorCount()")] diff --git a/precompiles/staking/src/tests.rs b/precompiles/staking/src/tests.rs index deeab70f0..1f1d2f0c0 100644 --- a/precompiles/staking/src/tests.rs +++ b/precompiles/staking/src/tests.rs @@ -90,7 +90,7 @@ fn is_validator_works() { .prepare_test( TestAccount::Alex, H160::from_low_u64_be(1), - PCall::is_validator { validator: H160::from(TestAccount::Alex).into() }, + PCall::is_restaker { validator: H160::from(TestAccount::Alex).into() }, ) .expect_cost(0) .expect_no_logs() diff --git a/primitives/src/jobs/mod.rs b/primitives/src/jobs/mod.rs index 0dc520198..7ea27c774 100644 --- a/primitives/src/jobs/mod.rs +++ b/primitives/src/jobs/mod.rs @@ -334,7 +334,7 @@ pub enum ValidatorOffenceType { /// An offence report that is filed if a validator misbehaves. #[derive(Clone, RuntimeDebug, TypeInfo, PartialEq, Eq)] -pub struct ReportValidatorOffence { +pub struct ReportRestakerOffence { /// The current session index in which offence is reported. pub session_index: u32, /// The size of the validator set in current session/era. diff --git a/primitives/src/roles/traits.rs b/primitives/src/roles/traits.rs index 7732837c3..ffc4f9cb6 100644 --- a/primitives/src/roles/traits.rs +++ b/primitives/src/roles/traits.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Tangle. If not, see . -use crate::jobs::ReportValidatorOffence; +use crate::jobs::ReportRestakerOffence; use sp_runtime::DispatchResult; use sp_std::vec::Vec; @@ -32,7 +32,7 @@ pub trait RolesHandler { /// # Returns /// /// Returns `true` if the validator is permitted to work with this job type, otherwise `false`. - fn is_validator(address: AccountId, role_type: RoleType) -> bool; + fn is_restaker(address: AccountId, role_type: RoleType) -> bool; /// Report offence for the given validator. /// This function will report validators for committing offence. @@ -43,7 +43,7 @@ pub trait RolesHandler { /// # Returns /// /// Returns Ok() if validator offence report is submitted successfully. - fn report_offence(offence_report: ReportValidatorOffence) -> DispatchResult; + fn report_offence(offence_report: ReportRestakerOffence) -> DispatchResult; /// Retrieves role key associated with given validator /// diff --git a/runtime/mainnet/src/lib.rs b/runtime/mainnet/src/lib.rs index 72722a4e8..c330e011c 100644 --- a/runtime/mainnet/src/lib.rs +++ b/runtime/mainnet/src/lib.rs @@ -1133,6 +1133,7 @@ impl ReportOffence for OffenceHandler { parameter_types! { pub InflationRewardPerSession: Balance = 10_000; + pub MaxRestake: Percent = Percent::from_percent(50); pub Reward : tangle_primitives::roles::ValidatorRewardDistribution = tangle_primitives::roles::ValidatorRewardDistribution::try_new(Percent::from_rational(1_u32,2_u32), Percent::from_rational(1_u32,2_u32)).unwrap(); } @@ -1147,6 +1148,7 @@ impl pallet_roles::Config for Runtime { type ValidatorRewardDistribution = Reward; type MaxRolesPerValidator = MaxRolesPerValidator; type MaxKeyLen = MaxKeyLen; + type MaxRestake = MaxRestake; type WeightInfo = (); } @@ -1177,7 +1179,7 @@ parameter_types! { pub const MaxParticipants: u32 = 10; #[derive(Clone, Eq, PartialEq, TypeInfo, Encode, Decode, RuntimeDebug)] #[derive(Serialize, Deserialize)] - pub const MaxSubmissionLen: u32 = 256; + pub const MaxSubmissionLen: u32 = 32; #[derive(Clone, Eq, PartialEq, TypeInfo, Encode, Decode, RuntimeDebug)] #[derive(Serialize, Deserialize)] pub const MaxKeyLen: u32 = 256; diff --git a/runtime/testnet/src/lib.rs b/runtime/testnet/src/lib.rs index 32a590541..a1308018b 100644 --- a/runtime/testnet/src/lib.rs +++ b/runtime/testnet/src/lib.rs @@ -1165,7 +1165,7 @@ parameter_types! { parameter_types! { #[derive(Clone, RuntimeDebug, Eq, PartialEq, TypeInfo, Encode, Decode)] #[derive(Serialize, Deserialize)] - pub const MaxSubmissionLen: u32 = 256; + pub const MaxSubmissionLen: u32 = 32; } parameter_types! { @@ -1228,6 +1228,7 @@ impl ReportOffence for OffenceHandler { parameter_types! { pub InflationRewardPerSession: Balance = 10_000; + pub MaxRestake: Percent = Percent::from_percent(50); pub Reward : ValidatorRewardDistribution = ValidatorRewardDistribution::try_new(Percent::from_rational(1_u32,2_u32), Percent::from_rational(1_u32,2_u32)).unwrap(); } @@ -1240,6 +1241,7 @@ impl pallet_roles::Config for Runtime { type ValidatorSet = Historical; type ReportOffences = OffenceHandler; type ValidatorRewardDistribution = Reward; + type MaxRestake = MaxRestake; type MaxRolesPerValidator = MaxRolesPerValidator; type MaxKeyLen = MaxKeyLen; type WeightInfo = (); diff --git a/types/src/interfaces/lookup.ts b/types/src/interfaces/lookup.ts index 140d2c078..cdb163c73 100644 --- a/types/src/interfaces/lookup.ts +++ b/types/src/interfaces/lookup.ts @@ -4359,7 +4359,7 @@ export default { _enum: ['AlreadyInitialized', 'LightClientUpdateNotAllowed', 'BlockAlreadySubmitted', 'UnknownParentHeader', 'NotTrustedSigner', 'ValidateUpdatesParameterError', 'TrustlessModeError', 'InvalidSyncCommitteeBitsSum', 'SyncCommitteeBitsSumLessThanThreshold', 'InvalidNetworkConfig', 'InvalidBlsSignature', 'InvalidExecutionBlock', 'ActiveHeaderSlotLessThanFinalizedSlot', 'UpdateHeaderSlotLessThanFinalizedHeaderSlot', 'UpdateSignatureSlotLessThanAttestedHeaderSlot', 'InvalidUpdatePeriod', 'InvalidFinalityProof', 'InvalidExecutionBlockHashProof', 'NextSyncCommitteeNotPresent', 'InvalidNextSyncCommitteeProof', 'FinalizedExecutionHeaderNotPresent', 'FinalizedBeaconHeaderNotPresent', 'UnfinalizedHeaderNotPresent', 'SyncCommitteeUpdateNotPresent', 'HeaderHashDoesNotExist', 'BlockHashesDoNotMatch', 'InvalidSignaturePeriod', 'CurrentSyncCommitteeNotSet', 'NextSyncCommitteeNotSet', 'InvalidClientMode', 'HashesGcThresholdInsufficient', 'ChainCannotBeClosed'] }, /** - * Lookup645: pallet_roles::RoleStakingLedger + * Lookup645: pallet_roles::RestakingLedger **/ PalletRolesRoleStakingLedger: { stash: 'AccountId32',