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

Account Model Refactor #236

Closed
xlc opened this issue May 20, 2020 · 1 comment · Fixed by #272
Closed

Account Model Refactor #236

xlc opened this issue May 20, 2020 · 1 comment · Fixed by #272

Comments

@xlc
Copy link
Member

xlc commented May 20, 2020

Account Model Refactor

ExistentialDeposit causes a lot of issues and edgecases:

So we will be dropping it.

The main reason of ExistentialDeposit is to prevent dust account attack, avoid state bloating to ensure people will not be unnecessarily to store account balances with near zero value and the storages are paid with enough compensation.

To prevent such attack without ExistentialDeposit, a new account model is required.

An account needs to be opened before it can exists and holding balances and system account data (i.e. nonce and ref count). A deposit will be reserved in order to open an account. This deposit essentially pays for the state usage of account data and all the token balances.

Account can be closed to wipe account data and token balances and release the reserved token.

System account ref counting can be used to prevent an account to be closed, so pallets can know it only need to dealing with opened accounts.

Workflow

  • any kind of transfer
    • check if receiver has account opened
    • if no, use the transfered fund to open account
      • if fund is not ACA
        • use DEX to convert required amount to ACA
      • reserve required ACA and mark account is open
  • to close account
    • parameter dest: Option<AccountId>
    • if no dest, use treasury address
    • check allow_death from system ref counting
    • if yes
      • iterate all token balances, send remaining fund including reserved ones to dest
      • kill account

Spec

  • orml-traits
    • Types
      • trait OnReceived
        • on_received(account: AccountId, currency: CurrencyId, amount: Balance)
  • orml-tokens
    • Trait
      • OnReceived: OnReceived
    • Module
      • update deposit & transfer to call OnReceived
  • module-accounts
    • Trait
      • OnCreatedAccount: Happened
      • KillAccount: Happened
      • NewAccountDeposit: Get<Balance>
      • Treasury: Get<ModuleId>
    • Calls
      • close_account(origin, to: Option<AccountId>)
        • ensure signed
        • ensure system::Module::allow_death
        • iterate all currencies and send all remaining funds to to
        • call KillAccount
    • Module
  • runtime
@xlc
Copy link
Member Author

xlc commented May 30, 2020

Just found StorageMapShim can be used to detect on receive balance

https://github.com/paritytech/substrate/blob/cd305af2a9f8ec7d13081b6dc6807014b207dab8/frame/support/src/traits.rs#L91

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant