From 35248dacfc5ca235c92b480daa0f4fd211f51367 Mon Sep 17 00:00:00 2001 From: Cosmin Damian <17934949+cdamian@users.noreply.github.com> Date: Sat, 17 Aug 2024 15:30:47 +0300 Subject: [PATCH] Message recovery follow ups (#1975) * lp-message: Use MessageHash for recovery fns * lp-gateway: Drop domain from message recovery extrinsics --- libs/traits/src/liquidity_pools.rs | 4 ++-- pallets/liquidity-pools-gateway/src/lib.rs | 8 +++++--- pallets/liquidity-pools-gateway/src/mock.rs | 10 ++++++++-- pallets/liquidity-pools-gateway/src/tests.rs | 10 ---------- pallets/liquidity-pools/src/message.rs | 4 ++-- 5 files changed, 17 insertions(+), 19 deletions(-) diff --git a/libs/traits/src/liquidity_pools.rs b/libs/traits/src/liquidity_pools.rs index d0dc006f7d..493796030a 100644 --- a/libs/traits/src/liquidity_pools.rs +++ b/libs/traits/src/liquidity_pools.rs @@ -48,13 +48,13 @@ pub trait LPMessage: Sized { /// /// Hash - hash of the message that should be recovered. /// Router - the address of the recovery router. - fn initiate_recovery_message(hash: [u8; 32], router: [u8; 32]) -> Self; + fn initiate_recovery_message(hash: MessageHash, router: [u8; 32]) -> Self; /// Creates a message used for disputing message recovery. /// /// Hash - hash of the message that should be disputed. /// Router - the address of the recovery router. - fn dispute_recovery_message(hash: [u8; 32], router: [u8; 32]) -> Self; + fn dispute_recovery_message(hash: MessageHash, router: [u8; 32]) -> Self; } pub trait RouterProvider: Sized { diff --git a/pallets/liquidity-pools-gateway/src/lib.rs b/pallets/liquidity-pools-gateway/src/lib.rs index 6e8371f93c..aadbbf1ff6 100644 --- a/pallets/liquidity-pools-gateway/src/lib.rs +++ b/pallets/liquidity-pools-gateway/src/lib.rs @@ -113,7 +113,7 @@ pub mod pallet { type MessageSender: MessageSender; /// An identification of a router - type RouterId: Parameter + MaxEncodedLen; + type RouterId: Parameter + MaxEncodedLen + Into; /// The type that provides the router available for a domain. type RouterProvider: RouterProvider; @@ -543,13 +543,14 @@ pub mod pallet { #[pallet::call_index(12)] pub fn initiate_message_recovery( origin: OriginFor, - domain: Domain, message_hash: MessageHash, recovery_router: [u8; 32], messaging_router: T::RouterId, ) -> DispatchResult { T::AdminOrigin::ensure_origin(origin)?; + let domain = messaging_router.clone().into(); + let message = T::Message::initiate_recovery_message(message_hash, recovery_router); Self::send_recovery_message(domain, message, messaging_router.clone())?; @@ -572,13 +573,14 @@ pub mod pallet { #[pallet::call_index(13)] pub fn dispute_message_recovery( origin: OriginFor, - domain: Domain, message_hash: MessageHash, recovery_router: [u8; 32], messaging_router: T::RouterId, ) -> DispatchResult { T::AdminOrigin::ensure_origin(origin)?; + let domain = messaging_router.clone().into(); + let message = T::Message::dispute_recovery_message(message_hash, recovery_router); Self::send_recovery_message(domain, message, messaging_router.clone())?; diff --git a/pallets/liquidity-pools-gateway/src/mock.rs b/pallets/liquidity-pools-gateway/src/mock.rs index 55689d8b56..19d14d3c37 100644 --- a/pallets/liquidity-pools-gateway/src/mock.rs +++ b/pallets/liquidity-pools-gateway/src/mock.rs @@ -117,11 +117,11 @@ impl LPMessage for Message { } } - fn initiate_recovery_message(hash: [u8; 32], router: [u8; 32]) -> Self { + fn initiate_recovery_message(hash: MessageHash, router: [u8; 32]) -> Self { Self::InitiateMessageRecovery((hash, router)) } - fn dispute_recovery_message(hash: [u8; 32], router: [u8; 32]) -> Self { + fn dispute_recovery_message(hash: MessageHash, router: [u8; 32]) -> Self { Self::DisputeMessageRecovery((hash, router)) } } @@ -142,6 +142,12 @@ impl RouterProvider for TestRouterProvider { } } +impl Into for RouterId { + fn into(self) -> Domain { + Domain::Evm(self.0.into()) + } +} + frame_support::construct_runtime!( pub enum Runtime { System: frame_system, diff --git a/pallets/liquidity-pools-gateway/src/tests.rs b/pallets/liquidity-pools-gateway/src/tests.rs index 58cdee3607..305882ea03 100644 --- a/pallets/liquidity-pools-gateway/src/tests.rs +++ b/pallets/liquidity-pools-gateway/src/tests.rs @@ -896,7 +896,6 @@ mod extrinsics { assert_ok!(LiquidityPoolsGateway::initiate_message_recovery( RuntimeOrigin::root(), - TEST_DOMAIN, MESSAGE_HASH, recovery_router, ROUTER_ID_1, @@ -919,7 +918,6 @@ mod extrinsics { assert_noop!( LiquidityPoolsGateway::initiate_message_recovery( RuntimeOrigin::signed(AccountId32::new([0u8; 32])), - TEST_DOMAIN, MESSAGE_HASH, recovery_router, ROUTER_ID_1, @@ -937,7 +935,6 @@ mod extrinsics { assert_noop!( LiquidityPoolsGateway::initiate_message_recovery( RuntimeOrigin::root(), - TEST_DOMAIN, MESSAGE_HASH, recovery_router, ROUTER_ID_1, @@ -969,7 +966,6 @@ mod extrinsics { assert_noop!( LiquidityPoolsGateway::initiate_message_recovery( RuntimeOrigin::root(), - TEST_DOMAIN, MESSAGE_HASH, recovery_router, RouterId(4), @@ -1003,7 +999,6 @@ mod extrinsics { assert_noop!( LiquidityPoolsGateway::initiate_message_recovery( RuntimeOrigin::root(), - TEST_DOMAIN, MESSAGE_HASH, recovery_router, ROUTER_ID_1, @@ -1038,7 +1033,6 @@ mod extrinsics { assert_ok!(LiquidityPoolsGateway::dispute_message_recovery( RuntimeOrigin::root(), - TEST_DOMAIN, MESSAGE_HASH, recovery_router, ROUTER_ID_1, @@ -1061,7 +1055,6 @@ mod extrinsics { assert_noop!( LiquidityPoolsGateway::dispute_message_recovery( RuntimeOrigin::signed(AccountId32::new([0u8; 32])), - TEST_DOMAIN, MESSAGE_HASH, recovery_router, ROUTER_ID_1, @@ -1079,7 +1072,6 @@ mod extrinsics { assert_noop!( LiquidityPoolsGateway::dispute_message_recovery( RuntimeOrigin::root(), - TEST_DOMAIN, MESSAGE_HASH, recovery_router, ROUTER_ID_1, @@ -1111,7 +1103,6 @@ mod extrinsics { assert_noop!( LiquidityPoolsGateway::dispute_message_recovery( RuntimeOrigin::root(), - TEST_DOMAIN, MESSAGE_HASH, recovery_router, RouterId(4), @@ -1145,7 +1136,6 @@ mod extrinsics { assert_noop!( LiquidityPoolsGateway::dispute_message_recovery( RuntimeOrigin::root(), - TEST_DOMAIN, MESSAGE_HASH, recovery_router, ROUTER_ID_1, diff --git a/pallets/liquidity-pools/src/message.rs b/pallets/liquidity-pools/src/message.rs index 1b52ca3e23..0683c0cf6b 100644 --- a/pallets/liquidity-pools/src/message.rs +++ b/pallets/liquidity-pools/src/message.rs @@ -576,11 +576,11 @@ impl LPMessage for Message { } } - fn initiate_recovery_message(hash: [u8; 32], router: [u8; 32]) -> Self { + fn initiate_recovery_message(hash: MessageHash, router: [u8; 32]) -> Self { Message::InitiateMessageRecovery { hash, router } } - fn dispute_recovery_message(hash: [u8; 32], router: [u8; 32]) -> Self { + fn dispute_recovery_message(hash: MessageHash, router: [u8; 32]) -> Self { Message::DisputeMessageRecovery { hash, router } } }