-
Notifications
You must be signed in to change notification settings - Fork 647
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
Use connection id instead of channel id in IsMiddlewareEnabled #2260
Changes from 11 commits
b56becd
5820a6a
9f51b23
8a0ea2b
492487a
c57c157
d83733e
e965a57
b100b22
91490fd
4f8f9b5
c085def
d81a664
b2454ba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,12 +22,12 @@ func (k Keeper) RegisterInterchainAccount(ctx sdk.Context, connectionID, owner, | |
return err | ||
} | ||
|
||
channelID, err := k.registerInterchainAccount(ctx, connectionID, portID, version) | ||
_, err = k.registerInterchainAccount(ctx, connectionID, portID, version) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
k.SetMiddlewareEnabled(ctx, portID, channelID) | ||
k.SetMiddlewareEnabled(ctx, portID, connectionID) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there an issue that moves this setting (it needs to be moved to be called before There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like its covered in #2283 |
||
|
||
return nil | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import ( | |
"github.com/cosmos/cosmos-sdk/codec" | ||
storetypes "github.com/cosmos/cosmos-sdk/store/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" | ||
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" | ||
"github.com/tendermint/tendermint/libs/log" | ||
|
@@ -61,6 +62,15 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger { | |
return ctx.Logger().With("module", fmt.Sprintf("x/%s-%s", host.ModuleName, icatypes.ModuleName)) | ||
} | ||
|
||
// GetConnectionID returns the connection id for the given port and channelIDs. | ||
func (k Keeper) GetConnectionID(ctx sdk.Context, portID, channelID string) (string, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I chose to add this function rather than export the channelKeeper, as so far it's the only time we've needed. |
||
channel, found := k.channelKeeper.GetChannel(ctx, portID, channelID) | ||
if !found { | ||
return "", sdkerrors.Wrapf(channeltypes.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID) | ||
} | ||
return channel.ConnectionHops[0], nil | ||
} | ||
|
||
// GetAllPorts returns all ports to which the interchain accounts controller module is bound. Used in ExportGenesis | ||
func (k Keeper) GetAllPorts(ctx sdk.Context) []string { | ||
store := ctx.KVStore(k.storeKey) | ||
|
@@ -144,11 +154,15 @@ func (k Keeper) GetAllActiveChannels(ctx sdk.Context) []genesistypes.ActiveChann | |
for ; iterator.Valid(); iterator.Next() { | ||
keySplit := strings.Split(string(iterator.Key()), "/") | ||
|
||
portID := keySplit[1] | ||
connectionID := keySplit[2] | ||
channelID := string(iterator.Value()) | ||
Comment on lines
+157
to
+159
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. extracted these out to make it more clear which values are being passed into |
||
|
||
ch := genesistypes.ActiveChannel{ | ||
ConnectionId: keySplit[2], | ||
PortId: keySplit[1], | ||
ChannelId: string(iterator.Value()), | ||
IsMiddlewareEnabled: k.IsMiddlewareEnabled(ctx, keySplit[1], string(iterator.Value())), | ||
ConnectionId: connectionID, | ||
PortId: portID, | ||
ChannelId: channelID, | ||
IsMiddlewareEnabled: k.IsMiddlewareEnabled(ctx, portID, connectionID), | ||
} | ||
|
||
activeChannels = append(activeChannels, ch) | ||
|
@@ -208,20 +222,20 @@ func (k Keeper) SetInterchainAccountAddress(ctx sdk.Context, connectionID, portI | |
store.Set(icatypes.KeyOwnerAccount(portID, connectionID), []byte(address)) | ||
} | ||
|
||
// IsMiddlewareEnabled returns true if the underlying application callbacks are enabled for given port and channel identifier pair, otherwise false | ||
func (k Keeper) IsMiddlewareEnabled(ctx sdk.Context, portID, channelID string) bool { | ||
// IsMiddlewareEnabled returns true if the underlying application callbacks are enabled for given port and connection identifier pair, otherwise false | ||
func (k Keeper) IsMiddlewareEnabled(ctx sdk.Context, portID, connectionID string) bool { | ||
store := ctx.KVStore(k.storeKey) | ||
return store.Has(icatypes.KeyIsMiddlewareEnabled(portID, channelID)) | ||
return store.Has(icatypes.KeyIsMiddlewareEnabled(portID, connectionID)) | ||
} | ||
|
||
// SetMiddlewareEnabled stores a flag to indicate that the underlying application callbacks should be enabled for the given port and channel identifier pair | ||
func (k Keeper) SetMiddlewareEnabled(ctx sdk.Context, portID, channelID string) { | ||
// SetMiddlewareEnabled stores a flag to indicate that the underlying application callbacks should be enabled for the given port and connection identifier pair | ||
func (k Keeper) SetMiddlewareEnabled(ctx sdk.Context, portID, connectionID string) { | ||
store := ctx.KVStore(k.storeKey) | ||
store.Set(icatypes.KeyIsMiddlewareEnabled(portID, channelID), []byte{byte(1)}) | ||
store.Set(icatypes.KeyIsMiddlewareEnabled(portID, connectionID), []byte{byte(1)}) | ||
} | ||
|
||
// DeleteMiddlewareEnabled deletes the middleware enabled flag stored in state | ||
func (k Keeper) DeleteMiddlewareEnabled(ctx sdk.Context, portID, channelID string) { | ||
func (k Keeper) DeleteMiddlewareEnabled(ctx sdk.Context, portID, connectionID string) { | ||
store := ctx.KVStore(k.storeKey) | ||
store.Delete(icatypes.KeyIsMiddlewareEnabled(portID, channelID)) | ||
store.Delete(icatypes.KeyIsMiddlewareEnabled(portID, connectionID)) | ||
} |
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.
unrelated docstring fix