Try   HackMD

Appendix C. Serialisation Codec (Element Encoding Method)

C.1.1. Trivial Encoding

以下有四種簡單的編碼情況:

(C.1) 空值

空值將會輸出空的序列

(C.2) octet-sequence

八位元序列輸入,不需要做任何轉換 (因為就是要轉換成八位元)

(C.3) tuple

分別將 tuple 中的成員進行序列化後,將序列結果串在一起。

(C.4) 多參數

將輸入的多個參數以 tuple 形式進行序列化

C.1.2. Integer Encoding

將自然數轉換為固定長度的八位元組序列 (octet-sequence), 使用 little-endian 編碼方式進行。(little-endian 會將結果,由左邊開始放置)

以下為簡易的整數轉換 (

0<=x<2(8l))

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

以下為通用版的整數轉換 (支持到

N264 => unsigned int64)

三個條件對應不同編碼計算:

  1. x=0
  2. 27x<256
  3. 256x<264
if x == 0:
    # 條件一
if 2**(7*l) <= x < 2**(7*(l+1)):
    # 條件二
else if x < 2**64:
    # 條件三

於 3.4 Numbers 中的定義:

N={0,1,...} and
Nn={x|xN,x<n}

因此
lN8
的範圍是
{0,1,2,3,4,5,6,7}

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

Yccinamoroll3741: 分段處理提升效率, 太小的數字不需要用到 2^64 這麼大
所以 integer encoding 是 256 進位, 但是需要用到的 byte 數量會動態調整(dynamic array)
Eugene:
這個公式會依照數值的大小回傳不同長度的八位元組序列 (

l 會依照
x
大小而改變)
Eugene:
Q: 為什麼輸出的
Y
長度會是 1~9?
A: 因為第一個位置都是用來作為識別使用, 可以辨識出該輸入
x
的數值範圍與長度

Eugene: 以 APPENDIX C. Block Serialization 的定義上,會定義
l
的大小,例如 C.22 案例,
l
會影響輸出序列的大小。(實際也可以透過 x 來反推最佳的
l
大小)

Eq. 303
符號代表長度與內容:

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

Eq. 305 Bit sequence Encoding:

簡單把 bit 轉成 8 位元組

Eq. 306 Dictionary Encoding:

"key:value" pair 的長度 + key : value

Eq. 307 Set Encoding:

同 Sequence Encoding 但因為 Set 本身沒有排序,所以要依照小到大排序

Eq. 308 Block Encoding:

C.2 Block Serialization

區塊的序列化是將 header 以及 extrinsic data 依照順序以 tuple 的形式放入進行序列化, 可以參考 equations 4.2, 4.3 以及 5.1 (關於 header 以及 extrinsic data 的定義)

  • equation 4.2

    B(H,E)

  • equation 4.3

    E(ET,ED,EP,EA,EG)

  • equation 5.1

    H(Hp,Hr,Hx,Ht,He,Hw,Ho,Hi,Hv,Hs)

C.13

以 tuple 的方式將 header 以及所有的 extrinsic data 放入進行序列化

ε(B)=ε(H, εT(ET), εP(EP), εG(EG), εA(EA), εD(ED))

C.14

ET (tickets)

tickets 用來決定哪個驗證者負責產生區塊

tickets 資料大小是可變動的,因此透過

的序列化方式進行。(序列化其長度與內容)

εT(ET)=ε(ET)

深入閱讀:6.7 The Extrinsic and Tickets. 有關於

ET 的介紹, 前往 Extrinsic 筆記

C.15

EP (preimages)

  • p
    : preimage, Preimage lookups 是區塊鏈中提供靜態數據查詢的一種機制
    • 可以在區塊鏈中儲存靜態數據,透過任意的 key/value pairs 進行儲存。(提供給 Refine 階段快速查詢數據使用)
    • 使用 hash 作為索引,查詢到原始數據
    • 資料來源是 extrinsic data
  • s
    : service of identifier (用來作為索引)
  • 需要排序(參考 3.7.1 sequence 有介紹排序規則)

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

深入閱讀 9. Service Account 以及 9.2 Preimage Lookups

C.16

EG (reports)

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

TODO: 11.4 Work Report Guarantees. 有關於

EG 的介紹, 尚未閱讀

C.17

EA (The Assurances Extrinsic)

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

TODO: 11.2 Package Availability Assurances. 有關於

EA 的介紹, 尚未閱讀

C.18

ED (The disputes extrinsic)

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

深入閱讀:10.2 Extrinsic. 有關於

ED 的介紹, 前往 Extrinsic 筆記

C.19

E(H) = 連結以下兩個序列化結果

  • Hs
    : a block seal
  • HU
    : 定義於 C.20

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

Seal (seal signature) 是以什麼格式記錄? sealing keys?

C.20

EU(H) 會使用於 C.19

  • Hp
    : parent hash
  • Hr
    : prior state root
  • Hx
    : extrinsic hash
  • Ht
    : a time slot index
  • He
    : the epoch
  • Hw
    : winning tickets
  • Ho
    : offenders markders
  • Hi
    : a Bandersnatch block author index
  • Hv
    : the entropy-rielding VRF signatrue
  • ¿
    : 定義於 APPENDIC C.8, 用來判斷輸入是否為空值,會有不同的輸出。

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

  • E2
    :定義於 APPENDIC C.5, 用來對於整數型態的編碼, 此處限制了
    l=2
    的狀況進行整數編碼。

image

image

C.21

  • X
    : The set of refinement contexts

image

TODO: 11. REPORTING AND ASSURANCE, 11.1.2 Refinement Context . 有關於

X 的介紹, 尚未閱讀

C.22

  • S
    : The set of availability specifications

image

TODO: 11. REPORTING AND ASSURANCE, 11.1.3 Availability . 有關於

S 的介紹, 尚未閱讀

C.23

  • L
    : The set of work results

image

TODO: 11. REPORTING AND ASSURANCE, 11.1.4 Work Result . 有關於

L 的介紹, 尚未閱讀

C.24

  • W
    : The set of work-reports

image

TODO: 11. REPORTING AND ASSURANCE, 11.1.1 Work Report . 有關於

W 的介紹, 尚未閱讀

C.25

  • P
    : The set of work-packages. See equation 14.2

image

TODO: 14.3. Packages and Items 有關於

P 的介紹, 尚未閱讀

C.26

I : The set of work items. See equation 14.3

image

TODO: 14.3. Packages and Items 有關於

I 的介紹, 尚未閱讀

C.27

C : The set of seal-key tickets. See equation 6.6. Not used as the set of complex numbers.

image

6.2. Safrole Basic State 有關於

C 的介紹, 前往 6.2 Safrole Basic State 筆記

C.28

O 會使用於 C.23

  • J
    : The set of work execution erros
  • Y
    : The set of octet strings/"blobs". Subscript denotes length. See section 3.7

image

C.29

EI 會使用於 C.26

image