midnight-onchain-logic
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseOnchain Logic and State
链上逻辑与状态
The Midnight node follows the standard Polkadot SDK model: core logic (except native pre-compiles) compiles to WebAssembly (WASM) and forms the runtime — the state transition function executed identically on every node.
Midnight节点遵循标准的Polkadot SDK模型:核心逻辑(原生预编译合约除外)编译为WebAssembly (WASM)并构成运行时(runtime)——每个节点都会执行相同的状态转换函数。
Runtime architecture
运行时架构
mermaid
flowchart TB
subgraph Runtime["WASM Runtime"]
direction TB
PA["pallet-aura"]
PG["pallet-grandpa"]
PS["pallet-partnerchains-session"]
PVM["pallet_session_validator_management"]
PM["pallet-midnight ★"]
Other["Other FRAME pallets"]
end
Block["Incoming block + extrinsics"] --> Runtime
Runtime --> Trie["Patricia-Merkle trie commit"]
Trie --> DB["ParityDB persistence"]
PM --> Ledger["Midnight Ledger state commitment"]mermaid
flowchart TB
subgraph Runtime["WASM Runtime"]
direction TB
PA["pallet-aura"]
PG["pallet-grandpa"]
PS["pallet-partnerchains-session"]
PVM["pallet_session_validator_management"]
PM["pallet-midnight ★"]
Other["Other FRAME pallets"]
end
Block["Incoming block + extrinsics"] --> Runtime
Runtime --> Trie["Patricia-Merkle trie commit"]
Trie --> DB["ParityDB persistence"]
PM --> Ledger["Midnight Ledger state commitment"]FRAME pallets
FRAME pallets
Each FRAME pallet encapsulates a domain of on-chain logic and may define:
- Storage (maps, multi-maps, lists, values)
- Events
- Dispatchable functions (transactions)
- Offchain workers
- Hooks
- Host-exposed functions
- RPC methods
This modular design is similar in spirit to a smart contract framework, but logic is compiled ahead of time and governed at the chain level.
每个FRAME pallet封装了一个链上逻辑领域,可能定义:
- 存储(映射、多映射、列表、值)
- 事件
- 可调度函数(交易)
- 链下工作器
- 钩子
- 主机暴露函数
- RPC方法
这种模块化设计在理念上类似智能合约框架,但逻辑是提前编译并在链层面进行管控的。
Key pallets on Midnight
Midnight上的关键pallets
| Pallet | Role |
|---|---|
| Block production via AURA |
| Finality via GRANDPA |
| Session rotation in Partnerchain context |
| Validator set coordination |
| Core privacy-preserving transaction logic |
| Pallet | 角色 |
|---|---|
| 通过AURA生成区块 |
| 通过GRANDPA实现最终确定性 |
| 合作链场景下的会话轮换 |
| 验证者集协调 |
| 核心隐私保护交易逻辑 |
pallet-midnight: the ledger state machine
pallet-midnight:账本状态机
pallet-midnightmermaid
sequenceDiagram
participant Tx as Ledger transaction
participant Pool as Transaction pool
participant PM as pallet-midnight
participant Lib as Native proof libraries
participant State as On-chain storage
Tx->>Pool: Submit (unsigned, proof-embedded)
Pool->>Pool: Well-formedness check
Pool->>PM: Included in block
PM->>Lib: Verify cryptographic proof
Lib-->>PM: Valid / invalid
PM->>State: Execute state transition
State->>State: Commit trie + ledger commitmentpallet-midnightmermaid
sequenceDiagram
participant Tx as Ledger transaction
participant Pool as Transaction pool
participant PM as pallet-midnight
participant Lib as Native proof libraries
participant State as On-chain storage
Tx->>Pool: Submit (unsigned, proof-embedded)
Pool->>Pool: Well-formedness check
Pool->>PM: Included in block
PM->>Lib: Verify cryptographic proof
Lib-->>PM: Valid / invalid
PM->>State: Execute state transition
State->>State: Commit trie + ledger commitmentWhat it processes
处理内容
- ZSwap asset transfers
- Contract operations (deploy, invoke)
- Specialized transactions from the Midnight Ledger format
- ZSwap资产转移
- 合约操作(部署、调用)
- Midnight Ledger格式的特殊交易
Validation model
验证模型
- Not traditional signature-based dispatch for ledger txs.
- Each transaction embeds a cryptographic proof attesting validity.
- Native libraries verify proofs and execute corresponding state transitions.
- 账本交易不采用传统的基于签名的调度方式。
- 每笔交易都嵌入一份密码学证明以证明其有效性。
- 原生库验证证明并执行相应的状态转换。
State commitment
状态承诺
After execution:
- New state is committed on-chain.
- Canonical ledger state lives in a Patricia-Merkle trie backed by a key-value database.
- A commitment to the full Midnight Ledger state is persisted per block — tamper-proof and verifiable.
执行完成后:
- 新状态在链上提交。
- 规范账本状态存储在由键值数据库支持的Patricia-Merkle前缀树中。
- 每个区块都会持久化一份完整Midnight Ledger状态的承诺——防篡改且可验证。
Public vs ledger state
公共状态 vs 账本状态
| State type | Where | Visibility |
|---|---|---|
| Substrate runtime storage | Patricia-Merkle trie | Standard on-chain queries |
| Midnight Ledger commitment | Persisted per block | Verifiable snapshot of ledger |
| Contract ledger fields | Via | Selectively public per contract design |
For application-level privacy patterns, see and .
why-midnight/compact/| 状态类型 | 存储位置 | 可见性 |
|---|---|---|
| Substrate运行时存储 | Patricia-Merkle前缀树 | 标准链上查询 |
| Midnight Ledger承诺 | 按区块持久化 | 可验证的账本快照 |
| 合约账本字段 | 通过Compact中的 | 根据合约设计选择性公开 |
如需了解应用级隐私模式,请查看和。
why-midnight/compact/Related skills
相关技能
- — AURA + GRANDPA pallets
midnight-consensus/ - — transaction pool → runtime → commit lifecycle
midnight-transactions/ - — ParityDB + trie details
midnight-storage/ - — querying contract and ledger state via RPC
midnight-rpc/
- — AURA + GRANDPA pallets
midnight-consensus/ - — 交易池→运行时→提交生命周期
midnight-transactions/ - — ParityDB + 前缀树细节
midnight-storage/ - — 通过RPC查询合约和账本状态
midnight-rpc/