區塊鏈的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總覽》
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/290722.html
標籤:區塊鏈
