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 message forwarding #1971

Merged
merged 25 commits into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
db9996e
refactor: LpMessage
wischli Aug 16, 2024
93512ea
feat: extend LpMessage with forwarding
wischli Aug 16, 2024
b4c4eda
wip: forwarding pallet
wischli Aug 16, 2024
bd6b064
Merge remote-tracking branch 'origin/main' into feat/lp-msg-relay
wischli Aug 16, 2024
893736a
chore: apply domainaddress refactor
wischli Aug 16, 2024
e5dedb2
refactor: combine traits, cleanup, add docs
wischli Aug 16, 2024
006c5a3
chore: compile runtimes
wischli Aug 16, 2024
042b08a
tests: add UTs
wischli Aug 17, 2024
67d5c3f
Merge remote-tracking branch 'origin/main' into feat/lp-msg-relay
wischli Aug 17, 2024
ce64041
fix: remove RouterProvider from Forwarder
wischli Aug 17, 2024
b39fa47
feat: move serialization to runtime type
wischli Aug 17, 2024
30eae5c
chore: apply suggestions from @cdamian's review
wischli Aug 17, 2024
5cf3752
fix: release build
wischli Aug 17, 2024
6a5cb5f
refactor: unite Receiver|SenderMessage types in mock
wischli Aug 18, 2024
4a0f751
refactor: remove trait namespaces in forwarder test
wischli Aug 18, 2024
cd72182
fix: re-add RouterProvider to forwarder pallet
wischli Aug 18, 2024
9f433f0
fix: use source domain
wischli Aug 18, 2024
be1fc23
fix: use source domain
wischli Aug 18, 2024
047ebac
feat: instantiate mock_router
wischli Aug 18, 2024
a253a6f
refactor: add MessageDeserializer to Gateway config
wischli Aug 18, 2024
ba726f0
Revert "refactor: add MessageDeserializer to Gateway config"
wischli Aug 18, 2024
cbb75b4
refactor: remove receive_message gateway extrinsic
wischli Aug 18, 2024
b24a5d4
refactor: remove artifacts
wischli Aug 18, 2024
3a15a49
taplo: fmt
wischli Aug 18, 2024
acc6f39
fix: ensure multi-router-setup validity
wischli Aug 18, 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
29 changes: 29 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ members = [
"pallets/liquidity-pools",
"pallets/liquidity-pools-gateway",
"pallets/liquidity-pools-gateway/queue",
"pallets/liquidity-pools-forwarder",
"pallets/liquidity-rewards",
"pallets/loans",
"pallets/oracle-feed",
Expand Down Expand Up @@ -236,6 +237,7 @@ pallet-keystore = { path = "pallets/keystore", default-features = false }
pallet-liquidity-pools = { path = "pallets/liquidity-pools", default-features = false }
pallet-liquidity-pools-gateway = { path = "pallets/liquidity-pools-gateway", default-features = false }
pallet-liquidity-pools-gateway-queue = { path = "pallets/liquidity-pools-gateway/queue", default-features = false }
pallet-liquidity-pools-forwarder = { path = "pallets/liquidity-pools-forwarder", default-features = false }
pallet-liquidity-rewards = { path = "pallets/liquidity-rewards", default-features = false }
pallet-loans = { path = "pallets/loans", default-features = false }
pallet-oracle-feed = { path = "pallets/oracle-feed", default-features = false }
Expand Down
3 changes: 2 additions & 1 deletion libs/mocks/src/router_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ pub mod pallet {
}

impl<T: Config> MessageSender for Pallet<T> {
type Message = Vec<u8>;
type Middleware = T::Middleware;
type Origin = T::Origin;

fn send(a: Self::Middleware, b: Self::Origin, c: Vec<u8>) -> DispatchResult {
fn send(a: Self::Middleware, b: Self::Origin, c: Self::Message) -> DispatchResult {
execute_call!((a, b, c))
}
}
Expand Down
26 changes: 22 additions & 4 deletions libs/traits/src/liquidity_pools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@
// GNU General Public License for more details.

use frame_support::{dispatch::DispatchResult, weights::Weight};
use sp_runtime::DispatchError;
use sp_runtime::{app_crypto::sp_core::H160, 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 {
pub trait LpMessage: Sized {
type Domain;

fn serialize(&self) -> Vec<u8>;
fn deserialize(input: &[u8]) -> Result<Self, DispatchError>;

Expand All @@ -39,6 +41,16 @@ pub trait LPEncoding: Sized {

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

/// Unwraps a forwarded message.
fn unwrap_forwarded(self) -> Option<(Self::Domain, H160, Self)>;

/// Attempts to wrap into a forwarded message.
fn try_wrap_forward(
domain: Self::Domain,
forwarding_contract: H160,
message: Self,
) -> Result<Self, DispatchError>;
}

pub trait RouterProvider<Domain>: Sized {
Expand All @@ -57,9 +69,15 @@ pub trait MessageSender {
/// The originator of the message to be sent
type Origin;

/// The type of the message
type Message;

/// Sends a message for origin to destination
fn send(middleware: Self::Middleware, origin: Self::Origin, message: Vec<u8>)
-> DispatchResult;
fn send(
middleware: Self::Middleware,
origin: Self::Origin,
message: Self::Message,
) -> DispatchResult;
}

/// The behavior of an entity that can receive messages
Expand Down
11 changes: 8 additions & 3 deletions pallets/axelar-router/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,13 @@ pub mod pallet {
/// messages from
type AdminOrigin: EnsureOrigin<Self::RuntimeOrigin>;

/// The target of the messages comming from other chains
/// The target of the messages coming from other chains
type Receiver: MessageReceiver<Middleware = Self::Middleware, Origin = DomainAddress>;

/// Middleware used by the gateway
type Middleware: From<AxelarId>;

/// The target of the messages comming from this chain
/// The target of the messages coming from this chain
type Transactor: EthereumTransactor;

/// Checker to ensure an evm account code is registered
Expand Down Expand Up @@ -319,10 +319,15 @@ pub mod pallet {
}

impl<T: Config> MessageSender for Pallet<T> {
type Message = Vec<u8>;
type Middleware = AxelarId;
type Origin = DomainAddress;

fn send(axelar_id: AxelarId, origin: Self::Origin, message: Vec<u8>) -> DispatchResult {
fn send(
axelar_id: AxelarId,
origin: Self::Origin,
message: Self::Message,
) -> DispatchResult {
let chain_name = ChainNameById::<T>::get(axelar_id)
.ok_or(Error::<T>::RouterConfigurationNotFound)?;
let config = Configuration::<T>::get(&chain_name)
Expand Down
83 changes: 83 additions & 0 deletions pallets/liquidity-pools-forwarder/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
[package]
name = "pallet-liquidity-pools-forwarder"
description = "Centrifuge Liquidity Pools Relayer Pallet"
version = "0.0.1"
authors.workspace = true
edition.workspace = true
license.workspace = true
homepage.workspace = true
repository.workspace = true
documentation.workspace = true

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
frame-support = { workspace = true }
frame-system = { workspace = true }
hex = { workspace = true }
orml-traits = { workspace = true }
parity-scale-codec = { workspace = true }
scale-info = { workspace = true }
serde = { workspace = true }
sp-arithmetic = { workspace = true }
sp-core = { workspace = true }
sp-runtime = { workspace = true }
sp-std = { workspace = true }

# Benchmarking
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 }

[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]
default = ["std"]
std = [
"parity-scale-codec/std",
"cfg-types/std",
"cfg-traits/std",
"frame-support/std",
"frame-system/std",
"frame-benchmarking/std",
"orml-traits/std",
"sp-std/std",
"sp-core/std",
"sp-runtime/std",
"scale-info/std",
"cfg-utils/std",
"hex/std",
"cfg-primitives/std",
"serde/std",
"sp-arithmetic/std",
]
try-runtime = [
"cfg-traits/try-runtime",
"cfg-types/try-runtime",
"frame-support/try-runtime",
"frame-system/try-runtime",
"sp-runtime/try-runtime",
"cfg-utils/try-runtime",
"cfg-mocks/try-runtime",
"cfg-primitives/try-runtime",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"cfg-traits/runtime-benchmarks",
"cfg-types/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"cfg-utils/runtime-benchmarks",
"cfg-mocks/runtime-benchmarks",
"cfg-primitives/runtime-benchmarks",
]
Loading