Skip to content

Commit

Permalink
Feat/lp v2 gateway multi router (#1961)
Browse files Browse the repository at this point in the history
* wip

* lp-gateway: Add router hash for inbound messages, extrinsic to set inbound routers, session ID storage

* lp-gateway: Add router hash for inbound messages, extrinsic to set inbound routers, session ID storage

* lp-gateway: Use router hashes for inbound, use session ID, update inbound message processing logic

* lp-gateway: Add and use InboundProcessingInfo

* lp-gateway: Unit tests WIP

* lp-gateway: Unit tests WIP 2

* docs: Improve comments

* lp-gateway: Move message processing logic to a new file

* lp-gateway: Merge inbound/outbound routers extrinsics into one, add logic for removing invalid session IDs on idle

* lp-gateway: Unit tests WIP

* lp-gateway: Add extrinsic for executing message recovery

* rebase: WIP

* Don't use domain when storing routers (#1962)

* lp-gateway: Unit tests WIP

* lp-gateway: Don't store routers under domain

* wip

* wip

* lp-gateway: Unit test WIP

* lp-gateway: Rename RouterSupport to RouterProvider, add separate entity that implements it

* lp-gateway: Add more asserts in unit tests

* lp-gateway: Attempt to execute message during recovery

* lp-gateway: Remove extra constraints from SessionId

* lp-gateway: Drop session ID invalidation (#1965)

* lp-gateway: Drop session ID invalidation

* lp-gateway: Add test for invalid router

* lp-gateway: Add more unit tests

* lp-gateway: Move InboundEntry logic to implementation

* lp-gateway: Use safe math

* lp-gateway: Add more unit tests

* checks: Fix clippy, taplo, formatting

* review: Remove mock-builder dep, rename LP encoding proof methods

* lp-gateway: Remove Default impls for RouterId and GatewayMessage

* lp-gateway: Allow empty list of routers

* lp-gateway: Drop InboundProcessingInfo

* lp-gateway: Rename LP encoding methods to get_proof and to_proof_message

* lp-gateway: Move outbound processing logic back to pallet

* review: Small fixes

* lp-gateway: Add comment for post voting dispatch error case

* lp-gatway: Drop session ID check in create_post_voting_entry

* lp: Remove unused import

* integration-tests: Register routers during setup (#1968)

* integration-tests: Set routers in all setup funcs and tests
  • Loading branch information
cdamian authored Aug 16, 2024
1 parent e8f1efd commit d1d823a
Show file tree
Hide file tree
Showing 30 changed files with 4,817 additions and 805 deletions.
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ impl-trait-for-tuples = "0.2.2"
num-traits = { version = "0.2.17", default-features = false }
num_enum = { version = "0.5.3", default-features = false }
chrono = { version = "0.4", default-features = false }
itertools = { version = "0.13.0", default-features = false }

# Cumulus
cumulus-pallet-aura-ext = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.7.2" }
Expand Down
8 changes: 5 additions & 3 deletions libs/mocks/src/liquidity_pools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pub mod pallet {
use cfg_traits::liquidity_pools::InboundMessageHandler;
use frame_support::pallet_prelude::*;
use mock_builder::{execute_call, register_call};
use mock_builder::{execute_call, register_call, CallHandler};

#[pallet::config]
pub trait Config: frame_system::Config {
Expand All @@ -17,8 +17,10 @@ pub mod pallet {
type CallIds<T: Config> = StorageMap<_, _, String, mock_builder::CallId>;

impl<T: Config> Pallet<T> {
pub fn mock_handle(f: impl Fn(T::DomainAddress, T::Message) -> DispatchResult + 'static) {
register_call!(move |(sender, msg)| f(sender, msg));
pub fn mock_handle(
f: impl Fn(T::DomainAddress, T::Message) -> DispatchResult + 'static,
) -> CallHandler {
register_call!(move |(sender, msg)| f(sender, msg))
}
}

Expand Down
6 changes: 3 additions & 3 deletions libs/mocks/src/router_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pub mod pallet {
use cfg_traits::liquidity_pools::{MessageReceiver, MessageSender};
use frame_support::pallet_prelude::*;
use mock_builder::{execute_call, register_call};
use mock_builder::{execute_call, register_call, CallHandler};

#[pallet::config]
pub trait Config: frame_system::Config {
Expand All @@ -25,8 +25,8 @@ pub mod pallet {

pub fn mock_send(
f: impl Fn(T::Middleware, T::Origin, Vec<u8>) -> DispatchResult + 'static,
) {
register_call!(move |(a, b, c)| f(a, b, c));
) -> CallHandler {
register_call!(move |(a, b, c)| f(a, b, c))
}
}

Expand Down
3 changes: 3 additions & 0 deletions libs/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ pub mod types {

/// The type for LP gateway message nonces.
pub type LPGatewayQueueMessageNonce = u64;

/// The type for LP gateway session IDs.
pub type LPGatewaySessionId = u64;
}

/// Common constants for all runtimes
Expand Down
15 changes: 13 additions & 2 deletions libs/traits/src/liquidity_pools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ use frame_support::{dispatch::DispatchResult, weights::Weight};
use sp_runtime::DispatchError;
use sp_std::vec::Vec;

pub type Proof = [u8; 32];

/// An encoding & decoding trait for the purpose of meeting the
/// LiquidityPools General Message Passing Format
pub trait LPEncoding: Sized {
Expand All @@ -31,11 +33,20 @@ pub trait LPEncoding: Sized {
/// Creates an empty message.
/// 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<Proof>;

/// Converts the message into a message proof type.
fn to_proof_message(&self) -> Self;
}

pub trait RouterSupport<Domain>: Sized {
pub trait RouterProvider<Domain>: Sized {
/// The router identifier.
type RouterId;

/// Returns a list of routers supported for the given domain.
fn for_domain(domain: Domain) -> Vec<Self>;
fn routers_for_domain(domain: Domain) -> Vec<Self::RouterId>;
}

/// The behavior of an entity that can send messages
Expand Down
6 changes: 6 additions & 0 deletions pallets/axelar-router/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ pub enum AxelarId {
Evm(EVMChainId),
}

impl Default for AxelarId {
fn default() -> Self {
Self::Evm(1)
}
}

/// Configuration for outbound messages though axelar
#[derive(Debug, Encode, Decode, Clone, PartialEq, Eq, TypeInfo, MaxEncodedLen)]
pub struct AxelarConfig {
Expand Down
4 changes: 4 additions & 0 deletions pallets/liquidity-pools-gateway/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ hex = { workspace = true }
orml-traits = { workspace = true }
parity-scale-codec = { workspace = true }
scale-info = { workspace = true }
sp-arithmetic = { workspace = true }
sp-core = { workspace = true }
sp-runtime = { workspace = true }
sp-std = { workspace = true }
Expand All @@ -34,6 +35,8 @@ cfg-utils = { workspace = true }

[dev-dependencies]
cfg-mocks = { workspace = true, default-features = true }
itertools = { workspace = true, default-features = true }
lazy_static = { workspace = true, default-features = true }
sp-io = { workspace = true, default-features = true }

[features]
Expand All @@ -53,6 +56,7 @@ std = [
"cfg-utils/std",
"hex/std",
"cfg-primitives/std",
"sp-arithmetic/std",
]
try-runtime = [
"cfg-traits/try-runtime",
Expand Down
2 changes: 1 addition & 1 deletion pallets/liquidity-pools-gateway/queue/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub mod pallet {
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;

/// The message type.
type Message: Clone + Debug + PartialEq + MaxEncodedLen + TypeInfo + FullCodec + Default;
type Message: Clone + Debug + PartialEq + MaxEncodedLen + TypeInfo + FullCodec;

/// Type used for message identification.
type MessageNonce: Parameter
Expand Down
Loading

0 comments on commit d1d823a

Please sign in to comment.