Skip to content

Commit

Permalink
Update review comments from Adrian
Browse files Browse the repository at this point in the history
Update cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs

Co-authored-by: Adrian Catangiu <[email protected]>

Update cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/bridge_hub_config.rs

Co-authored-by: Adrian Catangiu <[email protected]>

Update cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/bridge_hub_config.rs

Co-authored-by: Adrian Catangiu <[email protected]>

Update cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs

Co-authored-by: Adrian Catangiu <[email protected]>

Update cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/bridge_hub_config.rs

Co-authored-by: Adrian Catangiu <[email protected]>

Update cumulus/parachains/runtimes/assets/common/src/matching.rs

Co-authored-by: Adrian Catangiu <[email protected]>

Update cumulus/parachains/runtimes/assets/common/src/matching.rs

Co-authored-by: Adrian Catangiu <[email protected]>

Update cumulus/parachains/runtimes/assets/common/src/matching.rs

Co-authored-by: Adrian Catangiu <[email protected]>

Update cumulus/parachains/runtimes/assets/common/src/matching.rs

Co-authored-by: Adrian Catangiu <[email protected]>

Update cumulus/parachains/runtimes/assets/common/src/matching.rs

Co-authored-by: Adrian Catangiu <[email protected]>

Update cumulus/parachains/runtimes/assets/common/src/matching.rs

Co-authored-by: Adrian Catangiu <[email protected]>

Update cumulus/parachains/runtimes/assets/common/src/matching.rs

Co-authored-by: Adrian Catangiu <[email protected]>

Update cumulus/parachains/runtimes/assets/asset-hub-kusama/src/xcm_config.rs

Co-authored-by: Adrian Catangiu <[email protected]>

Update cumulus/parachains/runtimes/assets/asset-hub-kusama/src/xcm_config.rs

Co-authored-by: Adrian Catangiu <[email protected]>

Update cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/xcm_config.rs

Co-authored-by: Adrian Catangiu <[email protected]>

Update cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/xcm_config.rs

Co-authored-by: Adrian Catangiu <[email protected]>

Update cumulus/parachains/runtimes/assets/common/src/matching.rs

Co-authored-by: Adrian Catangiu <[email protected]>

Fmt + one any to all

Co-authored-by: Adrian Catangiu <[email protected]>
  • Loading branch information
bkontur and acatangiu committed Sep 5, 2023
1 parent 21037dc commit b66e64e
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -608,8 +608,7 @@ impl pallet_xcm::Config for Runtime {
type XcmTeleportFilter = Everything;
// Allow reserve based transfer to everywhere except for bridging, here we strictly check what
// assets are allowed.
type XcmReserveTransferFilter =
EverythingBut<bridging::IsNotAllowedExplicitlyForReserveTransfer>;
type XcmReserveTransferFilter = EverythingBut<bridging::DisallowForReserveTransfer>;
type Weigher = WeightInfoBounds<
crate::weights::xcm::AssetHubKusamaXcmWeight<RuntimeCall>,
RuntimeCall,
Expand Down Expand Up @@ -775,11 +774,12 @@ pub mod bridging {
>;

/// Filter out those assets which are not allowed for bridged reserve based transfer.
/// (asset, location) filter for `pallet_xcm::Config::XcmReserveTransferFilter`.
pub type IsNotAllowedExplicitlyForReserveTransfer = ExcludeOnlyForRemoteDestination<
/// Filter is made of (asset, location) and used by
/// `pallet_xcm::Config::XcmReserveTransferFilter`.
pub type DisallowForReserveTransfer = ExcludeOnlyForRemoteDestination<
UniversalLocation,
FilteredNetworkExportTable,
IsNotAllowedConcreteAssetBy<AllowedReserveTransferAssetsLocations>,
DisallowConcreteAssetUnless<AllowedReserveTransferAssetsLocations>,
>;

impl Contains<RuntimeCall> for ToPolkadotXcmRouter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,7 @@ impl pallet_xcm::Config for Runtime {
type XcmTeleportFilter = Everything;
// Allow reserve based transfer to everywhere except for bridging, here we strictly check what
// assets are allowed.
type XcmReserveTransferFilter =
EverythingBut<bridging::IsNotAllowedExplicitlyForReserveTransfer>;
type XcmReserveTransferFilter = EverythingBut<bridging::DisallowForReserveTransfer>;
type Weigher = WeightInfoBounds<
crate::weights::xcm::AssetHubPolkadotXcmWeight<RuntimeCall>,
RuntimeCall,
Expand Down Expand Up @@ -682,11 +681,12 @@ pub mod bridging {
>;

/// Filter out those assets which are not allowed for bridged reserve based transfer.
/// (asset, location) filter for `pallet_xcm::Config::XcmReserveTransferFilter`.
pub type IsNotAllowedExplicitlyForReserveTransfer = ExcludeOnlyForRemoteDestination<
/// Filter is made of (asset, location) and used by
/// `pallet_xcm::Config::XcmReserveTransferFilter`.
pub type DisallowForReserveTransfer = ExcludeOnlyForRemoteDestination<
UniversalLocation,
FilteredNetworkExportTable,
IsNotAllowedConcreteAssetBy<AllowedReserveTransferAssetsLocations>,
DisallowConcreteAssetUnless<AllowedReserveTransferAssetsLocations>,
>;

impl Contains<RuntimeCall> for ToKusamaXcmRouter {
Expand Down
34 changes: 17 additions & 17 deletions cumulus/parachains/runtimes/assets/common/src/matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,31 +126,31 @@ impl<

// check asset according to the configured reserve locations
for (reserve_location, asset_filter) in Reserves::get() {
if origin.eq(&reserve_location) {
if asset_filter.matches(asset_location) {
return true
}
if origin.eq(&reserve_location) && asset_filter.matches(asset_location) {
return true
}
}

false
}
}

/// Filter assets that are explicitly not allowed for destination.
/// Disallow all assets the are either not `Concrete`, or not explicitly allowed by
/// `LocationAssetFilters`, iff `dest` matches any location in `LocationAssetFilters`.
///
/// Returns true if asset is not `Concrete` or is explicitly not allowed by `LocationAssetFilters`.
/// Returns false if `dest` does not match any location in `LocationAssetFilters`.
pub struct IsNotAllowedConcreteAssetBy<LocationAssetFilters>(
/// Returns `false` regardless of `assets`, if `dest` does not match any location in
/// `LocationAssetFilters`. Otherwise, returns `true` if asset is either not `Concrete` or is not
/// explicitly allowed by `LocationAssetFilters`, otherwise returns `false`.
pub struct DisallowConcreteAssetUnless<LocationAssetFilters>(
sp_std::marker::PhantomData<LocationAssetFilters>,
);
impl<LocationAssetFilters: Get<sp_std::vec::Vec<FilteredLocation>>>
Contains<(MultiLocation, sp_std::vec::Vec<MultiAsset>)>
for IsNotAllowedConcreteAssetBy<LocationAssetFilters>
for DisallowConcreteAssetUnless<LocationAssetFilters>
{
fn contains((dest, assets): &(MultiLocation, sp_std::vec::Vec<MultiAsset>)) -> bool {
for (allowed_dest, asset_filter) in LocationAssetFilters::get().iter() {
// we care only about explicitly configured destinations
// we only disallow `assets` on explicitly configured destinations
if !allowed_dest.eq(dest) {
continue
}
Expand All @@ -162,22 +162,21 @@ impl<LocationAssetFilters: Get<sp_std::vec::Vec<FilteredLocation>>>
_ => return true,
};

// filter have to match for all assets
if !asset_filter.matches(asset_location) {
// if asset does not match filter, we found explicitly not allowed asset
// if asset does not match filter, disallow it
return true
}
}
}

// by default, everything is allowed
// if we got here, allow it
false
}
}

/// Adapter for `Contains<(MultiLocation, sp_std::vec::Vec<MultiAsset>)>` which checks
/// if `Exporters` contains exporter for **remote** `MultiLocation` and iff so, then checks
/// `Filter`, anyway return false.
/// Adapter for `Contains<(MultiLocation, sp_std::vec::Vec<MultiAsset>)>` which returns `true`
/// iff `Exporters` contains exporter for **remote** `MultiLocation` _and_
///`assets` also pass`Filter`, otherwise returns `false`.
///
/// Note: Assumes that `Exporters` do not depend on `XCM program` and works for `Xcm::default()`.
pub struct ExcludeOnlyForRemoteDestination<UniversalLocation, Exporters, Exclude>(
Expand All @@ -204,6 +203,7 @@ where
if Exporters::exporter_for(&remote_network, &remote_destination, &Xcm::default())
.is_some()
{
// destination is remote, and has configured exporter, now check filter
Exclude::contains(dest_and_assets)
} else {
log::trace!(
Expand All @@ -221,7 +221,7 @@ where
"CheckOnlyForRemoteDestination dest: {:?} is not remote to the universal_source: {:?}",
dest_and_assets.0, universal_source
);
//
// not a remote destination, do not exclude
false
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.

//! Bridge definitions.
//! Kusama BridgeHub definitions.

use crate::{
BridgeParachainPolkadotInstance, BridgePolkadotMessages, Runtime,
Expand Down Expand Up @@ -179,7 +179,7 @@ parameter_types! {
#[cfg(test)]
mod tests {
use super::*;
use crate::{constants, BridgeGrandpaPolkadotInstance};
use crate::BridgeGrandpaPolkadotInstance;
use bridge_runtime_common::{
assert_complete_bridge_types,
integrity::{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ impl Contains<RuntimeCall> for SafeCallFilter {
// Allow to change dedicated storage items (called by governance-like)
match call {
RuntimeCall::System(frame_system::Call::set_storage { items })
if items.iter().any(|(k, _)| {
if items.iter().all(|(k, _)| {
k.eq(&DeliveryRewardInBalance::key()) |
k.eq(&RequiredStakeForStakeAndSlash::key())
}) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.

//! Bridge definitions.
//! Polkadot BridgeHub definitions.

use crate::{
BridgeKusamaMessages, BridgeParachainKusamaInstance, Runtime,
Expand Down Expand Up @@ -168,8 +168,7 @@ pub type BridgeRefundBridgeHubKusamaMessages = RefundBridgedParachainMessages<
bp_runtime::generate_static_str_provider!(BridgeRefundBridgeHubKusamaMessages);

// TODO: rework once dynamic lanes are supported (https://github.com/paritytech/parity-bridges-common/issues/1760)
// now we support only StatemineToStatemint
/// Lanes setup
// now we support only AHP<>AHK Lanes setup
pub const ASSET_HUB_POLKADOT_TO_ASSET_HUB_KUSAMA_LANE_ID: LaneId = LaneId([0, 0, 0, 0]);
parameter_types! {
pub ActiveOutboundLanesToBridgeHubKusama: &'static [bp_messages::LaneId] = &[ASSET_HUB_POLKADOT_TO_ASSET_HUB_KUSAMA_LANE_ID];
Expand All @@ -179,7 +178,7 @@ parameter_types! {
#[cfg(test)]
mod tests {
use super::*;
use crate::{constants, BridgeGrandpaKusamaInstance};
use crate::BridgeGrandpaKusamaInstance;
use bridge_runtime_common::{
assert_complete_bridge_types,
integrity::{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl Contains<RuntimeCall> for SafeCallFilter {
// Allow to change dedicated storage items (called by governance-like)
match call {
RuntimeCall::System(frame_system::Call::set_storage { items })
if items.iter().any(|(k, _)| {
if items.iter().all(|(k, _)| {
k.eq(&DeliveryRewardInBalance::key()) |
k.eq(&RequiredStakeForStakeAndSlash::key())
}) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use bp_polkadot_core::Signature;
pub use bridge_hub_polkadot_runtime::{
bridge_hub_config,
constants::fee::WeightToFee,
xcm_config::{DotRelayLocation, RelayNetwork, XcmConfig},
AllPalletsWithoutSystem, Balances, BridgeGrandpaKusamaInstance,
BridgeRejectObsoleteHeadersAndMessages, ExistentialDeposit, ParachainSystem, PolkadotXcm,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ impl Contains<RuntimeCall> for SafeCallFilter {
// Allow to change dedicated storage items (called by governance-like)
match call {
RuntimeCall::System(frame_system::Call::set_storage { items })
if items.iter().any(|(k, _)| {
if items.iter().all(|(k, _)| {
k.eq(&DeliveryRewardInBalance::key()) |
k.eq(&RequiredStakeForStakeAndSlash::key())
}) =>
Expand Down

0 comments on commit b66e64e

Please sign in to comment.