mcpField
M
midnight-transactions

midnight-transactions

github.com/kali-decoder开发18126 次安装1 天前更新
代码仓库

关于 midnight-transactions

介绍 Midnight 网络交易流程的技术技能,面向 dApp 开发者和节点运营者。内容说明基于证明的交易格式、交易池检查、运行时执行与最终确认。

主要功能

  1. 01Midnight 交易生命周期概览
  2. 02基于证明的验证模型
  3. 03区分交易池与运行时检查
  4. 04部署、调用和 ZSwap 交易类型
  5. 05提交与最终确认阶段

适用场景

  1. 01了解 dApp 如何提交交易
  2. 02区分交易池检查与证明验证
  3. 03追踪合约或 ZSwap 状态更新
  4. 04从节点运营角度审视交易处理

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/kali-decoder/midnight-skills --skill midnight-transactions

安装后在 Claude Code 中输入/midnight-transactions确认已加载。

详细介绍

交易

Midnight 节点支持标准的 Polkadot SDK 交易格式,但实际上,默认的 Substrate 风格签名外部交易 并不常见。Midnight 依赖与 Midnight Ledger 紧密耦合的 基于证明的验证模型。

生命周期概览

flowchart TB
  Build["Build transaction + ZK proof<br/>(wallet / SDK)"]
  Submit["Submit to node RPC / P2P"]
  Pool["Transaction pool<br/>well-formedness check"]
  Block["Included in block"]
  Verify["Runtime verifies embedded proof"]
  Execute["Execute state transition"]
  Commit["Commit to trie + ledger commitment"]

  Build --> Submit --> Pool
  Pool -->|Valid structure| Block
  Pool -->|Reject| Reject["Dropped from pool"]
  Block --> Verify
  Verify -->|Invalid proof| Fail["Transaction fails"]
  Verify -->|Valid| Execute --> Commit

基于证明的模型

大多数 Midnight 交易都是 未签名的,并遵循 Midnight Ledger 格式。

传统链Midnight
签名授权操作加密证明证明交易有效
公开的签名者身份敏感数据保留在链下/证明中
标准外部交易格式Ledger 专用交易封装

该证明使网络能够验证状态转换,而无需直接暴露敏感数据或原始签名。

交易类型
  • 合约部署
  • 合约调用(电路调用)
  • ZSwap 资产转移

处理阶段

1. 提交

客户端(钱包、SDK、dApp)将交易提交到节点的 RPC,或通过 P2P gossip 传播。

2. 交易池验证

交易池检查交易是否 格式正确:

  • 符合运行时和 Ledger 规范的结构要求
  • 逻辑前置条件(格式、大小、基本有效性)
  • 此时 不会进行完整的证明验证(该验证在区块执行时进行)
sequenceDiagram
  participant Client
  participant Pool as Tx pool
  participant Block as Block author
  participant RT as Runtime (pallet-midnight)

  Client->>Pool: Submit unsigned proof tx
  Pool->>Pool: Well-formedness validation
  alt Invalid
    Pool-->>Client: Reject
  else Valid
    Pool->>Block: Candidate for inclusion
    Block->>RT: Execute in block
    RT->>RT: Full proof verification
    RT->>RT: State transition + commit
  end
3. 纳入区块

区块生产者(AURA 验证者)将交易纳入新区块。

4. 运行时验证与执行

pallet-midnight:

  1. 完整验证嵌入的加密证明(原生库)。
  2. 如果证明有效,执行相应的状态转换。
  3. 将更新后的状态提交到链上存储。
5. 最终确定

区块纳入后,可通过 GRANDPA 异步最终确定。


对比:交易池检查与运行时检查

检查项位置内容
格式正确性交易池结构、基本有效性
证明验证运行时(pallet-midnight)完整的加密验证
状态转换运行时ZSwap/合约状态更新
持久化存储层Trie + Ledger 提交

构建和提交交易(dApp 场景)

面向应用开发者:

层技能
生成证明 + 提交交易midnight-js/、1am-wallet/
合约逻辑compact/
读取结果midnight-indexer/、midnight-rpc/

节点运营者关注交易池大小、区块限制和 RPC 提交端点。


相关技能

  • midnight-onchain-logic/ — pallet-midnight 执行
  • midnight-storage/ — 提交内容的持久化方式
  • midnight-consensus/ — 哪些参与者会将交易纳入区块
  • midnight-rpc/ — 提交和状态查询端点
  • compact/ — 合约层面的证明内容

评论

支持 Markdown