-
Notifications
You must be signed in to change notification settings - Fork 78
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 gateway queue #1930
Merged
Merged
Feat/lp v2 gateway queue #1930
Changes from 8 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
ab8fcd4
pallets: Add LP Gateway queue pallet
cdamian 53b8472
lp-gateway-queue: Add benchmarks
cdamian 705bc49
integration-tests: Add LP gateway tests
cdamian a8969cb
docs: Update LP gateway queue entry
cdamian 66e3252
lp-gateway-queue: Use default weight for PostDispatchInfo
cdamian de162fd
lp-gateway-queue: Add DEFAULT_WEIGHT_REF_TIME const, extract message …
cdamian 1699eda
runtime: Add defensive weights for LP gateway queue
cdamian 8e51711
lint: Obey
cdamian 02d0b3d
taplo: Obey
cdamian 9c44e90
pallet: Use DispatchResult for extrinsics
cdamian bd5c49a
runtime: Update benchmarks and weight info
cdamian 7be3549
benchmarks: Add default for Message type (wip)
cdamian c55d8c9
pallet: Add Default bound to Message type
cdamian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#[frame_support::pallet(dev_mode)] | ||
pub mod pallet { | ||
use cfg_traits::liquidity_pools::MessageProcessor; | ||
use frame_support::pallet_prelude::*; | ||
use mock_builder::{execute_call, register_call}; | ||
|
||
#[pallet::config] | ||
pub trait Config: frame_system::Config { | ||
type Message; | ||
} | ||
|
||
#[pallet::pallet] | ||
pub struct Pallet<T>(_); | ||
|
||
#[pallet::storage] | ||
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) { | ||
register_call!(move |msg| f(msg)); | ||
} | ||
} | ||
|
||
impl<T: Config> MessageProcessor for Pallet<T> { | ||
type Message = T::Message; | ||
|
||
fn process(msg: Self::Message) -> DispatchResultWithPostInfo { | ||
execute_call!(msg) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#[frame_support::pallet(dev_mode)] | ||
pub mod pallet { | ||
use cfg_traits::liquidity_pools::MessageQueue; | ||
use frame_support::pallet_prelude::*; | ||
use mock_builder::{execute_call, register_call}; | ||
|
||
#[pallet::config] | ||
pub trait Config: frame_system::Config { | ||
type Message; | ||
} | ||
|
||
#[pallet::pallet] | ||
pub struct Pallet<T>(_); | ||
|
||
#[pallet::storage] | ||
type CallIds<T: Config> = StorageMap<_, _, String, mock_builder::CallId>; | ||
|
||
impl<T: Config> Pallet<T> { | ||
pub fn mock_submit(f: impl Fn(T::Message) -> DispatchResult + 'static) { | ||
register_call!(move |msg| f(msg)); | ||
} | ||
} | ||
|
||
impl<T: Config> MessageQueue for Pallet<T> { | ||
type Message = T::Message; | ||
|
||
fn submit(msg: Self::Message) -> DispatchResult { | ||
execute_call!(msg) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
[package] | ||
authors = ["Centrifuge <admin@centrifuge.io>"] | ||
description = "Centrifuge Liquidity Pools Gateway Queue Pallet" | ||
edition = "2021" | ||
license = "LGPL-3.0" | ||
name = "pallet-liquidity-pools-gateway-queue" | ||
repository = "https://github.com/centrifuge/centrifuge-chain" | ||
version = "0.0.1" | ||
|
||
[package.metadata.docs.rs] | ||
targets = ["x86_64-unknown-linux-gnu"] | ||
|
||
[dependencies] | ||
parity-scale-codec = { workspace = true } | ||
scale-info = { workspace = true } | ||
|
||
frame-benchmarking = { workspace = true, optional = true } | ||
frame-support = { workspace = true } | ||
frame-system = { workspace = true } | ||
sp-core = { workspace = true } | ||
sp-runtime = { workspace = true } | ||
sp-std = { workspace = true } | ||
sp-arithmetic = { workspace = true } | ||
|
||
cfg-traits = { workspace = true } | ||
|
||
[dev-dependencies] | ||
cfg-mocks = { workspace = true, default-features = true } | ||
cfg-primitives = { workspace = true, default-features = true } | ||
|
||
pallet-balances = { workspace = true, default-features = true } | ||
|
||
sp-core = { workspace = true, default-features = true } | ||
sp-io = { workspace = true, default-features = true } | ||
|
||
[features] | ||
default = ["std"] | ||
std = [ | ||
"parity-scale-codec/std", | ||
"scale-info/std", | ||
"frame-support/std", | ||
"frame-system/std", | ||
"sp-runtime/std", | ||
"sp-std/std", | ||
"sp-arithmetic/std", | ||
"frame-benchmarking/std", | ||
"cfg-primitives/std", | ||
] | ||
runtime-benchmarks = [ | ||
"frame-benchmarking/runtime-benchmarks", | ||
"frame-support/runtime-benchmarks", | ||
"frame-system/runtime-benchmarks", | ||
"sp-runtime/runtime-benchmarks", | ||
"cfg-primitives/runtime-benchmarks", | ||
] | ||
try-runtime = [ | ||
"frame-support/try-runtime", | ||
"frame-system/try-runtime", | ||
"sp-runtime/try-runtime", | ||
"cfg-primitives/try-runtime", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright 2024 Centrifuge Foundation (centrifuge.io). | ||
// This file is part of Centrifuge chain project. | ||
|
||
// Centrifuge is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version (see http://www.gnu.org/licenses). | ||
|
||
// Centrifuge is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
use cfg_traits::liquidity_pools::test_util::Message as LPTestMessage; | ||
use frame_benchmarking::{account, impl_benchmark_test_suite, v2::*}; | ||
use frame_system::RawOrigin; | ||
use parity_scale_codec::EncodeLike; | ||
|
||
use super::*; | ||
|
||
#[benchmarks( | ||
where | ||
T: Config<Message = LPTestMessage>, | ||
T::AccountId: EncodeLike<<T as frame_system::Config>::AccountId>, | ||
)] | ||
mod benchmarks { | ||
use super::*; | ||
|
||
#[benchmark] | ||
fn process_message() -> Result<(), BenchmarkError> { | ||
let caller: T::AccountId = account("acc_0", 0, 0); | ||
let message = LPTestMessage {}; | ||
let nonce = T::MessageNonce::one(); | ||
|
||
MessageQueue::<T>::insert(nonce, message.clone()); | ||
|
||
#[cfg(test)] | ||
mock::mock_lp_gateway_process_success(message); | ||
|
||
#[extrinsic_call] | ||
process_message(RawOrigin::Signed(caller), nonce); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[benchmark] | ||
fn process_failed_message() -> Result<(), BenchmarkError> { | ||
let caller: T::AccountId = account("acc_0", 0, 0); | ||
let message = LPTestMessage {}; | ||
let error = DispatchError::Unavailable; | ||
let nonce = T::MessageNonce::one(); | ||
|
||
FailedMessageQueue::<T>::insert(nonce, (message.clone(), error)); | ||
|
||
#[cfg(test)] | ||
mock::mock_lp_gateway_process_success(message); | ||
|
||
#[extrinsic_call] | ||
process_failed_message(RawOrigin::Signed(caller), nonce); | ||
|
||
Ok(()) | ||
} | ||
|
||
impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Runtime); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will probably not pass for the real runtimes. My suggestion is to add a
Default
bound forMessage
only when benchmarking it. (which would be anInvalid
one)Option2. Add a worst-case method under
runtime-benchmarks
inLPEncoding
, which allows creation of the worst message possible.Option3. Add a parameter to the benchmarks that allow to passing the
Message
, so each message is benchmarked for itself. This will be the most accurate/clean, but not sure if it is possible to pass non-integer parameters to benchmarking functions 🤔There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would go with option 2 since that makes the most sense for benchmarks IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this be possible? More specifically, does the benchmark test suite execute for each variant of an enum?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The benchmark doesn't know about
Message
itself. But if it receives theMessage
as a parameter, it would compute the effect of thatMessage
for that specific callThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But not sure if it would work. Option 2 seems good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like this you mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, added a default weight ref time that's also used in the pallet instead of default. PTAL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, just one thing, the issue is still there because the benchmark is tied to
LPTestMessage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Been trying things out for a while now and I'm still a bit confused...
Option 2 doesn't really work since
LPEncoding
is not a trait used as a constraint for theMessage
type of this pallet, as per these constraints.This will remain true if we use the mocked runtime anyway. The message type that we use here is thenvm, this should be fine as long as theLPTestMessage
.LPTestMessage
is not part of the actual benchmark tests.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated this btw, took me a while to figure out what was happening when running tests and then the check benchmark scripts.