Skip to content

Commit 4a6230c

Browse files
Block same DID transfers; Remove Constant; Fix Benchmark (#1938)
## changelog ### other - Block same DID transfers if asset is frozen; - Remove max proposals from the committee pallet; - Fix contracts benchmark
1 parent c05ade6 commit 4a6230c

8 files changed

Lines changed: 31 additions & 28 deletions

File tree

pallets/asset/src/lib.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3247,11 +3247,7 @@ impl<T: AssetConfig> Pallet<T> {
32473247
return Ok(());
32483248
}
32493249

3250-
// Verifies that the asset is not frozen
3251-
ensure!(
3252-
!Frozen::<T>::get(asset_id),
3253-
Error::<T>::InvalidTransferFrozenAsset
3254-
);
3250+
Self::ensure_asset_is_not_frozen(&asset_id)?;
32553251

32563252
ensure!(
32573253
IdentityPallet::<T>::is_did_active(receiver_did),
@@ -3278,6 +3274,15 @@ impl<T: AssetConfig> Pallet<T> {
32783274
Ok(())
32793275
}
32803276

3277+
/// Returns `Ok` if the asset is not frozen.
3278+
pub fn ensure_asset_is_not_frozen(asset_id: &AssetId) -> DispatchResult {
3279+
ensure!(
3280+
!Frozen::<T>::get(asset_id),
3281+
Error::<T>::InvalidTransferFrozenAsset
3282+
);
3283+
Ok(())
3284+
}
3285+
32813286
/// Returns a vector containing all errors for the transfer. An empty vec means there's no error.
32823287
pub fn asset_transfer_report(
32833288
sender: &AssetHolder,
@@ -4217,6 +4222,10 @@ impl<T: AssetConfig> AssetFnTrait<T::AccountId> for Pallet<T> {
42174222
<T as Config>::WeightInfo::spend_allowance()
42184223
}
42194224

4225+
fn asset_is_not_frozen(asset_id: &AssetId) -> DispatchResult {
4226+
Self::ensure_asset_is_not_frozen(asset_id)
4227+
}
4228+
42204229
#[cfg(feature = "runtime-benchmarks")]
42214230
fn register_unique_ticker(caller: T::AccountId, ticker: Ticker) -> DispatchResult {
42224231
let origin = RawOrigin::Signed(caller);

pallets/committee/src/benchmarking.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ const PROPOSAL_PADDING_WORDS: usize = 1_000;
3030
// aye vote leads to acceptance of that proposal.
3131
const PROPOSAL_ALMOST_APPROVED: u32 = COMMITTEE_MEMBERS_MAX - 3;
3232

33+
const PROPOSALS_MAX: u32 = 500;
34+
3335
fn make_proposal<T, I>(
3436
n: u32,
3537
) -> (

pallets/committee/src/lib.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,6 @@ use polymesh_primitives::traits::GovernanceGroupTrait;
7777
use polymesh_primitives::{IdentityId, MaybeBlock, SystematicIssuers, GC_DID};
7878

7979
type IdentityPallet<T> = pallet_identity::Pallet<T>;
80-
81-
/// The maximum number of concurrently active proposals defined for the sake of weight computation.
82-
/// This is not defined as a trait parameter but rather as a plain constant because this value has
83-
/// to be the same for all instances.
84-
pub const PROPOSALS_MAX: u32 = 500;
85-
8680
pub trait WeightInfo {
8781
fn set_vote_threshold() -> Weight;
8882
fn set_release_coordinator() -> Weight;
@@ -642,12 +636,6 @@ pub mod pallet {
642636
// 1. Ensure `origin` is a committee member.
643637
let did = Self::ensure_is_member(origin)?;
644638

645-
// 1.1 Ensure proposal limit has not been reached.
646-
ensure!(
647-
ProposalCount::<T, I>::get() < PROPOSALS_MAX,
648-
Error::<T, I>::ProposalsLimitReached
649-
);
650-
651639
// 2. Get hash & reject duplicate proposals.
652640
let proposal_hash = T::Hashing::hash_of(&proposal);
653641
ensure!(

pallets/contracts/src/benchmarking.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ where
148148
key_len: u32,
149149
output_len: usize,
150150
) -> Self {
151+
let mut in_ptr: i32 = 0;
151152
let code = WasmModule::<T>::from(ModuleDefinition {
152153
memory: Some(ImportedMemory::max::<T>()),
153154
imported_functions: vec![ImportedFunction {
@@ -166,18 +167,19 @@ where
166167
value: output_len.to_le_bytes().into(),
167168
},
168169
],
169-
call_body: Some(body::repeated(
170-
repetitions,
171-
&[
170+
call_body: Some(body::repeated_with_locals_using(&[], repetitions, || {
171+
let current_in_ptr = in_ptr;
172+
in_ptr += key_len as i32;
173+
[
172174
Instruction::I32Const(FuncId::GetKeyDid.into()),
173-
Instruction::I32Const(0),
175+
Instruction::I32Const(current_in_ptr),
174176
Instruction::I32Const(key_len as i32),
175177
Instruction::I32Const(input.len() as i32 + 4),
176178
Instruction::I32Const(input.len() as i32),
177179
Instruction::Call(0),
178180
Instruction::Drop,
179-
],
180-
)),
181+
]
182+
})),
181183
..Default::default()
182184
});
183185
Self::new(code)

pallets/nft/src/lib.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -687,11 +687,7 @@ impl<T: Config> Pallet<T> {
687687
return Ok(());
688688
}
689689

690-
// Verifies that the asset is not frozen
691-
ensure!(
692-
!Frozen::<T>::get(nfts.asset_id()),
693-
Error::<T>::InvalidNFTTransferFrozenAsset
694-
);
690+
pallet_asset::Pallet::<T>::ensure_asset_is_not_frozen(nfts.asset_id())?;
695691

696692
// Verifies if the receiver has an active DID.
697693
ensure!(

pallets/portfolio/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,10 +919,12 @@ impl<T: Config> Pallet<T> {
919919
unique_assets.insert(asset_id),
920920
Error::<T>::NoDuplicateAssetsAllowed
921921
);
922+
T::AssetFn::asset_is_not_frozen(asset_id)?;
922923
Self::ensure_sufficient_balance(sender_portfolio, &asset_id, *amount)?;
923924
}
924925
FundDescription::NonFungible(nfts) => {
925926
ensure!(nfts.len() > 0, Error::<T>::EmptyTransfer);
927+
T::AssetFn::asset_is_not_frozen(nfts.asset_id())?;
926928
Self::ensure_valid_nfts(sender_portfolio, nfts.asset_id(), nfts.ids())?;
927929
}
928930
}

pallets/settlement/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,6 +1619,7 @@ impl<T: Config> Pallet<T> {
16191619
match fund.description {
16201620
FundDescription::Fungible { asset_id, amount } => {
16211621
ensure!(amount > 0, Error::<T>::ZeroAmount);
1622+
Asset::<T>::ensure_asset_is_not_frozen(&asset_id)?;
16221623
Asset::<T>::ensure_sufficient_balance(&resolved_from, &asset_id, amount)?;
16231624
Asset::<T>::transfer_holders_balance(
16241625
resolved_from.clone(),

primitives/src/traits/asset.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ pub trait AssetFnTrait<AccountId> {
4242
/// Charged dynamically only when the caller is a spender (not the asset owner).
4343
fn spend_allowance_weight() -> Weight;
4444

45+
/// Returns `Ok` if the asset is not frozen.
46+
fn asset_is_not_frozen(asset_id: &AssetId) -> DispatchResult;
47+
4548
#[cfg(feature = "runtime-benchmarks")]
4649
fn register_unique_ticker(caller: AccountId, ticker: Ticker) -> DispatchResult;
4750

0 commit comments

Comments
 (0)