Skip to content
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

Flexible Channel Handshake Selection #7439

Merged
merged 7 commits into from
Oct 2, 2020

Conversation

colin-axner
Copy link
Contributor

@colin-axner colin-axner commented Oct 2, 2020

Description

closes: #7025


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.

  • Targeted PR against correct branch (see CONTRIBUTING.md)
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/)
  • Added relevant godoc comments.
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer
  • Review Codecov Report in the comment section below once CI passes

Add ProvedID to ChanOpenTry which allows for flexible handshake identifier selection. Add CounterpartyChannelID to OpenAck. Update and add to handshake tests. Modify msgs_test. Counterparty ValidateBasic will return nil on an empty channel identifier to allow for flexible handshake identifier selection to succeed.
@colin-axner colin-axner changed the title update channel handshake Flexible Channel Handshake Selection Oct 2, 2020
@codecov
Copy link

codecov bot commented Oct 2, 2020

Codecov Report

Merging #7439 into master will increase coverage by 0.02%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #7439      +/-   ##
==========================================
+ Coverage   55.09%   55.11%   +0.02%     
==========================================
  Files         588      588              
  Lines       36782    36800      +18     
==========================================
+ Hits        20266    20284      +18     
  Misses      14415    14415              
  Partials     2101     2101              

Copy link
Collaborator

@fedekunze fedekunze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK, minor comment

@@ -147,6 +148,15 @@ func (k Keeper) ChanOpenTry(
)
}

// empty-string is a sentinel value for "allow any identifier" to be selected by
// the counterparty channel
if provedChannelID != channelID && provedChannelID != "" {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, I know the result is the same but if we change the order the second clause won't need to be evaluated as the entire condition will return false. Usually, in JS you would use if object && object.field... to check for undefined objects.

Suggested change
if provedChannelID != channelID && provedChannelID != "" {
if provedChannelID != "" && provedChannelID != channelID {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea I agree which is why I did this in msgs.go. I left how the spec ordered it in handshake for consistency. This is also how it is in connection handshake so I'd prefer to update this in a separate pr since it isn't api breaking

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc/ @cwgoes should we apply this to the spec? I think it reads slightly better

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied to the spec in cosmos/ibc@890e3d0

@@ -214,6 +225,15 @@ func (k Keeper) ChanOpenAck(
return sdkerrors.Wrapf(types.ErrChannelCapabilityNotFound, "caller does not own capability for channel, port ID (%s) channel ID (%s)", portID, channelID)
}

// empty-string is a sentinel value for "allow any identifier" to be selected by
// the counterparty channel
if counterpartyChannelID != channel.Counterparty.ChannelId && channel.Counterparty.ChannelId != "" {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Suggested change
if counterpartyChannelID != channel.Counterparty.ChannelId && channel.Counterparty.ChannelId != "" {
if channel.Counterparty.ChannelId != "" && counterpartyChannelID != channel.Counterparty.ChannelId {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also applied to the spec in cosmos/ibc@890e3d0

@@ -164,6 +169,9 @@ func (msg MsgChannelOpenAck) ValidateBasic() error {
if err := host.ChannelIdentifierValidator(msg.ChannelId); err != nil {
return sdkerrors.Wrap(err, "invalid channel ID")
}
if err := host.ChannelIdentifierValidator(msg.CounterpartyChannelId); err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be

	if msg.CounterpartyChannelId != "" {
		if err := host.ChannelIdentifierValidator(msg.CounterpartyChannelId); err != nil {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, CounterpartyChannelId must be set. The != "" check in the handshake is against the stored counterparty channel id not the provided one

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the time Ack rolls around, a connection ID should have been selected. The "" stored string in the handshake just indicates that the selection was flexible and the counterparty channel id should be used as the counterparty's channel id

@colin-axner
Copy link
Contributor Author

colin-axner commented Oct 2, 2020

@fedekunze could you run make proto after this merges and before a rc is cut. My proto tools are still broken so there might be some diffs

@fedekunze
Copy link
Collaborator

fedekunze commented Oct 2, 2020

@fedekunze could you run make proto after this merges and before a rc is cut. My proto tools are still broken so there might be some diffs

Just checked and there wasn't any diff file

Copy link
Member

@AdityaSripal AdityaSripal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but one thing I don't understand is why not just always have flexible ID selection. It would be simpler to always have chains choosing their own identifiers.

Is there ever a reason why they shouldn't? cc: @cwgoes

Comment on lines +99 to +100
channelID,
provedChannelID string,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally this is very confusing for me to read. It's not immediately clear what these mean without poring through the spec+comments.

I would prefer channelID => desiredChannelID and provedChannelID => counterpartyChosenChannelID

cc: @cwgoes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree on the confusion. Why not just desiredChannelID and chosenChannelID? Using counterparty can be vague to whether the counterparty chose the channel ID for this chain or if the counterparty chose their own.

Then the logic would be

// empty chosen channel id allows the desired channel id to be used for identifier selection
if chosenChannelID != "" && chosenChannelID != desiredChannelID {
return err
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with this renaming, I can update the spec as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

upon further reflection I think counterpartyChosenChannelID works fine since in most cases the Counterparty will be a different field containing the counterparty.ChannelId

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK!

@fedekunze fedekunze added the x/ibc label Oct 2, 2020
@fedekunze fedekunze merged commit 0047099 into master Oct 2, 2020
@fedekunze fedekunze deleted the colin/7025-channel-handshake-selection branch October 2, 2020 19:17
colin-axner added a commit that referenced this pull request Oct 5, 2020
rename provedID to counterpartyChosenID for connection and channel. Update if statement in handshake and tests. Ref: #7439 (comment)
@colin-axner colin-axner mentioned this pull request Oct 5, 2020
9 tasks
mergify bot pushed a commit that referenced this pull request Oct 5, 2020
* rename provedID

rename provedID to counterpartyChosenID for connection and channel. Update if statement in handshake and tests. Ref: #7439 (comment)

* update docs

Co-authored-by: Christopher Goes <[email protected]>
daeMOn63 pushed a commit to fetchai/cosmos-sdk that referenced this pull request May 5, 2021
* rename provedID

rename provedID to counterpartyChosenID for connection and channel. Update if statement in handshake and tests. Ref: cosmos/cosmos-sdk#7439 (comment)

* update docs

Co-authored-by: Christopher Goes <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update handshake to match revised specification
4 participants