简体   繁体   English

Substrate Blockchain - 改变区块结构

[英]Substrate Blockchain - Change block structure

I'm trying to modify the block structure for a blockchain based on Substrate that I'm trying to develop.我正在尝试基于我正在尝试开发的 Substrate 修改区块链的块结构。 In particular I would like to add a vector in the header and another one inside the body of the block.特别是我想在 header 中添加一个向量,在块体中添加另一个向量。 Does someone know how it is possible to do that?有人知道怎么可能吗?

I'm a newbie in Substrate:'(我是 Substrate 的新手:'(

Thanks in advance to everyone who will contribute!在此先感谢所有愿意做出贡献的人!

The block and header type in Substrate are generic. Substrate 中的 block 和 header 类型是通用的。

The header needs to implement https://docs.rs/sp-runtime/latest/sp_runtime/traits/trait.Header.html and the block needs to implement https://docs.rs/sp-runtime/latest/sp_runtime/traits/trait.Block.html . The header needs to implement https://docs.rs/sp-runtime/latest/sp_runtime/traits/trait.Header.html and the block needs to implement https://docs.rs/sp-runtime/latest/sp_runtime/特征/特征.Block.html

Substrate itself provides two types for that already https://docs.rs/sp-runtime/latest/sp_runtime/generic/struct.Block.html and https://docs.rs/sp-runtime/latest/sp_runtime/generic/struct.Header.html . Substrate itself provides two types for that already https://docs.rs/sp-runtime/latest/sp_runtime/generic/struct.Block.html and https://docs.rs/sp-runtime/latest/sp_runtime/generic/ struct.Header.html

When you setup your blockchain, which you mainly do through the runtime you can choose these types.当您设置区块链时,您主要通过运行时进行设置,您可以选择这些类型。

If you're after including some data for each block then it's called an Inherent extrinsic ( https://docs.substrate.io/v3/concepts/extrinsics/#inherents ) and would not have a fee associated with it.如果您在为每个块包含一些数据之后,则它被称为固有的外部数据( https://docs.substrate.io/v3/concepts/extrinsics/#inherents )并且不会产生相关费用。

Header is a type defined in your runtime so you can change it to include any additional data that you'd like. Header 是在您的运行时定义的类型,因此您可以更改它以包含您想要的任何其他数据。 Search for this definition:搜索此定义:

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

See it in context here: https://github.com/substrate-developer-hub/substrate-node-template/blob/ad7ce8e3dabb2d1f8f4b4094db5b0e754760e9be/runtime/src/lib.rs#L75在此处查看上下文: https://github.com/substrate-developer-hub/substrate-node-template/blob/ad7ce8e3dabb2d1f8f4b4094db5b0e754760e9be/runtime/src/lib.rs#L75

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM