Skip to content

Commit 64657c5

Browse files
AdityaSripalfedekunzecrodriguezvega
authored
Add slash migration guide (#1518)
* add migration guide * Update docs/migrations/support-slashed-denoms.md Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * clarify upgrade name * remove unnecessary store loader * review comment, update migration code Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> Co-authored-by: Carlos Rodriguez <crodveg@gmail.com>
1 parent 58d1133 commit 64657c5

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed
+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# Migrating from not supporing base denoms with slashes to supporting base denoms with slashes
2+
3+
This document is intended to highlight significant changes which may require more information than presented in the CHANGELOG.
4+
Any changes that must be done by a user of ibc-go should be documented here.
5+
6+
There are four sections based on the four potential user groups of this document:
7+
- Chains
8+
- IBC Apps
9+
- Relayers
10+
- IBC Light Clients
11+
12+
This document is necessary when chains are upgrading from a version that does not support base denoms with slashes (e.g. v3.0.0) to a version that does (e.g. v3.1.0). All versions of ibc-go smaller than v1.5.0 for the v1.x release line, v2.3.0 for the v2.x release line, and v3.1.0 for the v3.x release line do *NOT** support IBC token transfers of coins whose base denoms contain slashes. Therefore the in-place of genesis migration described in this document are required when upgrading.
13+
14+
If a chain receives coins of a base denom with slashes before it upgrades to supporting it, the receive may pass however the trace information will be incorrect.
15+
16+
E.g. If a base denom of `testcoin/testcoin/testcoin` is sent to a chain that does not support slashes in the base denom, the receive will be successful. However, the trace information stored on the receiving chain will be: `Trace: "transfer/{channel-id}/testcoin/testcoin", BaseDenom: "testcoin"`.
17+
18+
This incorrect trace information must be corrected when the chain does upgrade to fully supporting denominations with slashes.
19+
20+
To do so, chain binaries should include a migration script that will run when the chain upgrades from not supporting base denominations with slashes to supporting base denominations with slashes.
21+
22+
## Chains
23+
24+
### ICS20 - Transfer
25+
26+
The transfer module will now support slashes in base denoms, so we must iterate over current traces to check if any of them are incorrectly formed and correct the trace information.
27+
28+
### Upgrade Proposal
29+
30+
```go
31+
// Here the upgrade name is the upgrade name set by the chain
32+
app.UpgradeKeeper.SetUpgradeHandler("supportSlashedDenomsUpgrade",
33+
func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
34+
// list of traces that must replace the old traces in store
35+
var newTraces []ibctransfertypes.DenomTrace
36+
app.TransferKeeper.IterateDenomTraces(ctx,
37+
func(dt ibctransfertypes.DenomTrace) bool {
38+
// check if the new way of splitting FullDenom
39+
// into Trace and BaseDenom passes validation and
40+
// is the same as the current DenomTrace.
41+
// If it isn't then store the new DenomTrace in the list of new traces.
42+
newTrace := ibctransfertypes.ParseDenomTrace(dt.GetFullDenomPath())
43+
if err := newTrace.Validate(); err == nil && !reflect.DeepEqual(newTrace, dt) {
44+
newTraces = append(newTraces, newTrace)
45+
}
46+
47+
return false
48+
})
49+
50+
// replace the outdated traces with the new trace information
51+
for _, nt := range newTraces {
52+
app.TransferKeeper.SetDenomTrace(ctx, nt)
53+
}
54+
55+
return app.mm.RunMigrations(ctx, app.configurator, fromVM)
56+
})
57+
```
58+
59+
This is only necessary if there are denom traces in the store with incorrect trace information from previously received coins that had a slash in the base denom. However, it is recommended that any chain upgrading to support base denominations with slashes runs this code for safety.
60+
61+
For a more detailed sample, please check out the code changes in [this pull request](https://github.com/cosmos/ibc-go/pull/1527).
62+
63+
### Genesis Migration
64+
65+
If the chain chooses to add support for slashes in base denoms via genesis export, then the trace information must be corrected during genesis migration.
66+
67+
The migration code required may look like:
68+
69+
```go
70+
func migrateGenesisSlashedDenomsUpgrade(appState genutiltypes.AppMap, clientCtx client.Context, genDoc *tmtypes.GenesisDoc) (genutiltypes.AppMap, error) {
71+
if appState[ibctransfertypes.ModuleName] != nil {
72+
transferGenState := &ibctransfertypes.GenesisState{}
73+
clientCtx.Codec.MustUnmarshalJSON(appState[ibctransfertypes.ModuleName], transferGenState)
74+
75+
substituteTraces := make([]ibctransfertypes.DenomTrace, len(transferGenState.DenomTraces))
76+
for i, dt := range transferGenState.DenomTraces {
77+
// replace all previous traces with the latest trace if validation passes
78+
// note most traces will have same value
79+
newTrace := ibctransfertypes.ParseDenomTrace(dt.GetFullDenomPath())
80+
81+
if err := newTrace.Validate(); err != nil {
82+
substituteTraces[i] = dt
83+
} else {
84+
substituteTraces[i] = newTrace
85+
}
86+
}
87+
88+
transferGenState.DenomTraces = substituteTraces
89+
90+
// delete old genesis state
91+
delete(appState, ibctransfertypes.ModuleName)
92+
93+
// set new ibc transfer genesis state
94+
appState[ibctransfertypes.ModuleName] = clientCtx.Codec.MustMarshalJSON(transferGenState)
95+
}
96+
97+
return appState, nil
98+
}
99+
```
100+
101+
For a more detailed sample, please check out the code changes in [this pull request](https://github.com/cosmos/ibc-go/pull/1528).

0 commit comments

Comments
 (0)