变更记录

  • 2023-03-12:提案中

背景

事务校验对于一个正常运行的状态机至关重要。在 Cosmos SDK 中,存在两条校验流程,一条位于消息服务器之外,另一条位于消息服务器之内。位于消息服务器之外的流程是 ValidateBasic 函数。它会在 antehandler 中于 CheckTx 和 DeliverTx 两个阶段被调用。这两条流程中的校验存在一定开销,有时还会出现重复。这部分额外校验会在事务进入 mempool 之前提供一次附加检查。 随着 GetSigners 被弃用,我们可以选择移除 sdk.Msg 和 ValidateBasic 函数。 随着 CometBFT 与 Cosmos-SDK 的分离,我们对哪些事务会被广播并纳入区块的控制能力有所不足。antehandler 中的这部分额外校验正是为此场景提供帮助。在大多数情况下,事务本来就会或应当先在某个节点上进行模拟校验。采用这一流程后,事务将被以相同方式处理。

提案

如果本 RFC 被接受,将把 ValidateBasic 中的校验逻辑迁移到各模块的消息服务器中,同时更新教程和文档,不再提及使用 ValidateBasic,改为在消息实际执行的位置统一处理该消息的全部校验逻辑。 我们仍然可以并且也会继续为用户支持 ValidateBasic 函数,并在 sdk.Msg 被弃用后为该函数提供一个扩展接口。
注意:这也是 Ethereum 和 CosmWasm 这类虚拟机处理消息的方式。

后果

更新事务流程带来的结果是:某些原本可能会在 ValidateBasic 流程中失败的事务,现在将被纳入区块并收取手续费。

Changelog

  • 2023-03-12: Proposed

Background

Transaction Validation is crucial to a functioning state machine. Within the Cosmos SDK there are two validation flows, one is outside the message server and the other within. The flow outside of the message server is the ValidateBasic function. It is called in the antehandler on both CheckTx and DeliverTx. There is an overhead and sometimes duplication of validation within these two flows. This extra validation provides an additional check before entering the mempool. With the deprecation of GetSigners we have the optionality to remove sdk.Msg and the ValidateBasic function. With the separation of CometBFT and Cosmos-SDK, there is a lack of control of what transactions get broadcasted and included in a block. This extra validation in the antehandler is meant to help in this case. In most cases the transaction is or should be simulated against a node for validation. With this flow transactions will be treated the same.

Proposal

The acceptance of this RFC would move validation within ValidateBasic to the message server in modules, update tutorials and docs to remove mention of using ValidateBasic in favour of handling all validation for a message where it is executed. We can and will still support the ValidateBasic function for users and provide an extension interface of the function once sdk.Msg is deprecated.
Note: This is how messages are handled in VMs like Ethereum and CosmWasm.

Consequences

The consequence of updating the transaction flow is that transaction that may have failed before with the ValidateBasic flow will now be included in a block and fees charged.