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

Update Balances Pallet events to help block explorers #4389

Merged
merged 5 commits into from Dec 17, 2019

Conversation

shawntabrizi
Copy link
Contributor

@shawntabrizi shawntabrizi commented Dec 13, 2019

Fixes #4382

The goal of this PR is to help an outside service like a block explorer to track the total token economy of the Balances Pallet through events, and without needing to querying individual account balances.

To accomplish this, we:

  • Updated ReapedAccount event to emit the dust burned when an account is reaped.
  • Added BalanceSet event to emit when root directly changes the balance of an account.

This PR includes the following changes:

  • When an account's free or reserved balance drops below the ED, any dust amount will move to the other balance if it is above ED. This means a none of a user's balance will be burned if only one part of their total balance drops below ED. (See test)
  • When an account is reaped (because both free and reserved balance is below ED), the ReapedAccount event now emits how much dust was burned.
  • When root calls set_balance with a value less than ED for either reserved or free, we automatically set the value to 0.
  • When set_balance is called, BalanceSet event is emitted with information about the user, final free balance, and final reserved balance.

I am not sure this solves all the problems around tracking tokens within the system, but it should help.

Some example issues:

  • We do not emit any information (necessarily) when a balance is moved between free and reserved.
  • We do not emit any information (necessarily) when low level functions are used to manipulate the balance of a user:
    • Slash
    • Deposit Creating
    • etc...

Follow up questions in the original issue.

@shawntabrizi shawntabrizi changed the title Track a user's total balance through events Update Balances Pallet events to help block explorers Dec 13, 2019
@gavofyork gavofyork added the A0-please_review Pull request needs code review. label Dec 13, 2019
@@ -456,22 +458,35 @@ decl_module! {
) {
ensure_root(origin)?;
let who = T::Lookup::lookup(who)?;
let existential_deposit = T::ExistentialDeposit::get();
let mut final_free = new_free;
Copy link
Member

Choose a reason for hiding this comment

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

more cleanly written as let new_free = if new_free < existential_deposit { Zero::zero() } else { new_free }; since this doesn't leave an intermediate value around nor needs use of mut.

Copy link
Member

@gavofyork gavofyork left a comment

Choose a reason for hiding this comment

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

Minor code style thing. Looks fine otherwise.

@gavofyork gavofyork added A6-mustntgrumble and removed A0-please_review Pull request needs code review. labels Dec 17, 2019
@gavofyork gavofyork merged commit a8ea665 into paritytech:master Dec 17, 2019
@shawntabrizi shawntabrizi deleted the shawntabrizi-reap-event branch December 19, 2019 23:04
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Additional event-attribute balances.ReapedAccount
2 participants