Skip to content

Update Lock amounts based on slashing.  #339

@kianenigma

Description

@kianenigma

Context. We have pallets that have the ability to reduce the balance of an account's in a particular token. For simplicity, we assume a single-currency chain. This can be achieved through T::Currency::slash_reserved() or T::Currency::slash(), or anything similar.

And there are other pallets that make an assumption on a particular account having a specific amount of tokens, and throw a lock in there to ensure the balance does not go below that.

The problem. The problem is that this assumption can be easily torn apart by the former group of pallets, and if there are no communication between them, the latter group will make wrong assumptions. Note that sometimes both sides of the above scenario can even be the same pallet. For example, PhragmenElections sets a lock for a particular amount as the weight of a vote, but staking can slash that account in the meantime, potentially even killing the account entirely, whilst the vote will stay remain in PhragmenElection, with the same weight.

Potential solution. The straightforward approach to me is to allow different pallets to listen to account balance changes from other pallets. Currently, staking aggregates all slash amounts into one NegativeImbalance and reports them to the outer world. This needs to stay, but we need another similar event that is triggered per-slashed-account. For example:

enum ImbalanceType {
   Free,
   Reserved,
}
trait OnAccountImbalance<A, B> {
    fn on_account_imbalance(who: A, amount: B, type: ImbalanceType) {}
} 

Any pallet that wants to listen to this event would implement the above. Staking, ElectionsPhragmen, and other pallets that have the ability to slash funds can then implement it.

Discussion. I hope someone will recommend an easier way to solve this. What I proposed can be a bit to expensive, and is quite a pain to weigh properly.

Similar: paritytech/substrate#3088

Metadata

Metadata

Assignees

Labels

C1-mentorA task where a mentor is available. Please indicate in the issue who the mentor could be.I5-enhancementAn additional feature request.T1-FRAMEThis PR/Issue is related to core FRAME, the framework.

Type

No type

Projects

Status

✅ Done

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions