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

WIP: Weights #1988

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
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
23 changes: 17 additions & 6 deletions pallets/liquidity-pools-gateway-queue/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,18 @@ pub mod pallet {

let message = MessageQueue::<T>::take(nonce).ok_or(Error::<T>::MessageNotFound)?;

let (result, weight) = Self::process_message_and_deposit_event(nonce, message.clone());
let (result, mut weight) =
Self::process_message_and_deposit_event(nonce, message.clone());

if let Err(e) = result {
FailedMessageQueue::<T>::insert(nonce, (message, e));
weight.saturating_accrue(T::DbWeight::get().writes(1));
}

Ok(PostDispatchInfo::from(Some(weight)))
// Add write from MessageQueue::take
Ok(PostDispatchInfo::from(Some(
weight.saturating_add(T::DbWeight::get().writes(1)),
)))
}

/// Convenience method for manually processing a failed message.
Expand All @@ -166,13 +171,17 @@ pub mod pallet {
let (message, _) =
FailedMessageQueue::<T>::get(nonce).ok_or(Error::<T>::MessageNotFound)?;

let (result, weight) = Self::process_message_and_deposit_event(nonce, message);
let (result, mut weight) = Self::process_message_and_deposit_event(nonce, message);

if result.is_ok() {
FailedMessageQueue::<T>::remove(nonce);
weight.saturating_accrue(T::DbWeight::get().writes(1));
}

Ok(PostDispatchInfo::from(Some(weight)))
// Add read from FailedMessageQueue
Ok(PostDispatchInfo::from(Some(
weight.saturating_add(T::DbWeight::get().reads(1)),
)))
}
}

Expand Down Expand Up @@ -205,7 +214,9 @@ pub mod pallet {
let mut processed_entries = Vec::new();

for (nonce, message) in MessageQueue::<T>::iter() {
let remaining_weight = max_weight.saturating_sub(weight_used);
let remaining_weight = max_weight
.saturating_sub(weight_used)
.saturating_sub(T::DbWeight::get().reads(1));
let next_weight = T::MessageProcessor::max_processing_weight(&message);

// We ensure we have still capacity in the block before processing the message
Expand Down Expand Up @@ -237,7 +248,7 @@ pub mod pallet {

weight_used = weight_used.saturating_add(weight);

if weight_used.all_gte(max_weight) {
if weight_used.any_gte(max_weight) {
break;
}
}
Expand Down
Loading