Skip to content

Commit

Permalink
Merge branch 'master' into ankan/staking/currency-fungible
Browse files Browse the repository at this point in the history
  • Loading branch information
Ank4n authored Jun 21, 2024
2 parents 192af84 + c4b3c1c commit 846381c
Show file tree
Hide file tree
Showing 23 changed files with 1,115 additions and 38 deletions.
54 changes: 46 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ members = [
"substrate/frame/asset-conversion/ops",
"substrate/frame/asset-rate",
"substrate/frame/assets",
"substrate/frame/assets-freezer",
"substrate/frame/atomic-swap",
"substrate/frame/aura",
"substrate/frame/authority-discovery",
Expand Down
13 changes: 7 additions & 6 deletions cumulus/pallets/xcmp-queue/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ impl<T: Config> Pallet<T> {
let channel_info =
T::ChannelInfo::get_channel_info(recipient).ok_or(MessageSendError::NoChannel)?;
// Max message size refers to aggregates, or pages. Not to individual fragments.
let max_message_size = channel_info.max_message_size as usize;
let max_message_size = channel_info.max_message_size.min(T::MaxPageSize::get()) as usize;
let format_size = format.encoded_size();
// We check the encoded fragment length plus the format size against the max message size
// because the format is concatenated if a new page is needed.
Expand Down Expand Up @@ -522,7 +522,7 @@ impl<T: Config> Pallet<T> {
// We return the size of the last page inside of the option, to not calculate it again.
let appended_to_last_page = have_active
.then(|| {
<OutboundXcmpMessages<T>>::mutate(
<OutboundXcmpMessages<T>>::try_mutate(
recipient,
channel_details.last_index - 1,
|page| {
Expand All @@ -532,17 +532,18 @@ impl<T: Config> Pallet<T> {
) != Ok(format)
{
defensive!("Bad format in outbound queue; dropping message");
return None
return Err(())
}
if page.len() + encoded_fragment.len() > max_message_size {
return None
return Err(())
}
for frag in encoded_fragment.iter() {
page.try_push(*frag).ok()?;
page.try_push(*frag)?;
}
Some(page.len())
Ok(page.len())
},
)
.ok()
})
.flatten();

Expand Down
31 changes: 30 additions & 1 deletion cumulus/pallets/xcmp-queue/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use frame_support::{
use mock::{new_test_ext, ParachainSystem, RuntimeOrigin as Origin, Test, XcmpQueue};
use sp_runtime::traits::{BadOrigin, Zero};
use std::iter::{once, repeat};
use xcm_builder::InspectMessageQueues;

#[test]
fn empty_concatenated_works() {
Expand Down Expand Up @@ -854,7 +855,6 @@ fn verify_fee_factor_increase_and_decrease() {
#[test]
fn get_messages_works() {
new_test_ext().execute_with(|| {
use xcm_builder::InspectMessageQueues;
let sibling_para_id = ParaId::from(2001);
ParachainSystem::open_outbound_hrmp_channel_for_benchmarks_or_tests(sibling_para_id);
let destination: Location = (Parent, Parachain(sibling_para_id.into())).into();
Expand Down Expand Up @@ -890,3 +890,32 @@ fn get_messages_works() {
);
});
}

/// We try to send a fragment that will not fit into the currently active page. This should
/// therefore not modify the current page but instead create a new one.
#[test]
fn page_not_modified_when_fragment_does_not_fit() {
new_test_ext().execute_with(|| {
let sibling = ParaId::from(2001);
ParachainSystem::open_outbound_hrmp_channel_for_benchmarks_or_tests(sibling);

let destination: Location = (Parent, Parachain(sibling.into())).into();
let message = Xcm(vec![ClearOrigin; 600]);

loop {
let old_page_zero = OutboundXcmpMessages::<Test>::get(sibling, 0);
assert_ok!(send_xcm::<XcmpQueue>(destination.clone(), message.clone()));

// If a new page was created by this send_xcm call, then page_zero was not also
// modified:
let num_pages = OutboundXcmpMessages::<Test>::iter_prefix(sibling).count();
if num_pages == 2 {
let new_page_zero = OutboundXcmpMessages::<Test>::get(sibling, 0);
assert_eq!(old_page_zero, new_page_zero);
break
} else if num_pages > 2 {
panic!("Too many pages created");
}
}
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pallet-asset-conversion-tx-payment = { path = "../../../../../substrate/frame/tr
pallet-assets = { path = "../../../../../substrate/frame/assets", default-features = false }
pallet-asset-conversion-ops = { path = "../../../../../substrate/frame/asset-conversion/ops", default-features = false }
pallet-asset-conversion = { path = "../../../../../substrate/frame/asset-conversion", default-features = false }
pallet-assets-freezer = { path = "../../../../../substrate/frame/assets-freezer", default-features = false }
pallet-aura = { path = "../../../../../substrate/frame/aura", default-features = false }
pallet-authorship = { path = "../../../../../substrate/frame/authorship", default-features = false }
pallet-balances = { path = "../../../../../substrate/frame/balances", default-features = false }
Expand Down Expand Up @@ -116,6 +117,7 @@ runtime-benchmarks = [
"frame-system/runtime-benchmarks",
"pallet-asset-conversion-ops/runtime-benchmarks",
"pallet-asset-conversion/runtime-benchmarks",
"pallet-assets-freezer/runtime-benchmarks",
"pallet-assets/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-collator-selection/runtime-benchmarks",
Expand Down Expand Up @@ -151,6 +153,7 @@ try-runtime = [
"pallet-asset-conversion-ops/try-runtime",
"pallet-asset-conversion-tx-payment/try-runtime",
"pallet-asset-conversion/try-runtime",
"pallet-assets-freezer/try-runtime",
"pallet-assets/try-runtime",
"pallet-aura/try-runtime",
"pallet-authorship/try-runtime",
Expand Down Expand Up @@ -200,6 +203,7 @@ std = [
"pallet-asset-conversion-ops/std",
"pallet-asset-conversion-tx-payment/std",
"pallet-asset-conversion/std",
"pallet-assets-freezer/std",
"pallet-assets/std",
"pallet-aura/std",
"pallet-authorship/std",
Expand Down
30 changes: 27 additions & 3 deletions cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ impl pallet_assets::Config<TrustBackedAssetsInstance> for Runtime {
type MetadataDepositPerByte = MetadataDepositPerByte;
type ApprovalDeposit = ApprovalDeposit;
type StringLimit = AssetsStringLimit;
type Freezer = ();
type Freezer = AssetsFreezer;
type Extra = ();
type WeightInfo = weights::pallet_assets_local::WeightInfo<Runtime>;
type CallbackHandle = ();
Expand All @@ -267,6 +267,13 @@ impl pallet_assets::Config<TrustBackedAssetsInstance> for Runtime {
type BenchmarkHelper = ();
}

// Allow Freezes for the `Assets` pallet
pub type AssetsFreezerInstance = pallet_assets_freezer::Instance1;
impl pallet_assets_freezer::Config<AssetsFreezerInstance> for Runtime {
type RuntimeFreezeReason = RuntimeFreezeReason;
type RuntimeEvent = RuntimeEvent;
}

parameter_types! {
pub const AssetConversionPalletId: PalletId = PalletId(*b"py/ascon");
pub const LiquidityWithdrawalFee: Permill = Permill::from_percent(0);
Expand Down Expand Up @@ -295,14 +302,21 @@ impl pallet_assets::Config<PoolAssetsInstance> for Runtime {
type MetadataDepositPerByte = ConstU128<0>;
type ApprovalDeposit = ApprovalDeposit;
type StringLimit = ConstU32<50>;
type Freezer = ();
type Freezer = PoolAssetsFreezer;
type Extra = ();
type WeightInfo = weights::pallet_assets_pool::WeightInfo<Runtime>;
type CallbackHandle = ();
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = ();
}

// Allow Freezes for the `PoolAssets` pallet
pub type PoolAssetsFreezerInstance = pallet_assets_freezer::Instance3;
impl pallet_assets_freezer::Config<PoolAssetsFreezerInstance> for Runtime {
type RuntimeFreezeReason = RuntimeFreezeReason;
type RuntimeEvent = RuntimeEvent;
}

/// Union fungibles implementation for `Assets` and `ForeignAssets`.
pub type LocalAndForeignAssets = fungibles::UnionOf<
Assets,
Expand Down Expand Up @@ -411,7 +425,7 @@ impl pallet_assets::Config<ForeignAssetsInstance> for Runtime {
type MetadataDepositPerByte = ForeignAssetsMetadataDepositPerByte;
type ApprovalDeposit = ForeignAssetsApprovalDeposit;
type StringLimit = ForeignAssetsAssetsStringLimit;
type Freezer = ();
type Freezer = ForeignAssetsFreezer;
type Extra = ();
type WeightInfo = weights::pallet_assets_foreign::WeightInfo<Runtime>;
type CallbackHandle = ();
Expand All @@ -421,6 +435,13 @@ impl pallet_assets::Config<ForeignAssetsInstance> for Runtime {
type BenchmarkHelper = xcm_config::XcmBenchmarkHelper;
}

// Allow Freezes for the `ForeignAssets` pallet
pub type ForeignAssetsFreezerInstance = pallet_assets_freezer::Instance2;
impl pallet_assets_freezer::Config<ForeignAssetsFreezerInstance> for Runtime {
type RuntimeFreezeReason = RuntimeFreezeReason;
type RuntimeEvent = RuntimeEvent;
}

parameter_types! {
// One storage item; key size is 32; value is size 4+4+16+32 bytes = 56 bytes.
pub const DepositBase: Balance = deposit(1, 88);
Expand Down Expand Up @@ -953,6 +974,9 @@ construct_runtime!(
NftFractionalization: pallet_nft_fractionalization = 54,
PoolAssets: pallet_assets::<Instance3> = 55,
AssetConversion: pallet_asset_conversion = 56,
AssetsFreezer: pallet_assets_freezer::<Instance1> = 57,
ForeignAssetsFreezer: pallet_assets_freezer::<Instance2> = 58,
PoolAssetsFreezer: pallet_assets_freezer::<Instance3> = 59,

// TODO: the pallet instance should be removed once all pools have migrated
// to the new account IDs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pallet-asset-conversion-ops = { path = "../../../../../substrate/frame/asset-con
pallet-asset-conversion-tx-payment = { path = "../../../../../substrate/frame/transaction-payment/asset-conversion-tx-payment", default-features = false }
pallet-assets = { path = "../../../../../substrate/frame/assets", default-features = false }
pallet-asset-conversion = { path = "../../../../../substrate/frame/asset-conversion", default-features = false }
pallet-assets-freezer = { path = "../../../../../substrate/frame/assets-freezer", default-features = false }
pallet-aura = { path = "../../../../../substrate/frame/aura", default-features = false }
pallet-authorship = { path = "../../../../../substrate/frame/authorship", default-features = false }
pallet-balances = { path = "../../../../../substrate/frame/balances", default-features = false }
Expand Down Expand Up @@ -115,6 +116,7 @@ runtime-benchmarks = [
"frame-system/runtime-benchmarks",
"pallet-asset-conversion-ops/runtime-benchmarks",
"pallet-asset-conversion/runtime-benchmarks",
"pallet-assets-freezer/runtime-benchmarks",
"pallet-assets/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-collator-selection/runtime-benchmarks",
Expand Down Expand Up @@ -150,6 +152,7 @@ try-runtime = [
"pallet-asset-conversion-ops/try-runtime",
"pallet-asset-conversion-tx-payment/try-runtime",
"pallet-asset-conversion/try-runtime",
"pallet-assets-freezer/try-runtime",
"pallet-assets/try-runtime",
"pallet-aura/try-runtime",
"pallet-authorship/try-runtime",
Expand Down Expand Up @@ -200,6 +203,7 @@ std = [
"pallet-asset-conversion-ops/std",
"pallet-asset-conversion-tx-payment/std",
"pallet-asset-conversion/std",
"pallet-assets-freezer/std",
"pallet-assets/std",
"pallet-aura/std",
"pallet-authorship/std",
Expand Down
Loading

0 comments on commit 846381c

Please sign in to comment.