Skip to content

feat: migrate tainted wasmd#641

Merged
kien6034 merged 3 commits intoclassic-terra:testnet/v14from
orbitorg:tuan/wasmd-sdk53-migration
Feb 26, 2026
Merged

feat: migrate tainted wasmd#641
kien6034 merged 3 commits intoclassic-terra:testnet/v14from
orbitorg:tuan/wasmd-sdk53-migration

Conversation

@TropicalDog17
Copy link
Copy Markdown
Contributor

@TropicalDog17 TropicalDog17 commented Feb 25, 2026

  • Added v15 upgrade handler and constants for wasm migration.
  • Implemented Migrator for handling field order changes in ContractInfo.
  • Updated run-node.sh and upgrade-test.sh scripts for enhanced functionality.
  • Improved wasm deployment and state querying scripts for better error handling.

Summary of changes

Before migration - query smart failed

OLD_VERSION=v4.0.0-rc.2 FORK=true FORK_HALT_HEIGHT=200   ADDITIONAL_PRE_SCRIPTS="scripts/wasm/wasm-deploy.sh"   ADDITIONAL_AFTER_SCRIPTS="scripts/wasm/wasm-tx-check.sh,scripts/wasm/wasm-write-state.sh"   bash scripts/upgrade-test.sh
image

After migration - query smart passed

OLD_VERSION=v4.0.0-rc.2 SOFTWARE_UPGRADE_NAME=v15 ADDITIONAL_PRE_SCRIPTS="scripts/wasm/wasm-deploy.sh" ADDITIONAL_AFTER_SCRIPTS="scripts/wasm/wasm-tx-check.sh,scripts/wasm/wasm-write-state.sh" bash scripts/upgrade-test.sh
image

Report of required housekeeping

  • Github issue OR spec proposal link
  • Wrote tests
  • Updated API documentation (client/lcd/swagger-ui/swagger.yaml)
  • Added a relevant changelog entry: clog add [section] [stanza] [message]

(FOR ADMIN) Before merging

  • Added appropriate labels to PR
  • Squashed all commits, uses message "Merge pull request #XYZ: [title]" (coding standards)
  • Confirm added tests are consistent with the intended behavior of changes
  • Ensure all tests pass

- Added v15 upgrade handler and constants for wasm migration.
- Implemented Migrator for handling field order changes in ContractInfo.
- Updated run-node.sh and upgrade-test.sh scripts for enhanced functionality.
- Improved wasm deployment and state querying scripts for better error handling.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a v15 upgrade path to migrate “tainted” CosmWasm ContractInfo state caused by a protobuf field-order mismatch (wasmd v0.61.4 → v0.61.5), and updates the upgrade testing / wasm helper scripts to better exercise and validate the migration during local upgrade runs.

Changes:

  • Add v15 upgrade wiring and bump wasm module consensus version to run a new v4→v5 ContractInfo field-order migration.
  • Introduce a wasm store migrator that rewrites legacy-encoded ContractInfo entries into the corrected schema.
  • Improve upgrade/wasm scripts (deploy, post-upgrade queries, proposal submission flow), and add example upgrade-test invocations.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
scripts/wasm_command.txt Adds an example command sequence for running the upgrade test with wasm deploy + post checks.
scripts/wasm/wasm-write-state.sh Adds structured post-upgrade queries (all/raw/smart) with summarized pass/fail reporting.
scripts/wasm/wasm-deploy.sh Improves tx inclusion waiting + more robust extraction of code_id / contract address.
scripts/wasm/stargate-after-upgrade.sh Improves extraction of code_id / contract address and makes --label conditional.
scripts/upgrade-test.sh Makes old/new binary install more flexible and improves fork/upgrade orchestration.
scripts/run-node.sh Adjusts genesis setup + supports halt-height and configurable self-delegation.
custom/wasm/module.go Bumps wasm consensus version and registers the new v4→v5 migration.
custom/wasm/migrations/v4/types.go Adds legacy protobuf types to decode v0.61.4 ContractInfo layout.
custom/wasm/migrations/v4/store.go Implements the v4→v5 in-place KV migration for ContractInfo.
app/upgrades/v15/upgrades.go Adds the v15 upgrade handler (runs module migrations).
app/upgrades/v15/constants.go Registers the v15 upgrade metadata in the upgrades registry.
app/app.go Adds v15 to the app’s upgrade list.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +60 to +65
// Unmarshal using LEGACY schema (field 7 = ibc2_port_id, field 8 = extension)
var legacyInfo LegacyContractInfo
if err := cdc.Unmarshal(iter.Value(), &legacyInfo); err != nil {
// Skip if unmarshal fails (shouldn't happen in normal operation)
continue
}
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This migration silently continues on unmarshal errors. If any ContractInfo entry is malformed, it will be left unmigrated (potentially preserving the exact failure this migration is meant to fix) with no visibility. Consider returning an error (fail the upgrade) or at least logging and counting failures so operators know the state is inconsistent.

Copilot uses AI. Check for mistakes.
Comment on lines +52 to +76
func (m Migrator) Migrate4to5(ctx sdk.Context, storeService corestoretypes.KVStoreService, cdc codec.BinaryCodec) error {
store := storeService.OpenKVStore(ctx)
prefixStore := prefix.NewStore(runtime.KVStoreAdapter(store), types.ContractKeyPrefix)

iter := prefixStore.Iterator(nil, nil)
defer iter.Close()

for ; iter.Valid(); iter.Next() {
// Unmarshal using LEGACY schema (field 7 = ibc2_port_id, field 8 = extension)
var legacyInfo LegacyContractInfo
if err := cdc.Unmarshal(iter.Value(), &legacyInfo); err != nil {
// Skip if unmarshal fails (shouldn't happen in normal operation)
continue
}

// Convert to NEW schema (field 7 = extension, field 8 = ibc2_port_id)
newInfo := types.ContractInfo{
CodeID: legacyInfo.CodeID,
Creator: legacyInfo.Creator,
Admin: legacyInfo.Admin,
Label: legacyInfo.Label,
IBCPortID: legacyInfo.IBCPortID,
IBC2PortID: legacyInfo.IBC2PortID, // Moved from field 7 to field 8
}

Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new ContractInfo field-order migration is consensus-critical, but there are no unit tests covering the marshal/unmarshal swap logic. Adding a focused test that round-trips a LegacyContractInfo-encoded value through Migrate4to5 and asserts the resulting types.ContractInfo has the correct Extension/IBC2PortID values would help prevent regressions.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

@kien6034 kien6034 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just needed to fix wasmd from 61.4 -> 61.5 on testnet (dont need this patch on mainnet)

@kien6034 kien6034 requested a review from fragwuerdig February 25, 2026 18:14
@fragwuerdig
Copy link
Copy Markdown
Collaborator

fragwuerdig commented Feb 25, 2026

Looks good. I see no weaknesses implementation wise.

However, can we rename the upgrade to v14rc4.

Also I don't think we should merge this test yet fixing upgrade handler into main. I would rather fork the development branch at HEAD~1 and tag HEAD with v4.0.0-rc.4 - then merge HEAD~1 instead

@mergify mergify bot mentioned this pull request Feb 26, 2026
8 tasks
@kien6034 kien6034 changed the base branch from main to testnet/v14 February 26, 2026 06:55
@kien6034
Copy link
Copy Markdown
Contributor

Looks good. I see no weaknesses implementation wise.

However, can we rename the upgrade to v14rc4.

Also I don't think we should merge this test yet fixing upgrade handler into main. I would rather fork the development branch at HEAD1 and tag HEAD with v4.0.0-rc.4 - then merge HEAD1 instead

already change to v14rc4 and point the pr to the testnet branch

@kien6034 kien6034 merged commit 4a6767d into classic-terra:testnet/v14 Feb 26, 2026
58 of 70 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants