-
Notifications
You must be signed in to change notification settings - Fork 606
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
chore: allow ics27 to select and return default JSON encoded metadata #1550
Conversation
…:cosmos/ibc-go into damian/1477-implement-payee-distribution
Co-authored-by: Charly <charly@interchain.berlin>
Codecov Report
@@ Coverage Diff @@
## damian/1477-implement-payee-distribution #1550 +/- ##
============================================================================
- Coverage 80.29% 80.19% -0.11%
============================================================================
Files 166 166
Lines 12304 12322 +18
============================================================================
+ Hits 9880 9882 +2
- Misses 1959 1974 +15
- Partials 465 466 +1
|
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 great! Just had a few questions/comments 👍
} | ||
} | ||
|
||
return nil | ||
return string(icatypes.ModuleCdc.MustMarshalJSON(&metadata)), nil |
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.
just to make sure I understand, if this panics this is handled at the sdk level right?
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.
Yep, its caught by the grpc recovery interceptor (essentially a middleware handler in grpc land)
@@ -28,26 +28,35 @@ func (k Keeper) OnChanOpenInit( | |||
chanCap *capabilitytypes.Capability, | |||
counterparty channeltypes.Counterparty, | |||
version string, | |||
) error { | |||
) (string, error) { |
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.
what is the implication of changing an OnChanOpenInit
signature like this? Are we free to do this without causing any issues?
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.
In this instance yes, the OnChanOpenInit
callback was already updated to include a second version return arg. The calling func in controller/ibc_middleware.go
already contains this function signature which is the entrypoint of the module handshake essentially.
In other situations we may need to more careful changing function sigs but this doesn't really cause any issues.
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.
to add to that: in general, we would also update the ibc spec for changes to these fn sigs. But like @damiannolan said the calling func already has this signature.
@@ -50,7 +50,8 @@ func (im IBCMiddleware) OnChanOpenInit( | |||
return "", types.ErrControllerSubModuleDisabled | |||
} | |||
|
|||
if err := im.keeper.OnChanOpenInit(ctx, order, connectionHops, portID, channelID, chanCap, counterparty, version); err != nil { | |||
version, err := im.keeper.OnChanOpenInit(ctx, order, connectionHops, portID, channelID, chanCap, counterparty, version) |
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 readability improvement 🥇
} else { | ||
if err := icatypes.ModuleCdc.UnmarshalJSON([]byte(version), &metadata); err != nil { |
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.
[nit] rather than having nested if/else clauses it might be cleaner to have a helper function to return the metadata (using early returns)
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 took a look at this and feel like there's not a massive difference making a helper function. You'd either need to return a new metadata type or take a pointer and a bunch of other args too... I'm pretty indifferent about it
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! Nice work.
Should we test this out manually as well?
Yup, already tested this manually as part of #396 QA scenarios. |
return sdkerrors.Wrapf(icatypes.ErrUnknownDataType, "cannot unmarshal ICS-27 interchain accounts metadata") | ||
if strings.TrimSpace(version) == "" { | ||
connection, err := k.channelKeeper.GetConnection(ctx, connectionHops[0]) | ||
if err != nil { |
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.
just a super tiny nit but you have the err statement in the second else clause in the ; err != nil
setup, would be nice if they were both like this or both the other way just as a tiny remark on style
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.
But we need to use the connection
below outside the scope of the returned error.
Generally we use the below for function return sigs with one single error
return:
if err := invokeFunc(); err != nil {
// handle err
}
If we use the following then we can't use the connection below, outside the scope of the conditional:
if connection, err := k.channelKeeper.GetConnection(ctx, connectionHops[0]); err != nil {
// connection and err are only available at this level of scope
}
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 yes, that makes sense 🙈
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.
you should technically be able to if you put the usage in an else clause, but I personally prefer the way you have it now rather than adding additional else
clauses!
if err := icatypes.ModuleCdc.UnmarshalJSON([]byte(version), &metadata); err != nil { | ||
return sdkerrors.Wrapf(icatypes.ErrUnknownDataType, "cannot unmarshal ICS-27 interchain accounts metadata") | ||
if strings.TrimSpace(version) == "" { | ||
connection, err := k.channelKeeper.GetConnection(ctx, connectionHops[0]) |
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.
why is connectionHops hardcoded to the first value of the array?
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.
The first value is the source chain connection end AFAIK
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.
ConnectionHops is an ordered list of connection ids, so using connectionHops[0]
here takes the first connection hop through which packets travel. There's a bunch of defensive checks in ibc core ensuring that this is always of length one at the moment. So on source chain connectionHops
will contain the connection ID of self, in this instance its the controller chain. And likewise, the counterparty handlers would have a connectionHops
array containing the connection of themself (host). Obviously in future with multi hop the semantics will change and ibc core will have to adapt for it. But due to the ordering, we can safely assume that the 0 index element is self.
Channel spec says:
The connectionHops stores the list of connection identifiers, in order, along which packets sent on this channel will travel. At the moment this list must be of length 1. In the future multi-hop channels may be supported.
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.
Awesome work, @damiannolan!
I just left a suggestion to potentially remove some duplicate code...
ControllerConnectionId: controllerConnectionID, | ||
HostConnectionId: hostConnectionID, | ||
Encoding: EncodingProtobuf, | ||
TxType: TxTypeSDKMultiMsg, | ||
Version: Version, | ||
} |
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.
Maybe you can replace now this whole object initialization with a call to the NewDefaultMetadata
function above?
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!
Description
Allow interchain accounts to accept an empty channel version and select a default.
version
return toOnChanOpenInit
cb handler in controllercloses: #1551
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