Skip to content

Latest commit

 

History

History
128 lines (101 loc) · 3.25 KB

cosmos_adminsigning_cli_panic_impact.md

File metadata and controls

128 lines (101 loc) · 3.25 KB

Cosmos Chain CLI Panic Impact Analysis

Overview

When a user calls the CLI on a Cosmos chain and it panics, the impact depends on where the panic occurs. This document outlines the different scenarios and their respective impacts.

1. Client-Side CLI Panic

If the panic happens in the CLI client code (before sending to the chain):

Impact

  • Only affects the user's local CLI process
  • No impact on the blockchain or other users
  • Transaction is never submitted to the chain
  • CLI process crashes and exits

Example

$ mychain tx bank send ... 
panic: runtime error: nil pointer dereference
# CLI crashes, nothing sent to chain

2. Chain-Side Panic (More Serious)

If the CLI successfully submits a transaction that causes a panic during execution:

During Transaction Execution

Impact

  • Transaction fails and is rejected
  • Gas is consumed up to the panic point
  • No state changes are committed
  • Chain continues operating normally
  • Error is returned to the user

Recovery Mechanism

// Cosmos SDK has panic recovery in BaseApp
defer func() {
    if r := recover(); r != nil {
        // Log the panic
        // Return error response
        // Continue chain operation
    }
}()

During Block Processing (Worst Case)

Impact

  • Entire blockchain halts
  • All validators stop producing blocks
  • Network becomes unavailable
  • Requires manual intervention/upgrade

3. Query Panic

If a CLI query command triggers a panic:

Impact

  • Query fails and returns error
  • No state changes (queries are read-only)
  • Chain continues normally
  • Only affects that specific query

Protection Mechanisms

1. Panic Recovery

// BaseApp wraps execution with recovery
func (app *BaseApp) runTx(mode runTxMode, txBytes []byte) (gInfo sdk.GasInfo, result *sdk.Result, err error) {
    defer func() {
        if r := recover(); r != nil {
            err = handlePanic(r)
        }
    }()
    // ... transaction execution
}

2. Gas Limits

  • Prevent infinite loops that could cause resource exhaustion
  • Force transactions to complete within gas bounds

3. Ante Handlers

  • Validate transactions before execution
  • Catch common issues early

Best Practices to Prevent Panics

Input Validation

// Always validate inputs
if msg.Amount.IsNil() {
    return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "amount cannot be nil")
}

Safe Operations

// Use safe operations
if balance.IsZero() {
    return nil, sdkerrors.Wrap(sdkerrors.ErrInsufficientFunds, "insufficient balance")
}

Edge Case Handling

// Handle edge cases
if len(msg.Recipients) == 0 {
    return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "no recipients specified")
}

Summary

Scenario Impact Level Description
CLI Panic Low Local issue only - affects single user
Transaction Panic Medium Transaction fails, chain continues
Block Processing Panic Critical Chain halts completely

Key Points

  • Cosmos SDK has built-in panic recovery for most scenarios
  • Proper validation and error handling prevent most panic situations
  • Client-side panics have minimal impact
  • Chain-side panics during block processing are the most serious concern