storage(substore): add delimiter handling #3441
Merged
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.
According to the ICS24 spec, substore prefixes are identifiers. This means that they "MUST" follow precise requirements:
This means that our decision to include a trailing delimiter for our IBC prefix is technically incompatible with the spec. This is unfortunate, because it greatly simplifies the routing logic. However, in practice this could become a problem if a counterparty IBC implementation decides to enforce this requirement.
This PR adds support for removing delimiters from our defined prefixes. Instead of defining an
ibc/
prefix, the user defines a prefix identifier"ibc"
. The routing logic handles adding/stripping a delimiter"/"
. For example, a key path:ibc/path/to/client/state
will result in a match to theibc
substore at keypath/to/client/state
.However, quietly managing delimiters adds some complexity. Naively, we could find ourselves in a situation where we collisions occur e.g.
"ibcpath/to/client/state"
andibc/path/to/client/state
. Similarly, we now have extra edge cases to enforce that we never write an empty key to a substore:ibc
,ibc/
would resolve to the same key.To avoid this, we only route a key to a substore if it contains a prefix, a delimiter, and a non-empty substore path e.g.
"ibc/path/to"
and"ibc/key"
routes to the"ibc"
substore, but"ibc/"
and"ibc"
don't.