Skip to content

Commit

Permalink
Merge branch 'stable2412' into gui-backport-6463-to-stable2412
Browse files Browse the repository at this point in the history
  • Loading branch information
gui1117 authored Nov 22, 2024
2 parents 090676f + a86fb86 commit 919dde6
Show file tree
Hide file tree
Showing 154 changed files with 6,599 additions and 5,262 deletions.
11 changes: 6 additions & 5 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ linked-hash-map = { version = "0.5.4" }
linked_hash_set = { version = "0.1.4" }
linregress = { version = "0.5.1" }
lite-json = { version = "0.2.0", default-features = false }
litep2p = { version = "0.8.0", features = ["websocket"] }
litep2p = { version = "0.8.1", features = ["websocket"] }
log = { version = "0.4.22", default-features = false }
macro_magic = { version = "0.5.1" }
maplit = { version = "1.0.2" }
Expand Down
23 changes: 16 additions & 7 deletions bridges/bin/runtime-common/src/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ macro_rules! generate_bridge_reject_obsolete_headers_and_messages {
_len: usize,
_self_implicit: Self::Implicit,
_inherited_implication: &impl codec::Encode,
_source: sp_runtime::transaction_validity::TransactionSource,
) -> Result<
(
sp_runtime::transaction_validity::ValidTransaction,
Expand Down Expand Up @@ -390,7 +391,9 @@ mod tests {
parameter_types, AsSystemOriginSigner, AsTransactionAuthorizedOrigin, ConstU64,
DispatchTransaction, Header as _, TransactionExtension,
},
transaction_validity::{InvalidTransaction, TransactionValidity, ValidTransaction},
transaction_validity::{
InvalidTransaction, TransactionSource::External, TransactionValidity, ValidTransaction,
},
DispatchError,
};

Expand Down Expand Up @@ -610,7 +613,9 @@ mod tests {
42u64.into(),
&MockCall { data: 1 },
&(),
0
0,
External,
0,
),
InvalidTransaction::Custom(1)
);
Expand All @@ -619,7 +624,8 @@ mod tests {
42u64.into(),
&MockCall { data: 1 },
&(),
0
0,
0,
),
InvalidTransaction::Custom(1)
);
Expand All @@ -629,7 +635,9 @@ mod tests {
42u64.into(),
&MockCall { data: 2 },
&(),
0
0,
External,
0,
),
InvalidTransaction::Custom(2)
);
Expand All @@ -638,21 +646,22 @@ mod tests {
42u64.into(),
&MockCall { data: 2 },
&(),
0
0,
0,
),
InvalidTransaction::Custom(2)
);

assert_eq!(
BridgeRejectObsoleteHeadersAndMessages
.validate_only(42u64.into(), &MockCall { data: 3 }, &(), 0)
.validate_only(42u64.into(), &MockCall { data: 3 }, &(), 0, External, 0)
.unwrap()
.0,
ValidTransaction { priority: 3, ..Default::default() },
);
assert_eq!(
BridgeRejectObsoleteHeadersAndMessages
.validate_and_prepare(42u64.into(), &MockCall { data: 3 }, &(), 0)
.validate_and_prepare(42u64.into(), &MockCall { data: 3 }, &(), 0, 0)
.unwrap()
.0
.unwrap(),
Expand Down
15 changes: 14 additions & 1 deletion bridges/modules/relayers/src/extension/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use bp_runtime::{Chain, RangeInclusiveExt, StaticStrProvider};
use codec::{Decode, Encode};
use frame_support::{
dispatch::{DispatchInfo, PostDispatchInfo},
pallet_prelude::TransactionSource,
weights::Weight,
CloneNoBound, DefaultNoBound, EqNoBound, PartialEqNoBound, RuntimeDebugNoBound,
};
Expand Down Expand Up @@ -304,6 +305,7 @@ where
_len: usize,
_self_implicit: Self::Implicit,
_inherited_implication: &impl Encode,
_source: TransactionSource,
) -> ValidateResult<Self::Val, R::RuntimeCall> {
// Prepare relevant data for `prepare`
let parsed_call = match C::parse_and_check_for_obsolete_call(call)? {
Expand Down Expand Up @@ -463,7 +465,9 @@ mod tests {
use pallet_utility::Call as UtilityCall;
use sp_runtime::{
traits::{ConstU64, DispatchTransaction, Header as HeaderT},
transaction_validity::{InvalidTransaction, TransactionValidity, ValidTransaction},
transaction_validity::{
InvalidTransaction, TransactionSource::External, TransactionValidity, ValidTransaction,
},
DispatchError,
};

Expand Down Expand Up @@ -1076,6 +1080,8 @@ mod tests {
&call,
&DispatchInfo::default(),
0,
External,
0,
)
.map(|t| t.0)
}
Expand All @@ -1088,6 +1094,8 @@ mod tests {
&call,
&DispatchInfo::default(),
0,
External,
0,
)
.map(|t| t.0)
}
Expand All @@ -1100,6 +1108,8 @@ mod tests {
&call,
&DispatchInfo::default(),
0,
External,
0,
)
.map(|t| t.0)
}
Expand All @@ -1125,6 +1135,7 @@ mod tests {
&call,
&DispatchInfo::default(),
0,
0,
)
.map(|(pre, _)| pre)
}
Expand All @@ -1142,6 +1153,7 @@ mod tests {
&call,
&DispatchInfo::default(),
0,
0,
)
.map(|(pre, _)| pre)
}
Expand All @@ -1159,6 +1171,7 @@ mod tests {
&call,
&DispatchInfo::default(),
0,
0,
)
.map(|(pre, _)| pre)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pallet-xcm = { workspace = true }
xcm-runtime-apis = { workspace = true }

# Cumulus
assets-common = { workspace = true }
parachains-common = { workspace = true, default-features = true }
asset-test-utils = { workspace = true, default-features = true }
cumulus-pallet-xcmp-queue = { workspace = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
use crate::imports::*;

use assets_common::runtime_api::runtime_decl_for_fungibles_api::FungiblesApiV2;
use emulated_integration_tests_common::test_chain_can_claim_assets;
use frame_support::traits::fungible::Mutate;
use xcm_executor::traits::DropAssets;

#[test]
Expand All @@ -33,3 +35,83 @@ fn assets_can_be_claimed() {
amount
);
}

#[test]
fn chain_can_claim_assets_for_its_users() {
// Many Penpal users have assets trapped in AssetHubWestend.
let beneficiaries: Vec<(Location, Assets)> = vec![
// Some WND.
(
Location::new(1, [Parachain(2000), AccountId32 { id: [0u8; 32], network: None }]),
(Parent, 10_000_000_000_000u128).into(),
),
// Some USDT.
(
Location::new(1, [Parachain(2000), AccountId32 { id: [1u8; 32], network: None }]),
([PalletInstance(ASSETS_PALLET_ID), GeneralIndex(USDT_ID.into())], 100_000_000u128)
.into(),
),
];

// Start with those assets trapped.
AssetHubWestend::execute_with(|| {
for (location, assets) in &beneficiaries {
<AssetHubWestend as AssetHubWestendPallet>::PolkadotXcm::drop_assets(
location,
assets.clone().into(),
&XcmContext { origin: None, message_id: [0u8; 32], topic: None },
);
}
});

let penpal_to_asset_hub = PenpalA::sibling_location_of(AssetHubWestend::para_id());
let mut builder = Xcm::<()>::builder()
.withdraw_asset((Parent, 1_000_000_000_000u128))
.pay_fees((Parent, 100_000_000_000u128));

// Loop through all beneficiaries.
for (location, assets) in &beneficiaries {
builder = builder.execute_with_origin(
// We take only the last part, the `AccountId32` junction.
Some((*location.interior().last().unwrap()).into()),
Xcm::<()>::builder_unsafe()
.claim_asset(assets.clone(), Location::new(0, [GeneralIndex(5)])) // Means lost assets were version 5.
.deposit_asset(assets.clone(), location.clone())
.build(),
)
}

// Finish assembling the message.
let message = builder.build();

// Fund PenpalA's sovereign account on AssetHubWestend so it can pay for fees.
AssetHubWestend::execute_with(|| {
let penpal_as_seen_by_asset_hub = AssetHubWestend::sibling_location_of(PenpalA::para_id());
let penpal_sov_account_on_asset_hub =
AssetHubWestend::sovereign_account_id_of(penpal_as_seen_by_asset_hub);
type Balances = <AssetHubWestend as AssetHubWestendPallet>::Balances;
assert_ok!(<Balances as Mutate<_>>::mint_into(
&penpal_sov_account_on_asset_hub,
2_000_000_000_000u128,
));
});

// We can send a message from Penpal root that claims all those assets for each beneficiary.
PenpalA::execute_with(|| {
assert_ok!(<PenpalA as PenpalAPallet>::PolkadotXcm::send(
<PenpalA as Chain>::RuntimeOrigin::root(),
bx!(penpal_to_asset_hub.into()),
bx!(VersionedXcm::from(message)),
));
});

// We assert beneficiaries have received their funds.
AssetHubWestend::execute_with(|| {
for (location, expected_assets) in &beneficiaries {
let sov_account = AssetHubWestend::sovereign_account_id_of(location.clone());
let actual_assets =
<AssetHubWestend as Chain>::Runtime::query_account_balances(sov_account).unwrap();
assert_eq!(VersionedAssets::from(expected_assets.clone()), actual_assets);
}
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,7 @@ impl<Call> XcmWeightInfo<Call> for AssetHubRococoXcmWeight<Call> {
fn unpaid_execution(_: &WeightLimit, _: &Option<Location>) -> Weight {
XcmGeneric::<Runtime>::unpaid_execution()
}
fn execute_with_origin(_: &Option<InteriorLocation>, _: &Xcm<Call>) -> Weight {
XcmGeneric::<Runtime>::execute_with_origin()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -373,4 +373,11 @@ impl<T: frame_system::Config> WeightInfo<T> {
// Minimum execution time: 668_000 picoseconds.
Weight::from_parts(726_000, 0)
}
pub fn execute_with_origin() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 713_000 picoseconds.
Weight::from_parts(776_000, 0)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,7 @@ impl<Call> XcmWeightInfo<Call> for AssetHubWestendXcmWeight<Call> {
fn unpaid_execution(_: &WeightLimit, _: &Option<Location>) -> Weight {
XcmGeneric::<Runtime>::unpaid_execution()
}
fn execute_with_origin(_: &Option<InteriorLocation>, _: &Xcm<Call>) -> Weight {
XcmGeneric::<Runtime>::execute_with_origin()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -373,4 +373,11 @@ impl<T: frame_system::Config> WeightInfo<T> {
// Minimum execution time: 638_000 picoseconds.
Weight::from_parts(708_000, 0)
}
pub fn execute_with_origin() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 713_000 picoseconds.
Weight::from_parts(776_000, 0)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,7 @@ impl<Call> XcmWeightInfo<Call> for BridgeHubRococoXcmWeight<Call> {
fn set_asset_claimer(_location: &Location) -> Weight {
XcmGeneric::<Runtime>::set_asset_claimer()
}
fn execute_with_origin(_: &Option<InteriorLocation>, _: &Xcm<Call>) -> Weight {
XcmGeneric::<Runtime>::execute_with_origin()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -380,4 +380,11 @@ impl<T: frame_system::Config> WeightInfo<T> {
// Minimum execution time: 707_000 picoseconds.
Weight::from_parts(749_000, 0)
}
pub fn execute_with_origin() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 713_000 picoseconds.
Weight::from_parts(776_000, 0)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,7 @@ impl<Call> XcmWeightInfo<Call> for BridgeHubWestendXcmWeight<Call> {
fn unpaid_execution(_: &WeightLimit, _: &Option<Location>) -> Weight {
XcmGeneric::<Runtime>::unpaid_execution()
}
fn execute_with_origin(_: &Option<InteriorLocation>, _: &Xcm<Call>) -> Weight {
XcmGeneric::<Runtime>::execute_with_origin()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -380,4 +380,11 @@ impl<T: frame_system::Config> WeightInfo<T> {
// Minimum execution time: 707_000 picoseconds.
Weight::from_parts(749_000, 0)
}
pub fn execute_with_origin() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 713_000 picoseconds.
Weight::from_parts(776_000, 0)
}
}
Loading

0 comments on commit 919dde6

Please sign in to comment.