10

The FRAME system for runtime development defines an AccountData type, which is coupled with data from the Balances Pallet in the Polkadot runtime.

  1. What other types of data could be tracked using this type?
  2. Why doesn't the Balances Pallet track its metadata "natively" as opposed to coupling with the FRAME System AccountData type?

2 Answers 2

5

I believe I'd asked a similar question on stackoverflow a while ago and it may answer your question: https://stackoverflow.com/questions/70845959/balances-accountstore-definition-in-substrate-runtime

Specifically this paragraph:

Storing account balances in the system pallet also maintains some other frame_system information that may be important to keep around for a certain runtime configuration. But having consumers, providers and sufficients inside a runtime with multiple pallets and potentially interacting with other runtimes becomes quite crucial.

1
  1. The FRAME System AccountData type could track any data structure that implements Member + FullCodec + Clone + Default + TypeInfo + MaxEncodedLen (which we know by looking at what AccountData is bound by here).

    The AccountData type from the Balances pallet satisfies this requirement. And in this context, this type is just a struct that holds account information.

  2. The Balances pallet could be configured to use storage native to its own instance, so long as it satisfies the AccountStore type it's configuration expects. This type is the Balance pallet's concept for "a location to store information about accounts using me". Because under the hood this type expects a StoredMap, any type that implements StoredMap can be used here.

    The reason the Balances pallet is typically set to use the System pallet (which has an implementation for StoredMap) is because AccountData from the Balances pallet is most commonly used alongside other data the System pallet keeps track of (such as nonce, consumers, providers and sufficients).

    This may sound more intuitive if you look into the system.account storage item of any Substrate chain built with FRAME:

     {
      nonce: 0
      consumers: 0
      providers: 0
      sufficients: 0
      data: {     // < - this is taken from `AccountData`
        free: 0
        reserved: 0
        miscFrozen: 0
        feeFrozen: 0
      }
    }
    

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.