From 173c44faf9bc0ec7a9ba5b51452452bcb9cd64a9 Mon Sep 17 00:00:00 2001 From: Cosmin Damian <17934949+cdamian@users.noreply.github.com> Date: Mon, 19 Aug 2024 18:13:55 +0300 Subject: [PATCH 1/2] lp-forwarder: Always use Centrifuge domain when wrapping outbound messages --- libs/traits/src/liquidity_pools.rs | 6 +----- pallets/liquidity-pools-forwarder/src/lib.rs | 4 +--- pallets/liquidity-pools-forwarder/src/mock.rs | 2 +- pallets/liquidity-pools/src/message.rs | 8 ++------ 4 files changed, 5 insertions(+), 15 deletions(-) diff --git a/libs/traits/src/liquidity_pools.rs b/libs/traits/src/liquidity_pools.rs index 8d983d272b..51d0717224 100644 --- a/libs/traits/src/liquidity_pools.rs +++ b/libs/traits/src/liquidity_pools.rs @@ -83,11 +83,7 @@ pub trait LpMessageForwarded: Sized { fn unwrap_forwarded(self) -> Option<(Self::Domain, H160, Self)>; /// Attempts to wrap into a forwarded message. - fn try_wrap_forward( - domain: Self::Domain, - forwarding_contract: H160, - message: Self, - ) -> Result; + fn try_wrap_forward(forwarding_contract: H160, message: Self) -> Result; } pub trait RouterProvider: Sized { diff --git a/pallets/liquidity-pools-forwarder/src/lib.rs b/pallets/liquidity-pools-forwarder/src/lib.rs index 78eaf60f47..dc30b839b5 100644 --- a/pallets/liquidity-pools-forwarder/src/lib.rs +++ b/pallets/liquidity-pools-forwarder/src/lib.rs @@ -210,9 +210,7 @@ pub mod pallet { message: T::Message, ) -> DispatchResult { let msg = RouterForwarding::::get(&router_id) - .map(|info| { - T::Message::try_wrap_forward(info.source_domain, info.contract, message.clone()) - }) + .map(|info| T::Message::try_wrap_forward(info.contract, message.clone())) .unwrap_or_else(|| { ensure!(!message.is_forwarded(), Error::::ForwardInfoNotFound); Ok(message) diff --git a/pallets/liquidity-pools-forwarder/src/mock.rs b/pallets/liquidity-pools-forwarder/src/mock.rs index c30bf2fcbb..32bd88ee10 100644 --- a/pallets/liquidity-pools-forwarder/src/mock.rs +++ b/pallets/liquidity-pools-forwarder/src/mock.rs @@ -46,7 +46,7 @@ impl LpMessageForwarded for Message { } } - fn try_wrap_forward(_: Self::Domain, _: H160, message: Self) -> Result { + fn try_wrap_forward(_: H160, message: Self) -> Result { match message { Self::Forward => Err(ERROR_NESTING), Self::NonForward => Ok(Self::Forward), diff --git a/pallets/liquidity-pools/src/message.rs b/pallets/liquidity-pools/src/message.rs index f3b3713023..0c41d19c64 100644 --- a/pallets/liquidity-pools/src/message.rs +++ b/pallets/liquidity-pools/src/message.rs @@ -659,13 +659,9 @@ impl LpMessageForwarded for Message { } } - fn try_wrap_forward( - source_domain: Domain, - forwarding_contract: H160, - message: Self, - ) -> Result { + fn try_wrap_forward(forwarding_contract: H160, message: Self) -> Result { Ok(Self::Forwarded { - source_domain: source_domain.into(), + source_domain: Domain::Centrifuge.into(), forwarding_contract, message: message.try_into().map_err(|_| { DispatchError::Other( From fa6c2530ce1c8cca14c1d7e207666cb9f21f61aa Mon Sep 17 00:00:00 2001 From: Cosmin Damian <17934949+cdamian@users.noreply.github.com> Date: Tue, 20 Aug 2024 11:22:16 +0300 Subject: [PATCH 2/2] lp-forwarder: Pass the domain to --- libs/traits/src/liquidity_pools.rs | 6 +++++- pallets/liquidity-pools-forwarder/src/lib.rs | 4 +++- pallets/liquidity-pools-forwarder/src/mock.rs | 2 +- pallets/liquidity-pools/src/message.rs | 8 ++++++-- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/libs/traits/src/liquidity_pools.rs b/libs/traits/src/liquidity_pools.rs index 51d0717224..8d983d272b 100644 --- a/libs/traits/src/liquidity_pools.rs +++ b/libs/traits/src/liquidity_pools.rs @@ -83,7 +83,11 @@ pub trait LpMessageForwarded: Sized { fn unwrap_forwarded(self) -> Option<(Self::Domain, H160, Self)>; /// Attempts to wrap into a forwarded message. - fn try_wrap_forward(forwarding_contract: H160, message: Self) -> Result; + fn try_wrap_forward( + domain: Self::Domain, + forwarding_contract: H160, + message: Self, + ) -> Result; } pub trait RouterProvider: Sized { diff --git a/pallets/liquidity-pools-forwarder/src/lib.rs b/pallets/liquidity-pools-forwarder/src/lib.rs index dc30b839b5..a93d4cb8d4 100644 --- a/pallets/liquidity-pools-forwarder/src/lib.rs +++ b/pallets/liquidity-pools-forwarder/src/lib.rs @@ -210,7 +210,9 @@ pub mod pallet { message: T::Message, ) -> DispatchResult { let msg = RouterForwarding::::get(&router_id) - .map(|info| T::Message::try_wrap_forward(info.contract, message.clone())) + .map(|info| { + T::Message::try_wrap_forward(Domain::Centrifuge, info.contract, message.clone()) + }) .unwrap_or_else(|| { ensure!(!message.is_forwarded(), Error::::ForwardInfoNotFound); Ok(message) diff --git a/pallets/liquidity-pools-forwarder/src/mock.rs b/pallets/liquidity-pools-forwarder/src/mock.rs index 32bd88ee10..c30bf2fcbb 100644 --- a/pallets/liquidity-pools-forwarder/src/mock.rs +++ b/pallets/liquidity-pools-forwarder/src/mock.rs @@ -46,7 +46,7 @@ impl LpMessageForwarded for Message { } } - fn try_wrap_forward(_: H160, message: Self) -> Result { + fn try_wrap_forward(_: Self::Domain, _: H160, message: Self) -> Result { match message { Self::Forward => Err(ERROR_NESTING), Self::NonForward => Ok(Self::Forward), diff --git a/pallets/liquidity-pools/src/message.rs b/pallets/liquidity-pools/src/message.rs index 0c41d19c64..07d469dd0e 100644 --- a/pallets/liquidity-pools/src/message.rs +++ b/pallets/liquidity-pools/src/message.rs @@ -659,9 +659,13 @@ impl LpMessageForwarded for Message { } } - fn try_wrap_forward(forwarding_contract: H160, message: Self) -> Result { + fn try_wrap_forward( + source_domain: Self::Domain, + forwarding_contract: H160, + message: Self, + ) -> Result { Ok(Self::Forwarded { - source_domain: Domain::Centrifuge.into(), + source_domain: source_domain.into(), forwarding_contract, message: message.try_into().map_err(|_| { DispatchError::Other(