substrate - 宏 #[pallet::genesis_config] 和 #[pallet::genesis_build] 在 sudo pallet 上做什么?

标签 substrate

#[pallet::genesis_config]
    pub struct GenesisConfig<T: Config> {
        /// The `AccountId` of the sudo key.
        pub key: T::AccountId,
    }

    #[cfg(feature = "std")]
    impl<T: Config> Default for GenesisConfig<T> {
        fn default() -> Self {
            Self { key: Default::default() }
        }
    }

    #[pallet::genesis_build]
    impl<T: Config> GenesisBuild<T> for GenesisConfig<T> {
        fn build(&self) {
            <Key<T>>::put(&self.key);
        }
    }

genesis_configgenesis_build 宏在这里发生了什么?一些阅读似乎建议实现特征 GenesisBuild<T,I = ()>但我对文档感到困惑:“TI 是 pallet trait 和 pallet 实例的占位符。”

什么是托盘实例?我还假设 pallet trait 是指 sudo pallet 的 Config trait。它与为创世 block 配置唯一的 StorageValue 有什么关系,以便运行节点的每个实例都可以验证同一个帐户是 Root 吗?谁能帮我分解一下。

最佳答案

What are pallet instances?

托盘可以实例化。这意味着一个 Pallet 可以在运行时多次使用。每个实例将使用相同的代码(通过配置特征对不同的配置取模),但每个实例的存储将不同。

参见:https://docs.substrate.io/how-to-guides/v3/basics/instantiable-pallets/

I also assume pallet trait means the Config trait for the sudo pallet. Is it some how related to configuring a unique StorageValue for the Genesis block so that each instance of a running node can verify that the same Account is Root? Can someone help break it down for me.

Yes Pallet trait 表示 Config trait。

GenesisBuild 采用两个通用参数的要点是支持所有类型的 Pallet。每个 Pallet 都可以通过 trait 进行配置,因此 GenesisBuild trait 需要采用 Config 泛型参数 T。有些Pallets是可以实例化的,所以也需要带上I

这一切归结为一些 Rust 的“怪癖”,以支持使用默认实例和自定义实例的可实例化 Pallet,以及支持根本不使用任何实例化的 Pallet。

关于substrate - 宏 #[pallet::genesis_config] 和 #[pallet::genesis_build] 在 sudo pallet 上做什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70324883/

相关文章:

substrate - 如何解决 Substrate `duplicate lang item in crate ' std'( 'myexternalcrate' 取决于): 'panic_impl' conflict with sr-io

blockchain - 如何在基板运行时进行浮点运算

substrate - 在Polkadot-js中是否有一种创建HD钱包地址的方法

底物创世 block 不匹配

substrate - 底层中的 block 'justification'是什么,它有什么作用?

rust - decl_storage 中 `storage_name` 的示例是什么

substrate - 我们可以在基质中使用不同的地址格式吗?

blockchain - 开发 key (Alice) 如何从 `chain_specs.rs` 添加到本地 keystore ?

substrate - 基底存储中私有(private)变量的可能性

rust - 如何将特征类型与基板模块中的字符串类型进行比较?