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

Altair loans sustitution #1266

Merged
merged 7 commits into from
Mar 31, 2023
Merged

Altair loans sustitution #1266

merged 7 commits into from
Mar 31, 2023

Conversation

lemunozm
Copy link
Contributor

@lemunozm lemunozm commented Mar 17, 2023

Fixes #1265 #1281

Tasks:

  • Substitute pallet-loans by pallet-loans-ref in altair.
  • Make a migration in pallet-loans-ref that nukes the previous pallet-loans storage only in case it is the old one.
  • Removed deprecated pallet-loans dependency and others associated with it in pallet-connectors

pallet-loans is now safe to be removed from centrifuge-chain if this PR is merged (do not need to wait for the migration).

@lemunozm lemunozm added D2-notify Pull request can be merged and notification about changes should be documented. crcl-protocol Circle protocol related. labels Mar 17, 2023
@lemunozm lemunozm requested a review from branan as a code owner March 17, 2023 10:48
@lemunozm lemunozm self-assigned this Mar 17, 2023
Copy link
Collaborator

@mustermeiszer mustermeiszer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We definietly need to check needed migrations. For this we need to
a) query the current state of Altair
b) we decide to nuke the old loans storage

@offerijns what is your thinking here?

For option b) we also need a migration logic that nukes the old storage.

@hieronx
Copy link
Contributor

hieronx commented Mar 22, 2023

b) we decide to nuke the old loans storage

This is fine, on Altair. There's only 1 pool with 1 closed loan.

Copy link
Contributor Author

@lemunozm lemunozm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some explanations below:

}

fn on_runtime_upgrade() -> Weight {
if v0::NextLoanId::<T>::iter_values().count() == 1 {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, I would have wanted to check here if the on_chain_storage_version() was 0, and bump the version to 1, but I could not do it because if I initialize the pallet with STORAGE_VERSION = 1, then it never enters here, because it will be already 1.

I think the issue was not setting the version to 0 in the past.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the issue was not setting the version to 0 in the past.

This makes me think that maybe we should add this version for all pallets, in this way, if in the future we have a new migration, we can easily fetch the correct version number 0 for them.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I have been meaning to open an issue for that. Here it is 🌚

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! ❤️

@@ -93,8 +94,11 @@ pub mod pallet {
<T as Config>::CurrencyId,
>>::PoolId;

const STORAGE_VERSION: StorageVersion = StorageVersion::new(0);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We initialize the version to 0, for futures migrations

Comment on lines 53 to 54
return T::DbWeight::get().writes(result.unique.into())
+ T::DbWeight::get().reads(result.loops.into());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is expected 8 read and 8 writes

@lemunozm
Copy link
Contributor Author

This PR is ready for review

wischli
wischli previously approved these changes Mar 31, 2023
Copy link
Contributor

@wischli wischli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Me gusta the check via the deprecated Storage entry 🥳

}

fn on_runtime_upgrade() -> Weight {
if v0::NextLoanId::<T>::iter_values().count() == 1 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I have been meaning to open an issue for that. Here it is 🌚

} else {
log::warn!("Loans: storage was already clear. This migration can be removed.");

Weight::zero()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK we still perform a read

Suggested change
Weight::zero()
T::DbWeight::get().reads(1)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following your hint, I've made a minor change for the sake of purism

Copy link
Contributor

@wischli wischli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-approve

Copy link
Collaborator

@mustermeiszer mustermeiszer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just want to ensure we are getting the right prefix. I might hardcode it, but I think the given approach is fine to.

/// If this storage is not found, the nuking process is aborted.
#[storage_alias]
pub(crate) type NextLoanId<T: Config> =
StorageMap<Pallet<T>, Blake2_128Concat, PoolIdOf<T>, u128, ValueQuery>;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we get the right prefix as pallet-loans-ref and pallet-laons are both using the same prefix (i.e. Loans)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They use the same prefix, yes!

@lemunozm lemunozm enabled auto-merge (squash) March 31, 2023 09:15
@lemunozm lemunozm merged commit 748c1e0 into main Mar 31, 2023
@lemunozm lemunozm deleted the altair-loans-sustitution branch March 31, 2023 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crcl-protocol Circle protocol related. D2-notify Pull request can be merged and notification about changes should be documented.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pallet loans sustitution in altair
5 participants