git.delta.rocks / unique-network / refs/commits / 752d713492c3

difftreelog

fix remove known xcm locations -- unneeded due to limited opened hrmp channels

Daniel Shiposha2023-03-22parent: #d0b6ad7.patch.diff
in: master

5 files changed

modifiedpallets/configuration/src/benchmarking.rsdiffbeforeafterboth
19use super::*;19use super::*;
20use frame_benchmarking::benchmarks;20use frame_benchmarking::benchmarks;
21use frame_system::{EventRecord, RawOrigin};21use frame_system::{EventRecord, RawOrigin};
22use frame_support::{assert_ok, BoundedVec, traits::Currency};22use frame_support::{assert_ok, traits::Currency};
23use xcm::latest::MultiLocation;
2423
25fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) {24fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) {
26 let events = frame_system::Pallet::<T>::events();25 let events = frame_system::Pallet::<T>::events();
49 );48 );
50 }49 }
51
52 set_xcm_allowed_locations {
53 let locations: BoundedVec<MultiLocation, T::MaxXcmAllowedLocations> = Default::default();
54 }: {
55 assert_ok!(
56 <Pallet<T>>::set_xcm_allowed_locations(RawOrigin::Root.into(), Some(locations))
57 );
58 }
5950
60 set_app_promotion_configuration_override {51 set_app_promotion_configuration_override {
61 let configuration: AppPromotionConfiguration<T::BlockNumber> = Default::default();52 let configuration: AppPromotionConfiguration<T::BlockNumber> = Default::default();
modifiedpallets/configuration/src/lib.rsdiffbeforeafterboth
43 use super::*;43 use super::*;
44 use frame_support::{44 use frame_support::{
45 traits::{Get, ReservableCurrency, Currency},45 traits::{Get, ReservableCurrency, Currency},
46 pallet_prelude::{StorageValue, ValueQuery, DispatchResult, IsType, OptionQuery},46 pallet_prelude::{StorageValue, ValueQuery, DispatchResult, IsType}, log,
47 BoundedVec, log,
48 };47 };
49 use frame_system::{pallet_prelude::OriginFor, ensure_root, Config as SystemConfig};48 use frame_system::{pallet_prelude::OriginFor, ensure_root, Config as SystemConfig};
50 use xcm::latest::MultiLocation;
5149
52 pub use crate::weights::WeightInfo;50 pub use crate::weights::WeightInfo;
53 pub type BalanceOf<T> =51 pub type BalanceOf<T> =
114 pub type MinGasPriceOverride<T: Config> =112 pub type MinGasPriceOverride<T: Config> =
115 StorageValue<Value = u64, QueryKind = ValueQuery, OnEmpty = T::DefaultMinGasPrice>;113 StorageValue<Value = u64, QueryKind = ValueQuery, OnEmpty = T::DefaultMinGasPrice>;
116
117 #[pallet::storage]
118 pub type XcmAllowedLocationsOverride<T: Config> = StorageValue<
119 Value = BoundedVec<xcm::v3::MultiLocation, T::MaxXcmAllowedLocations>,
120 QueryKind = OptionQuery,
121 >;
122114
123 #[pallet::storage]115 #[pallet::storage]
124 pub type AppPromomotionConfigurationOverride<T: Config> =116 pub type AppPromomotionConfigurationOverride<T: Config> =
177 Ok(())169 Ok(())
178 }170 }
179
180 #[pallet::call_index(2)]
181 #[pallet::weight(T::WeightInfo::set_xcm_allowed_locations())]
182 pub fn set_xcm_allowed_locations(
183 origin: OriginFor<T>,
184 locations: Option<BoundedVec<MultiLocation, T::MaxXcmAllowedLocations>>,
185 ) -> DispatchResult {
186 ensure_root(origin)?;
187 <XcmAllowedLocationsOverride<T>>::set(locations);
188 Ok(())
189 }
190171
191 #[pallet::call_index(3)]172 #[pallet::call_index(3)]
192 #[pallet::weight(T::WeightInfo::set_app_promotion_configuration_override())]173 #[pallet::weight(T::WeightInfo::set_app_promotion_configuration_override())]
modifiedruntime/common/config/xcm/mod.rsdiffbeforeafterboth
148 }148 }
149}149}
150
151// Allow xcm exchange only with locations in list
152pub struct DenyExchangeWithUnknownLocation<T>(PhantomData<T>);
153impl<T: Get<Vec<MultiLocation>>> TryPass for DenyExchangeWithUnknownLocation<T> {
154 fn try_pass<Call>(origin: &MultiLocation, message: &mut [Instruction<Call>]) -> Result<(), ()> {
155 let allowed_locations = T::get();
156
157 // Check if deposit or transfer belongs to allowed parachains
158 let mut allowed = allowed_locations.contains(origin);
159
160 message.iter().for_each(|inst| match inst {
161 DepositReserveAsset { dest: dst, .. }
162 | TransferReserveAsset { dest: dst, .. }
163 | InitiateReserveWithdraw { reserve: dst, .. } => {
164 allowed |= allowed_locations.contains(&dst);
165 }
166 // ? There are more instructions worth checking
167 _ => {}
168 });
169
170 if allowed {
171 return Ok(());
172 }
173
174 log::warn!(
175 target: "xcm::barrier",
176 "Unexpected deposit or transfer location"
177 );
178 // Deny
179 Err(())
180 }
181}
182150
183pub type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;151pub type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;
184152
modifiedruntime/quartz/src/xcm_barrier.rsdiffbeforeafterboth
15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
1616
17use frame_support::{17use frame_support::{
18 match_types, parameter_types,18 match_types,
19 traits::{Get, Everything},19 traits::Everything,
20};20};
21use sp_std::{vec, vec::Vec};
22use xcm::latest::{Junction::*, Junctions::*, MultiLocation};21use xcm::latest::{Junctions::*, MultiLocation};
23use xcm_builder::{22use xcm_builder::{
24 AllowKnownQueryResponses, AllowSubscriptionsFrom, TakeWeightCredit,23 AllowKnownQueryResponses, AllowSubscriptionsFrom, TakeWeightCredit,
25 AllowTopLevelPaidExecutionFrom,24 AllowTopLevelPaidExecutionFrom,
26};25};
2726
28use crate::{27use crate::PolkadotXcm;
29 Runtime, ParachainInfo, PolkadotXcm,
30 runtime_common::{
31 config::xcm::{DenyThenTry, DenyExchangeWithUnknownLocation},
32 xcm::OverridableAllowedLocations,
33 },
34};
3528
36match_types! {29match_types! {
37 pub type ParentOrSiblings: impl Contains<MultiLocation> = {30 pub type ParentOrSiblings: impl Contains<MultiLocation> = {
40 };33 };
41}34}
42
43parameter_types! {
44 pub QuartzDefaultAllowedLocations: Vec<MultiLocation> = vec![
45 // Self location
46 MultiLocation {
47 parents: 0,
48 interior: Here,
49 },
50 // Parent location
51 MultiLocation {
52 parents: 1,
53 interior: Here,
54 },
55 // Statemint/Statemint location
56 MultiLocation {
57 parents: 1,
58 interior: X1(Parachain(1000)),
59 },
60 // Karura/Acala location
61 MultiLocation {
62 parents: 1,
63 interior: X1(Parachain(2000)),
64 },
65 // Moonriver location
66 MultiLocation {
67 parents: 1,
68 interior: X1(Parachain(2023)),
69 },
70 // Self parachain address
71 MultiLocation {
72 parents: 1,
73 interior: X1(Parachain(ParachainInfo::get().into())),
74 },
75 ];
76}
7735
78pub type Barrier = DenyThenTry<36pub type Barrier = (
79 DenyExchangeWithUnknownLocation<
80 OverridableAllowedLocations<Runtime, QuartzDefaultAllowedLocations>,
81 >,
82 (
83 TakeWeightCredit,37 TakeWeightCredit,
84 AllowTopLevelPaidExecutionFrom<Everything>,38 AllowTopLevelPaidExecutionFrom<Everything>,
85 // Expected responses are OK.39 // Expected responses are OK.
86 AllowKnownQueryResponses<PolkadotXcm>,40 AllowKnownQueryResponses<PolkadotXcm>,
87 // Subscriptions for version tracking are OK.41 // Subscriptions for version tracking are OK.
88 AllowSubscriptionsFrom<ParentOrSiblings>,42 AllowSubscriptionsFrom<ParentOrSiblings>,
89 ),43);
90>;
9144
modifiedruntime/unique/src/xcm_barrier.rsdiffbeforeafterboth
15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
1616
17use frame_support::{17use frame_support::{
18 match_types, parameter_types,18 match_types,
19 traits::{Get, Everything},19 traits::Everything,
20};20};
21use sp_std::{vec, vec::Vec};
22use xcm::latest::{Junction::*, Junctions::*, MultiLocation};21use xcm::latest::{Junctions::*, MultiLocation};
23use xcm_builder::{22use xcm_builder::{
24 AllowKnownQueryResponses, AllowSubscriptionsFrom, TakeWeightCredit,23 AllowKnownQueryResponses, AllowSubscriptionsFrom, TakeWeightCredit,
25 AllowTopLevelPaidExecutionFrom,24 AllowTopLevelPaidExecutionFrom,
26};25};
2726
28use crate::{27use crate::PolkadotXcm;
29 Runtime, ParachainInfo, PolkadotXcm,
30 runtime_common::{
31 config::xcm::{DenyThenTry, DenyExchangeWithUnknownLocation},
32 xcm::OverridableAllowedLocations,
33 },
34};
3528
36match_types! {29match_types! {
37 pub type ParentOrSiblings: impl Contains<MultiLocation> = {30 pub type ParentOrSiblings: impl Contains<MultiLocation> = {
40 };33 };
41}34}
42
43parameter_types! {
44 pub UniqueDefaultAllowedLocations: Vec<MultiLocation> = vec![
45 // Self location
46 MultiLocation {
47 parents: 0,
48 interior: Here,
49 },
50 // Parent location
51 MultiLocation {
52 parents: 1,
53 interior: Here,
54 },
55 // Statemint/Statemint location
56 MultiLocation {
57 parents: 1,
58 interior: X1(Parachain(1000)),
59 },
60 // Karura/Acala location
61 MultiLocation {
62 parents: 1,
63 interior: X1(Parachain(2000)),
64 },
65 // Moonbeam location
66 MultiLocation {
67 parents: 1,
68 interior: X1(Parachain(2004)),
69 },
70 // Self parachain address
71 MultiLocation {
72 parents: 1,
73 interior: X1(Parachain(ParachainInfo::get().into())),
74 },
75 ];
76}
7735
78pub type Barrier = DenyThenTry<36pub type Barrier = (
79 DenyExchangeWithUnknownLocation<
80 OverridableAllowedLocations<Runtime, UniqueDefaultAllowedLocations>,
81 >,
82 (
83 TakeWeightCredit,37 TakeWeightCredit,
84 AllowTopLevelPaidExecutionFrom<Everything>,38 AllowTopLevelPaidExecutionFrom<Everything>,
85 // Expected responses are OK.39 // Expected responses are OK.
86 AllowKnownQueryResponses<PolkadotXcm>,40 AllowKnownQueryResponses<PolkadotXcm>,
87 // Subscriptions for version tracking are OK.41 // Subscriptions for version tracking are OK.
88 AllowSubscriptionsFrom<ParentOrSiblings>,42 AllowSubscriptionsFrom<ParentOrSiblings>,
89 ),43);
90>;
9144