在衬底运行时平衡 AccountStore 定义
Balances AccountStore definition in substrate runtime
在余额托盘中,配置特征有一项定义为 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' 配置实现的,但我可以看到 System
包含两种成分,即:一种 AccountData
和一种AccountId
。所以最后我的两个问题是
- 为什么会出现如此令人费解的设计?
type AccountStore = System;
如何计算出具体类型?
- 在系统托盘中存储帐户余额还会维护一些 other frame_system information,对于某些运行时配置来说可能很重要。但是在具有多个 pallet 的运行时中具有
consumers
、providers
和 sufficients
并可能与其他运行时交互变得非常重要。
AccountStore
定义了余额的存储位置,因为 this case is frame_system::Pallet<Runtime>
. If we follow the lead and check the configuration of frame_system we will see that the type for AccountData
定义为
type AccountData = pallet_balances::AccountData<Balance>
很好,现在我们知道 frame_system 中存储的 AccountData
将是 defined in pallet_balances.
因此系统中有关帐户的信息最终将如下所示:
/// 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,
}
其中 AccountData
符合前面提到的 pallet_balances 中的定义。
请也检查此提交以获取有关如何对其进行调整的更多信息 -> https://github.com/paritytech/substrate/commit/31d90c202d6df9ce3837ee55587b604619a912ba
在余额托盘中,配置特征有一项定义为 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' 配置实现的,但我可以看到 System
包含两种成分,即:一种 AccountData
和一种AccountId
。所以最后我的两个问题是
- 为什么会出现如此令人费解的设计?
type AccountStore = System;
如何计算出具体类型?
- 在系统托盘中存储帐户余额还会维护一些 other frame_system information,对于某些运行时配置来说可能很重要。但是在具有多个 pallet 的运行时中具有
consumers
、providers
和sufficients
并可能与其他运行时交互变得非常重要。 AccountStore
定义了余额的存储位置,因为 this case isframe_system::Pallet<Runtime>
. If we follow the lead and check the configuration of frame_system we will see that the type forAccountData
定义为
type AccountData = pallet_balances::AccountData<Balance>
很好,现在我们知道 frame_system 中存储的 AccountData
将是 defined in pallet_balances.
因此系统中有关帐户的信息最终将如下所示:
/// 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,
}
其中 AccountData
符合前面提到的 pallet_balances 中的定义。
请也检查此提交以获取有关如何对其进行调整的更多信息 -> https://github.com/paritytech/substrate/commit/31d90c202d6df9ce3837ee55587b604619a912ba