Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/lp v2 use gateway queue #1943

Merged
merged 24 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
bd54a1d
liquidity-pools: Use LP gateway queue for inbound and outbound messag…
cdamian Jul 31, 2024
8bfecdd
tests: wip
cdamian Jul 31, 2024
a7e5835
lp-gateway-queue: Add TODO for benchmarks
cdamian Jul 31, 2024
4de208c
lp-gateway: Add MaxEncodedLen of inbound Message
cdamian Jul 31, 2024
f31821b
gateway: Move GatewayMessage to gateway pallet
cdamian Jul 31, 2024
ef008cd
integration-tests: Adapt existing tests to LP gateway queue usage, ad…
cdamian Jul 31, 2024
3ba2f20
integration-tests: Add LP gateway queue tests
cdamian Aug 1, 2024
bd7f81b
unit-tests: Fix
cdamian Aug 1, 2024
d56675e
integration-tests: Enable all runtimes for LP gateway queue tests
cdamian Aug 1, 2024
839f004
integration-tests: Skip the gateway queue for LP gateway router tests
cdamian Aug 1, 2024
620e92d
integration-tests: Reduce visibility for LP utils module
cdamian Aug 1, 2024
89c9f6f
integration-tests: Drop fudge from router evm tests
cdamian Aug 1, 2024
42a3e09
integration-tests: Drop fudge from foreign investments tests
cdamian Aug 1, 2024
204f7bc
lp-gateway: Replace DispatchResultWithPostInfo with (DispatchResult, …
cdamian Aug 1, 2024
a4f5b46
integration-tests: Fix LP tests (wip)
cdamian Aug 1, 2024
967e86c
lp-gateway: Drop AddAssign
cdamian Aug 1, 2024
34e4f86
integration-tests: Fix failing tests
cdamian Aug 1, 2024
f9e4812
lp-gateway-queue: Add defensive weight to extrinsics
cdamian Aug 2, 2024
e1e458e
lp-gateway: Add defensive weight when processing inbound message
cdamian Aug 2, 2024
9689a41
unit-tests: Update expected weight in LP gateway tests
cdamian Aug 2, 2024
60bb6e8
lp: Add constants for LP defensive weights
cdamian Aug 2, 2024
8e399a6
deps: Add cfg-primitives
cdamian Aug 2, 2024
e6625f7
LP: Add and use LP_DEFENSIVE_WEIGHT
cdamian Aug 2, 2024
e164791
lp-gateway-queue: Drop benchmarks and use defensive weights instead
cdamian Aug 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion libs/mocks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ pub mod liquidity_pools;
pub mod liquidity_pools_gateway;
pub mod liquidity_pools_gateway_queue;
pub mod liquidity_pools_gateway_routers;
pub mod outbound_queue;
pub mod pay_fee;
pub mod permissions;
pub mod pools;
Expand Down
8 changes: 4 additions & 4 deletions libs/mocks/src/liquidity_pools.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[frame_support::pallet(dev_mode)]
pub mod pallet {
use cfg_traits::liquidity_pools::InboundQueue;
use cfg_traits::liquidity_pools::InboundMessageHandler;
use frame_support::pallet_prelude::*;
use mock_builder::{execute_call, register_call};

Expand All @@ -17,16 +17,16 @@ pub mod pallet {
type CallIds<T: Config> = StorageMap<_, _, String, mock_builder::CallId>;

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

impl<T: Config> InboundQueue for Pallet<T> {
impl<T: Config> InboundMessageHandler for Pallet<T> {
type Message = T::Message;
type Sender = T::DomainAddress;

fn submit(sender: Self::Sender, msg: Self::Message) -> DispatchResult {
fn handle(sender: Self::Sender, msg: Self::Message) -> DispatchResult {
execute_call!((sender, msg))
}
}
Expand Down
38 changes: 35 additions & 3 deletions libs/mocks/src/liquidity_pools_gateway.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#[frame_support::pallet(dev_mode)]
pub mod pallet {
use cfg_traits::liquidity_pools::MessageProcessor;
use cfg_traits::liquidity_pools::{MessageProcessor, OutboundMessageHandler};
use frame_support::pallet_prelude::*;
use mock_builder::{execute_call, register_call};
use orml_traits::GetByKey;

#[pallet::config]
pub trait Config: frame_system::Config {
type Message;
type Destination;
}

#[pallet::pallet]
Expand All @@ -16,16 +18,46 @@ pub mod pallet {
type CallIds<T: Config> = StorageMap<_, _, String, mock_builder::CallId>;

impl<T: Config> Pallet<T> {
pub fn mock_process(f: impl Fn(T::Message) -> DispatchResultWithPostInfo + 'static) {
pub fn mock_process(f: impl Fn(T::Message) -> (DispatchResult, Weight) + 'static) {
register_call!(f);
}

pub fn mock_get(f: impl Fn(&T::Destination) -> Option<[u8; 20]> + 'static) {
register_call!(f);
}

pub fn mock_handle(
f: impl Fn(T::AccountId, T::Destination, T::Message) -> DispatchResult + 'static,
) {
register_call!(move |(sender, destination, msg)| f(sender, destination, msg));
}
}

impl<T: Config> MessageProcessor for Pallet<T> {
type Message = T::Message;

fn process(msg: Self::Message) -> DispatchResultWithPostInfo {
fn process(msg: Self::Message) -> (DispatchResult, Weight) {
execute_call!(msg)
}
}

impl<T: Config> GetByKey<T::Destination, Option<[u8; 20]>> for Pallet<T> {
fn get(a: &T::Destination) -> Option<[u8; 20]> {
execute_call!(a)
}
}

impl<T: Config> OutboundMessageHandler for Pallet<T> {
type Destination = T::Destination;
type Message = T::Message;
type Sender = T::AccountId;

fn handle(
sender: Self::Sender,
destination: Self::Destination,
msg: Self::Message,
) -> DispatchResult {
execute_call!((sender, destination, msg))
}
}
}
48 changes: 0 additions & 48 deletions libs/mocks/src/outbound_queue.rs

This file was deleted.

11 changes: 8 additions & 3 deletions libs/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,6 @@ pub mod types {
/// The representation of a pool fee identifier
pub type PoolFeeId = u64;

/// The type for outbound LP message nonces.
pub type OutboundMessageNonce = u64;

/// The type for LP gateway message nonces.
pub type LPGatewayQueueMessageNonce = u64;
}
Expand Down Expand Up @@ -284,6 +281,14 @@ pub mod constants {
pub const TRACK_INDEX_REF_CANCELLER: u16 = 20;
/// The index of the referendum killer OpenGov track
pub const TRACK_INDEX_REF_KILLER: u16 = 21;

/// Defensive weight parts that are used in LP related pallets.
pub const LP_DEFENSIVE_WEIGHT_REF_TIME: u64 = 5_000_000_000;
pub const LP_DEFENSIVE_WEIGHT_POV: u64 = 4096;

/// Defensive weight for processing LP messages;
pub const LP_DEFENSIVE_WEIGHT: Weight =
Weight::from_parts(LP_DEFENSIVE_WEIGHT_REF_TIME, LP_DEFENSIVE_WEIGHT_POV);
}

/// Listing of parachains we integrate with.
Expand Down
64 changes: 34 additions & 30 deletions libs/traits/src/liquidity_pools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

use frame_support::dispatch::{DispatchResult, DispatchResultWithPostInfo};
use frame_support::{
dispatch::{DispatchResult, DispatchResultWithPostInfo},
weights::Weight,
};
use sp_runtime::DispatchError;
use sp_std::vec::Vec;

Expand Down Expand Up @@ -58,50 +61,51 @@ pub trait Router {
fn send(&self, sender: Self::Sender, message: Vec<u8>) -> DispatchResultWithPostInfo;
}

/// The trait required for processing outbound messages.
pub trait OutboundQueue {
/// The sender type of the outgoing message.
type Sender;
/// The trait required for queueing messages.
pub trait MessageQueue {
/// The message type.
type Message;

/// The destination this message should go to.
type Destination;
/// Submit a message to the queue.
fn submit(msg: Self::Message) -> DispatchResult;
}

/// The message type that is processed.
/// The trait required for processing queued messages.
pub trait MessageProcessor {
/// The message type.
type Message;

/// Submit a message to the outbound queue.
fn submit(
sender: Self::Sender,
destination: Self::Destination,
msg: Self::Message,
) -> DispatchResult;
/// Process a message.
fn process(msg: Self::Message) -> (DispatchResult, Weight);
}

/// The trait required for processing incoming messages.
pub trait InboundQueue {
/// The sender type of the incoming message.
/// The trait required for handling outbound LP messages.
pub trait OutboundMessageHandler {
/// The sender type of the outbound message.
type Sender;

/// The liquidityPools message type.
type Message;

/// Submit a message to the inbound queue.
fn submit(sender: Self::Sender, msg: Self::Message) -> DispatchResult;
}
/// The destination type of the outbound message.
type Destination;

/// The trait required for queueing messages.
pub trait MessageQueue {
/// The message type.
type Message;

/// Submit a message to the queue.
fn submit(msg: Self::Message) -> DispatchResult;
/// Handle an outbound message.
fn handle(
sender: Self::Sender,
destination: Self::Destination,
msg: Self::Message,
) -> DispatchResult;
}

pub trait MessageProcessor {
/// The trait required for handling inbound LP messages.
pub trait InboundMessageHandler {
/// The sender type of the inbound message.
type Sender;

/// The message type.
type Message;

/// Process a message.
fn process(msg: Self::Message) -> DispatchResultWithPostInfo;
/// Handle an inbound message.
fn handle(sender: Self::Sender, msg: Self::Message) -> DispatchResult;
}
6 changes: 6 additions & 0 deletions libs/types/src/domain_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ pub enum DomainAddress {
EVM(EVMChainId, [u8; 20]),
}

impl Default for DomainAddress {
cdamian marked this conversation as resolved.
Show resolved Hide resolved
fn default() -> Self {
DomainAddress::Centrifuge([0; 32])
}
}

impl DomainAddress {
pub fn evm(chain_id: EVMChainId, address: [u8; 20]) -> Self {
Self::EVM(chain_id, address)
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 @@ -27,6 +27,7 @@ sp-std = { workspace = true }
frame-benchmarking = { workspace = true, optional = true }

# Our custom pallets
cfg-primitives = { workspace = true }
cfg-traits = { workspace = true }
cfg-types = { workspace = true }
cfg-utils = { workspace = true }
Expand Down Expand Up @@ -56,6 +57,7 @@ std = [
"scale-info/std",
"cfg-utils/std",
"hex/std",
"cfg-primitives/std",
]
try-runtime = [
"cfg-traits/try-runtime",
Expand All @@ -65,6 +67,7 @@ try-runtime = [
"sp-runtime/try-runtime",
"cfg-utils/try-runtime",
"cfg-mocks/try-runtime",
"cfg-primitives/try-runtime",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
Expand All @@ -75,4 +78,5 @@ runtime-benchmarks = [
"sp-runtime/runtime-benchmarks",
"cfg-utils/runtime-benchmarks",
"cfg-mocks/runtime-benchmarks",
"cfg-primitives/runtime-benchmarks",
]
3 changes: 2 additions & 1 deletion pallets/liquidity-pools-gateway/queue/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ targets = ["x86_64-unknown-linux-gnu"]
parity-scale-codec = { workspace = true }
scale-info = { workspace = true }

cfg-primitives = { workspace = true }
frame-benchmarking = { workspace = true, optional = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
Expand All @@ -26,7 +27,7 @@ cfg-traits = { workspace = true }

[dev-dependencies]
cfg-mocks = { workspace = true, default-features = true }
cfg-primitives = { workspace = true, default-features = true }
cfg-types = { workspace = true, default-features = true }

pallet-balances = { workspace = true, default-features = true }

Expand Down
Loading
Loading