Skip to content

Commit

Permalink
Fix post_dispatch_details
Browse files Browse the repository at this point in the history
  • Loading branch information
gui1117 committed Aug 6, 2024
1 parent 30f8f4e commit 4d99a45
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions cumulus/pallets/weight-reclaim-tx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use frame_support::{
use sp_runtime::{
traits::{
DispatchInfoOf, Dispatchable, PostDispatchInfoOf, TransactionExtension,
TransactionExtensionBase,
TransactionExtensionBase, AccrueWeight,
},
transaction_validity::{TransactionValidityError, ValidTransaction},
DispatchResult,
Expand Down Expand Up @@ -179,26 +179,44 @@ where
result: &DispatchResult,
context: &Context,
) -> Result<Option<Weight>, TransactionValidityError> {
let (pre_dispatch_proof_size, inner_pre) = pre;
log::error!(
target: LOG_TARGET,
"Calling the post dispatch details of an aggregating transaction extensions is \
invalid. No information can sensibly be returned for `pays_fee`."
);

let mut post_info_copy = *post_info;

Self::post_dispatch(pre, info, &mut post_info_copy, len, result, context)?;
post_info_copy.accrue(T::WeightInfo::storage_weight_reclaim());

let mut actual_post_info = *post_info;
S::post_dispatch(inner_pre, info, &mut actual_post_info, len, result, context)?;
Ok(post_info_copy.actual_weight)
}

fn post_dispatch(
pre: Self::Pre,
info: &DispatchInfoOf<T::RuntimeCall>,
post_info: &mut PostDispatchInfoOf<T::RuntimeCall>,
len: usize,
result: &DispatchResult,
context: &Context,
) -> Result<(), TransactionValidityError> {
let (pre_dispatch_proof_size, inner_pre) = pre;

let inner_weight = actual_post_info
.actual_weight
.map(|actual_weight| actual_weight.saturating_sub(post_info.actual_weight.unwrap()));
S::post_dispatch(inner_pre, info, post_info, len, result, context)?;
post_info.accrue(T::WeightInfo::storage_weight_reclaim());

let Some(pre_dispatch_proof_size) = pre_dispatch_proof_size else {
// No information
return Ok(inner_weight);
return Ok(());
};

let Some(post_dispatch_proof_size) = get_proof_size() else {
log::debug!(
target: LOG_TARGET,
"Proof recording enabled during prepare, now disabled. This should not happen."
);
return Ok(inner_weight)
return Ok(())
};

let benchmarked_weight = info.total_weight().proof_size();
Expand Down Expand Up @@ -232,6 +250,6 @@ where
}
});

Ok(inner_weight)
Ok(())
}
}

0 comments on commit 4d99a45

Please sign in to comment.