-
Notifications
You must be signed in to change notification settings - Fork 585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix to correctly parse denoms with slashes in the base denom #1451
Merged
crodriguezvega
merged 13 commits into
main
from
carlos/1446-bugtransfer-cannot-send-namespaced-ibc-denom-using-slashes
Jun 14, 2022
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
6579211
fix to correctly parse denoms with slashes in the base denom
crodriguezvega 10c25cc
some logic refinement
crodriguezvega b713dd8
review comments
crodriguezvega 856d97a
Merge branch 'main' into carlos/1446-bugtransfer-cannot-send-namespac…
crodriguezvega 7f352ef
Merge branch 'main' into carlos/1446-bugtransfer-cannot-send-namespac…
crodriguezvega 5c8dedc
add changelog entry an other review comments
9bff589
review comment
crodriguezvega 3a85227
Merge branch 'main' into carlos/1446-bugtransfer-cannot-send-namespac…
crodriguezvega 7a79f95
Merge branch 'main' into carlos/1446-bugtransfer-cannot-send-namespac…
crodriguezvega 58d1133
Merge branch 'main' into carlos/1446-bugtransfer-cannot-send-namespac…
crodriguezvega 64657c5
Add slash migration guide (#1518)
AdityaSripal c5552e4
Merge branch 'main' into carlos/1446-bugtransfer-cannot-send-namespac…
crodriguezvega 4a2a8cd
rename migration file
crodriguezvega File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
# Migrating from not supporing base denoms with slashes to supporting base denoms with slashes | ||
|
||
This document is intended to highlight significant changes which may require more information than presented in the CHANGELOG. | ||
Any changes that must be done by a user of ibc-go should be documented here. | ||
|
||
There are four sections based on the four potential user groups of this document: | ||
- Chains | ||
- IBC Apps | ||
- Relayers | ||
- IBC Light Clients | ||
|
||
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. | ||
|
||
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. | ||
|
||
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"`. | ||
|
||
This incorrect trace information must be corrected when the chain does upgrade to fully supporting denominations with slashes. | ||
|
||
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. | ||
|
||
## Chains | ||
|
||
### ICS20 - Transfer | ||
|
||
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. | ||
|
||
### Upgrade Proposal | ||
|
||
```go | ||
// Here the upgrade name is the upgrade name set by the chain | ||
app.UpgradeKeeper.SetUpgradeHandler("supportSlashedDenomsUpgrade", | ||
func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { | ||
// list of traces that must replace the old traces in store | ||
var newTraces []ibctransfertypes.DenomTrace | ||
app.TransferKeeper.IterateDenomTraces(ctx, | ||
func(dt ibctransfertypes.DenomTrace) bool { | ||
// check if the new way of splitting FullDenom | ||
// into Trace and BaseDenom passes validation and | ||
// is the same as the current DenomTrace. | ||
// If it isn't then store the new DenomTrace in the list of new traces. | ||
newTrace := ibctransfertypes.ParseDenomTrace(dt.GetFullDenomPath()) | ||
if err := newTrace.Validate(); err == nil && !reflect.DeepEqual(newTrace, dt) { | ||
newTraces = append(newTraces, newTrace) | ||
} | ||
|
||
return false | ||
}) | ||
|
||
// replace the outdated traces with the new trace information | ||
for _, nt := range newTraces { | ||
app.TransferKeeper.SetDenomTrace(ctx, nt) | ||
} | ||
|
||
return app.mm.RunMigrations(ctx, app.configurator, fromVM) | ||
}) | ||
``` | ||
|
||
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. | ||
|
||
For a more detailed sample, please check out the code changes in [this pull request](https://github.com/cosmos/ibc-go/pull/1527). | ||
|
||
### Genesis Migration | ||
|
||
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. | ||
|
||
The migration code required may look like: | ||
|
||
```go | ||
func migrateGenesisSlashedDenomsUpgrade(appState genutiltypes.AppMap, clientCtx client.Context, genDoc *tmtypes.GenesisDoc) (genutiltypes.AppMap, error) { | ||
if appState[ibctransfertypes.ModuleName] != nil { | ||
transferGenState := &ibctransfertypes.GenesisState{} | ||
clientCtx.Codec.MustUnmarshalJSON(appState[ibctransfertypes.ModuleName], transferGenState) | ||
|
||
substituteTraces := make([]ibctransfertypes.DenomTrace, len(transferGenState.DenomTraces)) | ||
for i, dt := range transferGenState.DenomTraces { | ||
// replace all previous traces with the latest trace if validation passes | ||
// note most traces will have same value | ||
newTrace := ibctransfertypes.ParseDenomTrace(dt.GetFullDenomPath()) | ||
|
||
if err := newTrace.Validate(); err != nil { | ||
substituteTraces[i] = dt | ||
} else { | ||
substituteTraces[i] = newTrace | ||
} | ||
} | ||
|
||
transferGenState.DenomTraces = substituteTraces | ||
|
||
// delete old genesis state | ||
delete(appState, ibctransfertypes.ModuleName) | ||
|
||
// set new ibc transfer genesis state | ||
appState[ibctransfertypes.ModuleName] = clientCtx.Codec.MustMarshalJSON(transferGenState) | ||
} | ||
|
||
return appState, nil | ||
} | ||
``` | ||
|
||
For a more detailed sample, please check out the code changes in [this pull request](https://github.com/cosmos/ibc-go/pull/1528). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work @crodriguezvega! It should be noted this introduces undocumented changes. Specifically the usage of
PortID
. ICS20 does not specify the PortID that should be used for the transfer channel. See specification callbacks. This is also true in our code. This code now assumes the PortID to betransfer
. This should be enforced (in channel handshakes) if this the intended behaviourI'm unaware of any chains which have changed the portID, but last I checked, Agoric used a modified portID in testing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like it might be a problem with chains running wasm:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch @colin-axner ! Unfortunately without a standardized port, it's impossible to correctly differentiate between what is trace info and what is the base denom. Since the trace is largely internal information for a chain and will not affect correctness, I think we can live with the fact that non-standard ports and their subsequent traces will be part of the base denom.
Reiterating for future viewers that this will not affect correctness of the protocol. But when querying trace information, any nonstandard trace will be in the base denom