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

connection handshake updates for versioning #7328

Merged
merged 14 commits into from
Sep 22, 2020

Conversation

colin-axner
Copy link
Contributor

@colin-axner colin-axner commented Sep 16, 2020

Description

Reflects changes in spec for handshakes. Is there any specific handshake tests I should add?

part 1 of: #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

@codecov
Copy link

codecov bot commented Sep 16, 2020

Codecov Report

Merging #7328 into master will decrease coverage by 3.07%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #7328      +/-   ##
==========================================
- Coverage   55.86%   52.79%   -3.08%     
==========================================
  Files         585      436     -149     
  Lines       35898    26431    -9467     
==========================================
- Hits        20054    13953    -6101     
+ Misses      13878    11124    -2754     
+ Partials     1966     1354     -612     

Copy link
Contributor

@cwgoes cwgoes left a comment

Choose a reason for hiding this comment

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

ACK, this logic looks correct to me per https://github.com/cosmos/ics/pull/479/files

@colin-axner colin-axner added the A:automerge Automatically merge PR once all prerequisites pass. label Sep 17, 2020
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.

Some small nits.

Also it looks like this part of the spec change wasn't implemeneted:

https://github.com/cosmos/ics/pull/479/files#diff-4bb4959de91d075b70b4378c9000257cR323-R324

Is that going to be done in a separate PR?

@@ -120,7 +121,7 @@ func (k Keeper) ConnOpenTry(
bytes.Equal(previousConnection.Counterparty.Prefix.Bytes(), counterparty.Prefix.Bytes()) &&
previousConnection.ClientId == clientID &&
previousConnection.Counterparty.ClientId == counterparty.ClientId &&
previousConnection.Versions[0] == version) {
reflect.DeepEqual(previousConnection.Versions, types.GetCompatibleEncodedVersions())) {
Copy link
Member

Choose a reason for hiding this comment

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

docstring above needs to be changed.

        + // Check that existing connection versions for initialized connection is equal to compatible versions for this chain

@@ -120,7 +121,7 @@ func (k Keeper) ConnOpenTry(
bytes.Equal(previousConnection.Counterparty.Prefix.Bytes(), counterparty.Prefix.Bytes()) &&
Copy link
Member

Choose a reason for hiding this comment

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

nit: I think the previousConnection check should happen way earlier, before the version gets picked and current connection is created.

Copy link
Contributor Author

@colin-axner colin-axner Sep 22, 2020

Choose a reason for hiding this comment

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

I agree but this follows the ICS spec ordering so I think it makes sense to leave it where it is so its easier to verify correctness of the implementation against the spec. I'd suggest reordering this on the spec before reordering this in the code. Code readability for handshake calls includes readability against the spec

Copy link
Member

Choose a reason for hiding this comment

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

nit for @cwgoes

@cwgoes
Copy link
Contributor

cwgoes commented Sep 18, 2020

Some small nits.

Also it looks like this part of the spec change wasn't implemeneted:

https://github.com/cosmos/ics/pull/479/files#diff-4bb4959de91d075b70b4378c9000257cR323-R324

Is that going to be done in a separate PR?

Per discussion with @colin-axner, my understanding is that the SDK already takes the intersection of compatible versions - is that accurate? If so, I don't think anything else needs to be done (the spec previously just didn't specify an intersection).

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.

LGTM. One minor comment

Comment on lines 172 to 173
if !((connection.State == types.INIT && types.IsSupportedVersion(encodedVersion)) ||
(connection.State == types.TRYOPEN && len(connection.Versions) == 1 && connection.Versions[0] == encodedVersion)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit, this is hard to read. Can we assign a variable name for each case (init and tryopen)?

Copy link
Contributor Author

@colin-axner colin-axner Sep 22, 2020

Choose a reason for hiding this comment

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

I could alternatively do a swtich

switch {
    case connection.State != INIT || connection.State != TRYOPEN:

    case connection.State == INIT && !types.IsSupportedVersion(encodedVersion):

    case connection.State == TRYOPEN && (len(connection.Versions) != 1 || connection.Version[0] != encodedVersion):

}   

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@fedekunze I update this to use a switch. I think it is more clear, let me know if any adjustments should be made

@colin-axner
Copy link
Contributor Author

Some small nits.
Also it looks like this part of the spec change wasn't implemeneted:
https://github.com/cosmos/ics/pull/479/files#diff-4bb4959de91d075b70b4378c9000257cR323-R324
Is that going to be done in a separate PR?

Per discussion with @colin-axner, my understanding is that the SDK already takes the intersection of compatible versions - is that accurate? If so, I don't think anything else needs to be done (the spec previously just didn't specify an intersection).

correct. PickVersion will always return an error if the selected version is not in the intersection of the supported version and the counterparty versions.

I can add comments in the code to make this clear.

colin-axner and others added 5 commits September 22, 2020 10:55
Update the version checks in ConnOpenAck to use a switch to increase readability of the code as well as provide custom error messages for each possible case that may occur. Slighly modified version to review suggestion by @fedekunze
@mergify mergify bot merged commit 83f2c75 into master Sep 22, 2020
@mergify mergify bot deleted the colin/7025-connection-handshake-updates branch September 22, 2020 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:automerge Automatically merge PR once all prerequisites pass.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants