From 2e184744ef6db71e077b42acf37b6dbf75372bf5 Mon Sep 17 00:00:00 2001 From: Cosmin Damian <17934949+cdamian@users.noreply.github.com> Date: Tue, 13 Aug 2024 12:51:16 +0300 Subject: [PATCH] rebase: WIP --- .../src/liquidity_pools_gateway_routers.rs | 0 pallets/liquidity-pools-gateway/src/lib.rs | 26 +++++++------------ .../liquidity-pools-gateway/src/message.rs | 8 +++--- .../src/message_processing.rs | 13 +++++----- pallets/liquidity-pools-gateway/src/mock.rs | 14 ++++------ 5 files changed, 24 insertions(+), 37 deletions(-) delete mode 100644 libs/mocks/src/liquidity_pools_gateway_routers.rs diff --git a/libs/mocks/src/liquidity_pools_gateway_routers.rs b/libs/mocks/src/liquidity_pools_gateway_routers.rs deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/pallets/liquidity-pools-gateway/src/lib.rs b/pallets/liquidity-pools-gateway/src/lib.rs index 5ad416e6d0..f04b7c4543 100644 --- a/pallets/liquidity-pools-gateway/src/lib.rs +++ b/pallets/liquidity-pools-gateway/src/lib.rs @@ -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}; @@ -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); @@ -109,7 +106,7 @@ pub mod pallet { type MessageSender: MessageSender; /// An identification of a router - type RouterId: RouterSupport + Parameter; + type RouterId: RouterSupport + Parameter + Default + MaxEncodedLen; /// The type that processes inbound messages. type InboundMessageHandler: InboundMessageHandler< @@ -129,9 +126,7 @@ pub mod pallet { type Sender: Get; /// Type used for queueing messages. - type MessageQueue: MessageQueue< - Message = GatewayMessage, - >; + type MessageQueue: MessageQueue>; /// Maximum number of routers allowed for a domain. #[pallet::constant] @@ -545,7 +540,7 @@ pub mod pallet { } impl MessageProcessor for Pallet { - type Message = GatewayMessage; + type Message = GatewayMessage; fn process(msg: Self::Message) -> (DispatchResult, Weight) { match msg { @@ -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, ) -> DispatchResult { - // TODO handle router ids logic with votes and session_id - ensure!( Allowlist::::contains_key(origin_address.domain(), origin_address.clone()), Error::::UnknownInstance, ); - let gateway_message = GatewayMessage::::Inbound { + let gateway_message = GatewayMessage::::Inbound { domain_address: origin_address, message: T::Message::deserialize(&message)?, + router_id, }; T::MessageQueue::submit(gateway_message) diff --git a/pallets/liquidity-pools-gateway/src/message.rs b/pallets/liquidity-pools-gateway/src/message.rs index 0d6fc4ff38..0c6707814b 100644 --- a/pallets/liquidity-pools-gateway/src/message.rs +++ b/pallets/liquidity-pools-gateway/src/message.rs @@ -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 { +pub enum GatewayMessage { Inbound { domain_address: DomainAddress, message: Message, router_id: RouterId, }, Outbound { - sender: AccountId, + sender: DomainAddress, message: Message, router_id: RouterId, }, } -impl Default - for GatewayMessage -{ +impl Default for GatewayMessage { fn default() -> Self { GatewayMessage::Inbound { domain_address: Default::default(), diff --git a/pallets/liquidity-pools-gateway/src/message_processing.rs b/pallets/liquidity-pools-gateway/src/message_processing.rs index 80828991a1..ef46531522 100644 --- a/pallets/liquidity-pools-gateway/src/message_processing.rs +++ b/pallets/liquidity-pools-gateway/src/message_processing.rs @@ -378,7 +378,7 @@ impl Pallet { /// 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) { @@ -419,12 +419,11 @@ impl Pallet { // We are using the sender specified in the pallet config so that we can // ensure that the account is funded - let gateway_message = - GatewayMessage::::Outbound { - sender: T::Sender::get(), - message: router_msg, - router_id, - }; + let gateway_message = GatewayMessage::::Outbound { + sender: T::Sender::get(), + message: router_msg, + router_id, + }; T::MessageQueue::submit(gateway_message)?; } diff --git a/pallets/liquidity-pools-gateway/src/mock.rs b/pallets/liquidity-pools-gateway/src/mock.rs index 211dc61844..157e06c3ed 100644 --- a/pallets/liquidity-pools-gateway/src/mock.rs +++ b/pallets/liquidity-pools-gateway/src/mock.rs @@ -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}; @@ -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 for RouterId { @@ -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; + type Message = GatewayMessage; } impl cfg_mocks::router_message::pallet::Config for Runtime { @@ -161,7 +158,6 @@ impl pallet_liquidity_pools_gateway::Config for Runtime { type MaxRouterCount = MaxRouterCount; type Message = Message; type MessageQueue = MockLiquidityPoolsGatewayQueue; - type Router = RouterMock; type MessageSender = MockMessageSender; type RouterId = RouterId; type RuntimeEvent = RuntimeEvent;