Skip to content

Commit 24cd572

Browse files
committed
refactor(api/fungibles): refund appropriate burn weight on failure
1 parent 5495c52 commit 24cd572

File tree

1 file changed

+12
-3
lines changed
  • pallets/api-vnext/src/fungibles/precompiles

1 file changed

+12
-3
lines changed

pallets/api-vnext/src/fungibles/precompiles/mod.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,15 +222,24 @@ where
222222
Ok(mintCall::abi_encode_returns(&mintReturn {}))
223223
},
224224
IFungiblesCalls::burn(burnCall { token, account, value }) => {
225-
env.charge(<T as Config<I>>::WeightInfo::burn())?;
225+
let charged = env.charge(<T as Config<I>>::WeightInfo::burn())?;
226226

227227
self::burn::<T, I>(
228228
to_runtime_origin(env.caller()),
229229
(*token).into(),
230230
env.to_account_id(&(*account.0).into()),
231231
value.saturating_to(),
232-
) // TODO: adjust weight
233-
.map_err(|e| e.error)?;
232+
)
233+
.map_err(|e| {
234+
// Adjust weight
235+
if let Some(actual_weight) = e.post_info.actual_weight {
236+
// TODO: replace with `env.adjust_gas(charged, result.weight);` once
237+
// #8693 lands
238+
env.gas_meter_mut()
239+
.adjust_gas(charged, RuntimeCosts::Precompile(actual_weight));
240+
}
241+
e.error
242+
})?;
234243

235244
let from = account;
236245
let to = Address::default();

0 commit comments

Comments
 (0)