substrate knowledgebase: Substrate Key Concepts - Runtime

区块链的Runtime是业务逻辑,它定义了区块链的行为。在基于Substrate开发的区块链中,runtime被称为”状态转换函数“;Substrate开发人员在runtime中定义了用于表示区块链的状态的存储项,同时也定义了允许区块链用户对该状态进行更改的函数

为了能够提供无须分叉的升级功能,Substrate采用了可编译成WebAssembly (Wasm)字节码的runtime形式。此外,Substrate定义了runtime必须实现的核心基本类型。

Core Primitives

Substrate框架对runtime必须向Substrate的其他层提供的内容进行了最小化的假设。为了在Substrate框架内工作,它们必须定义并实现特定的接口。

他们是:

  • Hash: A type which encodes a cryptographic digest of some data. Typically just a 256-bit quantity.

  • DigestItem: A type which must be able to encode one of a number of “hard-wired” alternatives relevant to consensus and change-tracking as well as any number of “soft-coded” variants, relevant to specific modules within the runtime.

  • Digest: A series of DigestItems. This encodes all information that is relevant for a light-client to have on hand within the block.

  • Extrinsic: A type to represent a single piece of data external to the blockchain that is recognized by the blockchain. This typically involves one or more signatures, and some sort of encoded instruction (e.g. for transferring ownership of funds or calling into a smart contract).

  • Header: A type which is representative (cryptographically or otherwise) of all information relevant to a block. It includes the parent hash, the storage root and the extrinsics trie root, the digest and a block number.

  • Block: Essentially just a combination of Header and a series of Extrinsics, together with a specification of the hashing algorithm to be used.

  • BlockNumber: A type which encodes the total number of ancestors any valid block has. Typically a 32-bit quantity.

FRAME Primitives

核心Substrate代码库随附 FRAME 框架,FRAME是Parity的Substrate runtime的开发系统,已经应用于Kusama和Polkadot等链上。FRAME定义了一些额外的runtime基础类型,并提供了一个框架,使得通过编写模块(称为”pallets“)来构建runtime变得十分容易。每个pallet用于封装特定于该域的逻辑,这些逻辑可表示为一组存储项、事件、错误和可调用函数的集合。FRAME开发人员可选择创建自己的pallet,也可以选择重用包括50多个Substrate随附的pallet在内的现有的pallets。

如下图:
在这里插入图片描述

相关内容:
https://substrate.dev/docs/en/knowledgebase/runtime/

Substrate 2.0技术知识库翻译——Runtime篇<一>之《Runtime总览》

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值