From d854ce87e871cc65fd59bfc26eb6c1d9025fac62 Mon Sep 17 00:00:00 2001 From: Cosmin Damian <17934949+cdamian@users.noreply.github.com> Date: Fri, 16 Aug 2024 12:49:20 +0300 Subject: [PATCH 01/11] lp-gateway: Add extrinsics for initiating and disputing message recovery --- libs/traits/src/liquidity_pools.rs | 21 ++- pallets/liquidity-pools-gateway/src/lib.rs | 125 ++++++++++++++++-- .../src/message_processing.rs | 16 +-- pallets/liquidity-pools-gateway/src/mock.rs | 17 ++- pallets/liquidity-pools-gateway/src/tests.rs | 12 +- .../liquidity-pools-gateway/src/weights.rs | 24 ++++ pallets/liquidity-pools/src/message.rs | 22 ++- .../integration-tests/src/cases/routers.rs | 2 +- 8 files changed, 198 insertions(+), 41 deletions(-) diff --git a/libs/traits/src/liquidity_pools.rs b/libs/traits/src/liquidity_pools.rs index 0f80787337..f5bf7855ff 100644 --- a/libs/traits/src/liquidity_pools.rs +++ b/libs/traits/src/liquidity_pools.rs @@ -15,11 +15,12 @@ use frame_support::{dispatch::DispatchResult, weights::Weight}; use sp_runtime::DispatchError; use sp_std::vec::Vec; -pub type Proof = [u8; 32]; +/// Type that represents the hash of an LP message. +pub type MessageHash = [u8; 32]; /// An encoding & decoding trait for the purpose of meeting the /// LiquidityPools General Message Passing Format -pub trait LPEncoding: Sized { +pub trait LPMessage: Sized { fn serialize(&self) -> Vec; fn deserialize(input: &[u8]) -> Result; @@ -34,11 +35,23 @@ pub trait LPEncoding: Sized { /// It's the identity message for composing messages with pack_with fn empty() -> Self; - /// Retrieves the message proof hash, if the message is a proof type. - fn get_proof(&self) -> Option; + /// Retrieves the message hash, if the message is a proof type. + fn get_message_hash(&self) -> Option; /// Converts the message into a message proof type. fn to_proof_message(&self) -> Self; + + /// Creates a message used for initiating message recovery. + /// + /// Hash - hash of the message that should be recovered. + /// Router - the address of the recovery router. + fn initiate_message_recovery_message(hash: [u8; 32], router: [u8; 20]) -> 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_message_recovery_message(hash: [u8; 32], router: [u8; 20]) -> Self; } pub trait RouterProvider: Sized { diff --git a/pallets/liquidity-pools-gateway/src/lib.rs b/pallets/liquidity-pools-gateway/src/lib.rs index ad4ca6f8be..b6c76113b3 100644 --- a/pallets/liquidity-pools-gateway/src/lib.rs +++ b/pallets/liquidity-pools-gateway/src/lib.rs @@ -30,8 +30,8 @@ use core::fmt::Debug; use cfg_primitives::LP_DEFENSIVE_WEIGHT; use cfg_traits::liquidity_pools::{ - InboundMessageHandler, LPEncoding, MessageProcessor, MessageQueue, MessageReceiver, - MessageSender, OutboundMessageHandler, Proof, RouterProvider, + InboundMessageHandler, LPMessage, MessageHash, MessageProcessor, MessageQueue, MessageReceiver, + MessageSender, OutboundMessageHandler, RouterProvider, }; use cfg_types::domain_address::{Domain, DomainAddress}; use frame_support::{dispatch::DispatchResult, pallet_prelude::*}; @@ -95,7 +95,7 @@ pub mod pallet { type AdminOrigin: EnsureOrigin<::RuntimeOrigin>; /// The Liquidity Pools message type. - type Message: LPEncoding + type Message: LPMessage + Clone + Debug + PartialEq @@ -164,9 +164,25 @@ pub mod pallet { /// Message recovery was executed. MessageRecoveryExecuted { - proof: Proof, + message_hash: MessageHash, router_id: T::RouterId, }, + + /// Message recovery was initiated. + MessageRecoveryInitiated { + domain: Domain, + message_hash: MessageHash, + recovery_router: [u8; 20], + messaging_router: T::RouterId, + }, + + /// Message recovery was disputed. + MessageRecoveryDisputed { + domain: Domain, + message_hash: MessageHash, + recovery_router: [u8; 20], + messaging_router: T::RouterId, + }, } /// Storage for routers. @@ -208,7 +224,7 @@ pub mod pallet { pub type PendingInboundEntries = StorageDoubleMap< _, Blake2_128Concat, - Proof, + MessageHash, Blake2_128Concat, T::RouterId, InboundEntry, @@ -249,6 +265,9 @@ pub mod pallet { /// Unknown router. UnknownRouter, + /// Messaging router not found. + MessagingRouterNotFound, + /// The router that sent the message is not the first one. MessageExpectedFromFirstRouter, @@ -431,7 +450,7 @@ pub mod pallet { pub fn execute_message_recovery( origin: OriginFor, domain_address: DomainAddress, - proof: Proof, + message_hash: MessageHash, router_id: T::RouterId, ) -> DispatchResult { T::AdminOrigin::ensure_origin(origin)?; @@ -448,8 +467,10 @@ pub mod pallet { let session_id = SessionIdStore::::get(); - PendingInboundEntries::::try_mutate(proof, router_id.clone(), |storage_entry| { - match storage_entry { + PendingInboundEntries::::try_mutate( + message_hash, + router_id.clone(), + |storage_entry| match storage_entry { Some(stored_inbound_entry) => { stored_inbound_entry.increment_proof_count(session_id) } @@ -461,25 +482,105 @@ pub mod pallet { Ok::<(), DispatchError>(()) } - } - })?; + }, + )?; let expected_proof_count = Self::get_expected_proof_count(&router_ids)?; Self::execute_if_requirements_are_met( - proof, + message_hash, &router_ids, session_id, expected_proof_count, domain_address, )?; - Self::deposit_event(Event::::MessageRecoveryExecuted { proof, router_id }); + Self::deposit_event(Event::::MessageRecoveryExecuted { + message_hash, + router_id, + }); + + Ok(()) + } + + /// Sends a message that initiates a message recovery using the + /// messaging router. + /// + /// Can only be called by `AdminOrigin`. + #[pallet::weight(T::WeightInfo::initiate_message_recovery())] + #[pallet::call_index(12)] + pub fn initiate_message_recovery( + origin: OriginFor, + domain: Domain, + message_hash: MessageHash, + recovery_router: [u8; 20], + messaging_router: T::RouterId, + ) -> DispatchResult { + T::AdminOrigin::ensure_origin(origin)?; + + let message = + T::Message::initiate_message_recovery_message(message_hash, recovery_router); + + Self::send_message_recovery_message(domain.clone(), message, messaging_router.clone())?; + + Self::deposit_event(Event::::MessageRecoveryInitiated { + domain, + message_hash, + recovery_router, + messaging_router, + }); + + Ok(()) + } + + /// Sends a message that disputes a message recovery using the + /// messaging router. + /// + /// Can only be called by `AdminOrigin`. + #[pallet::weight(T::WeightInfo::initiate_message_recovery())] + #[pallet::call_index(13)] + pub fn dispute_message_recovery( + origin: OriginFor, + domain: Domain, + message_hash: MessageHash, + recovery_router: [u8; 20], + messaging_router: T::RouterId, + ) -> DispatchResult { + T::AdminOrigin::ensure_origin(origin)?; + + let message = + T::Message::dispute_message_recovery_message(message_hash, recovery_router); + + Self::send_message_recovery_message(domain.clone(), message, messaging_router.clone())?; + + Self::deposit_event(Event::::MessageRecoveryDisputed { + domain, + message_hash, + recovery_router, + messaging_router, + }); Ok(()) } } + impl Pallet { + fn send_message_recovery_message( + domain: Domain, + message: T::Message, + messaging_router: T::RouterId, + ) -> DispatchResult { + let router_ids = Self::get_router_ids_for_domain(domain)?; + + ensure!( + router_ids.iter().any(|x| x == &messaging_router), + Error::::MessagingRouterNotFound + ); + + T::MessageSender::send(messaging_router, T::Sender::get(), message.serialize()) + } + } + impl OutboundMessageHandler for Pallet { type Destination = Domain; type Message = T::Message; diff --git a/pallets/liquidity-pools-gateway/src/message_processing.rs b/pallets/liquidity-pools-gateway/src/message_processing.rs index 2ea6d0c401..9c060ea5ba 100644 --- a/pallets/liquidity-pools-gateway/src/message_processing.rs +++ b/pallets/liquidity-pools-gateway/src/message_processing.rs @@ -1,5 +1,5 @@ use cfg_traits::liquidity_pools::{ - InboundMessageHandler, LPEncoding, MessageQueue, Proof, RouterProvider, + InboundMessageHandler, LPMessage, MessageHash, MessageQueue, RouterProvider, }; use cfg_types::domain_address::{Domain, DomainAddress}; use frame_support::{ @@ -92,7 +92,7 @@ impl InboundEntry { domain_address: DomainAddress, expected_proof_count: u32, ) -> Self { - match message.get_proof() { + match message.get_message_hash() { None => InboundEntry::Message(MessageEntry { session_id, domain_address, @@ -291,11 +291,11 @@ impl Pallet { } /// Gets the message proof for a message. - pub(crate) fn get_message_proof(message: T::Message) -> Proof { - match message.get_proof() { + pub(crate) fn get_message_proof(message: T::Message) -> MessageHash { + match message.get_message_hash() { None => message .to_proof_message() - .get_proof() + .get_message_hash() .expect("message proof ensured by 'to_message_proof'"), Some(proof) => proof, } @@ -304,7 +304,7 @@ impl Pallet { /// Upserts an inbound entry for a particular message, increasing the /// relevant counts accordingly. pub(crate) fn upsert_pending_entry( - message_proof: Proof, + message_proof: MessageHash, router_id: &T::RouterId, new_inbound_entry: InboundEntry, ) -> DispatchResult { @@ -326,7 +326,7 @@ impl Pallet { /// were received, and if so, decreases the counts accordingly and executes /// the message. pub(crate) fn execute_if_requirements_are_met( - message_proof: Proof, + message_proof: MessageHash, router_ids: &[T::RouterId], session_id: T::SessionId, expected_proof_count: u32, @@ -368,7 +368,7 @@ impl Pallet { /// Decreases the counts for inbound entries and removes them if the /// counts reach 0. pub(crate) fn execute_post_voting_dispatch( - message_proof: Proof, + message_proof: MessageHash, router_ids: &[T::RouterId], expected_proof_count: u32, ) -> DispatchResult { diff --git a/pallets/liquidity-pools-gateway/src/mock.rs b/pallets/liquidity-pools-gateway/src/mock.rs index 629858220a..30e8d0b878 100644 --- a/pallets/liquidity-pools-gateway/src/mock.rs +++ b/pallets/liquidity-pools-gateway/src/mock.rs @@ -1,7 +1,7 @@ use std::fmt::{Debug, Formatter}; use cfg_mocks::{pallet_mock_liquidity_pools, pallet_mock_liquidity_pools_gateway_queue}; -use cfg_traits::liquidity_pools::{LPEncoding, Proof, RouterProvider}; +use cfg_traits::liquidity_pools::{LPMessage, MessageHash, RouterProvider}; use cfg_types::{ domain_address::{Domain, DomainAddress}, EVMChainId, @@ -36,6 +36,8 @@ pub enum Message { Simple, Pack(Vec), Proof([u8; 32]), + InitiateMessageRecovery(([u8; 32], [u8; 20])), + DisputeMessageRecovery(([u8; 32], [u8; 20])), } impl Debug for Message { @@ -44,6 +46,7 @@ impl Debug for Message { Message::Simple => write!(f, "Simple"), Message::Pack(p) => write!(f, "Pack - {:?}", p), Message::Proof(_) => write!(f, "Proof"), + other => write!(f, "{:?}", other), } } } @@ -55,7 +58,7 @@ impl MaxEncodedLen for Message { } } -impl LPEncoding for Message { +impl LPMessage for Message { fn serialize(&self) -> Vec { match self { Self::Pack(list) => list.iter().map(|_| 0x42).collect(), @@ -98,7 +101,7 @@ impl LPEncoding for Message { Self::Pack(vec![]) } - fn get_proof(&self) -> Option { + fn get_message_hash(&self) -> Option { match self { Message::Proof(p) => Some(p.clone()), _ => None, @@ -111,6 +114,14 @@ impl LPEncoding for Message { _ => Message::Proof(MESSAGE_PROOF), } } + + fn initiate_message_recovery_message(hash: [u8; 32], router: [u8; 20]) -> Self { + Self::InitiateMessageRecovery((hash, router)) + } + + fn dispute_message_recovery_message(hash: [u8; 32], router: [u8; 20]) -> Self { + Self::DisputeMessageRecovery((hash, router)) + } } #[derive(Default, Debug, Encode, Decode, Clone, PartialEq, Eq, TypeInfo, MaxEncodedLen, Hash)] diff --git a/pallets/liquidity-pools-gateway/src/tests.rs b/pallets/liquidity-pools-gateway/src/tests.rs index 69f25c4b0a..22c5d02d30 100644 --- a/pallets/liquidity-pools-gateway/src/tests.rs +++ b/pallets/liquidity-pools-gateway/src/tests.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; use cfg_primitives::LP_DEFENSIVE_WEIGHT; -use cfg_traits::liquidity_pools::{LPEncoding, MessageProcessor, OutboundMessageHandler}; +use cfg_traits::liquidity_pools::{LPMessage, MessageProcessor, OutboundMessageHandler}; use cfg_types::domain_address::*; use frame_support::{assert_err, assert_noop, assert_ok}; use itertools::Itertools; @@ -690,7 +690,7 @@ mod extrinsics { )); event_exists(Event::::MessageRecoveryExecuted { - proof: MESSAGE_PROOF, + message_hash: MESSAGE_PROOF, router_id: ROUTER_ID_2, }); @@ -734,7 +734,7 @@ mod extrinsics { )); event_exists(Event::::MessageRecoveryExecuted { - proof: MESSAGE_PROOF, + message_hash: MESSAGE_PROOF, router_id: ROUTER_ID_2, }); @@ -886,7 +886,7 @@ mod implementations { let domain = Domain::Evm(0); let sender = get_test_account_id(); let msg = Message::Simple; - let message_proof = msg.to_proof_message().get_proof().unwrap(); + let message_proof = msg.to_proof_message().get_message_hash().unwrap(); assert_ok!(LiquidityPoolsGateway::set_routers( RuntimeOrigin::root(), @@ -1143,7 +1143,7 @@ mod implementations { fn success() { new_test_ext().execute_with(|| { let message = Message::Simple; - let message_proof = message.to_proof_message().get_proof().unwrap(); + let message_proof = message.to_proof_message().get_message_hash().unwrap(); let session_id = 1; let domain_address = DomainAddress::Evm(1, H160::repeat_byte(1)); let router_id = ROUTER_ID_1; @@ -1224,7 +1224,7 @@ mod implementations { fn expected_message_proof_type() { new_test_ext().execute_with(|| { let message = Message::Simple; - let message_proof = message.to_proof_message().get_proof().unwrap(); + let message_proof = message.to_proof_message().get_message_hash().unwrap(); let session_id = 1; let domain_address = DomainAddress::Evm(1, H160::repeat_byte(1)); let router_id = ROUTER_ID_1; diff --git a/pallets/liquidity-pools-gateway/src/weights.rs b/pallets/liquidity-pools-gateway/src/weights.rs index b330d71ac6..a06926a7ba 100644 --- a/pallets/liquidity-pools-gateway/src/weights.rs +++ b/pallets/liquidity-pools-gateway/src/weights.rs @@ -23,6 +23,8 @@ pub trait WeightInfo { fn end_batch_message() -> Weight; fn set_domain_hook_address() -> Weight; fn execute_message_recovery() -> Weight; + fn initiate_message_recovery() -> Weight; + fn dispute_message_recovery() -> Weight; } // NOTE: We use temporary weights here. `execute_epoch` is by far our heaviest @@ -146,4 +148,26 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().reads(2)) .saturating_add(RocksDbWeight::get().writes(2)) } + + fn initiate_message_recovery() -> Weight { + // TODO: BENCHMARK CORRECTLY + // + // NOTE: Reasonable weight taken from `PoolSystem::set_max_reserve` + // This one has one read and one write for sure and possible one + // read for `AdminOrigin` + Weight::from_parts(30_117_000, 5991) + .saturating_add(RocksDbWeight::get().reads(2)) + .saturating_add(RocksDbWeight::get().writes(2)) + } + + fn dispute_message_recovery() -> Weight { + // TODO: BENCHMARK CORRECTLY + // + // NOTE: Reasonable weight taken from `PoolSystem::set_max_reserve` + // This one has one read and one write for sure and possible one + // read for `AdminOrigin` + Weight::from_parts(30_117_000, 5991) + .saturating_add(RocksDbWeight::get().reads(2)) + .saturating_add(RocksDbWeight::get().writes(2)) + } } diff --git a/pallets/liquidity-pools/src/message.rs b/pallets/liquidity-pools/src/message.rs index 8a191a631c..b12c0ed7d6 100644 --- a/pallets/liquidity-pools/src/message.rs +++ b/pallets/liquidity-pools/src/message.rs @@ -6,7 +6,7 @@ //! representation for each message variant. use cfg_traits::{ - liquidity_pools::{LPEncoding, Proof}, + liquidity_pools::{LPMessage, MessageHash}, Seconds, }; use cfg_types::domain_address::Domain; @@ -226,7 +226,7 @@ pub enum Message { /// The hash of the message which shall be recovered hash: [u8; 32], /// The address of the router - address: Address, + router: [u8; 20], }, /// Dispute the recovery of a message. /// @@ -235,9 +235,9 @@ pub enum Message { /// Directionality: Centrifuge -> EVM Domain. DisputeMessageRecovery { /// The hash of the message which shall be disputed - message: [u8; 32], + hash: [u8; 32], /// The address of the router - router: [u8; 32], + router: [u8; 20], }, /// A batch of ordered messages. /// Don't allow nested batch messages. @@ -532,7 +532,7 @@ pub enum Message { }, } -impl LPEncoding for Message { +impl LPMessage for Message { fn serialize(&self) -> Vec { gmpf::to_vec(self).unwrap_or_default() } @@ -562,7 +562,7 @@ impl LPEncoding for Message { Message::Batch(BatchMessages::default()) } - fn get_proof(&self) -> Option { + fn get_message_hash(&self) -> Option { match self { Message::MessageProof { hash } => Some(*hash), _ => None, @@ -570,10 +570,18 @@ impl LPEncoding for Message { } fn to_proof_message(&self) -> Self { - let hash = keccak_256(&LPEncoding::serialize(self)); + let hash = keccak_256(&LPMessage::serialize(self)); Message::MessageProof { hash } } + + fn initiate_message_recovery_message(hash: [u8; 32], router: [u8; 20]) -> Self { + Message::InitiateMessageRecovery { hash, router } + } + + fn dispute_message_recovery_message(hash: [u8; 32], router: [u8; 20]) -> Self { + Message::DisputeMessageRecovery { hash, router } + } } /// A Liquidity Pool message for updating restrictions on foreign domains. diff --git a/runtime/integration-tests/src/cases/routers.rs b/runtime/integration-tests/src/cases/routers.rs index 66a8f21c56..e892296c9b 100644 --- a/runtime/integration-tests/src/cases/routers.rs +++ b/runtime/integration-tests/src/cases/routers.rs @@ -1,5 +1,5 @@ use cfg_primitives::Balance; -use cfg_traits::liquidity_pools::{LPEncoding, MessageProcessor}; +use cfg_traits::liquidity_pools::{LPMessage, MessageProcessor}; use cfg_types::{ domain_address::{Domain, DomainAddress}, EVMChainId, From 1deee8e12c054bc75e03c3fbb4cb8e73f8fe42f2 Mon Sep 17 00:00:00 2001 From: Cosmin Damian <17934949+cdamian@users.noreply.github.com> Date: Fri, 16 Aug 2024 13:30:56 +0300 Subject: [PATCH 02/11] lp-message: Rename message recovery fns --- libs/traits/src/liquidity_pools.rs | 4 ++-- pallets/liquidity-pools-gateway/src/lib.rs | 10 ++++------ pallets/liquidity-pools-gateway/src/mock.rs | 4 ++-- pallets/liquidity-pools/src/message.rs | 6 +++--- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/libs/traits/src/liquidity_pools.rs b/libs/traits/src/liquidity_pools.rs index f5bf7855ff..f0af312b94 100644 --- a/libs/traits/src/liquidity_pools.rs +++ b/libs/traits/src/liquidity_pools.rs @@ -45,13 +45,13 @@ pub trait LPMessage: Sized { /// /// Hash - hash of the message that should be recovered. /// Router - the address of the recovery router. - fn initiate_message_recovery_message(hash: [u8; 32], router: [u8; 20]) -> Self; + fn initiate_recovery_message(hash: [u8; 32], router: [u8; 20]) -> 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_message_recovery_message(hash: [u8; 32], router: [u8; 20]) -> Self; + fn dispute_recovery_message(hash: [u8; 32], router: [u8; 20]) -> Self; } pub trait RouterProvider: Sized { diff --git a/pallets/liquidity-pools-gateway/src/lib.rs b/pallets/liquidity-pools-gateway/src/lib.rs index b6c76113b3..183a2fc637 100644 --- a/pallets/liquidity-pools-gateway/src/lib.rs +++ b/pallets/liquidity-pools-gateway/src/lib.rs @@ -518,8 +518,7 @@ pub mod pallet { ) -> DispatchResult { T::AdminOrigin::ensure_origin(origin)?; - let message = - T::Message::initiate_message_recovery_message(message_hash, recovery_router); + let message = T::Message::initiate_recovery_message(message_hash, recovery_router); Self::send_message_recovery_message(domain.clone(), message, messaging_router.clone())?; @@ -537,7 +536,7 @@ pub mod pallet { /// messaging router. /// /// Can only be called by `AdminOrigin`. - #[pallet::weight(T::WeightInfo::initiate_message_recovery())] + #[pallet::weight(T::WeightInfo::dispute_message_recovery())] #[pallet::call_index(13)] pub fn dispute_message_recovery( origin: OriginFor, @@ -548,8 +547,7 @@ pub mod pallet { ) -> DispatchResult { T::AdminOrigin::ensure_origin(origin)?; - let message = - T::Message::dispute_message_recovery_message(message_hash, recovery_router); + let message = T::Message::dispute_recovery_message(message_hash, recovery_router); Self::send_message_recovery_message(domain.clone(), message, messaging_router.clone())?; @@ -565,7 +563,7 @@ pub mod pallet { } impl Pallet { - fn send_message_recovery_message( + fn send_recovery_message( domain: Domain, message: T::Message, messaging_router: T::RouterId, diff --git a/pallets/liquidity-pools-gateway/src/mock.rs b/pallets/liquidity-pools-gateway/src/mock.rs index 30e8d0b878..fd0fe08fcf 100644 --- a/pallets/liquidity-pools-gateway/src/mock.rs +++ b/pallets/liquidity-pools-gateway/src/mock.rs @@ -115,11 +115,11 @@ impl LPMessage for Message { } } - fn initiate_message_recovery_message(hash: [u8; 32], router: [u8; 20]) -> Self { + fn initiate_recovery_message(hash: [u8; 32], router: [u8; 20]) -> Self { Self::InitiateMessageRecovery((hash, router)) } - fn dispute_message_recovery_message(hash: [u8; 32], router: [u8; 20]) -> Self { + fn dispute_recovery_message(hash: [u8; 32], router: [u8; 20]) -> Self { Self::DisputeMessageRecovery((hash, router)) } } diff --git a/pallets/liquidity-pools/src/message.rs b/pallets/liquidity-pools/src/message.rs index b12c0ed7d6..49380e882b 100644 --- a/pallets/liquidity-pools/src/message.rs +++ b/pallets/liquidity-pools/src/message.rs @@ -212,7 +212,7 @@ pub enum Message { // --- Gateway --- /// Proof a message has been executed. /// - /// Directionality: Centrifuge -> EVM Domain. + /// Directionality: Centrifuge <-> EVM Domain. MessageProof { // Hash of the message for which the proof is provided hash: [u8; 32], @@ -575,11 +575,11 @@ impl LPMessage for Message { Message::MessageProof { hash } } - fn initiate_message_recovery_message(hash: [u8; 32], router: [u8; 20]) -> Self { + fn initiate_recovery_message(hash: [u8; 32], router: [u8; 20]) -> Self { Message::InitiateMessageRecovery { hash, router } } - fn dispute_message_recovery_message(hash: [u8; 32], router: [u8; 20]) -> Self { + fn dispute_recovery_message(hash: [u8; 32], router: [u8; 20]) -> Self { Message::DisputeMessageRecovery { hash, router } } } From 1cd1932b61ffbec9b9a2b5e97c0dd2565bd2dbdf Mon Sep 17 00:00:00 2001 From: Cosmin Damian <17934949+cdamian@users.noreply.github.com> Date: Fri, 16 Aug 2024 13:35:01 +0300 Subject: [PATCH 03/11] lp-gateway: Remove sender field from outbound gateway message --- pallets/liquidity-pools-gateway/src/lib.rs | 4 +-- .../liquidity-pools-gateway/src/message.rs | 1 - .../src/message_processing.rs | 1 - pallets/liquidity-pools-gateway/src/tests.rs | 25 ++++++------------- 4 files changed, 9 insertions(+), 22 deletions(-) diff --git a/pallets/liquidity-pools-gateway/src/lib.rs b/pallets/liquidity-pools-gateway/src/lib.rs index 183a2fc637..639edaadcb 100644 --- a/pallets/liquidity-pools-gateway/src/lib.rs +++ b/pallets/liquidity-pools-gateway/src/lib.rs @@ -520,7 +520,7 @@ pub mod pallet { let message = T::Message::initiate_recovery_message(message_hash, recovery_router); - Self::send_message_recovery_message(domain.clone(), message, messaging_router.clone())?; + Self::send_recovery_message(domain.clone(), message, messaging_router.clone())?; Self::deposit_event(Event::::MessageRecoveryInitiated { domain, @@ -549,7 +549,7 @@ pub mod pallet { let message = T::Message::dispute_recovery_message(message_hash, recovery_router); - Self::send_message_recovery_message(domain.clone(), message, messaging_router.clone())?; + Self::send_recovery_message(domain.clone(), message, messaging_router.clone())?; Self::deposit_event(Event::::MessageRecoveryDisputed { domain, diff --git a/pallets/liquidity-pools-gateway/src/message.rs b/pallets/liquidity-pools-gateway/src/message.rs index 1c604f5d0d..6680179a8a 100644 --- a/pallets/liquidity-pools-gateway/src/message.rs +++ b/pallets/liquidity-pools-gateway/src/message.rs @@ -10,7 +10,6 @@ pub enum GatewayMessage { router_id: RouterId, }, Outbound { - sender: DomainAddress, message: Message, router_id: RouterId, }, diff --git a/pallets/liquidity-pools-gateway/src/message_processing.rs b/pallets/liquidity-pools-gateway/src/message_processing.rs index 9c060ea5ba..eceda9373a 100644 --- a/pallets/liquidity-pools-gateway/src/message_processing.rs +++ b/pallets/liquidity-pools-gateway/src/message_processing.rs @@ -459,7 +459,6 @@ 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, }; diff --git a/pallets/liquidity-pools-gateway/src/tests.rs b/pallets/liquidity-pools-gateway/src/tests.rs index 22c5d02d30..d6d71c9361 100644 --- a/pallets/liquidity-pools-gateway/src/tests.rs +++ b/pallets/liquidity-pools-gateway/src/tests.rs @@ -898,18 +898,12 @@ mod implementations { GatewayMessage::Inbound { .. } => { assert!(false, "expected outbound message") } - GatewayMessage::Outbound { - sender, message, .. - } => { - assert_eq!(sender, ::Sender::get()); - - match message { - Message::Proof(p) => { - assert_eq!(p, message_proof); - } - _ => {} + GatewayMessage::Outbound { message, .. } => match message { + Message::Proof(p) => { + assert_eq!(p, message_proof); } - } + _ => {} + }, } Ok(()) @@ -961,7 +955,6 @@ mod implementations { )); let gateway_message = GatewayMessage::Outbound { - sender: ::Sender::get(), message: msg.clone(), router_id: ROUTER_ID_1, }; @@ -3167,11 +3160,9 @@ mod implementations { #[test] fn success() { new_test_ext().execute_with(|| { - let sender = TEST_DOMAIN_ADDRESS; let message = Message::Simple; let gateway_message = GatewayMessage::Outbound { - sender: sender.clone(), message: message.clone(), router_id: ROUTER_ID_1, }; @@ -3179,7 +3170,7 @@ mod implementations { let handler = MockMessageSender::mock_send( move |mock_router_id, mock_sender, mock_message| { assert_eq!(mock_router_id, ROUTER_ID_1); - assert_eq!(mock_sender, sender); + assert_eq!(mock_sender, ::Sender::get()); assert_eq!(mock_message, message.serialize()); Ok(()) @@ -3196,11 +3187,9 @@ mod implementations { #[test] fn message_sender_error() { new_test_ext().execute_with(|| { - let sender = TEST_DOMAIN_ADDRESS; let message = Message::Simple; let gateway_message = GatewayMessage::Outbound { - sender: sender.clone(), message: message.clone(), router_id: ROUTER_ID_1, }; @@ -3210,7 +3199,7 @@ mod implementations { MockMessageSender::mock_send( move |mock_router_id, mock_sender, mock_message| { assert_eq!(mock_router_id, ROUTER_ID_1); - assert_eq!(mock_sender, sender); + assert_eq!(mock_sender, ::Sender::get()); assert_eq!(mock_message, message.serialize()); Err(router_err) From 3a09a1b852fbd2aa95ad5012ba3d5fa6c9b9b591 Mon Sep 17 00:00:00 2001 From: Cosmin Damian <17934949+cdamian@users.noreply.github.com> Date: Fri, 16 Aug 2024 14:22:55 +0300 Subject: [PATCH 04/11] lp-gateway: Add unit tests for new message recovery extrinsics --- pallets/liquidity-pools-gateway/src/mock.rs | 5 +- pallets/liquidity-pools-gateway/src/tests.rs | 618 ++++++++++++++----- 2 files changed, 452 insertions(+), 171 deletions(-) diff --git a/pallets/liquidity-pools-gateway/src/mock.rs b/pallets/liquidity-pools-gateway/src/mock.rs index fd0fe08fcf..9c3cb842bc 100644 --- a/pallets/liquidity-pools-gateway/src/mock.rs +++ b/pallets/liquidity-pools-gateway/src/mock.rs @@ -17,6 +17,7 @@ use crate::{pallet as pallet_liquidity_pools_gateway, EnsureLocal, GatewayMessag pub const TEST_SESSION_ID: u32 = 1; pub const TEST_EVM_CHAIN: EVMChainId = 1; +pub const TEST_DOMAIN: Domain = Domain::EVM(TEST_EVM_CHAIN); pub const TEST_DOMAIN_ADDRESS: DomainAddress = DomainAddress::Evm(TEST_EVM_CHAIN, H160::repeat_byte(1)); @@ -29,7 +30,7 @@ pub const LP_ADMIN_ACCOUNT: AccountId32 = AccountId32::new([u8::MAX; 32]); pub const MAX_PACKED_MESSAGES_ERR: &str = "packed limit error"; pub const MAX_PACKED_MESSAGES: usize = 10; -pub const MESSAGE_PROOF: [u8; 32] = [1; 32]; +pub const MESSAGE_HASH: [u8; 32] = [1; 32]; #[derive(Eq, PartialEq, Clone, Encode, Decode, TypeInfo, Hash)] pub enum Message { @@ -111,7 +112,7 @@ impl LPMessage for Message { fn to_proof_message(&self) -> Self { match self { Message::Proof(_) => self.clone(), - _ => Message::Proof(MESSAGE_PROOF), + _ => Message::Proof(MESSAGE_HASH), } } diff --git a/pallets/liquidity-pools-gateway/src/tests.rs b/pallets/liquidity-pools-gateway/src/tests.rs index d6d71c9361..9ff5dd394c 100644 --- a/pallets/liquidity-pools-gateway/src/tests.rs +++ b/pallets/liquidity-pools-gateway/src/tests.rs @@ -664,7 +664,7 @@ mod extrinsics { SessionIdStore::::set(session_id); PendingInboundEntries::::insert( - MESSAGE_PROOF, + MESSAGE_HASH, ROUTER_ID_1, InboundEntry::Message(MessageEntry { session_id, @@ -685,23 +685,19 @@ mod extrinsics { assert_ok!(LiquidityPoolsGateway::execute_message_recovery( RuntimeOrigin::root(), TEST_DOMAIN_ADDRESS, - MESSAGE_PROOF, + MESSAGE_HASH, ROUTER_ID_2, )); event_exists(Event::::MessageRecoveryExecuted { - message_hash: MESSAGE_PROOF, + message_hash: MESSAGE_HASH, router_id: ROUTER_ID_2, }); assert_eq!(handler.times(), 1); - assert!( - PendingInboundEntries::::get(MESSAGE_PROOF, ROUTER_ID_1).is_none() - ); - assert!( - PendingInboundEntries::::get(MESSAGE_PROOF, ROUTER_ID_2).is_none() - ); + assert!(PendingInboundEntries::::get(MESSAGE_HASH, ROUTER_ID_1).is_none()); + assert!(PendingInboundEntries::::get(MESSAGE_HASH, ROUTER_ID_2).is_none()); }); } @@ -716,7 +712,7 @@ mod extrinsics { SessionIdStore::::set(session_id); PendingInboundEntries::::insert( - MESSAGE_PROOF, + MESSAGE_HASH, ROUTER_ID_1, InboundEntry::Message(MessageEntry { session_id, @@ -729,17 +725,17 @@ mod extrinsics { assert_ok!(LiquidityPoolsGateway::execute_message_recovery( RuntimeOrigin::root(), TEST_DOMAIN_ADDRESS, - MESSAGE_PROOF, + MESSAGE_HASH, ROUTER_ID_2, )); event_exists(Event::::MessageRecoveryExecuted { - message_hash: MESSAGE_PROOF, + message_hash: MESSAGE_HASH, router_id: ROUTER_ID_2, }); assert_eq!( - PendingInboundEntries::::get(MESSAGE_PROOF, ROUTER_ID_1), + PendingInboundEntries::::get(MESSAGE_HASH, ROUTER_ID_1), Some( MessageEntry { session_id, @@ -751,7 +747,7 @@ mod extrinsics { ) ); assert_eq!( - PendingInboundEntries::::get(MESSAGE_PROOF, ROUTER_ID_2), + PendingInboundEntries::::get(MESSAGE_HASH, ROUTER_ID_2), Some( ProofEntry { session_id, @@ -760,7 +756,7 @@ mod extrinsics { .into() ) ); - assert!(PendingInboundEntries::::get(MESSAGE_PROOF, ROUTER_ID_3).is_none()) + assert!(PendingInboundEntries::::get(MESSAGE_HASH, ROUTER_ID_3).is_none()) }); } @@ -771,7 +767,7 @@ mod extrinsics { LiquidityPoolsGateway::execute_message_recovery( RuntimeOrigin::root(), TEST_DOMAIN_ADDRESS, - MESSAGE_PROOF, + MESSAGE_HASH, ROUTER_ID_1, ), Error::::NotEnoughRoutersForDomain @@ -783,7 +779,7 @@ mod extrinsics { LiquidityPoolsGateway::execute_message_recovery( RuntimeOrigin::root(), TEST_DOMAIN_ADDRESS, - MESSAGE_PROOF, + MESSAGE_HASH, ROUTER_ID_1, ), Error::::NotEnoughRoutersForDomain @@ -801,7 +797,7 @@ mod extrinsics { LiquidityPoolsGateway::execute_message_recovery( RuntimeOrigin::root(), TEST_DOMAIN_ADDRESS, - MESSAGE_PROOF, + MESSAGE_HASH, ROUTER_ID_2 ), Error::::UnknownRouter @@ -819,7 +815,7 @@ mod extrinsics { ); SessionIdStore::::set(session_id); PendingInboundEntries::::insert( - MESSAGE_PROOF, + MESSAGE_HASH, ROUTER_ID_2, InboundEntry::Proof(ProofEntry { session_id, @@ -831,7 +827,7 @@ mod extrinsics { LiquidityPoolsGateway::execute_message_recovery( RuntimeOrigin::root(), TEST_DOMAIN_ADDRESS, - MESSAGE_PROOF, + MESSAGE_HASH, ROUTER_ID_2 ), Arithmetic(Overflow) @@ -850,7 +846,7 @@ mod extrinsics { ); SessionIdStore::::set(session_id); PendingInboundEntries::::insert( - MESSAGE_PROOF, + MESSAGE_HASH, ROUTER_ID_2, InboundEntry::Message(MessageEntry { session_id, @@ -864,7 +860,7 @@ mod extrinsics { LiquidityPoolsGateway::execute_message_recovery( RuntimeOrigin::root(), TEST_DOMAIN_ADDRESS, - MESSAGE_PROOF, + MESSAGE_HASH, ROUTER_ID_2 ), Error::::ExpectedMessageProofType @@ -872,6 +868,290 @@ mod extrinsics { }); } } + + mod initiate_message_recovery { + use super::*; + + #[test] + fn success() { + new_test_ext().execute_with(|| { + let recovery_router = [1u8; 20]; + + Routers::::set(BoundedVec::try_from(vec![ROUTER_ID_1]).unwrap()); + + MockMessageSender::mock_send(move |mock_router_id, mock_sender, mock_message| { + assert_eq!(mock_router_id, ROUTER_ID_1); + assert_eq!(mock_sender, ::Sender::get()); + assert_eq!( + mock_message, + Message::InitiateMessageRecovery((MESSAGE_HASH, recovery_router)) + .serialize() + ); + + Ok(()) + }); + + assert_ok!(LiquidityPoolsGateway::initiate_message_recovery( + RuntimeOrigin::root(), + TEST_DOMAIN, + MESSAGE_HASH, + recovery_router, + ROUTER_ID_1, + )); + + event_exists(Event::::MessageRecoveryInitiated { + domain: TEST_DOMAIN, + message_hash: MESSAGE_HASH, + recovery_router, + messaging_router: ROUTER_ID_1, + }) + }); + } + + #[test] + fn bad_origin() { + new_test_ext().execute_with(|| { + let recovery_router = [1u8; 20]; + + assert_noop!( + LiquidityPoolsGateway::initiate_message_recovery( + RuntimeOrigin::signed(AccountId32::new([0u8; 32])), + TEST_DOMAIN, + MESSAGE_HASH, + recovery_router, + ROUTER_ID_1, + ), + BadOrigin + ); + }); + } + + #[test] + fn not_enough_routers_for_domain() { + new_test_ext().execute_with(|| { + let recovery_router = [1u8; 20]; + + assert_noop!( + LiquidityPoolsGateway::initiate_message_recovery( + RuntimeOrigin::root(), + TEST_DOMAIN, + MESSAGE_HASH, + recovery_router, + ROUTER_ID_1, + ), + Error::::NotEnoughRoutersForDomain, + ); + }); + } + + #[test] + fn messaging_router_not_found() { + new_test_ext().execute_with(|| { + let recovery_router = [1u8; 20]; + + Routers::::set(BoundedVec::try_from(vec![ROUTER_ID_1]).unwrap()); + + MockMessageSender::mock_send(move |mock_router_id, mock_sender, mock_message| { + assert_eq!(mock_router_id, ROUTER_ID_1); + assert_eq!(mock_sender, ::Sender::get()); + assert_eq!( + mock_message, + Message::InitiateMessageRecovery((MESSAGE_HASH, recovery_router)) + .serialize() + ); + + Ok(()) + }); + + assert_noop!( + LiquidityPoolsGateway::initiate_message_recovery( + RuntimeOrigin::root(), + TEST_DOMAIN, + MESSAGE_HASH, + recovery_router, + RouterId(4), + ), + Error::::MessagingRouterNotFound, + ); + }); + } + + #[test] + fn message_sender_error() { + new_test_ext().execute_with(|| { + let recovery_router = [1u8; 20]; + + Routers::::set(BoundedVec::try_from(vec![ROUTER_ID_1]).unwrap()); + + let err = DispatchError::Unavailable; + + MockMessageSender::mock_send(move |mock_router_id, mock_sender, mock_message| { + assert_eq!(mock_router_id, ROUTER_ID_1); + assert_eq!(mock_sender, ::Sender::get()); + assert_eq!( + mock_message, + Message::InitiateMessageRecovery((MESSAGE_HASH, recovery_router)) + .serialize() + ); + + Err(err) + }); + + assert_noop!( + LiquidityPoolsGateway::initiate_message_recovery( + RuntimeOrigin::root(), + TEST_DOMAIN, + MESSAGE_HASH, + recovery_router, + ROUTER_ID_1, + ), + err + ); + }); + } + } + + mod dispute_message_recovery { + use super::*; + + #[test] + fn success() { + new_test_ext().execute_with(|| { + let recovery_router = [1u8; 20]; + + Routers::::set(BoundedVec::try_from(vec![ROUTER_ID_1]).unwrap()); + + MockMessageSender::mock_send(move |mock_router_id, mock_sender, mock_message| { + assert_eq!(mock_router_id, ROUTER_ID_1); + assert_eq!(mock_sender, ::Sender::get()); + assert_eq!( + mock_message, + Message::DisputeMessageRecovery((MESSAGE_HASH, recovery_router)) + .serialize() + ); + + Ok(()) + }); + + assert_ok!(LiquidityPoolsGateway::dispute_message_recovery( + RuntimeOrigin::root(), + TEST_DOMAIN, + MESSAGE_HASH, + recovery_router, + ROUTER_ID_1, + )); + + event_exists(Event::::MessageRecoveryDisputed { + domain: TEST_DOMAIN, + message_hash: MESSAGE_HASH, + recovery_router, + messaging_router: ROUTER_ID_1, + }) + }); + } + + #[test] + fn bad_origin() { + new_test_ext().execute_with(|| { + let recovery_router = [1u8; 20]; + + assert_noop!( + LiquidityPoolsGateway::dispute_message_recovery( + RuntimeOrigin::signed(AccountId32::new([0u8; 32])), + TEST_DOMAIN, + MESSAGE_HASH, + recovery_router, + ROUTER_ID_1, + ), + BadOrigin + ); + }); + } + + #[test] + fn not_enough_routers_for_domain() { + new_test_ext().execute_with(|| { + let recovery_router = [1u8; 20]; + + assert_noop!( + LiquidityPoolsGateway::dispute_message_recovery( + RuntimeOrigin::root(), + TEST_DOMAIN, + MESSAGE_HASH, + recovery_router, + ROUTER_ID_1, + ), + Error::::NotEnoughRoutersForDomain, + ); + }); + } + + #[test] + fn messaging_router_not_found() { + new_test_ext().execute_with(|| { + let recovery_router = [1u8; 20]; + + Routers::::set(BoundedVec::try_from(vec![ROUTER_ID_1]).unwrap()); + + MockMessageSender::mock_send(move |mock_router_id, mock_sender, mock_message| { + assert_eq!(mock_router_id, ROUTER_ID_1); + assert_eq!(mock_sender, ::Sender::get()); + assert_eq!( + mock_message, + Message::DisputeMessageRecovery((MESSAGE_HASH, recovery_router)) + .serialize() + ); + + Ok(()) + }); + + assert_noop!( + LiquidityPoolsGateway::dispute_message_recovery( + RuntimeOrigin::root(), + TEST_DOMAIN, + MESSAGE_HASH, + recovery_router, + RouterId(4), + ), + Error::::MessagingRouterNotFound, + ); + }); + } + + #[test] + fn message_sender_error() { + new_test_ext().execute_with(|| { + let recovery_router = [1u8; 20]; + + Routers::::set(BoundedVec::try_from(vec![ROUTER_ID_1]).unwrap()); + + let err = DispatchError::Unavailable; + + MockMessageSender::mock_send(move |mock_router_id, mock_sender, mock_message| { + assert_eq!(mock_router_id, ROUTER_ID_1); + assert_eq!(mock_sender, ::Sender::get()); + assert_eq!( + mock_message, + Message::DisputeMessageRecovery((MESSAGE_HASH, recovery_router)) + .serialize() + ); + + Err(err) + }); + + assert_noop!( + LiquidityPoolsGateway::dispute_message_recovery( + RuntimeOrigin::root(), + TEST_DOMAIN, + MESSAGE_HASH, + recovery_router, + ROUTER_ID_1, + ), + err + ); + }); + } + } } mod implementations { @@ -1029,7 +1309,7 @@ mod implementations { let expected_inbound_entry = expected_storage_entry.1; let storage_entry = PendingInboundEntries::::get( - MESSAGE_PROOF, expected_storage_entry_router_id, + MESSAGE_HASH, expected_storage_entry_router_id, ); assert_eq!(storage_entry, expected_inbound_entry, "Expected inbound entry {expected_inbound_entry:?}, found {storage_entry:?}"); } @@ -1255,7 +1535,7 @@ mod implementations { lazy_static! { static ref TEST_DATA: Vec = vec![ (ROUTER_ID_1, Message::Simple), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), ]; } @@ -1294,8 +1574,8 @@ mod implementations { ), ( vec![ - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), ], ExpectedTestResult { message_submitted_times: 0, @@ -1317,7 +1597,7 @@ mod implementations { ( vec![ (ROUTER_ID_1, Message::Simple), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), ], ExpectedTestResult { message_submitted_times: 1, @@ -1329,7 +1609,7 @@ mod implementations { ), ( vec![ - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), (ROUTER_ID_1, Message::Simple), ], ExpectedTestResult { @@ -1389,9 +1669,9 @@ mod implementations { ), ( vec![ - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), ], ExpectedTestResult { message_submitted_times: 0, @@ -1414,7 +1694,7 @@ mod implementations { vec![ (ROUTER_ID_1, Message::Simple), (ROUTER_ID_1, Message::Simple), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), ], ExpectedTestResult { message_submitted_times: 1, @@ -1438,7 +1718,7 @@ mod implementations { ( vec![ (ROUTER_ID_1, Message::Simple), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), (ROUTER_ID_1, Message::Simple), ], ExpectedTestResult { @@ -1463,8 +1743,8 @@ mod implementations { ( vec![ (ROUTER_ID_1, Message::Simple), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), ], ExpectedTestResult { message_submitted_times: 1, @@ -1485,7 +1765,7 @@ mod implementations { ), ( vec![ - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), (ROUTER_ID_1, Message::Simple), (ROUTER_ID_1, Message::Simple), ], @@ -1510,9 +1790,9 @@ mod implementations { ), ( vec![ - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), (ROUTER_ID_1, Message::Simple), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), ], ExpectedTestResult { message_submitted_times: 1, @@ -1533,8 +1813,8 @@ mod implementations { ), ( vec![ - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), (ROUTER_ID_1, Message::Simple), ], ExpectedTestResult { @@ -1604,10 +1884,10 @@ mod implementations { ), ( vec![ - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), ], ExpectedTestResult { message_submitted_times: 0, @@ -1631,7 +1911,7 @@ mod implementations { (ROUTER_ID_1, Message::Simple), (ROUTER_ID_1, Message::Simple), (ROUTER_ID_1, Message::Simple), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), ], ExpectedTestResult { message_submitted_times: 1, @@ -1656,7 +1936,7 @@ mod implementations { vec![ (ROUTER_ID_1, Message::Simple), (ROUTER_ID_1, Message::Simple), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), (ROUTER_ID_1, Message::Simple), ], ExpectedTestResult { @@ -1681,7 +1961,7 @@ mod implementations { ( vec![ (ROUTER_ID_1, Message::Simple), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), (ROUTER_ID_1, Message::Simple), (ROUTER_ID_1, Message::Simple), ], @@ -1706,7 +1986,7 @@ mod implementations { ), ( vec![ - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), (ROUTER_ID_1, Message::Simple), (ROUTER_ID_1, Message::Simple), (ROUTER_ID_1, Message::Simple), @@ -1734,8 +2014,8 @@ mod implementations { vec![ (ROUTER_ID_1, Message::Simple), (ROUTER_ID_1, Message::Simple), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), ], ExpectedTestResult { message_submitted_times: 2, @@ -1747,10 +2027,10 @@ mod implementations { ), ( vec![ - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), (ROUTER_ID_1, Message::Simple), (ROUTER_ID_1, Message::Simple), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), ], ExpectedTestResult { message_submitted_times: 2, @@ -1762,9 +2042,9 @@ mod implementations { ), ( vec![ - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), (ROUTER_ID_1, Message::Simple), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), (ROUTER_ID_1, Message::Simple), ], ExpectedTestResult { @@ -1778,9 +2058,9 @@ mod implementations { ( vec![ (ROUTER_ID_1, Message::Simple), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), (ROUTER_ID_1, Message::Simple), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), ], ExpectedTestResult { message_submitted_times: 2, @@ -1793,8 +2073,8 @@ mod implementations { ( vec![ (ROUTER_ID_1, Message::Simple), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), (ROUTER_ID_1, Message::Simple), ], ExpectedTestResult { @@ -1807,8 +2087,8 @@ mod implementations { ), ( vec![ - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), (ROUTER_ID_1, Message::Simple), (ROUTER_ID_1, Message::Simple), ], @@ -1823,9 +2103,9 @@ mod implementations { ( vec![ (ROUTER_ID_1, Message::Simple), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), ], ExpectedTestResult { message_submitted_times: 1, @@ -1846,10 +2126,10 @@ mod implementations { ), ( vec![ - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), (ROUTER_ID_1, Message::Simple), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), ], ExpectedTestResult { message_submitted_times: 1, @@ -1870,10 +2150,10 @@ mod implementations { ), ( vec![ - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), (ROUTER_ID_1, Message::Simple), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), ], ExpectedTestResult { message_submitted_times: 1, @@ -1894,9 +2174,9 @@ mod implementations { ), ( vec![ - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), (ROUTER_ID_1, Message::Simple), ], ExpectedTestResult { @@ -1968,7 +2248,7 @@ mod implementations { let gateway_message = GatewayMessage::Inbound { domain_address: TEST_DOMAIN_ADDRESS, - message: Message::Proof(MESSAGE_PROOF), + message: Message::Proof(MESSAGE_HASH), router_id: ROUTER_ID_1, }; @@ -1985,8 +2265,8 @@ mod implementations { lazy_static! { static ref TEST_DATA: Vec = vec![ (ROUTER_ID_1, Message::Simple), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), - (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), + (ROUTER_ID_3, Message::Proof(MESSAGE_HASH)), ]; } @@ -2026,8 +2306,8 @@ mod implementations { ), ( vec![ - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), ], ExpectedTestResult { message_submitted_times: 0, @@ -2049,8 +2329,8 @@ mod implementations { ), ( vec![ - (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), - (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_3, Message::Proof(MESSAGE_HASH)), + (ROUTER_ID_3, Message::Proof(MESSAGE_HASH)), ], ExpectedTestResult { message_submitted_times: 0, @@ -2072,8 +2352,8 @@ mod implementations { ), ( vec![ - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), - (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), + (ROUTER_ID_3, Message::Proof(MESSAGE_HASH)), ], ExpectedTestResult { message_submitted_times: 0, @@ -2104,8 +2384,8 @@ mod implementations { ), ( vec![ - (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_3, Message::Proof(MESSAGE_HASH)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), ], ExpectedTestResult { message_submitted_times: 0, @@ -2137,7 +2417,7 @@ mod implementations { ( vec![ (ROUTER_ID_1, Message::Simple), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), ], ExpectedTestResult { message_submitted_times: 0, @@ -2171,7 +2451,7 @@ mod implementations { ( vec![ (ROUTER_ID_1, Message::Simple), - (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_3, Message::Proof(MESSAGE_HASH)), ], ExpectedTestResult { message_submitted_times: 0, @@ -2204,7 +2484,7 @@ mod implementations { ), ( vec![ - (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_3, Message::Proof(MESSAGE_HASH)), (ROUTER_ID_1, Message::Simple), ], ExpectedTestResult { @@ -2238,7 +2518,7 @@ mod implementations { ), ( vec![ - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), (ROUTER_ID_1, Message::Simple), ], ExpectedTestResult { @@ -2273,7 +2553,7 @@ mod implementations { ( vec![ (ROUTER_ID_1, Message::Simple), - (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_3, Message::Proof(MESSAGE_HASH)), ], ExpectedTestResult { message_submitted_times: 0, @@ -2354,9 +2634,9 @@ mod implementations { ), ( vec![ - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), ], ExpectedTestResult { message_submitted_times: 0, @@ -2378,9 +2658,9 @@ mod implementations { ), ( vec![ - (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), - (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), - (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_3, Message::Proof(MESSAGE_HASH)), + (ROUTER_ID_3, Message::Proof(MESSAGE_HASH)), + (ROUTER_ID_3, Message::Proof(MESSAGE_HASH)), ], ExpectedTestResult { message_submitted_times: 0, @@ -2404,7 +2684,7 @@ mod implementations { vec![ (ROUTER_ID_1, Message::Simple), (ROUTER_ID_1, Message::Simple), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), ], ExpectedTestResult { message_submitted_times: 0, @@ -2438,7 +2718,7 @@ mod implementations { ( vec![ (ROUTER_ID_1, Message::Simple), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), (ROUTER_ID_1, Message::Simple), ], ExpectedTestResult { @@ -2473,8 +2753,8 @@ mod implementations { ( vec![ (ROUTER_ID_1, Message::Simple), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), ], ExpectedTestResult { message_submitted_times: 0, @@ -2508,8 +2788,8 @@ mod implementations { ( vec![ (ROUTER_ID_1, Message::Simple), - (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), - (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_3, Message::Proof(MESSAGE_HASH)), + (ROUTER_ID_3, Message::Proof(MESSAGE_HASH)), ], ExpectedTestResult { message_submitted_times: 0, @@ -2542,9 +2822,9 @@ mod implementations { ), ( vec![ - (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_3, Message::Proof(MESSAGE_HASH)), (ROUTER_ID_1, Message::Simple), - (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_3, Message::Proof(MESSAGE_HASH)), ], ExpectedTestResult { message_submitted_times: 0, @@ -2577,8 +2857,8 @@ mod implementations { ), ( vec![ - (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), - (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_3, Message::Proof(MESSAGE_HASH)), + (ROUTER_ID_3, Message::Proof(MESSAGE_HASH)), (ROUTER_ID_1, Message::Simple), ], ExpectedTestResult { @@ -2612,9 +2892,9 @@ mod implementations { ), ( vec![ - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), (ROUTER_ID_1, Message::Simple), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), ], ExpectedTestResult { message_submitted_times: 0, @@ -2647,8 +2927,8 @@ mod implementations { ), ( vec![ - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), (ROUTER_ID_1, Message::Simple), ], ExpectedTestResult { @@ -2684,7 +2964,7 @@ mod implementations { vec![ (ROUTER_ID_1, Message::Simple), (ROUTER_ID_1, Message::Simple), - (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_3, Message::Proof(MESSAGE_HASH)), ], ExpectedTestResult { message_submitted_times: 0, @@ -2717,7 +2997,7 @@ mod implementations { ), ( vec![ - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), (ROUTER_ID_1, Message::Simple), (ROUTER_ID_1, Message::Simple), ], @@ -2753,7 +3033,7 @@ mod implementations { ( vec![ (ROUTER_ID_1, Message::Simple), - (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_3, Message::Proof(MESSAGE_HASH)), (ROUTER_ID_1, Message::Simple), ], ExpectedTestResult { @@ -2787,7 +3067,7 @@ mod implementations { ), ( vec![ - (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_3, Message::Proof(MESSAGE_HASH)), (ROUTER_ID_1, Message::Simple), (ROUTER_ID_1, Message::Simple), ], @@ -2823,8 +3103,8 @@ mod implementations { ( vec![ (ROUTER_ID_1, Message::Simple), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), - (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), + (ROUTER_ID_3, Message::Proof(MESSAGE_HASH)), ], ExpectedTestResult { message_submitted_times: 1, @@ -2837,8 +3117,8 @@ mod implementations { ), ( vec![ - (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_3, Message::Proof(MESSAGE_HASH)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), (ROUTER_ID_1, Message::Simple), ], ExpectedTestResult { @@ -2853,8 +3133,8 @@ mod implementations { ( vec![ (ROUTER_ID_1, Message::Simple), - (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_3, Message::Proof(MESSAGE_HASH)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), ], ExpectedTestResult { message_submitted_times: 1, @@ -2867,9 +3147,9 @@ mod implementations { ), ( vec![ - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), (ROUTER_ID_1, Message::Simple), - (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_3, Message::Proof(MESSAGE_HASH)), ], ExpectedTestResult { message_submitted_times: 1, @@ -2882,8 +3162,8 @@ mod implementations { ), ( vec![ - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), - (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), + (ROUTER_ID_3, Message::Proof(MESSAGE_HASH)), (ROUTER_ID_1, Message::Simple), ], ExpectedTestResult { @@ -2897,9 +3177,9 @@ mod implementations { ), ( vec![ - (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_3, Message::Proof(MESSAGE_HASH)), (ROUTER_ID_1, Message::Simple), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), ], ExpectedTestResult { message_submitted_times: 1, @@ -2912,9 +3192,9 @@ mod implementations { ), ( vec![ - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), - (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), + (ROUTER_ID_3, Message::Proof(MESSAGE_HASH)), ], ExpectedTestResult { message_submitted_times: 0, @@ -2945,9 +3225,9 @@ mod implementations { ), ( vec![ - (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_3, Message::Proof(MESSAGE_HASH)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), ], ExpectedTestResult { message_submitted_times: 0, @@ -2978,9 +3258,9 @@ mod implementations { ), ( vec![ - (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), - (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_3, Message::Proof(MESSAGE_HASH)), + (ROUTER_ID_3, Message::Proof(MESSAGE_HASH)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), ], ExpectedTestResult { message_submitted_times: 0, @@ -3011,9 +3291,9 @@ mod implementations { ), ( vec![ - (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), - (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_3, Message::Proof(MESSAGE_HASH)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), + (ROUTER_ID_3, Message::Proof(MESSAGE_HASH)), ], ExpectedTestResult { message_submitted_times: 0, @@ -3044,9 +3324,9 @@ mod implementations { ), ( vec![ - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), - (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), + (ROUTER_ID_3, Message::Proof(MESSAGE_HASH)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), ], ExpectedTestResult { message_submitted_times: 0, @@ -3077,9 +3357,9 @@ mod implementations { ), ( vec![ - (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), - (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), - (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_HASH)), + (ROUTER_ID_3, Message::Proof(MESSAGE_HASH)), + (ROUTER_ID_3, Message::Proof(MESSAGE_HASH)), ], ExpectedTestResult { message_submitted_times: 0, @@ -3314,7 +3594,7 @@ mod implementations { .into(), ), ( - Message::Proof(MESSAGE_PROOF), + Message::Proof(MESSAGE_HASH), ProofEntry { session_id, current_count: 1, @@ -3370,13 +3650,13 @@ mod implementations { for (test_router_id, test_inbound_entry) in tests { assert_ok!(LiquidityPoolsGateway::upsert_pending_entry( - MESSAGE_PROOF, + MESSAGE_HASH, &test_router_id.clone(), test_inbound_entry.clone(), )); let res = - PendingInboundEntries::::get(MESSAGE_PROOF, test_router_id) + PendingInboundEntries::::get(MESSAGE_HASH, test_router_id) .unwrap(); assert_eq!(res, test_inbound_entry); @@ -3396,19 +3676,19 @@ mod implementations { .into(); PendingInboundEntries::::insert( - MESSAGE_PROOF, + MESSAGE_HASH, ROUTER_ID_1, inbound_entry.clone(), ); assert_ok!(LiquidityPoolsGateway::upsert_pending_entry( - MESSAGE_PROOF, + MESSAGE_HASH, &ROUTER_ID_1, inbound_entry, )); let res = - PendingInboundEntries::::get(MESSAGE_PROOF, ROUTER_ID_1).unwrap(); + PendingInboundEntries::::get(MESSAGE_HASH, ROUTER_ID_1).unwrap(); assert_eq!( res, MessageEntry { @@ -3426,7 +3706,7 @@ mod implementations { fn message_entry_new_session() { new_test_ext().execute_with(|| { PendingInboundEntries::::insert( - MESSAGE_PROOF, + MESSAGE_HASH, ROUTER_ID_1, InboundEntry::Message(MessageEntry { session_id: 1, @@ -3437,7 +3717,7 @@ mod implementations { ); assert_ok!(LiquidityPoolsGateway::upsert_pending_entry( - MESSAGE_PROOF, + MESSAGE_HASH, &ROUTER_ID_1, MessageEntry { session_id: 2, @@ -3449,7 +3729,7 @@ mod implementations { )); let res = - PendingInboundEntries::::get(MESSAGE_PROOF, ROUTER_ID_1).unwrap(); + PendingInboundEntries::::get(MESSAGE_HASH, ROUTER_ID_1).unwrap(); assert_eq!( res, MessageEntry { @@ -3475,14 +3755,14 @@ mod implementations { .into(); PendingInboundEntries::::insert( - MESSAGE_PROOF, + MESSAGE_HASH, ROUTER_ID_1, inbound_entry.clone(), ); assert_noop!( LiquidityPoolsGateway::upsert_pending_entry( - MESSAGE_PROOF, + MESSAGE_HASH, &ROUTER_ID_1, InboundEntry::Proof(ProofEntry { session_id: 1, @@ -3504,19 +3784,19 @@ mod implementations { .into(); PendingInboundEntries::::insert( - MESSAGE_PROOF, + MESSAGE_HASH, ROUTER_ID_1, inbound_entry.clone(), ); assert_ok!(LiquidityPoolsGateway::upsert_pending_entry( - MESSAGE_PROOF, + MESSAGE_HASH, &ROUTER_ID_1, inbound_entry, )); let res = - PendingInboundEntries::::get(MESSAGE_PROOF, ROUTER_ID_1).unwrap(); + PendingInboundEntries::::get(MESSAGE_HASH, ROUTER_ID_1).unwrap(); assert_eq!( res, ProofEntry { @@ -3532,7 +3812,7 @@ mod implementations { fn proof_entry_new_session() { new_test_ext().execute_with(|| { PendingInboundEntries::::insert( - MESSAGE_PROOF, + MESSAGE_HASH, ROUTER_ID_1, InboundEntry::Proof(ProofEntry { session_id: 1, @@ -3541,7 +3821,7 @@ mod implementations { ); assert_ok!(LiquidityPoolsGateway::upsert_pending_entry( - MESSAGE_PROOF, + MESSAGE_HASH, &ROUTER_ID_1, ProofEntry { session_id: 2, @@ -3551,7 +3831,7 @@ mod implementations { )); let res = - PendingInboundEntries::::get(MESSAGE_PROOF, ROUTER_ID_1).unwrap(); + PendingInboundEntries::::get(MESSAGE_HASH, ROUTER_ID_1).unwrap(); assert_eq!( res, ProofEntry { @@ -3573,14 +3853,14 @@ mod implementations { .into(); PendingInboundEntries::::insert( - MESSAGE_PROOF, + MESSAGE_HASH, ROUTER_ID_1, inbound_entry.clone(), ); assert_noop!( LiquidityPoolsGateway::upsert_pending_entry( - MESSAGE_PROOF, + MESSAGE_HASH, &ROUTER_ID_1, InboundEntry::Message(MessageEntry { session_id: 1, @@ -3607,7 +3887,7 @@ mod implementations { let expected_proof_count = 2; PendingInboundEntries::::insert( - MESSAGE_PROOF, + MESSAGE_HASH, ROUTER_ID_1, InboundEntry::Message(MessageEntry { session_id: 1, @@ -3617,7 +3897,7 @@ mod implementations { }), ); PendingInboundEntries::::insert( - MESSAGE_PROOF, + MESSAGE_HASH, ROUTER_ID_2, InboundEntry::Proof(ProofEntry { session_id: 2, @@ -3625,7 +3905,7 @@ mod implementations { }), ); PendingInboundEntries::::insert( - MESSAGE_PROOF, + MESSAGE_HASH, ROUTER_ID_3, InboundEntry::Proof(ProofEntry { session_id: 3, @@ -3634,20 +3914,20 @@ mod implementations { ); assert_ok!(LiquidityPoolsGateway::execute_if_requirements_are_met( - MESSAGE_PROOF, + MESSAGE_HASH, &router_ids, session_id, expected_proof_count, domain_address, )); assert!( - PendingInboundEntries::::get(MESSAGE_PROOF, ROUTER_ID_1).is_some() + PendingInboundEntries::::get(MESSAGE_HASH, ROUTER_ID_1).is_some() ); assert!( - PendingInboundEntries::::get(MESSAGE_PROOF, ROUTER_ID_2).is_some() + PendingInboundEntries::::get(MESSAGE_HASH, ROUTER_ID_2).is_some() ); assert!( - PendingInboundEntries::::get(MESSAGE_PROOF, ROUTER_ID_3).is_some() + PendingInboundEntries::::get(MESSAGE_HASH, ROUTER_ID_3).is_some() ); }); } @@ -3664,7 +3944,7 @@ mod implementations { assert_noop!( LiquidityPoolsGateway::execute_post_voting_dispatch( - MESSAGE_PROOF, + MESSAGE_HASH, &router_ids, expected_proof_count, ), From da632bf886ceb9903b794f6da49fa7645c806764 Mon Sep 17 00:00:00 2001 From: Cosmin Damian <17934949+cdamian@users.noreply.github.com> Date: Fri, 16 Aug 2024 14:26:53 +0300 Subject: [PATCH 05/11] lp-gateway: Rename message_proof vars to message_hash --- .../src/message_processing.rs | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/pallets/liquidity-pools-gateway/src/message_processing.rs b/pallets/liquidity-pools-gateway/src/message_processing.rs index eceda9373a..39b0f03626 100644 --- a/pallets/liquidity-pools-gateway/src/message_processing.rs +++ b/pallets/liquidity-pools-gateway/src/message_processing.rs @@ -291,12 +291,12 @@ impl Pallet { } /// Gets the message proof for a message. - pub(crate) fn get_message_proof(message: T::Message) -> MessageHash { + pub(crate) fn get_message_hash(message: T::Message) -> MessageHash { match message.get_message_hash() { None => message .to_proof_message() .get_message_hash() - .expect("message proof ensured by 'to_message_proof'"), + .expect("message hash ensured by 'to_proof_message'"), Some(proof) => proof, } } @@ -304,11 +304,11 @@ impl Pallet { /// Upserts an inbound entry for a particular message, increasing the /// relevant counts accordingly. pub(crate) fn upsert_pending_entry( - message_proof: MessageHash, + message_hash: MessageHash, router_id: &T::RouterId, new_inbound_entry: InboundEntry, ) -> DispatchResult { - PendingInboundEntries::::try_mutate(message_proof, router_id, |storage_entry| { + PendingInboundEntries::::try_mutate(message_hash, router_id, |storage_entry| { match storage_entry { None => { *storage_entry = Some(new_inbound_entry); @@ -326,7 +326,7 @@ impl Pallet { /// were received, and if so, decreases the counts accordingly and executes /// the message. pub(crate) fn execute_if_requirements_are_met( - message_proof: MessageHash, + message_hash: MessageHash, router_ids: &[T::RouterId], session_id: T::SessionId, expected_proof_count: u32, @@ -336,7 +336,7 @@ impl Pallet { let mut votes = 0; for router_id in router_ids { - match PendingInboundEntries::::get(message_proof, router_id) { + match PendingInboundEntries::::get(message_hash, router_id) { // We expected one InboundEntry for each router, if that's not the case, // we can return. None => return Ok(()), @@ -357,7 +357,7 @@ impl Pallet { } if let Some(msg) = message { - Self::execute_post_voting_dispatch(message_proof, router_ids, expected_proof_count)?; + Self::execute_post_voting_dispatch(message_hash, router_ids, expected_proof_count)?; T::InboundMessageHandler::handle(domain_address, msg)?; } @@ -368,12 +368,12 @@ impl Pallet { /// Decreases the counts for inbound entries and removes them if the /// counts reach 0. pub(crate) fn execute_post_voting_dispatch( - message_proof: MessageHash, + message_hash: MessageHash, router_ids: &[T::RouterId], expected_proof_count: u32, ) -> DispatchResult { for router_id in router_ids { - PendingInboundEntries::::try_mutate(message_proof, router_id, |storage_entry| { + PendingInboundEntries::::try_mutate(message_hash, router_id, |storage_entry| { match storage_entry { None => { // This case cannot be reproduced in production since this function is @@ -413,7 +413,7 @@ impl Pallet { for submessage in message.submessages() { counter.ensure_add_assign(1)?; - let message_proof = Self::get_message_proof(submessage.clone()); + let message_hash = Self::get_message_hash(submessage.clone()); let inbound_entry: InboundEntry = InboundEntry::create( submessage, @@ -426,7 +426,7 @@ impl Pallet { Self::upsert_pending_entry(message_proof, &router_id, inbound_entry)?; Self::execute_if_requirements_are_met( - message_proof, + message_hash, &router_ids, session_id, expected_proof_count, @@ -445,7 +445,7 @@ impl Pallet { ) -> DispatchResult { let router_ids = Self::get_router_ids_for_domain(destination)?; - let message_proof = message.to_proof_message(); + let proof_message = message.to_proof_message(); let mut message_opt = Some(message); for router_id in router_ids { @@ -453,7 +453,7 @@ impl Pallet { // The remaining routers will send the message proof. let router_msg = match message_opt.take() { Some(m) => m, - None => message_proof.clone(), + None => proof_message.clone(), }; // We are using the sender specified in the pallet config so that we can From a7b75f4568ca52a2e99964f42151119b1481d1ab Mon Sep 17 00:00:00 2001 From: Cosmin Damian <17934949+cdamian@users.noreply.github.com> Date: Fri, 16 Aug 2024 21:10:43 +0300 Subject: [PATCH 06/11] lp-gateway: Update integration tests --- libs/traits/src/liquidity_pools.rs | 4 ++-- pallets/liquidity-pools-gateway/src/lib.rs | 12 +++++----- pallets/liquidity-pools-gateway/src/mock.rs | 10 ++++---- pallets/liquidity-pools-gateway/src/tests.rs | 20 ++++++++-------- pallets/liquidity-pools/src/message.rs | 8 +++---- .../src/cases/liquidity_pools.rs | 23 +------------------ .../cases/liquidity_pools_gateway_queue.rs | 2 -- .../integration-tests/src/cases/lp/utils.rs | 10 +------- .../integration-tests/src/cases/routers.rs | 3 +-- 9 files changed, 30 insertions(+), 62 deletions(-) diff --git a/libs/traits/src/liquidity_pools.rs b/libs/traits/src/liquidity_pools.rs index f0af312b94..1baede4c3e 100644 --- a/libs/traits/src/liquidity_pools.rs +++ b/libs/traits/src/liquidity_pools.rs @@ -45,13 +45,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; 20]) -> Self; + fn initiate_recovery_message(hash: [u8; 32], 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; 20]) -> Self; + fn dispute_recovery_message(hash: [u8; 32], 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 639edaadcb..ecf21abba2 100644 --- a/pallets/liquidity-pools-gateway/src/lib.rs +++ b/pallets/liquidity-pools-gateway/src/lib.rs @@ -172,7 +172,7 @@ pub mod pallet { MessageRecoveryInitiated { domain: Domain, message_hash: MessageHash, - recovery_router: [u8; 20], + recovery_router: [u8; 32], messaging_router: T::RouterId, }, @@ -180,7 +180,7 @@ pub mod pallet { MessageRecoveryDisputed { domain: Domain, message_hash: MessageHash, - recovery_router: [u8; 20], + recovery_router: [u8; 32], messaging_router: T::RouterId, }, } @@ -513,14 +513,14 @@ pub mod pallet { origin: OriginFor, domain: Domain, message_hash: MessageHash, - recovery_router: [u8; 20], + recovery_router: [u8; 32], messaging_router: T::RouterId, ) -> DispatchResult { T::AdminOrigin::ensure_origin(origin)?; let message = T::Message::initiate_recovery_message(message_hash, recovery_router); - Self::send_recovery_message(domain.clone(), message, messaging_router.clone())?; + Self::send_recovery_message(domain, message, messaging_router.clone())?; Self::deposit_event(Event::::MessageRecoveryInitiated { domain, @@ -542,14 +542,14 @@ pub mod pallet { origin: OriginFor, domain: Domain, message_hash: MessageHash, - recovery_router: [u8; 20], + recovery_router: [u8; 32], messaging_router: T::RouterId, ) -> DispatchResult { T::AdminOrigin::ensure_origin(origin)?; let message = T::Message::dispute_recovery_message(message_hash, recovery_router); - Self::send_recovery_message(domain.clone(), message, messaging_router.clone())?; + Self::send_recovery_message(domain, message, messaging_router.clone())?; Self::deposit_event(Event::::MessageRecoveryDisputed { domain, diff --git a/pallets/liquidity-pools-gateway/src/mock.rs b/pallets/liquidity-pools-gateway/src/mock.rs index 9c3cb842bc..8f5c2db475 100644 --- a/pallets/liquidity-pools-gateway/src/mock.rs +++ b/pallets/liquidity-pools-gateway/src/mock.rs @@ -17,7 +17,7 @@ use crate::{pallet as pallet_liquidity_pools_gateway, EnsureLocal, GatewayMessag pub const TEST_SESSION_ID: u32 = 1; pub const TEST_EVM_CHAIN: EVMChainId = 1; -pub const TEST_DOMAIN: Domain = Domain::EVM(TEST_EVM_CHAIN); +pub const TEST_DOMAIN: Domain = Domain::Evm(TEST_EVM_CHAIN); pub const TEST_DOMAIN_ADDRESS: DomainAddress = DomainAddress::Evm(TEST_EVM_CHAIN, H160::repeat_byte(1)); @@ -37,8 +37,8 @@ pub enum Message { Simple, Pack(Vec), Proof([u8; 32]), - InitiateMessageRecovery(([u8; 32], [u8; 20])), - DisputeMessageRecovery(([u8; 32], [u8; 20])), + InitiateMessageRecovery(([u8; 32], [u8; 32])), + DisputeMessageRecovery(([u8; 32], [u8; 32])), } impl Debug for Message { @@ -116,11 +116,11 @@ impl LPMessage for Message { } } - fn initiate_recovery_message(hash: [u8; 32], router: [u8; 20]) -> Self { + fn initiate_recovery_message(hash: [u8; 32], router: [u8; 32]) -> Self { Self::InitiateMessageRecovery((hash, router)) } - fn dispute_recovery_message(hash: [u8; 32], router: [u8; 20]) -> Self { + fn dispute_recovery_message(hash: [u8; 32], router: [u8; 32]) -> Self { Self::DisputeMessageRecovery((hash, router)) } } diff --git a/pallets/liquidity-pools-gateway/src/tests.rs b/pallets/liquidity-pools-gateway/src/tests.rs index 9ff5dd394c..455b5bdb32 100644 --- a/pallets/liquidity-pools-gateway/src/tests.rs +++ b/pallets/liquidity-pools-gateway/src/tests.rs @@ -875,7 +875,7 @@ mod extrinsics { #[test] fn success() { new_test_ext().execute_with(|| { - let recovery_router = [1u8; 20]; + let recovery_router = [1u8; 32]; Routers::::set(BoundedVec::try_from(vec![ROUTER_ID_1]).unwrap()); @@ -911,7 +911,7 @@ mod extrinsics { #[test] fn bad_origin() { new_test_ext().execute_with(|| { - let recovery_router = [1u8; 20]; + let recovery_router = [1u8; 32]; assert_noop!( LiquidityPoolsGateway::initiate_message_recovery( @@ -929,7 +929,7 @@ mod extrinsics { #[test] fn not_enough_routers_for_domain() { new_test_ext().execute_with(|| { - let recovery_router = [1u8; 20]; + let recovery_router = [1u8; 32]; assert_noop!( LiquidityPoolsGateway::initiate_message_recovery( @@ -947,7 +947,7 @@ mod extrinsics { #[test] fn messaging_router_not_found() { new_test_ext().execute_with(|| { - let recovery_router = [1u8; 20]; + let recovery_router = [1u8; 32]; Routers::::set(BoundedVec::try_from(vec![ROUTER_ID_1]).unwrap()); @@ -979,7 +979,7 @@ mod extrinsics { #[test] fn message_sender_error() { new_test_ext().execute_with(|| { - let recovery_router = [1u8; 20]; + let recovery_router = [1u8; 32]; Routers::::set(BoundedVec::try_from(vec![ROUTER_ID_1]).unwrap()); @@ -1017,7 +1017,7 @@ mod extrinsics { #[test] fn success() { new_test_ext().execute_with(|| { - let recovery_router = [1u8; 20]; + let recovery_router = [1u8; 32]; Routers::::set(BoundedVec::try_from(vec![ROUTER_ID_1]).unwrap()); @@ -1053,7 +1053,7 @@ mod extrinsics { #[test] fn bad_origin() { new_test_ext().execute_with(|| { - let recovery_router = [1u8; 20]; + let recovery_router = [1u8; 32]; assert_noop!( LiquidityPoolsGateway::dispute_message_recovery( @@ -1071,7 +1071,7 @@ mod extrinsics { #[test] fn not_enough_routers_for_domain() { new_test_ext().execute_with(|| { - let recovery_router = [1u8; 20]; + let recovery_router = [1u8; 32]; assert_noop!( LiquidityPoolsGateway::dispute_message_recovery( @@ -1089,7 +1089,7 @@ mod extrinsics { #[test] fn messaging_router_not_found() { new_test_ext().execute_with(|| { - let recovery_router = [1u8; 20]; + let recovery_router = [1u8; 32]; Routers::::set(BoundedVec::try_from(vec![ROUTER_ID_1]).unwrap()); @@ -1121,7 +1121,7 @@ mod extrinsics { #[test] fn message_sender_error() { new_test_ext().execute_with(|| { - let recovery_router = [1u8; 20]; + let recovery_router = [1u8; 32]; Routers::::set(BoundedVec::try_from(vec![ROUTER_ID_1]).unwrap()); diff --git a/pallets/liquidity-pools/src/message.rs b/pallets/liquidity-pools/src/message.rs index 49380e882b..3017e96800 100644 --- a/pallets/liquidity-pools/src/message.rs +++ b/pallets/liquidity-pools/src/message.rs @@ -226,7 +226,7 @@ pub enum Message { /// The hash of the message which shall be recovered hash: [u8; 32], /// The address of the router - router: [u8; 20], + router: [u8; 32], }, /// Dispute the recovery of a message. /// @@ -237,7 +237,7 @@ pub enum Message { /// The hash of the message which shall be disputed hash: [u8; 32], /// The address of the router - router: [u8; 20], + router: [u8; 32], }, /// A batch of ordered messages. /// Don't allow nested batch messages. @@ -575,11 +575,11 @@ impl LPMessage for Message { Message::MessageProof { hash } } - fn initiate_recovery_message(hash: [u8; 32], router: [u8; 20]) -> Self { + fn initiate_recovery_message(hash: [u8; 32], router: [u8; 32]) -> Self { Message::InitiateMessageRecovery { hash, router } } - fn dispute_recovery_message(hash: [u8; 32], router: [u8; 20]) -> Self { + fn dispute_recovery_message(hash: [u8; 32], router: [u8; 32]) -> Self { Message::DisputeMessageRecovery { hash, router } } } diff --git a/runtime/integration-tests/src/cases/liquidity_pools.rs b/runtime/integration-tests/src/cases/liquidity_pools.rs index 604d382670..328bb305e4 100644 --- a/runtime/integration-tests/src/cases/liquidity_pools.rs +++ b/runtime/integration-tests/src/cases/liquidity_pools.rs @@ -1026,15 +1026,12 @@ mod foreign_investments { let nonce = MessageNonceStore::::get(); - let sender = T::Sender::get(); - // Clearing of foreign InvestState should be dispatched assert!(frame_system::Pallet::::events().iter().any(|e| { e.event == pallet_liquidity_pools_gateway_queue::Event::MessageSubmitted { nonce, message: GatewayMessage::Outbound { - sender: sender.clone(), router_id: DEFAULT_ROUTER_ID, message: LiquidityPoolMessage::FulfilledDepositRequest { pool_id, @@ -1130,14 +1127,11 @@ mod foreign_investments { let nonce = MessageNonceStore::::get(); - let sender = T::Sender::get(); - assert!(frame_system::Pallet::::events().iter().any(|e| { e.event == pallet_liquidity_pools_gateway_queue::Event::::MessageSubmitted { nonce, message: GatewayMessage::Outbound { - sender: sender.clone(), router_id: DEFAULT_ROUTER_ID, message: Message::FulfilledDepositRequest { pool_id, @@ -1230,7 +1224,6 @@ mod foreign_investments { == pallet_liquidity_pools_gateway_queue::Event::::MessageSubmitted { nonce, message: GatewayMessage::Outbound { - sender: sender.clone(), router_id: DEFAULT_ROUTER_ID, message: LiquidityPoolMessage::FulfilledDepositRequest { pool_id, @@ -1265,12 +1258,11 @@ mod foreign_investments { pallet_liquidity_pools_gateway_queue::Event::MessageSubmitted { message: GatewayMessage::Outbound { - sender: event_sender, router_id: event_router_id, message: Message::FulfilledDepositRequest { .. }, }, .. - } => event_sender == sender && event_router_id == DEFAULT_ROUTER_ID, + } => event_router_id == DEFAULT_ROUTER_ID, _ => false, } } else { @@ -1502,14 +1494,11 @@ mod foreign_investments { let nonce = MessageNonceStore::::get(); - let sender = T::Sender::get(); - assert!(frame_system::Pallet::::events().iter().any(|e| { e.event == pallet_liquidity_pools_gateway_queue::Event::::MessageSubmitted { nonce, message: GatewayMessage::Outbound { - sender: sender.clone(), router_id: DEFAULT_ROUTER_ID, message: LiquidityPoolMessage::FulfilledRedeemRequest { pool_id, @@ -1599,7 +1588,6 @@ mod foreign_investments { == pallet_liquidity_pools_gateway_queue::Event::::MessageSubmitted { nonce, message: GatewayMessage::Outbound { - sender: sender.clone(), router_id: DEFAULT_ROUTER_ID, message: LiquidityPoolMessage::FulfilledRedeemRequest { pool_id, @@ -1940,14 +1928,11 @@ mod foreign_investments { let nonce = MessageNonceStore::::get(); - let sender = T::Sender::get(); - assert!(frame_system::Pallet::::events().iter().any(|e| { e.event == pallet_liquidity_pools_gateway_queue::Event::::MessageSubmitted { nonce, message: GatewayMessage::Outbound { - sender: sender.clone(), router_id: DEFAULT_ROUTER_ID, message: LiquidityPoolMessage::FulfilledDepositRequest { pool_id, @@ -2091,14 +2076,11 @@ mod foreign_investments { let nonce = MessageNonceStore::::get(); - let sender = ::Sender::get(); - assert!(frame_system::Pallet::::events().iter().any(|e| { e.event == pallet_liquidity_pools_gateway_queue::Event::::MessageSubmitted { nonce, message: GatewayMessage::Outbound { - sender: sender.clone(), router_id: DEFAULT_ROUTER_ID, message: LiquidityPoolMessage::FulfilledCancelDepositRequest { pool_id, @@ -2202,14 +2184,11 @@ mod foreign_investments { let nonce = MessageNonceStore::::get(); - let sender = ::Sender::get(); - assert!(frame_system::Pallet::::events().iter().any(|e| { e.event == pallet_liquidity_pools_gateway_queue::Event::::MessageSubmitted { nonce, message: GatewayMessage::Outbound { - sender: sender.clone(), router_id: DEFAULT_ROUTER_ID, message: LiquidityPoolMessage::FulfilledCancelDepositRequest { pool_id, diff --git a/runtime/integration-tests/src/cases/liquidity_pools_gateway_queue.rs b/runtime/integration-tests/src/cases/liquidity_pools_gateway_queue.rs index 7699fb7052..85573a4581 100644 --- a/runtime/integration-tests/src/cases/liquidity_pools_gateway_queue.rs +++ b/runtime/integration-tests/src/cases/liquidity_pools_gateway_queue.rs @@ -1,4 +1,3 @@ -use cfg_primitives::AccountId; use cfg_traits::liquidity_pools::MessageQueue; use cfg_types::domain_address::DomainAddress; use frame_support::{assert_ok, traits::OriginTrait}; @@ -72,7 +71,6 @@ fn outbound() { let nonce = ::MessageNonce::one(); let message = GatewayMessage::Outbound { - sender: DomainAddress::Centrifuge(AccountId::new([1; 32])), router_id: DEFAULT_ROUTER_ID, message: Message::Invalid, }; diff --git a/runtime/integration-tests/src/cases/lp/utils.rs b/runtime/integration-tests/src/cases/lp/utils.rs index 8188118c1b..c7d5c72121 100644 --- a/runtime/integration-tests/src/cases/lp/utils.rs +++ b/runtime/integration-tests/src/cases/lp/utils.rs @@ -139,15 +139,7 @@ pub fn process_gateway_message( match msg { GatewayMessage::Inbound { message, .. } => verifier(message), - GatewayMessage::Outbound { - sender, - router_id, - message, - } => { - assert_eq!( - sender, - ::Sender::get() - ); + GatewayMessage::Outbound { router_id, message } => { assert_eq!(router_id, EVM_ROUTER_ID); verifier(message) } diff --git a/runtime/integration-tests/src/cases/routers.rs b/runtime/integration-tests/src/cases/routers.rs index e892296c9b..9394b18b1b 100644 --- a/runtime/integration-tests/src/cases/routers.rs +++ b/runtime/integration-tests/src/cases/routers.rs @@ -14,7 +14,7 @@ use runtime_common::{ account_conversion::AccountConverter, evm::precompile::LP_AXELAR_GATEWAY, gateway::get_gateway_domain_address, routing::RouterId, }; -use sp_core::{Get, H160, H256, U256}; +use sp_core::{H160, H256, U256}; use sp_runtime::traits::{BlakeTwo256, Hash}; use crate::{ @@ -139,7 +139,6 @@ mod axelar_evm { )); let gateway_message = GatewayMessage::Outbound { - sender: T::Sender::get(), router_id: TEST_ROUTER_ID, message: Message::Invalid, }; From f8881b9950718ec7c9317c50dfcdee97fd041c6b Mon Sep 17 00:00:00 2001 From: Cosmin Damian <17934949+cdamian@users.noreply.github.com> Date: Fri, 16 Aug 2024 21:40:57 +0300 Subject: [PATCH 07/11] lp-gateway: Emit event when processing gateway message --- pallets/liquidity-pools-gateway/src/lib.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pallets/liquidity-pools-gateway/src/lib.rs b/pallets/liquidity-pools-gateway/src/lib.rs index ecf21abba2..8dd97c2eac 100644 --- a/pallets/liquidity-pools-gateway/src/lib.rs +++ b/pallets/liquidity-pools-gateway/src/lib.rs @@ -183,6 +183,11 @@ pub mod pallet { recovery_router: [u8; 32], messaging_router: T::RouterId, }, + + /// A message has been processed. + ProcessedMessage { + message: GatewayMessage, + }, } /// Storage for routers. @@ -611,6 +616,10 @@ pub mod pallet { type Message = GatewayMessage; fn process(msg: Self::Message) -> (DispatchResult, Weight) { + Self::deposit_event(Event::::ProcessedMessage { + message: msg.clone(), + }); + match msg { GatewayMessage::Inbound { domain_address, From 6dc6b7b4192c99245483d6f8f0060c883fe2e97c Mon Sep 17 00:00:00 2001 From: Cosmin Damian <17934949+cdamian@users.noreply.github.com> Date: Fri, 16 Aug 2024 22:24:27 +0300 Subject: [PATCH 08/11] lp-gateway: Add more events for inbound and outbound message processing --- libs/traits/src/liquidity_pools.rs | 5 +- pallets/liquidity-pools-gateway/src/lib.rs | 36 +++++++++----- .../src/message_processing.rs | 49 ++++++++++++------- pallets/liquidity-pools-gateway/src/mock.rs | 13 ++--- pallets/liquidity-pools-gateway/src/tests.rs | 20 ++++---- pallets/liquidity-pools/src/message.rs | 17 ++++--- 6 files changed, 85 insertions(+), 55 deletions(-) diff --git a/libs/traits/src/liquidity_pools.rs b/libs/traits/src/liquidity_pools.rs index 1baede4c3e..5b274599b3 100644 --- a/libs/traits/src/liquidity_pools.rs +++ b/libs/traits/src/liquidity_pools.rs @@ -35,8 +35,11 @@ pub trait LPMessage: Sized { /// It's the identity message for composing messages with pack_with fn empty() -> Self; + /// Returns whether the message is a proof or not. + fn is_proof_message(&self) -> bool; + /// Retrieves the message hash, if the message is a proof type. - fn get_message_hash(&self) -> Option; + fn get_message_hash(&self) -> MessageHash; /// Converts the message into a message proof type. fn to_proof_message(&self) -> Self; diff --git a/pallets/liquidity-pools-gateway/src/lib.rs b/pallets/liquidity-pools-gateway/src/lib.rs index 8dd97c2eac..07eab22107 100644 --- a/pallets/liquidity-pools-gateway/src/lib.rs +++ b/pallets/liquidity-pools-gateway/src/lib.rs @@ -44,7 +44,10 @@ use sp_arithmetic::traits::{BaseArithmetic, EnsureAddAssign, One}; use sp_runtime::SaturatedConversion; use sp_std::{convert::TryInto, vec::Vec}; -use crate::{message_processing::InboundEntry, weights::WeightInfo}; +use crate::{ + message_processing::{InboundEntry, ProofEntry}, + weights::WeightInfo, +}; mod origin; pub use origin::*; @@ -63,7 +66,6 @@ mod tests; #[frame_support::pallet] pub mod pallet { use super::*; - use crate::message_processing::ProofEntry; const STORAGE_VERSION: StorageVersion = StorageVersion::new(1); @@ -162,6 +164,27 @@ pub mod pallet { hook_address: [u8; 20], }, + /// An inbound message was processed. + InboundMessageProcessed { + message_hash: MessageHash, + router_id: T::RouterId, + }, + + /// An inbound message proof was processed. + InboundProofProcessed { + message_hash: MessageHash, + router_id: T::RouterId, + }, + + /// An inbound message was executed. + InboundMessageExecuted { message_hash: MessageHash }, + + /// An outbound message was sent. + OutboundMessageSent { + message_hash: MessageHash, + router_id: T::RouterId, + }, + /// Message recovery was executed. MessageRecoveryExecuted { message_hash: MessageHash, @@ -183,11 +206,6 @@ pub mod pallet { recovery_router: [u8; 32], messaging_router: T::RouterId, }, - - /// A message has been processed. - ProcessedMessage { - message: GatewayMessage, - }, } /// Storage for routers. @@ -616,10 +634,6 @@ pub mod pallet { type Message = GatewayMessage; fn process(msg: Self::Message) -> (DispatchResult, Weight) { - Self::deposit_event(Event::::ProcessedMessage { - message: msg.clone(), - }); - match msg { GatewayMessage::Inbound { domain_address, diff --git a/pallets/liquidity-pools-gateway/src/message_processing.rs b/pallets/liquidity-pools-gateway/src/message_processing.rs index 39b0f03626..0ae12d25b0 100644 --- a/pallets/liquidity-pools-gateway/src/message_processing.rs +++ b/pallets/liquidity-pools-gateway/src/message_processing.rs @@ -13,7 +13,8 @@ use sp_runtime::DispatchError; use sp_std::vec::Vec; use crate::{ - message::GatewayMessage, Config, Error, Pallet, PendingInboundEntries, Routers, SessionIdStore, + message::GatewayMessage, Config, Error, Event, Pallet, PendingInboundEntries, Routers, + SessionIdStore, }; /// Type that holds the information needed for inbound message entries. @@ -92,17 +93,18 @@ impl InboundEntry { domain_address: DomainAddress, expected_proof_count: u32, ) -> Self { - match message.get_message_hash() { - None => InboundEntry::Message(MessageEntry { + if message.is_proof_message() { + InboundEntry::Message(MessageEntry { session_id, domain_address, message, expected_proof_count, - }), - Some(_) => InboundEntry::Proof(ProofEntry { + }) + } else { + InboundEntry::Proof(ProofEntry { session_id, current_count: 1, - }), + }) } } @@ -290,17 +292,6 @@ impl Pallet { Ok(expected_proof_count.saturated_into()) } - /// Gets the message proof for a message. - pub(crate) fn get_message_hash(message: T::Message) -> MessageHash { - match message.get_message_hash() { - None => message - .to_proof_message() - .get_message_hash() - .expect("message hash ensured by 'to_proof_message'"), - Some(proof) => proof, - } - } - /// Upserts an inbound entry for a particular message, increasing the /// relevant counts accordingly. pub(crate) fn upsert_pending_entry( @@ -360,6 +351,8 @@ impl Pallet { Self::execute_post_voting_dispatch(message_hash, router_ids, expected_proof_count)?; T::InboundMessageHandler::handle(domain_address, msg)?; + + Self::deposit_event(Event::::InboundMessageExecuted { message_hash }) } Ok(()) @@ -413,7 +406,7 @@ impl Pallet { for submessage in message.submessages() { counter.ensure_add_assign(1)?; - let message_hash = Self::get_message_hash(submessage.clone()); + let message_hash = submessage.get_message_hash(); let inbound_entry: InboundEntry = InboundEntry::create( submessage, @@ -423,7 +416,7 @@ impl Pallet { ); inbound_entry.validate(&router_ids, &router_id.clone())?; - Self::upsert_pending_entry(message_proof, &router_id, inbound_entry)?; + Self::upsert_pending_entry(message_hash, &router_id, inbound_entry)?; Self::execute_if_requirements_are_met( message_hash, @@ -437,6 +430,24 @@ impl Pallet { Ok(()) } + fn deposit_processing_event( + message: T::Message, + message_hash: MessageHash, + router_id: T::RouterId, + ) { + if message.is_proof_message() { + Self::deposit_event(Event::::InboundProofProcessed { + message_hash, + router_id, + }) + } else { + Self::deposit_event(Event::::InboundMessageProcessed { + message_hash, + router_id, + }) + } + } + /// Retrieves the IDs of the routers set for a domain and queues the /// message and proofs accordingly. pub(crate) fn queue_outbound_message( diff --git a/pallets/liquidity-pools-gateway/src/mock.rs b/pallets/liquidity-pools-gateway/src/mock.rs index 8f5c2db475..acd3d052ce 100644 --- a/pallets/liquidity-pools-gateway/src/mock.rs +++ b/pallets/liquidity-pools-gateway/src/mock.rs @@ -102,17 +102,18 @@ impl LPMessage for Message { Self::Pack(vec![]) } - fn get_message_hash(&self) -> Option { - match self { - Message::Proof(p) => Some(p.clone()), - _ => None, - } + fn is_proof_message(&self) -> bool { + matches!(self, Message::Proof(..)) + } + + fn get_message_hash(&self) -> MessageHash { + MESSAGE_HASH } fn to_proof_message(&self) -> Self { match self { Message::Proof(_) => self.clone(), - _ => Message::Proof(MESSAGE_HASH), + _ => Message::Proof(self.get_message_hash()), } } diff --git a/pallets/liquidity-pools-gateway/src/tests.rs b/pallets/liquidity-pools-gateway/src/tests.rs index 455b5bdb32..b8ca112b5e 100644 --- a/pallets/liquidity-pools-gateway/src/tests.rs +++ b/pallets/liquidity-pools-gateway/src/tests.rs @@ -836,7 +836,7 @@ mod extrinsics { } #[test] - fn expected_message_proof_type() { + fn expected_message_hash_type() { new_test_ext().execute_with(|| { let domain_address = TEST_DOMAIN_ADDRESS; let session_id = 1; @@ -1166,7 +1166,7 @@ mod implementations { let domain = Domain::Evm(0); let sender = get_test_account_id(); let msg = Message::Simple; - let message_proof = msg.to_proof_message().get_message_hash().unwrap(); + let message_hash = msg.get_message_hash(); assert_ok!(LiquidityPoolsGateway::set_routers( RuntimeOrigin::root(), @@ -1180,7 +1180,7 @@ mod implementations { } GatewayMessage::Outbound { message, .. } => match message { Message::Proof(p) => { - assert_eq!(p, message_proof); + assert_eq!(p, message_hash); } _ => {} }, @@ -1416,7 +1416,7 @@ mod implementations { fn success() { new_test_ext().execute_with(|| { let message = Message::Simple; - let message_proof = message.to_proof_message().get_message_hash().unwrap(); + let message_hash = message.get_message_hash(); let session_id = 1; let domain_address = DomainAddress::Evm(1, H160::repeat_byte(1)); let router_id = ROUTER_ID_1; @@ -1445,7 +1445,7 @@ mod implementations { assert_eq!(handler.times(), 1); assert!( - PendingInboundEntries::::get(message_proof, router_id) + PendingInboundEntries::::get(message_hash, router_id) .is_none() ); }); @@ -1494,10 +1494,10 @@ mod implementations { } #[test] - fn expected_message_proof_type() { + fn expected_message_hash_type() { new_test_ext().execute_with(|| { let message = Message::Simple; - let message_proof = message.to_proof_message().get_message_hash().unwrap(); + let message_hash = message.get_message_hash(); let session_id = 1; let domain_address = DomainAddress::Evm(1, H160::repeat_byte(1)); let router_id = ROUTER_ID_1; @@ -1512,7 +1512,7 @@ mod implementations { ); SessionIdStore::::set(session_id); PendingInboundEntries::::insert( - message_proof, + message_hash, router_id, InboundEntry::Proof(ProofEntry { session_id, @@ -3844,7 +3844,7 @@ mod implementations { } #[test] - fn expected_message_proof_type() { + fn expected_message_hash_type() { new_test_ext().execute_with(|| { let inbound_entry: InboundEntry = ProofEntry { session_id: 1, @@ -4221,7 +4221,7 @@ mod inbound_entry { } #[test] - fn expected_message_proof_type() { + fn expected_message_hash_type() { new_test_ext().execute_with(|| { let mut inbound_entry = InboundEntry::::Message(MessageEntry { session_id: 1, diff --git a/pallets/liquidity-pools/src/message.rs b/pallets/liquidity-pools/src/message.rs index 3017e96800..1b52ca3e23 100644 --- a/pallets/liquidity-pools/src/message.rs +++ b/pallets/liquidity-pools/src/message.rs @@ -562,17 +562,18 @@ impl LPMessage for Message { Message::Batch(BatchMessages::default()) } - fn get_message_hash(&self) -> Option { - match self { - Message::MessageProof { hash } => Some(*hash), - _ => None, - } + fn is_proof_message(&self) -> bool { + matches!(self, Message::MessageProof { .. }) } - fn to_proof_message(&self) -> Self { - let hash = keccak_256(&LPMessage::serialize(self)); + fn get_message_hash(&self) -> MessageHash { + keccak_256(&LPMessage::serialize(self)) + } - Message::MessageProof { hash } + fn to_proof_message(&self) -> Self { + Message::MessageProof { + hash: self.get_message_hash(), + } } fn initiate_recovery_message(hash: [u8; 32], router: [u8; 32]) -> Self { From 0fe64fdeabf7f21868996272c6a55db0c633db24 Mon Sep 17 00:00:00 2001 From: Cosmin Damian <17934949+cdamian@users.noreply.github.com> Date: Fri, 16 Aug 2024 23:03:47 +0300 Subject: [PATCH 09/11] lp-gateway: Update events --- pallets/liquidity-pools-gateway/src/lib.rs | 8 +++++++- .../liquidity-pools-gateway/src/message_processing.rs | 10 ++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/pallets/liquidity-pools-gateway/src/lib.rs b/pallets/liquidity-pools-gateway/src/lib.rs index 07eab22107..16e39e836d 100644 --- a/pallets/liquidity-pools-gateway/src/lib.rs +++ b/pallets/liquidity-pools-gateway/src/lib.rs @@ -166,21 +166,27 @@ pub mod pallet { /// An inbound message was processed. InboundMessageProcessed { + domain_address: DomainAddress, message_hash: MessageHash, router_id: T::RouterId, }, /// An inbound message proof was processed. InboundProofProcessed { + domain_address: DomainAddress, message_hash: MessageHash, router_id: T::RouterId, }, /// An inbound message was executed. - InboundMessageExecuted { message_hash: MessageHash }, + InboundMessageExecuted { + domain_address: DomainAddress, + message_hash: MessageHash, + }, /// An outbound message was sent. OutboundMessageSent { + domain_address: DomainAddress, message_hash: MessageHash, router_id: T::RouterId, }, diff --git a/pallets/liquidity-pools-gateway/src/message_processing.rs b/pallets/liquidity-pools-gateway/src/message_processing.rs index 0ae12d25b0..2fdc7adfaf 100644 --- a/pallets/liquidity-pools-gateway/src/message_processing.rs +++ b/pallets/liquidity-pools-gateway/src/message_processing.rs @@ -350,9 +350,12 @@ impl Pallet { if let Some(msg) = message { Self::execute_post_voting_dispatch(message_hash, router_ids, expected_proof_count)?; - T::InboundMessageHandler::handle(domain_address, msg)?; + T::InboundMessageHandler::handle(domain_address.clone(), msg)?; - Self::deposit_event(Event::::InboundMessageExecuted { message_hash }) + Self::deposit_event(Event::::InboundMessageExecuted { + domain_address, + message_hash, + }) } Ok(()) @@ -431,17 +434,20 @@ impl Pallet { } fn deposit_processing_event( + domain_address: DomainAddress, message: T::Message, message_hash: MessageHash, router_id: T::RouterId, ) { if message.is_proof_message() { Self::deposit_event(Event::::InboundProofProcessed { + domain_address, message_hash, router_id, }) } else { Self::deposit_event(Event::::InboundMessageProcessed { + domain_address, message_hash, router_id, }) From e413e2fc530c3337de9a34f25b69fdec062e0650 Mon Sep 17 00:00:00 2001 From: Cosmin Damian <17934949+cdamian@users.noreply.github.com> Date: Sat, 17 Aug 2024 00:43:53 +0300 Subject: [PATCH 10/11] lp-gateway: Create correct inbound entry type --- .../liquidity-pools-gateway/src/message_processing.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pallets/liquidity-pools-gateway/src/message_processing.rs b/pallets/liquidity-pools-gateway/src/message_processing.rs index 2fdc7adfaf..eac35c05c9 100644 --- a/pallets/liquidity-pools-gateway/src/message_processing.rs +++ b/pallets/liquidity-pools-gateway/src/message_processing.rs @@ -94,17 +94,17 @@ impl InboundEntry { expected_proof_count: u32, ) -> Self { if message.is_proof_message() { + InboundEntry::Proof(ProofEntry { + session_id, + current_count: 1, + }) + } else { InboundEntry::Message(MessageEntry { session_id, domain_address, message, expected_proof_count, }) - } else { - InboundEntry::Proof(ProofEntry { - session_id, - current_count: 1, - }) } } From b3f2f07cc5f2a9feb6aba1739c72bcd4420b08a0 Mon Sep 17 00:00:00 2001 From: Cosmin Damian <17934949+cdamian@users.noreply.github.com> Date: Sat, 17 Aug 2024 00:53:15 +0300 Subject: [PATCH 11/11] lp-gateway: Rebase fixes --- pallets/liquidity-pools-gateway/src/lib.rs | 9 +++------ .../liquidity-pools-gateway/src/message_processing.rs | 11 +++++++++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/pallets/liquidity-pools-gateway/src/lib.rs b/pallets/liquidity-pools-gateway/src/lib.rs index 16e39e836d..2fd6e75c2f 100644 --- a/pallets/liquidity-pools-gateway/src/lib.rs +++ b/pallets/liquidity-pools-gateway/src/lib.rs @@ -662,12 +662,9 @@ pub mod pallet { (res, weight) } - GatewayMessage::Outbound { - sender, - message, - router_id, - } => { - let res = T::MessageSender::send(router_id, sender, message.serialize()); + GatewayMessage::Outbound { message, router_id } => { + let res = + T::MessageSender::send(router_id, T::Sender::get(), message.serialize()); (res, LP_DEFENSIVE_WEIGHT) } diff --git a/pallets/liquidity-pools-gateway/src/message_processing.rs b/pallets/liquidity-pools-gateway/src/message_processing.rs index eac35c05c9..377b6b7a9c 100644 --- a/pallets/liquidity-pools-gateway/src/message_processing.rs +++ b/pallets/liquidity-pools-gateway/src/message_processing.rs @@ -5,7 +5,7 @@ use cfg_types::domain_address::{Domain, DomainAddress}; use frame_support::{ dispatch::DispatchResult, ensure, - pallet_prelude::{Decode, Encode, Get, TypeInfo}, + pallet_prelude::{Decode, Encode, TypeInfo}, }; use parity_scale_codec::MaxEncodedLen; use sp_arithmetic::traits::{EnsureAddAssign, EnsureSub, SaturatedConversion}; @@ -412,7 +412,7 @@ impl Pallet { let message_hash = submessage.get_message_hash(); let inbound_entry: InboundEntry = InboundEntry::create( - submessage, + submessage.clone(), session_id, domain_address.clone(), expected_proof_count, @@ -421,6 +421,13 @@ impl Pallet { inbound_entry.validate(&router_ids, &router_id.clone())?; Self::upsert_pending_entry(message_hash, &router_id, inbound_entry)?; + Self::deposit_processing_event( + domain_address.clone(), + submessage, + message_hash, + router_id.clone(), + ); + Self::execute_if_requirements_are_met( message_hash, &router_ids,