Skip to content

Commit

Permalink
rebase: WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
cdamian committed Aug 13, 2024
1 parent c6dc81a commit 86ed19a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 37 deletions.
Empty file.
26 changes: 10 additions & 16 deletions pallets/liquidity-pools-gateway/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ use core::fmt::Debug;
use cfg_primitives::LP_DEFENSIVE_WEIGHT;
use cfg_traits::liquidity_pools::{
InboundMessageHandler, LPEncoding, MessageProcessor, MessageQueue, MessageReceiver,
MessageSender, OutboundMessageHandler, RouterSupport,
MessageSender, OutboundMessageHandler, Proof, RouterSupport,
};
use cfg_types::domain_address::{Domain, DomainAddress};
use frame_support::{dispatch::DispatchResult, pallet_prelude::*};
use frame_system::pallet_prelude::{ensure_signed, OriginFor};
use frame_system::pallet_prelude::{ensure_signed, BlockNumberFor, OriginFor};
use message::GatewayMessage;
use orml_traits::GetByKey;
pub use pallet::*;
use parity_scale_codec::{EncodeLike, FullCodec};
use sp_arithmetic::traits::{BaseArithmetic, One};
use parity_scale_codec::FullCodec;
use sp_arithmetic::traits::{BaseArithmetic, EnsureAddAssign, One};
use sp_std::convert::TryInto;

use crate::{message_processing::InboundEntry, weights::WeightInfo};
Expand All @@ -61,9 +61,6 @@ mod tests;

#[frame_support::pallet]
pub mod pallet {
use frame_system::pallet_prelude::BlockNumberFor;
use sp_arithmetic::traits::{EnsureAdd, EnsureAddAssign};

use super::*;

const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);
Expand Down Expand Up @@ -109,7 +106,7 @@ pub mod pallet {
type MessageSender: MessageSender<Middleware = Self::RouterId, Origin = DomainAddress>;

/// An identification of a router
type RouterId: RouterSupport<Domain> + Parameter;
type RouterId: RouterSupport<Domain> + Parameter + Default + MaxEncodedLen;

/// The type that processes inbound messages.
type InboundMessageHandler: InboundMessageHandler<
Expand All @@ -129,9 +126,7 @@ pub mod pallet {
type Sender: Get<DomainAddress>;

/// Type used for queueing messages.
type MessageQueue: MessageQueue<
Message = GatewayMessage<Self::AccountId, Self::Message, Self::RouterId>,
>;
type MessageQueue: MessageQueue<Message = GatewayMessage<Self::Message, Self::RouterId>>;

/// Maximum number of routers allowed for a domain.
#[pallet::constant]
Expand Down Expand Up @@ -545,7 +540,7 @@ pub mod pallet {
}

impl<T: Config> MessageProcessor for Pallet<T> {
type Message = GatewayMessage<T::AccountId, T::Message, T::RouterId>;
type Message = GatewayMessage<T::Message, T::RouterId>;

fn process(msg: Self::Message) -> (DispatchResult, Weight) {
match msg {
Expand Down Expand Up @@ -579,20 +574,19 @@ pub mod pallet {
type Origin = DomainAddress;

fn receive(
_router_id: T::RouterId,
router_id: T::RouterId,
origin_address: DomainAddress,
message: Vec<u8>,
) -> DispatchResult {
// TODO handle router ids logic with votes and session_id

ensure!(
Allowlist::<T>::contains_key(origin_address.domain(), origin_address.clone()),
Error::<T>::UnknownInstance,
);

let gateway_message = GatewayMessage::<T::Message>::Inbound {
let gateway_message = GatewayMessage::<T::Message, T::RouterId>::Inbound {
domain_address: origin_address,
message: T::Message::deserialize(&message)?,
router_id,
};

T::MessageQueue::submit(gateway_message)
Expand Down
8 changes: 3 additions & 5 deletions pallets/liquidity-pools-gateway/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,20 @@ use frame_support::pallet_prelude::{Decode, Encode, MaxEncodedLen, TypeInfo};

/// Message type used by the LP gateway.
#[derive(Debug, Encode, Decode, Clone, Eq, MaxEncodedLen, PartialEq, TypeInfo)]
pub enum GatewayMessage<AccountId, Message, RouterId> {
pub enum GatewayMessage<Message, RouterId> {
Inbound {
domain_address: DomainAddress,
message: Message,
router_id: RouterId,
},
Outbound {
sender: AccountId,
sender: DomainAddress,
message: Message,
router_id: RouterId,
},
}

impl<AccountId, Message: Default, Hash: Default> Default
for GatewayMessage<AccountId, Message, Hash>
{
impl<Message: Default, RouterId: Default> Default for GatewayMessage<Message, RouterId> {
fn default() -> Self {
GatewayMessage::Inbound {
domain_address: Default::default(),
Expand Down
13 changes: 6 additions & 7 deletions pallets/liquidity-pools-gateway/src/message_processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ impl<T: Config> Pallet<T> {
/// Retrieves the stored router, sends the message, and calculates and
/// returns the router operation result and the weight used.
pub(crate) fn process_outbound_message(
sender: T::AccountId,
sender: DomainAddress,
message: T::Message,
router_id: T::RouterId,
) -> (DispatchResult, Weight) {
Expand Down Expand Up @@ -419,12 +419,11 @@ impl<T: Config> Pallet<T> {

// We are using the sender specified in the pallet config so that we can
// ensure that the account is funded
let gateway_message =
GatewayMessage::<T::AccountId, T::Message, T::RouterId>::Outbound {
sender: T::Sender::get(),
message: router_msg,
router_id,
};
let gateway_message = GatewayMessage::<T::Message, T::RouterId>::Outbound {
sender: T::Sender::get(),
message: router_msg,
router_id,
};

T::MessageQueue::submit(gateway_message)?;
}
Expand Down
14 changes: 5 additions & 9 deletions pallets/liquidity-pools-gateway/src/mock.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
use std::fmt::{Debug, Formatter};

use cfg_mocks::{
pallet_mock_liquidity_pools, pallet_mock_liquidity_pools_gateway_queue, pallet_mock_routers,
RouterMock,
};
use cfg_traits::liquidity_pools::{LPEncoding, Proof};
use cfg_types::domain_address::DomainAddress;
use cfg_mocks::{pallet_mock_liquidity_pools, pallet_mock_liquidity_pools_gateway_queue};
use cfg_traits::liquidity_pools::{LPEncoding, Proof, RouterSupport};
use cfg_types::domain_address::{Domain, DomainAddress};
use frame_support::{derive_impl, weights::constants::RocksDbWeight};
use frame_system::EnsureRoot;
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
Expand Down Expand Up @@ -105,7 +102,7 @@ impl LPEncoding for Message {
}
}

#[derive(Debug, Encode, Decode, Clone, PartialEq, Eq, TypeInfo, MaxEncodedLen)]
#[derive(Default, Debug, Encode, Decode, Clone, PartialEq, Eq, TypeInfo, MaxEncodedLen)]
pub struct RouterId(u32);

impl RouterSupport<Domain> for RouterId {
Expand Down Expand Up @@ -138,7 +135,7 @@ impl pallet_mock_liquidity_pools::Config for Runtime {
}

impl pallet_mock_liquidity_pools_gateway_queue::Config for Runtime {
type Message = GatewayMessage<Message>;
type Message = GatewayMessage<Message, RouterId>;
}

impl cfg_mocks::router_message::pallet::Config for Runtime {
Expand All @@ -161,7 +158,6 @@ impl pallet_liquidity_pools_gateway::Config for Runtime {
type MaxRouterCount = MaxRouterCount;
type Message = Message;
type MessageQueue = MockLiquidityPoolsGatewayQueue;
type Router = RouterMock<Runtime>;
type MessageSender = MockMessageSender;
type RouterId = RouterId;
type RuntimeEvent = RuntimeEvent;
Expand Down

0 comments on commit 86ed19a

Please sign in to comment.