Skip to content
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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Improve deposits migration #1636

wants to merge 9 commits into from

Conversation

AurevoirXavier
Copy link
Member

@AurevoirXavier AurevoirXavier commented Nov 29, 2024

Closes #1635.

@AurevoirXavier AurevoirXavier added C-Pallet [Component] Something about pallet C-Runtime [Component] Something about runtime labels Nov 29, 2024
Signed-off-by: Xavier Lau <[email protected]>

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()),
Copy link
Contributor

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.

Copy link
Member Author

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.

@hackfisher
Copy link
Contributor

@AurevoirXavier CI failed

Signed-off-by: Xavier Lau <[email protected]>
@@ -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)?;
Copy link
Contributor

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 {
}

Copy link
Contributor

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]>
{
Self::deposit_event(Event::MigrationFailedOnRefund);

Err(e)?;
Copy link
Contributor

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.

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)?;
Copy link
Contributor

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?

Copy link
Member Author

@AurevoirXavier AurevoirXavier Dec 2, 2024

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.

Copy link
Contributor

@hackfisher hackfisher Dec 2, 2024

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.)

Copy link
Member Author

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)

Copy link
Contributor

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.

Copy link

github-actions bot commented Dec 3, 2024

Check 6a6eaf9 crab-dev

Check runtime version

Check runtime storage

Copy link

github-actions bot commented Dec 3, 2024

Check 6a6eaf9 darwinia-dev

Check runtime version

Check runtime storage

Copy link

github-actions bot commented Dec 3, 2024

Check 6a6eaf9 koi-dev

Check runtime version

Check runtime storage

Pallet DarwiniaStaking
+ Entry: StorageEntryMetadata { name: "UnissuedReward", modifier: Default, ty: Plain(UntrackedSymbol { id: 6, marker: PhantomData<fn() -> core::any::TypeId> }), default: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], docs: [" Unissued reward to Treasury."] }

Pallet Deposit
+ Entry: StorageEntryMetadata { name: "MigrationFailures", modifier: Optional, ty: Map { hashers: [Blake2_128Concat], key: UntrackedSymbol { id: 0, marker: PhantomData<fn() -> core::any::TypeId> }, value: UntrackedSymbol { id: 368, marker: PhantomData<fn() -> core::any::TypeId> } }, default: [0], docs: [" Failures of migration.", "", " The first value is the deposits that failed to migrate,", " the second value is the type of failure."] }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-Pallet [Component] Something about pallet C-Runtime [Component] Something about runtime
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

Filter non-zero deposit items during migration
2 participants