-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve deposits migration #1636
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Xavier Lau <[email protected]>
f410124
to
7a91c09
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@@ -86,5 +87,11 @@ fn migrate() -> frame_support::weights::Weight { | |||
]), | |||
); | |||
|
|||
<Runtime as frame_system::Config>::DbWeight::get().reads_writes(r, w + 5) | |||
let _ = Balances::transfer_all( | |||
RuntimeOrigin::signed(PalletId(*b"dar/depo").into_account_truncating()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The is still some CRAB left in deposit pallet account on Crab chain.
https://crab-scan.darwinia.network/address/0x6d6F646C6461722F6465706F0000000000000000
We also need to do the transfer migration for CRAB to clean it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't noticed anything from a few days back. This might be due to the account migration.
@AurevoirXavier CI failed |
Signed-off-by: Xavier Lau <[email protected]>
pallet/deposit/src/lib.rs
Outdated
@@ -216,14 +213,13 @@ pub mod pallet { | |||
} | |||
|
|||
if to_claim.0 != 0 { | |||
T::Ring::transfer(&account_id(), who, to_claim.0, AllowDeath)?; | |||
T::Ring::transfer(&T::Treasury::get(), who, to_claim.0, AllowDeath)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also emit failure event here if error.
@@ -52,6 +52,11 @@ fn migrate() -> frame_support::weights::Weight { | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove previous migration which have been done in last upgrade.
Signed-off-by: Xavier Lau <[email protected]>
Signed-off-by: Xavier Lau <[email protected]>
pallet/deposit/src/lib.rs
Outdated
{ | ||
Self::deposit_event(Event::MigrationFailedOnRefund); | ||
|
||
Err(e)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not throw errors, otherwise there are still side effects l.
pallet/deposit/src/lib.rs
Outdated
Self::deposit_event(Event::DepositsClaimed { | ||
owner: who.clone(), | ||
deposits: to_claim.1, | ||
}); | ||
} | ||
if to_migrate.0 != 0 { | ||
T::Ring::transfer(&account_id(), &T::Treasury::get(), to_migrate.0, AllowDeath)?; | ||
T::DepositMigrator::migrate(who.clone(), to_migrate.0, to_migrate.2)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should not throw errors here right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In FP, we treat any I/O operation as the side effect.
And here, especially we interact with the DB, take
has already introduced the side effects. We should keep the error and utilize it to help rollback the state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You didn't get what I mean.
If keep the error, this batch (10 items) will be inserted again, but some of them might have been migrated, then they will be keep migrated again and again. You didn't do the rollback entirely outside (re-insert is not rollback), so just giveup rollup and record it here.
(It OK as we can always adopt migrate by script if there is.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then we can remove the event and insert the failure items into a different storage, and process that storage manually later. Using storage is easier to track and process compare to event. (Event is also a storage, same cost)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considering that you are on vacation and the likelihood of errors is very low, I suggest we keep things simple. At the same time, we must absolutely avoid any ledger inaccuracies or double-spending in case an error does occur.
Then we can remove the event and insert the failure items into a different storage, and process that storage manually later. Using storage is easier to track and process compare to event.
If this looks simpler for you, It works for me. (Just need me take another several minutes to review the difference between them, good so far.)
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Signed-off-by: Xavier Lau <[email protected]>
Check 6a6eaf9
|
Closes #1635.