Skip to content

Commit

Permalink
Use Contains rather than StaticLookup
Browse files Browse the repository at this point in the history
  • Loading branch information
vgeddes committed Dec 18, 2023
1 parent 9f6d01d commit 3febd4b
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 19 deletions.
8 changes: 4 additions & 4 deletions parachain/pallets/outbound-queue/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ use bridge_hub_common::{AggregateMessageOrigin, CustomDigestItem};
use codec::Decode;
use frame_support::{
storage::StorageStreamIter,
traits::{tokens::Balance, Defensive, EnqueueMessage, Get, ProcessMessageError},
traits::{tokens::Balance, Contains, Defensive, EnqueueMessage, Get, ProcessMessageError},
weights::{Weight, WeightToFee},
};
use snowbridge_core::{
outbound::{Fee, GasMeter, QueuedMessage, VersionedQueuedMessage, ETHER_DECIMALS},
BasicOperatingMode, Channel, ChannelId, StaticLookup,
BasicOperatingMode, ChannelId,
};
use snowbridge_outbound_queue_merkle_tree::merkle_root;
pub use snowbridge_outbound_queue_merkle_tree::MerkleProof;
Expand Down Expand Up @@ -150,8 +150,8 @@ pub mod pallet {
#[pallet::constant]
type MaxMessagesPerBlock: Get<u32>;

/// Lookup a channel descriptor
type ChannelLookup: StaticLookup<Source = ChannelId, Target = Channel>;
/// Check whether a channel exists
type Channels: Contains<ChannelId>;

type PricingParameters: Get<PricingParameters<Self::Balance>>;

Expand Down
18 changes: 7 additions & 11 deletions parachain/pallets/outbound-queue/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ use super::*;

use frame_support::{
parameter_types,
traits::{Everything, Hooks},
traits::{Contains, Everything, Hooks},
weights::IdentityFee,
};

use hex_literal::hex;
use snowbridge_core::{
gwei, meth,
outbound::*,
pricing::{PricingParameters, Rewards},
Channel, ParaId, StaticLookup, PRIMARY_GOVERNANCE_CHANNEL,
ParaId, PRIMARY_GOVERNANCE_CHANNEL,
};
use sp_core::{ConstU32, ConstU8, H160, H256};
use sp_runtime::{
Expand Down Expand Up @@ -94,13 +93,10 @@ parameter_types! {

pub const DOT: u128 = 10_000_000_000;

pub struct MockChannelLookup;
impl StaticLookup for MockChannelLookup {
type Source = ChannelId;
type Target = Channel;

fn lookup(channel_id: Self::Source) -> Option<Self::Target> {
Some(Channel { agent_id: H256::zero(), para_id: 0.into() })
pub struct MockChannels;
impl Contains<ChannelId> for MockChannels {
fn contains(_: &ChannelId) -> bool {
true
}
}

Expand All @@ -114,7 +110,7 @@ impl crate::Config for Test {
type GasMeter = ConstantGasMeter;
type Balance = u128;
type PricingParameters = Parameters;
type ChannelLookup = MockChannelLookup;
type Channels = MockChannels;
type WeightToFee = IdentityFee<u128>;
type WeightInfo = ();
}
Expand Down
2 changes: 1 addition & 1 deletion parachain/pallets/outbound-queue/src/send_message_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ where
);

// Ensure there is a registered channel we can transmit this message on
ensure!(T::ChannelLookup::lookup(message.channel_id).is_some(), SendError::InvalidChannel);
ensure!(T::Channels::contains(&message.channel_id), SendError::InvalidChannel);

// Generate a unique message id unless one is provided
let message_id: H256 = message
Expand Down
8 changes: 7 additions & 1 deletion parachain/pallets/system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ use frame_support::{
traits::{
fungible::{Inspect, Mutate},
tokens::Preservation,
EnsureOrigin,
Contains, EnsureOrigin,
},
};
use frame_system::pallet_prelude::*;
Expand Down Expand Up @@ -653,6 +653,12 @@ pub mod pallet {
}
}

impl<T: Config> Contains<ChannelId> for Pallet<T> {
fn contains(channel_id: &ChannelId) -> bool {
Channels::<T>::get(channel_id).is_some()
}
}

impl<T: Config> Get<PricingParametersOf<T>> for Pallet<T> {
fn get() -> PricingParametersOf<T> {
PricingParameters::<T>::get()
Expand Down
2 changes: 1 addition & 1 deletion parachain/pallets/system/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ impl snowbridge_outbound_queue::Config for Test {
type GasMeter = ConstantGasMeter;
type Balance = u128;
type PricingParameters = EthereumSystem;
type ChannelLookup = EthereumSystem;
type Channels = EthereumSystem;
type WeightToFee = IdentityFee<u128>;
type WeightInfo = ();
}
Expand Down
2 changes: 1 addition & 1 deletion polkadot-sdk

0 comments on commit 3febd4b

Please sign in to comment.