From 32b37d3d84ce5017fd49226f997c612ed6394193 Mon Sep 17 00:00:00 2001 From: str-mv Date: Tue, 12 Jan 2021 17:32:17 +0000 Subject: [PATCH] NFTPAR-288. Limit schema size --- --- a/node/src/chain_spec.rs +++ b/node/src/chain_spec.rs @@ -209,7 +209,10 @@ custom_data_limit: 2048, nft_sponsor_transfer_timeout: 15, fungible_sponsor_transfer_timeout: 15, - refungible_sponsor_transfer_timeout: 15, + refungible_sponsor_transfer_timeout: 15, + offchain_schema_limit: 1024, + variable_on_chain_schema_limit: 1024, + const_on_chain_schema_limit: 1024, }, }), pallet_contracts: Some(ContractsConfig { --- a/pallets/nft/src/lib.rs +++ b/pallets/nft/src/lib.rs @@ -74,6 +74,12 @@ ReFungible(DecimalPoints), } +impl Default for CollectionMode { + fn default() -> Self { + Self::Invalid + } +} + impl Into for CollectionMode { fn into(self) -> u8 { match self { @@ -97,12 +103,6 @@ } } -impl Default for CollectionMode { - fn default() -> Self { - Self::Invalid - } -} - #[derive(Encode, Decode, Eq, Debug, Clone, PartialEq)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] pub enum SchemaVersion { @@ -208,6 +208,11 @@ pub nft_sponsor_transfer_timeout: u32, pub fungible_sponsor_transfer_timeout: u32, pub refungible_sponsor_transfer_timeout: u32, + + // Schema limits + pub offchain_schema_limit: u32, + pub variable_on_chain_schema_limit: u32, + pub const_on_chain_schema_limit: u32, } pub trait WeightInfo { @@ -367,7 +372,9 @@ /// Account token limit exceeded per collection AccountTokenLimitExceeded, /// Collection limit bounds per collection exceeded - CollectionLimitBoundsExceeded + CollectionLimitBoundsExceeded, + /// Schema data size limit bound exceeded + SchemaDataLimitExceeded } } @@ -1281,6 +1288,9 @@ let sender = ensure_signed(origin)?; Self::check_owner_or_admin_permissions(collection_id, sender.clone())?; + // check schema limit + ensure!(schema.len() as u32 > ChainLimit::get().offchain_schema_limit, ""); + let mut target_collection = >::get(collection_id); target_collection.offchain_schema = schema; >::insert(collection_id, target_collection); @@ -1309,6 +1319,9 @@ let sender = ensure_signed(origin)?; Self::check_owner_or_admin_permissions(collection_id, sender.clone())?; + // check schema limit + ensure!(schema.len() as u32 > ChainLimit::get().const_on_chain_schema_limit, ""); + let mut target_collection = >::get(collection_id); target_collection.const_on_chain_schema = schema; >::insert(collection_id, target_collection); @@ -1337,6 +1350,9 @@ let sender = ensure_signed(origin)?; Self::check_owner_or_admin_permissions(collection_id, sender.clone())?; + // check schema limit + ensure!(schema.len() as u32 > ChainLimit::get().variable_on_chain_schema_limit, ""); + let mut target_collection = >::get(collection_id); target_collection.variable_on_chain_schema = schema; >::insert(collection_id, target_collection); -- gitstuff