Skip to content

Commit 9bed6c4

Browse files
committed
emit ConversionFailed instead of swallowing silently
1 parent c09e025 commit 9bed6c4

2 files changed

Lines changed: 24 additions & 4 deletions

File tree

pallets/referrals/src/lib.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,11 @@ pub mod pallet {
298298
from: AssetAmount<T::AssetId>,
299299
to: AssetAmount<T::AssetId>,
300300
},
301+
/// A pending asset could not be converted; skipped, not blocking.
302+
ConversionFailed {
303+
asset_id: T::AssetId,
304+
reason: DispatchError,
305+
},
301306
/// Rewards claimed.
302307
Claimed {
303308
who: T::AccountId,
@@ -484,12 +489,17 @@ pub mod pallet {
484489
let asset_balance = T::Currency::balance(asset_id.clone(), &Self::pot_account_id());
485490
// Best-effort, like `on_idle`: skip an un-convertible slice rather than revert the
486491
// whole claim. Funds stay in the pot and re-queue on the next fee.
487-
let _ = T::Convert::convert(
492+
if let Err(reason) = T::Convert::convert(
488493
Self::pot_account_id(),
489494
asset_id.clone(),
490495
T::RewardAsset::get(),
491496
asset_balance,
492-
);
497+
) {
498+
Self::deposit_event(Event::ConversionFailed {
499+
asset_id: asset_id.clone(),
500+
reason,
501+
});
502+
}
493503
PendingConversions::<T>::remove(asset_id);
494504
}
495505
let referrer_shares = ReferrerShares::<T>::take(&who);
@@ -616,12 +626,17 @@ pub mod pallet {
616626
for asset_id in PendingConversions::<T>::iter_keys().take(max_converts as usize) {
617627
let asset_balance = T::Currency::balance(asset_id.clone(), &Self::pot_account_id());
618628
// remove the asset_id from PendingConversions even when the conversion fails
619-
let _ = T::Convert::convert(
629+
if let Err(reason) = T::Convert::convert(
620630
Self::pot_account_id(),
621631
asset_id.clone(),
622632
T::RewardAsset::get(),
623633
asset_balance,
624-
);
634+
) {
635+
Self::deposit_event(Event::ConversionFailed {
636+
asset_id: asset_id.clone(),
637+
reason,
638+
});
639+
}
625640
PendingConversions::<T>::remove(asset_id);
626641
actual_converts += 1;
627642
}

pallets/referrals/src/tests/claim.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ fn claim_rewards_should_succeed_when_pending_asset_balance_is_below_min_trading_
100100
assert_eq!(Tokens::free_balance(HDX, &BOB), 5_000_000_000_000);
101101
// The dust entry is dropped rather than left to block future claims.
102102
assert_eq!(PendingConversions::<Test>::count(), 0);
103+
// The skipped conversion is surfaced as an event, not silently swallowed.
104+
assert!(System::events().iter().any(|r| matches!(
105+
&r.event,
106+
RuntimeEvent::Referrals(Event::ConversionFailed { asset_id, .. }) if *asset_id == DAI
107+
)));
103108
});
104109
}
105110

0 commit comments

Comments
 (0)