x/upgrade module enables coordinated, height-based chain upgrades with automatic binary validation and migration execution. It ensures all validators switch to the new binary at exactly the same block height.
Overview
Coordinated upgrades allow blockchains to upgrade their software without forking or halting. The upgrade module:- Schedules upgrades at specific block heights
- Validates binary versions match expected upgrades
- Executes migration handlers automatically
- Handles store schema changes
- Prevents premature or late upgrades
Upgrade Flow
The upgrade process in PreBlocker:x/upgrade/abci.go
Upgrade Plan
An upgrade plan specifies when and how to upgrade:x/upgrade/types/plan.go
Implementing an Upgrade
1. Define the Upgrade Handler
Create a handler that performs the upgrade logic:2. Configure Store Upgrades
Specify store additions or deletions:3. Submit Upgrade Proposal
Create and submit an upgrade proposal via governance:Module Migrations
Implement migrations in your modules:Real-World Example: v0.50 to v0.53
From the SDK’s upgrade guide:app/upgrades.go
Skip Heights
Skip specific upgrade heights for testing or emergency scenarios:Upgrade Info File
The upgrade module writes upgrade info to disk:data/upgrade-info.json
Keeper Interface
Key keeper methods:x/upgrade/keeper/keeper.go
Best Practices
- Test Thoroughly: Test upgrades on testnets first
- Version Mapping: Track module versions in
VersionMap - Store Changes: Plan store additions/deletions carefully
- Binary Distribution: Ensure binaries are available before upgrade height
- Communication: Coordinate with validators well in advance
- Rollback Plan: Have a contingency plan for failed upgrades
- Gas Limits: Upgrades run with infinite gas, but keep them efficient
- State Migrations: Test state migrations with production data snapshots
Testing Upgrades
Test your upgrade logic:Emergency Procedures
Cancel Upgrade
Force Skip
See Also
- Module Development - Creating upgradeable modules
- Governance - Submitting upgrade proposals
- Store - Understanding store migrations
- UPGRADE_GUIDE.md - Official upgrade guide