余额托盘中的“AccountStore”配置如何工作?

Wee*_*ezy 2 account substrate

在余额托盘中,配置特征有一项定义如下type AccountStore: StoredMap<Self::AccountId, AccountData<Self::Balance>>;:这对我来说有点奇怪,因为我期望一个普通的存储映射来存储从AccountId到 的映射AccountData,但在查看文档后,StoredMap我意识到这也是在 StorageMaps 上实现的一个特征。现在这更有意义了,所以我继续看看运行时如何定义这个字段,令我惊讶的是我在runtime/src/lib.rs:中找到了它type AccountStore = System;。现在我以前从未见过这样的运行时定义,因为如果我是正确的,System它应该代表frame_system托盘。所以我去查看frame_system::Config运行时,发现了这个定义:

type AccountData = pallet_balances::AccountData<Balance>;

现在我不知道这些定义是如何进入pallet_balances's Configimpl 的,但我可以看到 FRAMESystem托盘包含两种类型,即:一种类型AccountData和一种类型AccountId

最后我的两个问题是:

  1. 如此复杂的设计的原因是什么?
  2. type AccountStore = System;具体类型如何判断呢?

小智 6

  1. 在系统托盘中存储帐户余额还维护一些其他的frame_system信息,这些信息对于特定的运行时配置来说可能很重要。但是consumers,在具有多个托盘的运行时中拥有 、 和 并可能与其他运行时交互变得非常重要providerssufficients
  2. AccountStore定义此余额将存储在哪里,在本例中是frame_system::Pallet<Runtime>。如果我们按照线索检查frame_system的配置,我们会看到类型AccountData定义为
type AccountData = pallet_balances::AccountData<Balance>
Run Code Online (Sandbox Code Playgroud)

好,现在我们知道frame_system 中存储的内容将是pallet_balances 中定义的AccountData内容。

因此,系统中有关帐户的信息最终将如下所示:

/// Information of an account.
#[derive(Clone, Eq, PartialEq, Default, RuntimeDebug, Encode, Decode, TypeInfo)]
pub struct AccountInfo<Index, AccountData> {
    /// The number of transactions this account has sent.
    pub nonce: Index,
    /// The number of other modules that currently depend on this account's existence. The account
    /// cannot be reaped until this is zero.
    pub consumers: RefCount,
    /// The number of other modules that allow this account to exist. The account may not be reaped
    /// until this and `sufficients` are both zero.
    pub providers: RefCount,
    /// The number of modules that allow this account to exist for their own purposes only. The
    /// account may not be reaped until this and `providers` are both zero.
    pub sufficients: RefCount,
    /// The additional data that belongs to this account. Used to store the balance(s) in a lot of
    /// chains.
    pub data: AccountData,
}
Run Code Online (Sandbox Code Playgroud)

哪里AccountData符合前面提到的在pallet_balances中的定义。

请检查此提交,以获取有关如何调整的更多信息 -> https://github.com/paritytech/substrate/commit/31d90c202d6df9ce3837ee55587b604619a912ba