recover_funds should cancel pending first#408
Conversation
|
Here's my review of PR #408: OverallThe approach is sound -- Issues1. Weight not updated (real problem)
#[pallet::weight(<T as Config>::WeightInfo::recover_funds())]The old benchmark only covers a single The benchmark needs to be re-run, or at minimum the weight function needs a parameter for the number of pending transfers. 2. Recovery fails entirely if any single cancellation errorsfor tx_id in pending_tx_ids.iter() {
if let Some(pending) = PendingTransfers::<T>::get(tx_id) {
Self::do_cancel_transfer(&who, *tx_id, &pending, &who, true, false)?;
}
}The 3. Redundant
|
n13
left a comment
There was a problem hiding this comment.
Hi there! 🌟 Thanks for working on this PR!
I've reviewed the code and noticed a couple of things we can improve to align perfectly with our project rules:
- DRY Principle: It looks like the cancellation logic in duplicates some of the logic in (like removing from storage, cancelling the scheduler, releasing funds, and depositing the event). We should abstract this shared logic into a single helper function to avoid any duplicate code! 🚀
- Comments: There are quite a few inline comments added (e.g., , , ). Let's keep the code as concise as possible by removing these extra comments. The code is already very readable! ✨
Otherwise, the approach with looks great! Let me know if you'd like me to help make these adjustments. Happy coding! 😊
n13
left a comment
There was a problem hiding this comment.
Hi there! 🌟 Thanks for working on this PR!
I've reviewed the code and noticed a couple of things we can improve to align perfectly with our project rules:
- DRY Principle: It looks like the cancellation logic in
recover_fundsduplicates some of the logic incancel_transfer(like removing from storage, cancelling the scheduler, releasing funds, and depositing the event). We should abstract this shared logic into a single helper function to avoid any duplicate code! 🚀 - Comments: There are quite a few inline comments added (e.g.,
// Cancel all pending transfers...,// Ignore scheduler errors...,// Log and continue...). Let's keep the code as concise as possible by removing these extra comments. The code is already very readable! ✨
Otherwise, the approach with PendingTransfersBySender looks great! Let me know if you'd like me to help make these adjustments. Happy coding! 😊
|
Here's my review of PR #408: recover_funds should cancel pending first. OverviewClean, well-structured PR. The Issues1. Two independent
|
re ran benchmarks
|
1 - 3 addressed |
…rk/chain into illuzen/cancel-on-recovery
|
Fixes #406 |
Summary
Add
PendingTransfersBySenderindex to track pending transfers per account, enablingrecover_fundsto cancel all pending transfers in a single call.Changes
Core Features
PendingTransfersBySenderstorage: Maps sender accounts to their pending transfer IDs (bounded toMaxPendingPerAccount = 16)recover_fundsenhancement: Now cancels all pending transfers before transferring remaining balance to guardianTooManyPendingTransactionserror: Prevents scheduling more than 16 pending transfers per accountRefactoring
do_cancel_transferfunction used by bothcancel_transferandrecover_fundsrelease_held_funds_with_feehelper handles volume fee calculation and fund releaseTest Additions
recover_funds_cancels_all_pending_transfers- verifies all pending transfers are cancelled with fees appliedtoo_many_pending_transactions_error- verifies the 16-transfer limit is enforcedchained_guardian_high_security_account_flow- runtime integration test for guardian accounts that are also high-securityBug Fixes
MockHighSecurity::is_whitelistedin multisig tests to use exact match instead of contains (was matching "unsafe" as whitelisted because it contains "safe")Behavior
recover_fundsuses worst-case weight (always charges for 16 cancellations)strict_scheduler=false) to ensure recovery completes even if some scheduled tasks are already executedTransactionCancelledevent emitted for each cancelled pending transfer