Skip to content

Commit

Permalink
benchmarks: Add default for Message type (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdamian committed Jul 29, 2024
1 parent bd5c49a commit 5bb5402
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
4 changes: 4 additions & 0 deletions libs/traits/src/liquidity_pools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ pub mod test_util {
use super::*;

#[derive(Debug, Eq, PartialEq, Clone, Encode, Decode, TypeInfo, MaxEncodedLen)]
#[cfg_attr(
any(test, feature = "std", feature = "runtime-benchmarks"),
derive(Default)
)]
pub struct Message;
impl LPEncoding for Message {
fn serialize(&self) -> Vec<u8> {
Expand Down
11 changes: 5 additions & 6 deletions pallets/liquidity-pools-gateway/queue/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
// 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;
Expand All @@ -20,7 +19,7 @@ use super::*;

#[benchmarks(
where
T: Config<Message = LPTestMessage>,
T: Config,
T::AccountId: EncodeLike<<T as frame_system::Config>::AccountId>,
)]
mod benchmarks {
Expand All @@ -29,13 +28,13 @@ mod benchmarks {
#[benchmark]
fn process_message() -> Result<(), BenchmarkError> {
let caller: T::AccountId = account("acc_0", 0, 0);
let message = LPTestMessage {};
let message = T::Message::default();
let nonce = T::MessageNonce::one();

MessageQueue::<T>::insert(nonce, message.clone());

#[cfg(test)]
mock::mock_lp_gateway_process_success(message);
mock::mock_lp_gateway_process_success::<T>();

#[extrinsic_call]
process_message(RawOrigin::Signed(caller), nonce);
Expand All @@ -46,14 +45,14 @@ mod benchmarks {
#[benchmark]
fn process_failed_message() -> Result<(), BenchmarkError> {
let caller: T::AccountId = account("acc_0", 0, 0);
let message = LPTestMessage {};
let message = T::Message::default();
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);
mock::mock_lp_gateway_process_success::<T>();

#[extrinsic_call]
process_failed_message(RawOrigin::Signed(caller), nonce);
Expand Down
5 changes: 5 additions & 0 deletions pallets/liquidity-pools-gateway/queue/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,14 @@ pub mod pallet {
pub trait Config: frame_system::Config {
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;

#[cfg(not(feature = "runtime-benchmarks"))]
/// The message type.
type Message: Clone + Debug + PartialEq + MaxEncodedLen + TypeInfo + FullCodec;

#[cfg(feature = "runtime-benchmarks")]
/// The message type.
type Message: Clone + Debug + PartialEq + MaxEncodedLen + TypeInfo + FullCodec + Default;

/// Type used for message identification.
type MessageNonce: Parameter
+ Member
Expand Down
6 changes: 2 additions & 4 deletions pallets/liquidity-pools-gateway/queue/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,8 @@ impl Config for Runtime {
type WeightInfo = ();
}

pub fn mock_lp_gateway_process_success(expected_message: LPTestMessage) {
LPGatewayMock::mock_process(move |msg| {
assert_eq!(msg, expected_message);

pub fn mock_lp_gateway_process_success<T: Config>() {
LPGatewayMock::mock_process(move |_| {
Ok(PostDispatchInfo {
// Defensive weight that we should also use during bookmarks.
actual_weight: Some(Weight::from_parts(DEFAULT_WEIGHT_REF_TIME, 256)),
Expand Down
16 changes: 5 additions & 11 deletions pallets/liquidity-pools/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,9 @@ impl BatchMessages {
TypeInfo,
MaxEncodedLen,
)]
#[cfg_attr(feature = "runtime-benchmarks", derive(Default))]
pub enum Message<BatchContent = BatchMessages> {
#[default]
Invalid,
// --- Gateway ---
/// Proof a message has been executed.
Expand Down Expand Up @@ -286,9 +288,7 @@ pub enum Message<BatchContent = BatchMessages> {
/// Add a pool to a domain.
///
/// Directionality: Centrifuge -> EVM Domain.
AddPool {
pool_id: u64,
},
AddPool { pool_id: u64 },
/// Add a tranche to an already existing pool on the target domain.
/// The decimals of a tranche MUST be equal to the decimals of a pool.
/// Thus, consuming domains MUST take care of storing the decimals upon
Expand All @@ -309,18 +309,12 @@ pub enum Message<BatchContent = BatchMessages> {
/// Allow a currency to be used as a pool currency and to invest in a pool.
///
/// Directionality: Centrifuge -> EVM Domain.
AllowAsset {
pool_id: u64,
currency: u128,
},
AllowAsset { pool_id: u64, currency: u128 },
/// Disallow a currency to be used as a pool currency and to invest in a
/// pool.
///
/// Directionality: Centrifuge -> EVM Domain.
DisallowAsset {
pool_id: u64,
currency: u128,
},
DisallowAsset { pool_id: u64, currency: u128 },
/// Update the price of a tranche token on the target domain.
///
/// Directionality: Centrifuge -> EVM Domain.
Expand Down

0 comments on commit 5bb5402

Please sign in to comment.