# 4.7 MPT + LevelDB

DxChain使用了MPT树（Merkle Patricia Trie）作为数据组织形式，不仅可用来组织并管理用户的账户状态、交易信息、区块信息等重要数据，还能达到区块链数据高性能存储、不可篡改的目的。MPT是一种加密认证的数据结构，它融合了Merkle树和Trie树（前缀树）两种数据类型的优点。在MPT树中，数据节点的Key值通常存储着从根节点到Value所在子节点的路径。

在DxChain中，该Key值由节点数据的RLP编码（Recursive length prefix encoding，递归长度前缀编码）的SHA3散列值产生，Value值由节点数据的RLP编码产生，整个MPT树的数据存储在内置LevelDB数据库中。想要获得一个数据节点的内容，只需要根据该数据节点的散列值访问数据库以获得节点的RLP编码，然后进行RLP解码即可。

结合Merkle树的优点，MPT树允许区块的数据零散的传送，避免固定顺序传送带来的传输效率低下，允许节点从不同的P2P节点同步区块数据，确保来自不同源同步数据的准确性。同时由于MPT树是自下向上扩散的结构，如果节点数据被恶意篡改，MPT树中该数据节点后的所有节点数据都将发生偏差，DxChain区块验证机制将无法验证该区块数据，并不会记录在区块链网络中，以此防止恶意区块的产生。

下图展示了一个MPT树的底层节点数据被篡改后，自它以上的节点数据散列值都将存在偏差。

<figure><img src="/files/yWnr5rGf67PvEGBUaGZK" alt=""><figcaption><p>图9：交易数据篡改前后的MPT树</p></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dxchain.gitbook.io/dxchain-wiki/zhong-wen-she-qu/dxchain-v3-ji-shu-wen-dang/4.-ji-shu-de-she-ji-yuan-li-yu-jia-gou/4.7-mpt-+-leveldb.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
