# Smooth 模块化区块链系列教程(五): Celestia App

By [wiger.eth](https://paragraph.com/@wiger) · 2022-10-13

---

### Celestia App: 一个 PoS 链

![Celestia App](https://storage.googleapis.com/papyrus_images/921c7c246fd2e4642c07bb23084f6c2ff685cb425e7307638e691ae2137bba0b.png)

Celestia App

Celestia 本质上由 PoS 区块链组成，这条链被称作 Celestia App，采用 Cosmos SDK 构建。

Celestia App 建立在 Celestia Core 之上，Celestia Core 通过 Tendermint 共识算法的修改得到，修改的地方在前文提到过，同时 Celestia Core 节点仍在使用 Tendermint p2p 网络：

1.  采用了 2D R-S 编码方案：
    
    [https://mirror.xyz/wiger.eth/sqxu0qWWyS6TmxH89qKlmDGkdjh2g-HseZLygIWBOwQ](https://mirror.xyz/wiger.eth/sqxu0qWWyS6TmxH89qKlmDGkdjh2g-HseZLygIWBOwQ)
    
2.  将 Tendermint 中存储数据的常规 Merkle Tree 替换为 Namespaced Merkle Tree：
    
    [https://mirror.xyz/wiger.eth/WkJKoUoqgROOx\_orWrCETZSy5vJfb-Fyo-r9uP8bGZY](https://mirror.xyz/wiger.eth/WkJKoUoqgROOx_orWrCETZSy5vJfb-Fyo-r9uP8bGZY)
    

与 Tendermint 类似，Celestia Core 通过 ABCI 连接到应用层（即状态机），Celestia App 状态机是执行 PoS 和进行 DA 层治理所必需的。

但 Celestia App 与数据无关：状态机既不验证也不存储 Celestia App 提供的数据。

### Celestia App 上交易的生命周期

![The Lifecycle of a Celestia App Transaction](https://storage.googleapis.com/papyrus_images/f123f2f23198914b83d4468df74802403e5bb4c5b60aab958fab2ebe81537361.png)

The Lifecycle of a Celestia App Transaction

1.  用户通过 PayForData 交易，向 Celestia App (Celestia Core) 请求，使交易数据可用。
    
2.  在 Block Producer 中，Celestia Core 通过 ABCI 将 PayForData 交易传递给状态机。
    
3.  状态机将 PayForData 交易拆分为 2 部分，并传回给 Celestia Core：
    
    1.  Msg 命名空间消息：当中包含了交易数据和 Namespace ID。
        
    2.  e-Tx 可执行交易：不包含数据，只有一个 commitment 在之后用于证明数据可用。
        
4.  每个出块的节点，将多笔 PayForData 打包在一个块内，块中就包含了上面提到的 Msg 和 e-Tx。
    
5.  然后区块生产者向块头添加块数据的 commitment，不同于 e-Tx 的 commitment，这里的是 2D R-S 编码后 4k 个交易 Merkle Roots 的 Merkle Root。
    
6.  最后出块。
    

### 检验数据可用性

![Checking Data Availability](https://storage.googleapis.com/papyrus_images/f149fd61b961c060c49b66e192a346840893ba7db2b3fef9f3cad320ada72770.png)

Checking Data Availability

Celestia 采用了一个 DA Network 来为 Consensus Network 处理 DAS 验证，二者通过 RPC 通信。

1.  轻节点向全节点请求通过 2D R-S 编码得到的 4k Merkle Roots 和 DA 原始数据。
    
2.  轻节点在获取数据后进行 DAS 抽样验证，只要有一个查询失败，即没有收到数据块，或 Merkle 证明无效，则轻节点拒绝区块头部并稍后重试。
    
3.  轻节点还可以通过全节点，向 Celestia App 提交 PayForData 交易。
    

有时候尽管数据不可用，轻节点也可以接受区块头部，即误报。

通过微调 Celestia 的参数，例如，每个轻节点采样数据块的数量，可以充分降低误报的可能性，从而使区块生产者没有动机扣留区块数据。

### 引用

> Celestia's Data Availability Layer: [https://docs.celestia.org/concepts/how-celestia-works/data-availability-layer](https://docs.celestia.org/concepts/how-celestia-works/data-availability-layer)

> The Lifecycle of a Celestia App Transaction: [https://docs.celestia.org/concepts/how-celestia-works/transaction-lifecycle](https://docs.celestia.org/concepts/how-celestia-works/transaction-lifecycle)

---

*Originally published on [wiger.eth](https://paragraph.com/@wiger/smooth-celestia-app)*
