-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Improve in using multiple instance of balances #6531
Conversation
It looks like @chenwei767 signed our Contributor License Agreement. 👍 Many thanks, Parity Technologies CLA Bot |
I think you want to use this: https://github.com/paritytech/substrate/blob/master/frame/balances/src/tests_local.rs#L110-L115 |
Yes, I have used the altered version of:
Currently all instances including the default instance share one system module, that is to say all instances share the same I am not sure whether sharing substrate/frame/system/src/lib.rs Lines 348 to 357 in 4be954a
I think |
do you mean multiple instance use This can't work you basically put all kind of balances at the same place, all balances are thus mixed together, if you add funds to balances::instance1 to some account, this account will have the same amount of found in balances::instance2. This is not correct. Each instance must store their accountData at their own places, maybe having system::AccoundData being a tuple or similar mecanism can works. A simple way to test it is, to have one balance use u128 for currency and another one use u64, then compilation must fail. |
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.
maybe I can write the code:
system::Module::<T>::allow_death(I::INDEX, transactor);
I don't see how instance index helps here, if system want to allow death to some modules only then it can use the type ModuleToIndex
.
About the PR itself, maybe it can be used in some other context
That is totally fine, why should the account be repeated if he still has funds? |
I do not want multiple instance to use the same
Yes, it is. I already have the flowing code:
It works fine if I set Suppose the If the balance of Alice in substrate/frame/balances/src/lib.rs Lines 989 to 991 in 4be954a
So, I want to add the In balances pallet: In system pallet:
|
I basically do not want all instances to share one |
Why not? What do you try to achieve? |
When using two instances simultaneously, the locks on substrate/frame/balances/src/lib.rs Lines 989 to 991 in 4be954a
A simple way to achieve this is we change the above code to the following:
and the |
Why not just set |
I actually have already set If we want to clean up the dust accounts, And maybe this PR can be used in some other context. For example, If I write A multiple instance module |
All the other changes you propose here will require more changes in balances etc. But with the current changes we can not be sure that everything will work out as you expect and we maybe need other changes or whatever. I would be nice to have a simple POC impl that proofs your statements. |
Good idea. I will think it over. |
This is fundamentally nonsensical. However, I believe what you ultimately want to do is reasonable. Namely:
The question is what should happen for low balances of the latter instance. There are four options:
Both of the last two models are secure and make sense, but imply that any account with a balance in the latter instance would have a balance >= ED in the former instance, which the balances pallet doesn't currently support enforcement of. |
This is a very good analysis and I am going to implement the fourth option. |
For two instances of balances,
|
I'm not quite convinced of the need for multiple separate reference counting. "Option 4" certainly doesn't require multiple reference counters. I would also prefer to avoid introducing additional types into What use-case could you imagine where the system reference-count and the The point of the reference count is to ensure that some ED exists in deposit for an account as long as a reference is held. With "Option 4", an ED in the secondary balances implies a reference in System and therefore an ED in the first balances. There is no need for a second, independent reference-counting system. |
Thanks for your advice. To avoid the overhead, maybe I can add a new method to
I think you are right. One reference-counting system is enough. Setting a lock on a secondary account should not change the system reference-count or the local one. This was an oversight on my part. |
|
Add a
INDEX
field to the generated traitInstance
to make pallets with multiple instants more easy to be used.For example, If I want to make
system
module aware of which instance ofbalances
module currently used,substrate/frame/balances/src/lib.rs
Lines 989 to 991 in 4be954a
maybe I can write the code:
system::Module::<T>::allow_death(I::INDEX, transactor);