Adding GetChannelsWithPortPrefix function to 04-channel#2304
Conversation
| isAuthenticated := m.keeper.scopedKeeper.AuthenticateCapability(ctx, cap, name) | ||
| if !isAuthenticated { | ||
| return sdkerrors.Wrapf(capabilitytypes.ErrCapabilityNotOwned, "expected capability owner: %s", types.SubModuleName) | ||
| return sdkerrors.Wrapf(capabilitytypes.ErrCapabilityNotOwned, "expected capability owner: %s", commitmenttypes.SubModuleName) |
There was a problem hiding this comment.
Not sure how this ended up as commitmenttypes I see the import previously would've been incorrect also.
It should be controllertypes.SubModuleName.
There was a problem hiding this comment.
Ah right, I was wondering about that actually, I changed the import to be inline with other imports in the file. I can update this now.
There was a problem hiding this comment.
I think the dangers of types as the import alias.
|
|
||
| // filteredPortPrefix returns the prefix key for the given port prefix. | ||
| func filteredPortPrefix(portPrefix string) []byte { | ||
| return []byte(fmt.Sprintf("%s/ports/%s", host.KeyChannelEndPrefix, portPrefix)) |
There was a problem hiding this comment.
small nit:
| return []byte(fmt.Sprintf("%s/ports/%s", host.KeyChannelEndPrefix, portPrefix)) | |
| return []byte(fmt.Sprintf("%s/%s/%s", host.KeyChannelEndPrefix, host.KeyPortPrefix, portPrefix)) |
| for _, ch := range filteredChannels { | ||
| name := host.ChannelCapabilityPath(ch.PortId, ch.ChannelId) | ||
| cap, found := m.keeper.scopedKeeper.GetCapability(ctx, name) | ||
| capacity, found := m.keeper.scopedKeeper.GetCapability(ctx, name) |
There was a problem hiding this comment.
I renamed this to avoid shadowing the built in cap function.
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #2304 +/- ##
==========================================
- Coverage 79.54% 79.45% -0.09%
==========================================
Files 175 175
Lines 12069 12149 +80
==========================================
+ Hits 9600 9653 +53
- Misses 2045 2067 +22
- Partials 424 429 +5
|
| } | ||
|
|
||
| // filteredPortPrefix returns the prefix key for the given port prefix. | ||
| func filteredPortPrefix(portPrefix string) []byte { |
There was a problem hiding this comment.
Would it make sense to place this function in types/keys.go instead?
There was a problem hiding this comment.
good suggestion, done!
colin-axner
left a comment
There was a problem hiding this comment.
LGTM, just would like a little testing in 04-channel as well. Nice work thus far!
damiannolan
left a comment
There was a problem hiding this comment.
Looks good to me! Left a couple of nits and a question regarding naming.
Great work! ⭐
modules/apps/27-interchain-accounts/controller/keeper/migrations.go
Outdated
Show resolved
Hide resolved
| portIdWithOutPrefix := ibctesting.MockPort | ||
| suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.SetChannel(suite.chainA.GetContext(), portIdWithOutPrefix, ibctesting.FirstChannelID, channeltypes.Channel{ | ||
| ConnectionHops: []string{ibctesting.FirstConnectionID}, | ||
| }) |
There was a problem hiding this comment.
We normally favour using ID over Id in naming (except proto generated code).
| portIdWithOutPrefix := ibctesting.MockPort | |
| suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.SetChannel(suite.chainA.GetContext(), portIdWithOutPrefix, ibctesting.FirstChannelID, channeltypes.Channel{ | |
| ConnectionHops: []string{ibctesting.FirstConnectionID}, | |
| }) | |
| portIDWithOutPrefix := ibctesting.MockPort | |
| suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.SetChannel(suite.chainA.GetContext(), portIDWithOutPrefix, ibctesting.FirstChannelID, channeltypes.Channel{ | |
| ConnectionHops: []string{ibctesting.FirstConnectionID}, | |
| }) |
There was a problem hiding this comment.
We only favor "Id" in proto naming because using "ID" messes with the grpc gateway generation (I'm not sure why nor if this is still an issue, but it was when we initially switched to proto)
| } | ||
|
|
||
| // GetChannelsWithPortPrefix returns all channels with the specified port prefix. | ||
| func (k Keeper) GetChannelsWithPortPrefix(ctx sdk.Context, portPrefix string) []types.IdentifiedChannel { |
There was a problem hiding this comment.
Should we consider naming this function to align with GetAllChannels below which returns []types.IdentifiedChannel also?
Maybe GetAllChannelsWithPortPrefix or GetAllPortPrefixedChannels?
I don't feel particularly strongly but just a thought. cc. @crodriguezvega @colin-axner
There was a problem hiding this comment.
I like GetAllChannelsWithPortPrefix to stay consistent
There was a problem hiding this comment.
Sounds good to me. I have no preference
| if strings.TrimSpace(portPrefix) == "" { | ||
| return k.GetAllChannels(ctx) | ||
| } |
There was a problem hiding this comment.
missed this condition before the tests!
There was a problem hiding this comment.
Nice! This is a good addition
…ns.go Co-authored-by: Damian Nolan <damiannolan@gmail.com>
colin-axner
left a comment
There was a problem hiding this comment.
LGTM! Left some suggestions for the tests, mostly nits. Happy to go with what you think would be best
modules/apps/27-interchain-accounts/controller/keeper/migrations_test.go
Outdated
Show resolved
Hide resolved
| if strings.TrimSpace(portPrefix) == "" { | ||
| return k.GetAllChannels(ctx) | ||
| } |
There was a problem hiding this comment.
Nice! This is a good addition
|
|
||
| // containsAll verifies if all elements in the expected slice exist in the actual slice | ||
| // independent of order. | ||
| func containsAll(expected, actual []types.IdentifiedChannel) bool { |
There was a problem hiding this comment.
I added this function as I saw that the order of the values returned in GetAllChannels is not necessarily in the order they were added.
…ction-to-04-channel
…-channel' of https://github.com/cosmos/ibc-go into cian/issue#2245-add-port-prefix-iterator-function-to-04-channel
…ction-to-04-channel
| allChannels := []types.IdentifiedChannel{ | ||
| types.NewIdentifiedChannel(transfertypes.PortID, ibctesting.FirstChannelID, types.Channel{}), | ||
| types.NewIdentifiedChannel(differentChannelPortID, secondChannelID, types.Channel{}), | ||
| } | ||
|
|
There was a problem hiding this comment.
great suggestion @colin-axner , this makes things much cleaner.
…ction-to-04-channel
(cherry picked from commit ce5aba8) # Conflicts: # CHANGELOG.md
Description
closes: #2245
Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.
docs/) or specification (x/<module>/spec/)godoccomments.Unreleasedsection inCHANGELOG.mdFiles changedin the Github PR explorerCodecov Reportin the comment section below once CI passes