Upgrade Module (x/upgrade)
Overview
Thex/upgrade module facilitates smooth upgrades of live Cosmos chains to new software versions by coordinating the upgrade process across all validators.
Purpose: Enable coordinated blockchain upgrades without requiring manual coordination or risking state inconsistencies.
Key Concepts
Plan
A scheduled upgrade at a specific block height:Handler
Logic executed during upgrade:StoreLoader
Configures store upgrades:Cosmovisor Integration
Cosmovisor automates binary upgrades:- Monitors for upgrade plans
- Downloads new binary from
Infofield - Switches to new binary at upgrade height
- Restarts node with new version
State
The module maintains minimal state:Messages
MsgSoftwareUpgrade
Schedule a software upgrade:MsgCancelUpgrade
Cancel a scheduled upgrade:PreBlocker
Upgrade execution happens in PreBlocker:Queries
Query Current Plan
Query Applied Plan
Check if upgrade was applied:Query Module Versions
gRPC Endpoints
CurrentPlan
AppliedPlan
ModuleVersions
Code Examples
Register Upgrade Handler
Configure Store Upgrades
Custom State Migration
Module Migration Example
Cosmovisor Configuration
Directory Structure:Upgrade Workflow
1. Prepare New Binary
2. Submit Upgrade Proposal
3. Vote on Proposal
4. Install New Binary (Manual)
5. Or Use Cosmovisor (Automatic)
Cosmovisor handles upgrade automatically:- Detects upgrade plan
- Downloads binary from URL
- Switches binary at upgrade height
- Restarts node
CLI Commands Reference
| Command | Description |
|---|---|
simd query upgrade plan | Query current upgrade plan |
simd query upgrade applied [name] | Check if upgrade was applied |
simd query upgrade module_versions | Query module versions |
simd tx gov submit-proposal software-upgrade | Submit upgrade proposal |
simd tx gov submit-proposal cancel-software-upgrade | Cancel upgrade proposal |
Integration Guide
Best Practices
- Test Thoroughly: Test upgrades on testnet first
- Communicate Early: Announce upgrades well in advance
- Provide Binaries: Host binaries with checksums
- Document Changes: Clear upgrade documentation
- Use Cosmovisor: Automate upgrade process
- Monitor Network: Watch validator participation
- Plan Rollback: Have contingency plans
- Version Consensus: Coordinate with validators