Skip to content

Commit 6fe576d

Browse files
authored
Reserved transfer to relay chain (#367)
1 parent 16ebc19 commit 6fe576d

File tree

3 files changed

+36
-249
lines changed

3 files changed

+36
-249
lines changed

runtime/neumann/src/xcm_config.rs

Lines changed: 12 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -105,89 +105,18 @@ match_types! {
105105
};
106106
}
107107

108-
//TODO: move DenyThenTry to polkadot's xcm module.
109-
/// Deny executing the xcm message if it matches any of the Deny filter regardless of anything else.
110-
/// If it passes the Deny, and matches one of the Allow cases then it is let through.
111-
pub struct DenyThenTry<Deny, Allow>(PhantomData<Deny>, PhantomData<Allow>)
112-
where
113-
Deny: ShouldExecute,
114-
Allow: ShouldExecute;
115-
116-
impl<Deny, Allow> ShouldExecute for DenyThenTry<Deny, Allow>
117-
where
118-
Deny: ShouldExecute,
119-
Allow: ShouldExecute,
120-
{
121-
fn should_execute<Call>(
122-
origin: &MultiLocation,
123-
message: &mut [Instruction<Call>],
124-
max_weight: Weight,
125-
weight_credit: &mut Weight,
126-
) -> Result<(), ()> {
127-
Deny::should_execute(origin, message, max_weight, weight_credit)?;
128-
Allow::should_execute(origin, message, max_weight, weight_credit)
129-
}
130-
}
131-
132-
// See issue #5233
133-
pub struct DenyReserveTransferToRelayChain;
134-
impl ShouldExecute for DenyReserveTransferToRelayChain {
135-
fn should_execute<Call>(
136-
origin: &MultiLocation,
137-
message: &mut [Instruction<Call>],
138-
_max_weight: Weight,
139-
_weight_credit: &mut Weight,
140-
) -> Result<(), ()> {
141-
if message.iter().any(|inst| {
142-
matches!(
143-
inst,
144-
InitiateReserveWithdraw {
145-
reserve: MultiLocation { parents: 1, interior: Here },
146-
..
147-
} | DepositReserveAsset { dest: MultiLocation { parents: 1, interior: Here }, .. } |
148-
TransferReserveAsset {
149-
dest: MultiLocation { parents: 1, interior: Here },
150-
..
151-
}
152-
)
153-
}) {
154-
return Err(()) // Deny
155-
}
156-
157-
// An unexpected reserve transfer has arrived from the Relay Chain. Generally, `IsReserve`
158-
// should not allow this, but we just log it here.
159-
if matches!(origin, MultiLocation { parents: 1, interior: Here }) &&
160-
message.iter().any(|inst| matches!(inst, ReserveAssetDeposited { .. }))
161-
{
162-
log::warn!(
163-
target: "xcm::barriers",
164-
"Unexpected ReserveAssetDeposited from the relay chain",
165-
);
166-
}
167-
// Permit everything else
168-
Ok(())
169-
}
170-
}
171-
172-
pub type Barrier = DenyThenTry<
173-
DenyReserveTransferToRelayChain,
174-
(
175-
TakeWeightCredit,
176-
AllowTopLevelPaidExecutionFrom<Everything>,
177-
// This will first calculate the derived origin, before checking it against the barrier implementation
178-
WithComputedOrigin<
179-
AllowTopLevelPaidExecutionFrom<Everything>,
180-
UniversalLocation,
181-
ConstU32<8>,
182-
>,
183-
// Expected responses are OK.
184-
AllowKnownQueryResponses<PolkadotXcm>,
185-
// Subscriptions for version tracking are OK.
186-
AllowSubscriptionsFrom<Everything>,
187-
// Parent and its exec plurality get free execution
188-
AllowUnpaidExecutionFrom<ParentOrParentsExecutivePlurality>,
189-
),
190-
>;
108+
pub type Barrier = (
109+
TakeWeightCredit,
110+
AllowTopLevelPaidExecutionFrom<Everything>,
111+
// This will first calculate the derived origin, before checking it against the barrier implementation
112+
WithComputedOrigin<AllowTopLevelPaidExecutionFrom<Everything>, UniversalLocation, ConstU32<8>>,
113+
// Expected responses are OK.
114+
AllowKnownQueryResponses<PolkadotXcm>,
115+
// Subscriptions for version tracking are OK.
116+
AllowSubscriptionsFrom<Everything>,
117+
// Parent and its exec plurality get free execution
118+
AllowUnpaidExecutionFrom<ParentOrParentsExecutivePlurality>,
119+
);
191120

192121
pub struct ToTreasury;
193122
impl TakeRevenue for ToTreasury {

runtime/oak/src/xcm_config.rs

Lines changed: 12 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -107,89 +107,18 @@ match_types! {
107107
};
108108
}
109109

110-
//TODO: move DenyThenTry to polkadot's xcm module.
111-
/// Deny executing the xcm message if it matches any of the Deny filter regardless of anything else.
112-
/// If it passes the Deny, and matches one of the Allow cases then it is let through.
113-
pub struct DenyThenTry<Deny, Allow>(PhantomData<Deny>, PhantomData<Allow>)
114-
where
115-
Deny: ShouldExecute,
116-
Allow: ShouldExecute;
117-
118-
impl<Deny, Allow> ShouldExecute for DenyThenTry<Deny, Allow>
119-
where
120-
Deny: ShouldExecute,
121-
Allow: ShouldExecute,
122-
{
123-
fn should_execute<Call>(
124-
origin: &MultiLocation,
125-
message: &mut [Instruction<Call>],
126-
max_weight: Weight,
127-
weight_credit: &mut Weight,
128-
) -> Result<(), ()> {
129-
Deny::should_execute(origin, message, max_weight, weight_credit)?;
130-
Allow::should_execute(origin, message, max_weight, weight_credit)
131-
}
132-
}
133-
134-
// See issue #5233
135-
pub struct DenyReserveTransferToRelayChain;
136-
impl ShouldExecute for DenyReserveTransferToRelayChain {
137-
fn should_execute<Call>(
138-
origin: &MultiLocation,
139-
message: &mut [Instruction<Call>],
140-
_max_weight: Weight,
141-
_weight_credit: &mut Weight,
142-
) -> Result<(), ()> {
143-
if message.iter().any(|inst| {
144-
matches!(
145-
inst,
146-
InitiateReserveWithdraw {
147-
reserve: MultiLocation { parents: 1, interior: Here },
148-
..
149-
} | DepositReserveAsset { dest: MultiLocation { parents: 1, interior: Here }, .. } |
150-
TransferReserveAsset {
151-
dest: MultiLocation { parents: 1, interior: Here },
152-
..
153-
}
154-
)
155-
}) {
156-
return Err(()) // Deny
157-
}
158-
159-
// An unexpected reserve transfer has arrived from the Relay Chain. Generally, `IsReserve`
160-
// should not allow this, but we just log it here.
161-
if matches!(origin, MultiLocation { parents: 1, interior: Here }) &&
162-
message.iter().any(|inst| matches!(inst, ReserveAssetDeposited { .. }))
163-
{
164-
log::warn!(
165-
target: "xcm::barriers",
166-
"Unexpected ReserveAssetDeposited from the relay chain",
167-
);
168-
}
169-
// Permit everything else
170-
Ok(())
171-
}
172-
}
173-
174-
pub type Barrier = DenyThenTry<
175-
DenyReserveTransferToRelayChain,
176-
(
177-
TakeWeightCredit,
178-
AllowTopLevelPaidExecutionFrom<Everything>,
179-
// This will first calculate the derived origin, before checking it against the barrier implementation
180-
WithComputedOrigin<
181-
AllowTopLevelPaidExecutionFrom<Everything>,
182-
UniversalLocation,
183-
ConstU32<8>,
184-
>,
185-
// Expected responses are OK.
186-
AllowKnownQueryResponses<PolkadotXcm>,
187-
// Subscriptions for version tracking are OK.
188-
AllowSubscriptionsFrom<Everything>,
189-
// Parent and its exec plurality get free execution
190-
AllowUnpaidExecutionFrom<ParentOrParentsExecutivePlurality>,
191-
),
192-
>;
110+
pub type Barrier = (
111+
TakeWeightCredit,
112+
AllowTopLevelPaidExecutionFrom<Everything>,
113+
// This will first calculate the derived origin, before checking it against the barrier implementation
114+
WithComputedOrigin<AllowTopLevelPaidExecutionFrom<Everything>, UniversalLocation, ConstU32<8>>,
115+
// Expected responses are OK.
116+
AllowKnownQueryResponses<PolkadotXcm>,
117+
// Subscriptions for version tracking are OK.
118+
AllowSubscriptionsFrom<Everything>,
119+
// Parent and its exec plurality get free execution
120+
AllowUnpaidExecutionFrom<ParentOrParentsExecutivePlurality>,
121+
);
193122

194123
pub struct ToTreasury;
195124
impl TakeRevenue for ToTreasury {

runtime/turing/src/xcm_config.rs

Lines changed: 12 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -106,89 +106,18 @@ match_types! {
106106
};
107107
}
108108

109-
//TODO: move DenyThenTry to polkadot's xcm module.
110-
/// Deny executing the xcm message if it matches any of the Deny filter regardless of anything else.
111-
/// If it passes the Deny, and matches one of the Allow cases then it is let through.
112-
pub struct DenyThenTry<Deny, Allow>(PhantomData<Deny>, PhantomData<Allow>)
113-
where
114-
Deny: ShouldExecute,
115-
Allow: ShouldExecute;
116-
117-
impl<Deny, Allow> ShouldExecute for DenyThenTry<Deny, Allow>
118-
where
119-
Deny: ShouldExecute,
120-
Allow: ShouldExecute,
121-
{
122-
fn should_execute<Call>(
123-
origin: &MultiLocation,
124-
message: &mut [Instruction<Call>],
125-
max_weight: Weight,
126-
weight_credit: &mut Weight,
127-
) -> Result<(), ()> {
128-
Deny::should_execute(origin, message, max_weight, weight_credit)?;
129-
Allow::should_execute(origin, message, max_weight, weight_credit)
130-
}
131-
}
132-
133-
// See issue #5233
134-
pub struct DenyReserveTransferToRelayChain;
135-
impl ShouldExecute for DenyReserveTransferToRelayChain {
136-
fn should_execute<Call>(
137-
origin: &MultiLocation,
138-
message: &mut [Instruction<Call>],
139-
_max_weight: Weight,
140-
_weight_credit: &mut Weight,
141-
) -> Result<(), ()> {
142-
if message.iter().any(|inst| {
143-
matches!(
144-
inst,
145-
InitiateReserveWithdraw {
146-
reserve: MultiLocation { parents: 1, interior: Here },
147-
..
148-
} | DepositReserveAsset { dest: MultiLocation { parents: 1, interior: Here }, .. } |
149-
TransferReserveAsset {
150-
dest: MultiLocation { parents: 1, interior: Here },
151-
..
152-
}
153-
)
154-
}) {
155-
return Err(()) // Deny
156-
}
157-
158-
// An unexpected reserve transfer has arrived from the Relay Chain. Generally, `IsReserve`
159-
// should not allow this, but we just log it here.
160-
if matches!(origin, MultiLocation { parents: 1, interior: Here }) &&
161-
message.iter().any(|inst| matches!(inst, ReserveAssetDeposited { .. }))
162-
{
163-
log::warn!(
164-
target: "xcm::barriers",
165-
"Unexpected ReserveAssetDeposited from the relay chain",
166-
);
167-
}
168-
// Permit everything else
169-
Ok(())
170-
}
171-
}
172-
173-
pub type Barrier = DenyThenTry<
174-
DenyReserveTransferToRelayChain,
175-
(
176-
TakeWeightCredit,
177-
AllowTopLevelPaidExecutionFrom<Everything>,
178-
// This will first calculate the derived origin, before checking it against the barrier implementation
179-
WithComputedOrigin<
180-
AllowTopLevelPaidExecutionFrom<Everything>,
181-
UniversalLocation,
182-
ConstU32<8>,
183-
>,
184-
// Expected responses are OK.
185-
AllowKnownQueryResponses<PolkadotXcm>,
186-
// Subscriptions for version tracking are OK.
187-
AllowSubscriptionsFrom<Everything>,
188-
// Parent and its exec plurality get free execution
189-
AllowUnpaidExecutionFrom<ParentOrParentsExecutivePlurality>,
190-
),
191-
>;
109+
pub type Barrier = (
110+
TakeWeightCredit,
111+
AllowTopLevelPaidExecutionFrom<Everything>,
112+
// This will first calculate the derived origin, before checking it against the barrier implementation
113+
WithComputedOrigin<AllowTopLevelPaidExecutionFrom<Everything>, UniversalLocation, ConstU32<8>>,
114+
// Expected responses are OK.
115+
AllowKnownQueryResponses<PolkadotXcm>,
116+
// Subscriptions for version tracking are OK.
117+
AllowSubscriptionsFrom<Everything>,
118+
// Parent and its exec plurality get free execution
119+
AllowUnpaidExecutionFrom<ParentOrParentsExecutivePlurality>,
120+
);
192121

193122
pub struct ToTreasury;
194123
impl TakeRevenue for ToTreasury {

0 commit comments

Comments
 (0)