qkc/types: refactor transactions to two-layer TxData - #43
Open
ping-ke wants to merge 1 commit into
Open
Conversation
Restructure QKC transactions from the three-layer Transaction -> EvmTransaction -> txdata model to a geth-style two-layer Transaction -> QkcTx (implements TxData) model. Wire bytes, transaction hash, signature results and minor-block Merkle root are preserved for existing (v0) transactions. Caches and setters move to the outer Transaction, and version-2 signing is now internally consistent. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
ping-ke
requested review from
blockchaindevsh,
iteyelmp,
qizhou,
qzhodl and
syntrust
July 28, 2026 16:40
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
QKC Transaction 两层设计
1. 改什么
将 goquarkchain 的现有设计,也就是本 branch 修改前
qkc/types/transaction.go的三层对象结构:改成类似 geth
Transaction/LegacyTx的两层对象结构:TxData只是接口约束,不是额外的数据包装层。Transaction.inner的类型是TxData,实际保存*QkcTx。具体修改:
EvmTransaction和内部txdata合并为QkcTx,直接保存 Nonce、Gas 和签名等交易字段。Transaction通过TxData接口读写和编码交易数据,QkcTx提供具体实现;新增交易类型只需实现TxData。Transaction。setter 修改交易字段时会清理相关 cache,避免后续返回修改前的 hash、size 或 sender。NewQkcTransaction和NewQkcContractCreation,并直接返回*Transaction。Serialize、hash 或签名的FromShardsize、ToShardsize字段、getter 和 setter。相关计算直接使用常量1。兼容性说明:
Serialize/Deserialize、交易 hash、签名和 minor-block Merkle leaf 的实现会随新结构做适配,但编码格式和计算结果保持不变。Deserialize根据 type byte 创建对应的TxData实现后解码;DecodeRLP处理不包含 type byte 的 inner RLP,目前创建唯一支持的QkcTx实现。新增交易类型时可以参考core/types/transaction.go的扩展方式。2. 有什么好处
Transaction + TxData implementation模型一致,更容易理解和 review。core/types时,由于两者结构一致、接口相似,扩展和迁移都会更简单。外部调用的修改简单直观,大部分是删除
.EvmTx:新增交易类型
修改前,
Transaction直接保存每一种具体交易。新增类型需要修改Transaction,调用方也需要根据TxType访问不同字段:修改后,
Transaction只保存TxData。新类型实现TxData,调用方继续使用外层统一接口:新增类型还需要在 type factory 中增加对应的解码分支,但不需要给
Transaction增加新字段。3. 修改量
除了当前代码的修改,参考 goquarkchain 的实际使用场景:
.EvmTx的简单机械替换。NewEvmTransaction、NewEvmContractCreation约有 69 处调用,都需要分别重命名为NewQkcTransaction、NewQkcContractCreation。EvmTransaction的代码可以直接删除:整体上,这是一次范围较广但以机械修改为主。实现和 review 时需要重点验证
Serialize/Deserialize的交易字节、交易 hash、签名结果及 minor-block Merkle root 与修改前完全一致。