Injective | Documentation
InjectiveGithub
Injective | 中文文档
Injective | 中文文档
  • 关于 Injective
  • 快速入门
    • 钱包
      • 创建钱包
      • 账户
      • 质押
      • 治理
      • 拍卖
    • 代币标准
      • INJ 代币
      • Token Factory
      • CW20 标准
    • 交易
      • Gas 和 Fees
  • 指南
    • 创建钱包
    • 桥接
      • From Ethereum
      • Using Wormhole
      • Using IBC
      • From Solana
    • 发布代币
    • 发布市场
    • Denom 元数据
    • 获取INJ
  • 工具包
    • injectived
      • 安装 injectived
      • 使用 injectived
      • 指令
    • Injective TS SDK
    • Injective Go SDK
    • Injective Python SDK
    • Injective CW SDK
    • The Graph
  • 参考
  • 术语表
  • 开发者
    • 快速入门
      • 指南
        • 测试网提案
        • 转换地址
        • 计算
          • 最低价格刻度
          • 最低数量刻度
    • 交易所开发者
      • 构建 DEX
      • 预言机提供方
    • Cosmwasm 开发者
      • 您的首个智能合约
      • 指南
        • 本地开发
        • 主网开发
        • 给部署地址白名单
        • 创建您的 Swap 合约
        • 创建 UIs
      • CW20 适配器
      • Injective Test Tube
    • 模块
      • Injective
        • 拍卖(Auction)
          • State
          • 消息
          • EndBlock
          • 事件
          • 参数
        • 交易所(Exchange)
          • 衍生品市场概念
          • 现货市场概念
          • 二元期权市场概念
          • 其他概念
          • 状态
          • 状态转换
          • 消息
          • 提案
          • BeginBlock
          • EndBlock
          • 事件
          • 参数
          • MsgPrivilegedExecuteContract
        • 保险(Insurance)
          • 状态
          • 状态转换
          • 消息
          • EndBlock
          • 事件
          • 参数
          • 改进
        • OCR
          • 概念
          • 状态
          • 消息
          • 提案
          • BeginBlock
          • 钩子(Hooks)
          • 事件
          • 参数
        • 预言机(Oracle)
          • 状态
          • Keeper
          • 消息
          • 提案
          • 事件
          • 改进
        • Peggy
          • 定义
          • 工作流
          • 状态
          • 消息
          • 处罚
          • EndBlock
          • 事件
          • 参数
          • 中继语义
          • 改进
        • 权限(Permissions)
          • 概念
          • 状态
          • 状态转换
        • 代币工厂(TokenFactory)
          • 概念
          • 状态
          • 消息
          • 事件
          • 参数
        • WasmX
          • 概念
          • 数据
          • 提案
          • 消息
          • 参数
      • 核心
        • Auth
        • AuthZ
        • 银行(Bank)
        • 共识(Consensus)
        • 危机(Crisis)
        • 分发(Distribution)
        • 证据(Evidence)
        • 费用授权(Feegrant)
        • 治理(Gov)
        • 群组(Group)
        • 铸造(Mint)
        • NFT
        • 参数(Params)
        • 惩罚(Slashing)
        • 质押(Staking)
        • 升级(Upgrade)
        • Circuit
        • Genutils
    • dApps 开发文档
  • 节点
    • 快速入门
      • 和节点交互
      • 运行节点
        • 设置密钥环
        • 加入网络
        • Cosmovisor
        • 升级您的节点
    • 验证者
      • 主网
        • Peggo
        • 规范链升级
          • Upgrade to 10002-rc1
          • Upgrade to 10002-rc2
          • Upgrade to 10003-rc1
          • Upgrade to 10004-rc1
          • Upgrade to 10004-rc1-patch
          • Upgrade to 10005-rc1
          • Upgrade to 10006-rc1
          • Upgrade to 10007-rc1
          • Upgrade to 10008 - Camelot
          • Upgrade to 10009
          • Upgrade to v1.10
          • Upgrade to v1.11
          • Upgrade to v1.12.0 - Volan
          • Upgrade to v1.12.1
          • Upgrade to v1.13.0 - Altaris
          • Upgrade to v1.13.2
          • Upgrade to v1.13.3
          • Upgrade to v1.14.0
          • Upgrade to v1.14.1
      • 测试网
        • 测试网 Peggo
    • 公共端点
    • 高级端点
    • Injective 索引器设置
  • 交易员
    • 快速入门
    • 文档
    • API 参考
  • 常用链接
    • Injective 101
    • Injective Hub
    • Injective 浏览器
    • Chain API Reference
    • Indexer API Reference
    • 测试网水龙头
Powered by GitBook
On this page
  • 概念
  • 状态
  • Accounts
  • Disable List
  • 状态转移
  • Authorize
  • Trip
  • Reset
  • 消息
  • MsgAuthorizeCircuitBreaker
  • MsgTripCircuitBreaker
  • MsgResetCircuitBreaker
  • 事件 - 列出并描述事件标签
  • 消息事件
  • 键 - circuit模块使用的键前缀列表
  • 客户端 - 列出并描述CLI命令以及gRPC和REST端点
Export as PDF
  1. 开发者
  2. 模块
  3. 核心

Circuit

Previous升级(Upgrade)NextGenutils

Last updated 1 month ago

概念

Circuit Breaker 是一个模块,旨在避免在存在漏洞时链需要停运/关闭,相反,该模块将允许禁用特定消息或所有消息。当运营链时,如果是应用特定的,那么链的停止影响较小,但如果链上有构建的应用程序,则停止链会由于对应用程序的干扰而变得非常昂贵。

Circuit Breaker 的工作原理是,某个地址或一组地址有权阻止消息的执行和/或包含在交易池中。任何具有权限的地址都能够重置该消息的断路器。

交易在两个阶段进行检查,并可能被拒绝:

  • 在 CircuitBreakerDecorator 中:

https://github.com/cosmos/cosmos-sdk/blob/x/circuit/v0.1.0/x/circuit/ante/circuit.go#L27-L41
  • 通过消息:

https://github.com/cosmos/cosmos-sdk/blob/v0.50.1/baseapp/msg_service_router.go#L104-L115

:::note CircuitBreakerDecorator 适用于大多数用例,但不检查交易的内部消息。因此,一些交易(例如 x/authz 交易或某些 x/gov 交易)可能会通过前置处理器。这不会影响断路器,因为消息路由器的检查仍然会导致交易失败。这个折衷是为了避免在 x/circuit 模块中引入更多依赖。如果链希望这样做,可以重新定义 CircuitBreakerDecorator 以检查内部消息。 :::

状态

Accounts

  • AccountPermissions 0x1 | account_address -> ProtocolBuffer(CircuitBreakerPermissions)

type level int32

const (
    // LEVEL_NONE_UNSPECIFIED indicates that the account will have no circuit
    // breaker permissions.
    LEVEL_NONE_UNSPECIFIED = iota
    // LEVEL_SOME_MSGS indicates that the account will have permission to
    // trip or reset the circuit breaker for some Msg type URLs. If this level
    // is chosen, a non-empty list of Msg type URLs must be provided in
    // limit_type_urls.
    LEVEL_SOME_MSGS
    // LEVEL_ALL_MSGS indicates that the account can trip or reset the circuit
    // breaker for Msg's of all type URLs.
    LEVEL_ALL_MSGS 
    // LEVEL_SUPER_ADMIN indicates that the account can take all circuit breaker
    // actions and can grant permissions to other accounts.
    LEVEL_SUPER_ADMIN
)

type Access struct {
	level int32 
	msgs []string // if full permission, msgs can be empty
}

Disable List

禁用的类型 URL 列表:

  • DisableList 0x2 | msg_type_url -> []byte{}

状态转移

Authorize

Authorize 由模块权限(默认的治理模块账户)或任何具有 LEVEL_SUPER_ADMIN 权限的账户调用,用于授予另一个账户禁用/启用消息的权限。可以授予三种权限级别:LEVEL_SOME_MSGS 限制可以禁用的消息数量。LEVEL_ALL_MSGS 允许禁用所有消息。LEVEL_SUPER_ADMIN 允许账户执行所有断路器操作,包括授权和撤销授权其他账户。

  // AuthorizeCircuitBreaker allows a super-admin to grant (or revoke) another
  // account's circuit breaker permissions.
  rpc AuthorizeCircuitBreaker(MsgAuthorizeCircuitBreaker) returns (MsgAuthorizeCircuitBreakerResponse);

Trip

Trip 由授权账户调用,用于禁用特定 msgURL 的消息执行。如果为空,则会禁用所有消息。

  // TripCircuitBreaker pauses processing of Msg's in the state machine.
  rpc TripCircuitBreaker(MsgTripCircuitBreaker) returns (MsgTripCircuitBreakerResponse);

Reset

Reset 由授权账户调用,用于启用之前禁用的特定 msgURL 消息的执行。如果为空,则会启用所有禁用的消息。

  // ResetCircuitBreaker resumes processing of Msg's in the state machine that
  // have been been paused using TripCircuitBreaker.
  rpc ResetCircuitBreaker(MsgResetCircuitBreaker) returns (MsgResetCircuitBreakerResponse);

消息

MsgAuthorizeCircuitBreaker

https://github.com/cosmos/cosmos-sdk/blob/main/proto/cosmos/circuit/v1/tx.proto#L25-L75

如果出现以下情况,预计此消息会失败:

  • 授权者不是具有 LEVEL_SUPER_ADMIN 权限级别的账户或模块权限账户。

MsgTripCircuitBreaker

https://github.com/cosmos/cosmos-sdk/blob/main/proto/cosmos/circuit/v1/tx.proto#L77-L93

如果出现以下情况,预计此消息会失败:

  • 签名者没有权限级别,无法禁用指定类型 URL 的消息。

MsgResetCircuitBreaker

https://github.com/cosmos/cosmos-sdk/blob/main/proto/cosmos/circuit/v1/tx.proto#L95-109

如果出现以下情况,预计此消息会失败:

  • 类型 URL 未被禁用。

事件 - 列出并描述事件标签

circuit模块会触发以下事件:

消息事件

MsgAuthorizeCircuitBreaker

类型
属性键
属性值

string

granter

{granterAddress}

string

grantee

{granteeAddress}

string

permission

{granteePermissions}

message

module

circuit

message

action

authorize_circuit_breaker

MsgTripCircuitBreaker

类型
属性键
属性值

string

authority

{authorityAddress}

[]string

msg_urls

[]string{msg_urls}

message

module

circuit

message

action

trip_circuit_breaker

ResetCircuitBreaker

类型
属性键
属性值

string

authority

{authorityAddress}

[]string

msg_urls

[]string{msg_urls}

message

module

circuit

message

action

reset_circuit_breaker

键 - circuit模块使用的键前缀列表

  • AccountPermissionPrefix - 0x01

  • DisableListPrefix - 0x02

客户端 - 列出并描述CLI命令以及gRPC和REST端点

前置处理器
路由器检查