-
Notifications
You must be signed in to change notification settings - Fork 586
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
Adding GetChannelsWithPortPrefix function to 04-channel #2304
Adding GetChannelsWithPortPrefix function to 04-channel #2304
Conversation
@@ -31,7 +33,7 @@ func (m Migrator) AssertChannelCapabilityMigrations(ctx sdk.Context) error { | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small nit:
return []byte(fmt.Sprintf("%s/ports/%s", host.KeyChannelEndPrefix, portPrefix)) | |
return []byte(fmt.Sprintf("%s/%s/%s", host.KeyChannelEndPrefix, host.KeyPortPrefix, portPrefix)) |
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.
good call
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
|
@@ -469,3 +488,8 @@ func (k Keeper) iterateHashes(_ sdk.Context, iterator db.Iterator, cb func(portI | |||
} | |||
} | |||
} | |||
|
|||
// filteredPortPrefix returns the prefix key for the given port prefix. | |||
func filteredPortPrefix(portPrefix string) []byte { |
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.
Would it make sense to place this function in types/keys.go
instead?
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.
good suggestion, done!
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.
LGTM, just would like a little testing in 04-channel as well. Nice work thus far!
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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)
@@ -384,6 +384,24 @@ func (k Keeper) IterateChannels(ctx sdk.Context, cb func(types.IdentifiedChannel | |||
} | |||
} | |||
|
|||
// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like GetAllChannelsWithPortPrefix
to stay consistent
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.
Sounds good to me. I have no preference
if strings.TrimSpace(portPrefix) == "" { | ||
return k.GetAllChannels(ctx) | ||
} |
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.
missed this condition before the tests!
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! This is a good addition
…ns.go Co-authored-by: Damian Nolan <damiannolan@gmail.com>
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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.
Followup ACK
…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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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/
)godoc
comments.Unreleased
section inCHANGELOG.md
Files changed
in the Github PR explorerCodecov Report
in the comment section below once CI passes