CKB Pulse

全部经验 · CKB node, RPC and indexer · 从这里开始 · 术语表

Computing a transaction's molecule packed size from RPC JSON进阶来自一次修复

来自一次修复 · 核对结果:正确 · 核对于 2026-11-19

A CKB Transaction's packed size (the length of get_transaction with verbosity 0) can be computed from its RPC JSON without serializing it. It is 12 (table header) + RawTransaction + witnesses. RawTransaction is 28 (table header) + 4 (version) + cell_deps (4 + 37 each) + header_deps (4 + 32 each) + inputs (4 + 44 each) + outputs + outputs_data. Each CellOutput is 16 + 8 + lock size, plus the type script size only when a type is present. Each Script is 53 + len(args). A dynvec costs 4 + 4 * count + the sum of its item sizes, and every Bytes item in outputs_data and witnesses costs 4 + len.

为什么重要: Without the exact molecule layout, a tool cannot confirm the node's reported packed transaction size from RPC JSON. The cross-check against the measured node wire bytes would then fail or be skipped.

代码模式

推荐
return 12 + raw_size + dynamic([4 + len(raw(v)) for v in tx['witnesses']])

摘自提交,已缩短。

概念
Data encoding (molecule, hex, bigints), Transaction building and fees
证据
来自一次修复: 来自一个项目,已对照其提交核对
首次出现
2026-10-10
最近改动
2026-10-10
最近核对
2026-11-19
对照提交的核对结果
正确:这条经验出自该提交,并且在今天的代码中仍然成立

来源(1)

更多关于CKB node, RPC and indexer

查看此主题的全部 45 条

你维护这条经验的来源项目吗?请确认或纠正

引用这条经验
LusoCryptoLabs, "Computing a transaction's molecule packed size from RPC JSON", CKB lessons, https://pulse.lusocryptolabs.com/learned/node/computing-a-transaction-s-molecule-packed-size-from-rpc-json, CC BY 4.0, last changed 2026-10-10.

取自公开提交,并对照每条经验的来源提交和项目当前代码做了核对。使用前请先读来源。 文本采用 CC BY 4.0:请署名 LusoCryptoLabs, CKB lessons,并附上经验的链接。 想修改或撤下某条经验?请提交 issue。