Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Fix Inconsistent behaviour of repatriate_reserved after introducing account reference provider when ED is 0 #9463

Closed

Conversation

Mr-Leshiy
Copy link
Contributor

This test was moved from this issue paritytech/polkadot-sdk#337

alex pozhilenkov added 2 commits July 29, 2021 21:13
@shawntabrizi shawntabrizi requested a review from gui1117 July 30, 2021 07:38
@Mr-Leshiy Mr-Leshiy changed the title Add new test for the repatriate_reserved() function Fix Inconsistent behaviour of repatriate_reserved after introducing account reference provider when ED is 0 Jul 30, 2021
@@ -900,7 +900,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
f: impl FnOnce(&mut AccountData<T::Balance>, bool) -> Result<R, E>,
) -> Result<(R, DustCleaner<T, I>), E> {
let result = T::AccountStore::try_mutate_exists(who, |maybe_account| {
let is_new = maybe_account.is_none();
let is_new = maybe_account.is_none() && !system::Pallet::<T>::account_exists(who);
Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't think about the whole picture and how this modification but this doesn't solve the whole picture I think.

at the end of your test below alice has 2 providers and 1 consumer.
Maybe it is ok when ED is 0 to consider that balance can increment providers indefinitely ?

If pallet balance has ED 0 then is there a way for an account to be deleted ? if there is no way to delete an account, then I guess having increments of provider doesn't harm.

Copy link
Contributor

@gui1117 gui1117 Jul 30, 2021

Choose a reason for hiding this comment

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

@liuchengxu do you think increment providers like this makes sense ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, it's fine with ED 0 from my point of view since the account will never be deleted anyway. But this PR specifically patches for these using system as the account store of balances, what if there is a project that uses another pallet instead of system? Even though the chances are pretty low, we'd better use a more general solution.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@liuchengxu , system pallet as I know is a base layer for all pallets from frame and any other new pallets which will be added into the runtime. Meanwhile in the pallet balances you can already see the usage of the system pallet so I do not think that it will be a problem.

if frame_system::Pallet::<T>::can_dec_provider(who) {

system::Pallet::<T>::dec_consumers(who);
etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But I think increasing of the providers field it is not good and can lead to the problems.
Need deeper investigation of this problem.

Copy link
Contributor

Choose a reason for hiding this comment

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

@Mr-Leshiy I meant the account store in balances pallet:

/// The means of storing the balances of an account.
type AccountStore: StoredMap<Self::AccountId, AccountData<Self::Balance>>;

This patch does not work if some project stores the account in a non-system pallet.

But I fully agree we should think more about this problem as it's pretty fundamental.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My initial research have found the following.
According to this trait

pub trait StoredMap<K, T: Default> {
we can have default value of item at generally it does not considered as special case, because we can store a default item in the storage. But if we will remove something or reset it can be assigned to the default value.
Moving to the implementation of this trait, to this function
fn try_mutate_exists<R, E: From<DispatchError>>(
, it seems we can see that here we are considering default value as special case that before we do not have any value that it is initialized the first time, that is why we have incremented providers field

Copy link
Contributor

Choose a reason for hiding this comment

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

isn't it what is documented on the item:

/// Implement StoredMap for a simple single-item, provide-when-not-default system. This works fine
/// for storing a single item which allows the account to continue existing as long as it's not
/// empty/default.
///
/// Anything more complex will need more sophisticated logic.
impl<T: Config> StoredMap<T::AccountId, T::AccountData> for Pallet<T> {

The stored map is considered as a provide when not default.
Using an option here instead of relying on the default for currency would solve it. But requires migrating all the accounts which is annoying.

@stale
Copy link

stale bot commented Sep 19, 2021

Hey, is anyone still working on this? Due to the inactivity this issue has been automatically marked as stale. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the A5-stale Pull request did not receive any updates in a long time. No review needed at this stage. Close it. label Sep 19, 2021
@liuchengxu
Copy link
Contributor

Still relevant, but haven't found enough time to really look into this :D

@stale stale bot removed the A5-stale Pull request did not receive any updates in a long time. No review needed at this stage. Close it. label Sep 19, 2021
@stale
Copy link

stale bot commented Oct 19, 2021

Hey, is anyone still working on this? Due to the inactivity this issue has been automatically marked as stale. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the A5-stale Pull request did not receive any updates in a long time. No review needed at this stage. Close it. label Oct 19, 2021
@stale stale bot closed this Nov 2, 2021
@Mr-Leshiy Mr-Leshiy deleted the test/repatriate_reserved branch July 8, 2023 08:48
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A5-stale Pull request did not receive any updates in a long time. No review needed at this stage. Close it.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants