Skip to content

Commit

Permalink
Message recovery follow ups (#1975)
Browse files Browse the repository at this point in the history
* lp-message: Use MessageHash for recovery fns

* lp-gateway: Drop domain from message recovery extrinsics
  • Loading branch information
cdamian authored Aug 17, 2024
1 parent a29e723 commit 35248da
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 19 deletions.
4 changes: 2 additions & 2 deletions libs/traits/src/liquidity_pools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Domain>: Sized {
Expand Down
8 changes: 5 additions & 3 deletions pallets/liquidity-pools-gateway/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ pub mod pallet {
type MessageSender: MessageSender<Middleware = Self::RouterId, Origin = DomainAddress>;

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

/// The type that provides the router available for a domain.
type RouterProvider: RouterProvider<Domain, RouterId = Self::RouterId>;
Expand Down Expand Up @@ -543,13 +543,14 @@ pub mod pallet {
#[pallet::call_index(12)]
pub fn initiate_message_recovery(
origin: OriginFor<T>,
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())?;
Expand All @@ -572,13 +573,14 @@ pub mod pallet {
#[pallet::call_index(13)]
pub fn dispute_message_recovery(
origin: OriginFor<T>,
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())?;
Expand Down
10 changes: 8 additions & 2 deletions pallets/liquidity-pools-gateway/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
Expand All @@ -142,6 +142,12 @@ impl RouterProvider<Domain> for TestRouterProvider {
}
}

impl Into<Domain> for RouterId {
fn into(self) -> Domain {
Domain::Evm(self.0.into())
}
}

frame_support::construct_runtime!(
pub enum Runtime {
System: frame_system,
Expand Down
10 changes: 0 additions & 10 deletions pallets/liquidity-pools-gateway/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,6 @@ mod extrinsics {

assert_ok!(LiquidityPoolsGateway::initiate_message_recovery(
RuntimeOrigin::root(),
TEST_DOMAIN,
MESSAGE_HASH,
recovery_router,
ROUTER_ID_1,
Expand All @@ -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,
Expand All @@ -937,7 +935,6 @@ mod extrinsics {
assert_noop!(
LiquidityPoolsGateway::initiate_message_recovery(
RuntimeOrigin::root(),
TEST_DOMAIN,
MESSAGE_HASH,
recovery_router,
ROUTER_ID_1,
Expand Down Expand Up @@ -969,7 +966,6 @@ mod extrinsics {
assert_noop!(
LiquidityPoolsGateway::initiate_message_recovery(
RuntimeOrigin::root(),
TEST_DOMAIN,
MESSAGE_HASH,
recovery_router,
RouterId(4),
Expand Down Expand Up @@ -1003,7 +999,6 @@ mod extrinsics {
assert_noop!(
LiquidityPoolsGateway::initiate_message_recovery(
RuntimeOrigin::root(),
TEST_DOMAIN,
MESSAGE_HASH,
recovery_router,
ROUTER_ID_1,
Expand Down Expand Up @@ -1038,7 +1033,6 @@ mod extrinsics {

assert_ok!(LiquidityPoolsGateway::dispute_message_recovery(
RuntimeOrigin::root(),
TEST_DOMAIN,
MESSAGE_HASH,
recovery_router,
ROUTER_ID_1,
Expand All @@ -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,
Expand All @@ -1079,7 +1072,6 @@ mod extrinsics {
assert_noop!(
LiquidityPoolsGateway::dispute_message_recovery(
RuntimeOrigin::root(),
TEST_DOMAIN,
MESSAGE_HASH,
recovery_router,
ROUTER_ID_1,
Expand Down Expand Up @@ -1111,7 +1103,6 @@ mod extrinsics {
assert_noop!(
LiquidityPoolsGateway::dispute_message_recovery(
RuntimeOrigin::root(),
TEST_DOMAIN,
MESSAGE_HASH,
recovery_router,
RouterId(4),
Expand Down Expand Up @@ -1145,7 +1136,6 @@ mod extrinsics {
assert_noop!(
LiquidityPoolsGateway::dispute_message_recovery(
RuntimeOrigin::root(),
TEST_DOMAIN,
MESSAGE_HASH,
recovery_router,
ROUTER_ID_1,
Expand Down
4 changes: 2 additions & 2 deletions pallets/liquidity-pools/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
}
Expand Down

0 comments on commit 35248da

Please sign in to comment.