x/crisis 已迁移至 ./contrib/x/crisis,不再作为 Cosmos SDK 核心的一部分进行积极维护。它仍可继续使用,但不包含在 SDK 漏洞赏金计划中。该模块之所以被迁移,是因为它从未按预期方式工作。

概述

当区块链不变量被破坏时,crisis 模块会停止区块链运行。不变量可以在应用初始化过程中注册到应用中。

目录

状态

ConstantFee

由于校验不变量预计需要消耗大量 gas,并且可能超过区块允许的最大 gas 上限,因此这里使用固定费用,而不是标准的 gas 消耗方式。该固定费用的设计目标是高于使用标准 gas 消耗方式执行不变量检查时的预期 gas 成本。 ConstantFee 参数以 0x01 前缀存储在模块参数状态中,可以通过治理或由具备权限的地址进行更新。
  • 参数:mint/params -> legacy_amino(sdk.Coin)

消息

本节介绍 crisis 消息的处理流程,以及它们对状态产生的相应更新。

MsgVerifyInvariant

可以使用 MsgVerifyInvariant 消息检查区块链不变量。
// Reference: https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/proto/cosmos/crisis/v1beta1/tx.proto#L26-L42
在以下情况下,该消息预期会失败:
  • 发送者没有足够的代币支付固定费用
  • 不变量路由未注册
该消息会检查所提供的不变量;如果该不变量被破坏,则会触发 panic,从而使区块链停止运行。如果不变量被破坏,由于交易不会被提交到区块中,因此不会扣除固定费用,等价于被退还。然而,如果不变量未被破坏,则固定费用不会退还。

事件

crisis 模块会发出以下事件:

处理器

MsgVerifyInvariant

类型属性键属性值
invariantroute{invariantRoute}
messagemodulecrisis
messageactionverify_invariant
messagesender{senderAddress}

参数

crisis 模块包含以下参数:
键类型示例
ConstantFeeobject (coin){"denom":"uatom","amount":"1000"}

客户端

CLI

用户可以使用 CLI 查询并与 crisis 模块交互。

交易

tx 命令允许用户与 crisis 模块交互。
simd tx crisis --help
invariant-broken
invariant-broken 命令会在不变量被破坏时提交证明,以停止链运行
simd tx crisis invariant-broken [module-name] [invariant-route] [flags]
示例:
simd tx crisis invariant-broken bank total-supply --from=[keyname or address]

x/crisis has been moved to ./contrib/x/crisis and is no longer actively maintained as part of the core Cosmos SDK. It is still available for use but is not included in the SDK Bug Bounty program. The module was moved because it never worked as intended.

Overview

The crisis module halts the blockchain under the circumstance that a blockchain invariant is broken. Invariants can be registered with the application during the application initialization process.

Contents

State

ConstantFee

Due to the anticipated large gas cost requirement to verify an invariant (and potential to exceed the maximum allowable block gas limit) a constant fee is used instead of the standard gas consumption method. The constant fee is intended to be larger than the anticipated gas cost of running the invariant with the standard gas consumption method. The ConstantFee param is stored in the module params state with the prefix of 0x01, it can be updated with governance or the address with authority.
  • Params: mint/params -> legacy_amino(sdk.Coin)

Messages

In this section we describe the processing of the crisis messages and the corresponding updates to the state.

MsgVerifyInvariant

Blockchain invariants can be checked using the MsgVerifyInvariant message.
// Reference: https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/proto/cosmos/crisis/v1beta1/tx.proto#L26-L42
This message is expected to fail if:
  • the sender does not have enough coins for the constant fee
  • the invariant route is not registered
This message checks the invariant provided, and if the invariant is broken it panics, halting the blockchain. If the invariant is broken, the constant fee is never deducted as the transaction is never committed to a block (equivalent to being refunded). However, if the invariant is not broken, the constant fee will not be refunded.

Events

The crisis module emits the following events:

Handlers

MsgVerifyInvariant

TypeAttribute KeyAttribute Value
invariantroute{invariantRoute}
messagemodulecrisis
messageactionverify_invariant
messagesender{senderAddress}

Parameters

The crisis module contains the following parameters:
KeyTypeExample
ConstantFeeobject (coin){"denom":"uatom","amount":"1000"}

Client

CLI

A user can query and interact with the crisis module using the CLI.

Transactions

The tx commands allow users to interact with the crisis module.
simd tx crisis --help
invariant-broken
The invariant-broken command submits proof when an invariant was broken to halt the chain
simd tx crisis invariant-broken [module-name] [invariant-route] [flags]
Example:
simd tx crisis invariant-broken bank total-supply --from=[keyname or address]