Skip to content

Commit

Permalink
fix: pay fees benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscoaguirre committed Nov 6, 2024
1 parent 603db91 commit 407383f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2000,7 +2000,7 @@ impl_runtime_apis! {
fn fee_asset() -> Result<Asset, BenchmarkError> {
Ok(Asset {
id: AssetId(WestendLocation::get()),
fun: Fungible(1_000_000 * UNITS),
fun: Fungible(1_000 * UNITS),
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ benchmarks! {

let mut executor = new_executor::<T>(Default::default());
executor.set_holding(holding);
// Set some weight to be paid for.
executor.set_message_weight(Weight::from_parts(100_000_000, 100_000));

let fee_asset: Asset = T::fee_asset().unwrap_or(
(Here, 100_000_000u128).into()
);
let fee_asset: Asset = T::fee_asset().unwrap();

let instruction = Instruction::<XcmCallOf<T>>::PayFees { asset: fee_asset };

Expand Down
2 changes: 1 addition & 1 deletion polkadot/xcm/xcm-builder/src/weight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ impl<
log::trace!(target: "xcm::weight", "UsingComponents::buy_weight weight: {:?}, payment: {:?}, context: {:?}", weight, payment, context);
let amount = WeightToFee::weight_to_fee(&weight);
let u128_amount: u128 = amount.try_into().map_err(|_| XcmError::Overflow)?;
let required = (AssetId(AssetIdValue::get()), u128_amount).into();
let required = Asset { id: AssetId(AssetIdValue::get()), fun: Fungible(u128_amount) };
let unused = payment.checked_sub(required).map_err(|_| XcmError::TooExpensive)?;
self.0 = self.0.saturating_add(weight);
self.1 = self.1.saturating_add(amount);
Expand Down
16 changes: 16 additions & 0 deletions polkadot/xcm/xcm-executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ impl<Config: config::Config> XcmExecutor<Config> {
pub fn asset_claimer(&self) -> Option<Location> {
self.asset_claimer.clone()
}
pub fn set_message_weight(&mut self, weight: Weight) {
self.message_weight = weight;
}
}

pub struct WeighedMessage<Call>(Weight, Xcm<Call>);
Expand Down Expand Up @@ -1298,9 +1301,22 @@ impl<Config: config::Config> XcmExecutor<Config> {
result
},
PayFees { asset } => {
// Message was not weighed, there is nothing to pay.
if self.message_weight == Weight::zero() {
tracing::warn!(
target: "xcm::executor::PayFees",
"Message was not weighed or weight was 0. Nothing will be charged.",
);
return Ok(());
}
// Record old holding in case we need to rollback.
let old_holding = self.holding.clone();
// The max we're willing to pay for fees is decided by the `asset` operand.
tracing::trace!(
target: "xcm::executor::PayFees",
asset_for_fees = ?asset,
message_weight = ?self.message_weight,
);
let max_fee =
self.holding.try_take(asset.into()).map_err(|_| XcmError::NotHoldingFees)?;
// Pay for execution fees.
Expand Down

0 comments on commit 407383f

Please sign in to comment.