【问题标题】:Substrate Blockchain - Change block structureSubstrate Blockchain - 改变区块结构
【发布时间】:2021-12-12 17:26:37
【问题描述】:

我正在尝试修改基于我正在尝试开发的 Substrate 的区块链的块结构。特别是我想在标题中添加一个向量,在块的主体中​​添加另一个向量。有人知道如何做到这一点吗?

我是 Substrate 的新手 :'(

提前感谢所有愿意做出贡献的人!

【问题讨论】:

    标签: blockchain substrate


    【解决方案1】:

    Substrate 中的 block 和 header 类型是通用的。

    header需要实现https://docs.rs/sp-runtime/latest/sp_runtime/traits/trait.Header.html,block需要实现https://docs.rs/sp-runtime/latest/sp_runtime/traits/trait.Block.html。

    Substrate 本身已经为 https://docs.rs/sp-runtime/latest/sp_runtime/generic/struct.Block.html 和 https://docs.rs/sp-runtime/latest/sp_runtime/generic/struct.Header.html 提供了两种类型。

    当您设置区块链时,您主要通过运行时进行设置,您可以选择这些类型。

    【讨论】:

    • 假设我需要这些数据。然后我还需要添加一些在共识过程中需要被区块链调用的方法。我怎样才能做到这一点?我是否必须修改所有需要 Block 特征实例的方法?你会建议任何说明如何做到这一点的教程吗?
    • 你想把什么样的数据附加到一个块上?
    • 我想添加一个向量,存储一些挑战的结果,其 ID 由块生产者在块本身中发布,然后由其他块验证器更新
    【解决方案2】:

    如果您为每个块添加了一些数据,那么它被称为固有外部 (https://docs.substrate.io/v3/concepts/extrinsics/#inherents),并且不会产生相关费用。

    Header 是在您的运行时定义的类型,因此您可以更改它以包含您想要的任何其他数据。搜索这个定义:

    pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
    

    在此处的上下文中查看它: https://github.com/substrate-developer-hub/substrate-node-template/blob/ad7ce8e3dabb2d1f8f4b4094db5b0e754760e9be/runtime/src/lib.rs#L75

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-17
      • 2019-05-06
      • 1970-01-01
      • 2023-03-12
      • 2021-07-30
      • 1970-01-01
      相关资源
      最近更新 更多