# VII. Recent History
- 保留了 state 資訊在最近的 $\mathsf{H} = 8$ 個區塊中
(保留最近 8 個區塊的歷史狀態)
- $\mathsf{H} = 8$, The size of recent history, in blocks.
- 保留歷史狀態的原因:用來排除重複或是過期的 work-reports 被提交
---
以下為 recent blocks 的定義

(7.1)
$$
\beta \in ⟦(h \in \mathbb{H}, \mathbf{b} \in ⟦\mathbb{H}?⟧, s \in \mathbb{H}, \mathbf{p} \in \mathbb{D} \langle \mathbb{H} \to \mathbb{H} \rangle)⟧_{:\mathsf{H}}
$$
:::info
最多有 $\mathsf{H} = 8$ 個區塊組成,每個 recent block 記錄的資訊包含以下四種:
- $h$ : header hash
- ==尚未閱讀==$\mathbf{b}$ : MMR(Merkle Range Mountain) append function $\mathcal{A}$ 的計算結果 (參考 appendix E.2)
- $s$ : state root
- $\mathbf{p}$ : 一個 dictionary, work package (key) 映射到對應的 work item report (value) :question:
- 一個 core 一次只能處理一個 WR -> 不應該超過 $\mathsf{C}=341$ 的數量
:::
> ⟦ (U+27E6) $[\![x]\!]$
> ⟧ (U+27E7)
---
在 accumulate 期間,部份狀態更新,recent blocks $\beta$ 會更新最新的 parent block 的 state root

(7.2)
$$
\beta^{\dagger} \equiv \beta \quad \text{except } \quad \beta^{\dagger} \left[ |\beta| - 1 \right]_s = \mathbf{H}_r
$$
:::info
- $\beta^{\dagger}[|\beta| - 1]_s$: recent blocks 最後一個區塊的 state root (hash)
- $\beta^{\dagger}$: 更新後的 recent blocks
- $\mathbf{H}_r$: prior state root (parent state root)
- $\mathbf{H}_r \equiv \mathcal{M}_{\sigma}(\sigma)$
==:question:問題:是因為狀態轉換後,區塊才是最終確定,因此將近期區塊集合中,最後一個區塊的 state root, 更新為當前區塊的 $\mathbf{H}_r$ (prior state root)?==
> [name=yu2c] 複製 $\beta$ 到 $\beta^{\dagger}$ 除了裡面 state root 要用後面條件更新
:::
---
以下會定義 recent block 中的數值是如何被計算出來的

$n$ 是一個新的近期區塊
==:question:小問題:不過為什麼他的 tuple 元素順序與 $\beta$ 定義的不同?==
$$
\text{let } n = ({\mathbf{p}, h:\mathcal{H}(\mathbf{H}), \mathbf{b}, s:\mathbb{H}^0})
$$
:::info
- $\mathbf{p}$: work-reports
- h: header hash
- ==尚未閱讀==$\mathbf{b}$: MMR(Merkle Range Mountain) append function $\mathcal{A}$ 的計算結果 (參考 appendix E.2)
- $s$: state-trie root, 是一個 zero hash ($\mathbb{H}^0$)
- zero hash: $[0, 0, 0,...]_{32}$
:::
---
(7.3)
$$
\text{let } r = \mathcal{M}_B ([s \wr \mathcal{E}_4(s) \frown \mathcal{E}(h)) \mid (s, h) \in \mathbf{C}], \mathcal{H}_K)
$$
:::info
- $r$: accumulation-result tree root
- 從 $\mathbf{C}$ 導出,定義於 section 12 ==尚未閱讀==
- 此變數 $r$ 會使用在 $\mathbf{b}$ 公式中
- $\mathcal{M}_B$: binary Merklization function (定義於 Appendix E.) ==尚未閱讀==
- $s$: state root
- $h$: header hash
- $\mathcal{E}$: 序列化函數
- $\mathcal{E}_4$: 定義了輸出長度為 4 個八位元組
- $\wr$: 基於 $s$ 進行排序
- $\mathcal{H}_K$: The Keccak 256-bit hash function. See section 3.8.
:::
---
$$
\text{let } \mathbf{b} = \mathcal{A}(\text{last}([[]] \frown [x_\mathbf{b} \mid x ⪪ \beta ], r, \mathcal{H}_K)
$$
:::info
把最後一個 $x_\mathbf{b}$ append 到 r by $\mathcal{A}$ (如果是第一個區塊, 沒有 $\beta$, last 就會拿到空序列[[]])
- $\mathbf{b}$: MMR(Merkle Range Mountain) append function $\mathcal{A}$ 的計算結果 (參考 appendix E.2)==尚未閱讀==
- $[x_\mathbf{b} \mid x ⪪ \beta ]$: 將 $\beta$ 中的區塊 $x$ 的 $b$ 輸出為序列 [$x_{1_b}$ , $x_{2_b}$ , $x_{3_b}$ ,...]
- $r$: accumulation-result tree root
- $\mathcal{H}_K$: The Keccak 256-bit hash function. See section 3.8.
:::
> ⪪ (U+2AAA)
---
$$
\text{let } \mathbf{p} = \{((g_w)_s)_h \mapsto ((g_w)_s)_e \mid g \in \mathbf{E}_G\}
$$
:::info
- $\mathbf{p}$: 一個 dictionary
- key: $((g_w)_s)_h$
- $g_w$: guarantee 的 work report
- $s$: work report 的 package specification
- $h$: work package 的 hash
- value: $((g_w)_s)_e$
- $g_w$: guarantee 的 work report
- $s$: work report 的 package specification
- $e$: segement root (hash)
> 11.1.1. work report: 定義 work report
> 11.1.3. Availability: 定義 availability specifications $\mathbb{S}$ (work report spec)
> 11.39 定義相同的公式 $\mathbf{p}$
:::
---
- $n$ 中使用 $s: \mathbb{H}^0$ (state root) 作為 recent blocks $\beta^{\prime}$ 的最後狀態並不正確, 但這是安全的 :arrow_right: 因為 $\beta'$ 只會用來定義下一個區塊的 $\beta^{\dagger}$, $\beta^{\dagger}$ 會包含更新後正確的數值。
- 7.2 公式,有提到狀態更新後,會將 $\beta$ 的 state root 進行更新,轉換為 $\beta'$, 因此 zero hash 的數值將會被正確的 parent state root 更新。
(7.4)
$$
\beta' \equiv \overleftarrow{\beta^{\dagger} ⧺ n}^H
$$
:::info
- $\beta'$: 新的 recent blocks
- $\beta^{\dagger}$: 舊的 recent blocks
- $\overleftarrow{s}^\mathsf{n}$: 代表從序列 $s$ 中,從後面最後面 $n$ 元素
- ⧺: 該符號代表序列的串連, 兩個序列中的元素合併
- $\beta^{\dagger}$ 串上新的 recent block 後, 由後面往前取(取新的) $H=8$ 個元素, 就會等同於 $\beta'$
:::
> ⧺ (U+29FA)