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

Remove Last Header from ClientState #6873

Merged
merged 23 commits into from
Aug 4, 2020
Merged

Conversation

AdityaSripal
Copy link
Member

Description

  • Removes LastHeader from ClientState
  • Allow updates to past heights

closes: #6736 and https://github.com/cosmos/ics/issues/420


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 Jul 29, 2020

Codecov Report

Merging #6873 into master will increase coverage by 5.84%.
The diff coverage is 55.73%.

@@            Coverage Diff             @@
##           master    #6873      +/-   ##
==========================================
+ Coverage   55.60%   61.44%   +5.84%     
==========================================
  Files         457      517      +60     
  Lines       27440    32103    +4663     
==========================================
+ Hits        15257    19726    +4469     
+ Misses      11083    10804     -279     
- Partials     1100     1573     +473     

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.

looks good. Minor comments

Time: chain.CurrentHeader.Time,
Time: chain.CurrentHeader.Time,
ValidatorsHash: chain.Vals.Hash(),
NextValidatorsHash: chain.Vals.Hash(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess it's ok for now but it would be useful to test validator changes

Copy link
Contributor

Choose a reason for hiding this comment

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

could we open up an issue for this?

Copy link
Contributor

Choose a reason for hiding this comment

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

add to #6509 testing pkg wishlist

@@ -31,6 +33,8 @@ const (
channelOrder = channeltypes.ORDERED
channelVersion = "1.0"

height = 10
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit, can we use the ibc testing package here? 🙏

Copy link
Contributor

Choose a reason for hiding this comment

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

this is just used by genesis_test.go, fine for now. handler_test.go uses ibc testing pkg

x/ibc/07-tendermint/update.go Outdated Show resolved Hide resolved
ErrTrustingPeriodExpired = sdkerrors.Register(SubModuleName, 6, "time since latest trusted state has passed the trusting period")
ErrUnbondingPeriodExpired = sdkerrors.Register(SubModuleName, 7, "time since latest trusted state has passed the unbonding period")
ErrInvalidProofSpecs = sdkerrors.Register(SubModuleName, 8, "invalid proof specs")
ErrInvalidChainID = sdkerrors.Register(SubModuleName, 2, "invalid chain-id")
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this should live on the sdkerrors package since it's very general

x/ibc/07-tendermint/types/client_state.go Outdated Show resolved Hide resolved
@AdityaSripal
Copy link
Member Author

Note: This PR currently does not support updating past heights once a client has already been frozen.

Thus, in an unfrozen client: It is possible for the latest height of client to be at height 10, and update to fill in a consensus state height at 7

In a frozen client with frozen height 10, it is not possible to update and fill in a consensus state at height < frozenheight.

Enabling this would require adding a method on ClientState interface FrozenHeight() uint64

If this addition is worth it, I can implement it in this PR; it is a fairly trivial addition from an implementation standpoint

cc: @cwgoes

@cwgoes
Copy link
Contributor

cwgoes commented Jul 31, 2020

Note: This PR currently does not support updating past heights once a client has already been frozen.

Thus, in an unfrozen client: It is possible for the latest height of client to be at height 10, and update to fill in a consensus state height at 7

In a frozen client with frozen height 10, it is not possible to update and fill in a consensus state at height < frozenheight.

Enabling this would require adding a method on ClientState interface FrozenHeight() uint64

If this addition is worth it, I can implement it in this PR; it is a fairly trivial addition from an implementation standpoint

cc: @cwgoes

Hmm, good question, per our current definition of frozenHeight this would be technically correct to allow, I think, although it doesn't matter too much - but if it's easy, let's do it.

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.

Let's not store the validator set but rather the hash. Otherwise looks fine.

Root commitmentexported.Root `json:"root" yaml:"root"`
Height uint64 `json:"height" yaml:"height"`
NextValidatorsHash tmbytes.HexBytes `json:"next_validators_hash"` // validators hash for the next block
ValidatorSet *tmtypes.ValidatorSet `json:"validator_set" yaml:"validator_set"`
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we want to store the whole validator set in each consensus state - too large - can we store the hash and require that the validator set be passed in update messages instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm yea that's fine. Note this makes relayer flow for updating more complicated since the relayer needs to know the LatestHeight of the client in order to query the last trusted valset.

Though since this is true, we can just query for the ValidatorSet at LatestHeight+1 so that we can use NextValidators of last trusted header in lite.Verify

Ref issue here: https://github.com/cosmos/ics/issues/456#issuecomment-665118922

Copy link
Member Author

Choose a reason for hiding this comment

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

This requires significant changes with tradeoffs, I will implement this in a separate PR so people can see the diffs in isolation.

Copy link
Contributor

Choose a reason for hiding this comment

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

opened an issue to track this #6930

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed, this can be done in a follow-up.

Copy link
Contributor

@colin-axner colin-axner left a comment

Choose a reason for hiding this comment

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

Implementation looks good to me. This is a great add on, nice work!

The godoc and error messages seem to be have been neglected and need some love in being updated to convey the new functionality. I think it'd be fantastic if you could update the ibc spec on this logic as well. Maybe add a section in concepts.

The testing pkg was also relying on the client state needing the full signed header, which means there is now a lot of redundant info being tracked that can be discarded. Could you update the changes this pr does in relation to those fields?

I think it'd also be very nice to add some testing with the testing pkg. Just adding a func to update at a specific height would be nice and then testing filling consensus states for previous height. This could be done in a followup issue though

x/ibc/07-tendermint/types/consensus_state.go Outdated Show resolved Hide resolved
Time: chain.CurrentHeader.Time,
Time: chain.CurrentHeader.Time,
ValidatorsHash: chain.Vals.Hash(),
NextValidatorsHash: chain.Vals.Hash(),
Copy link
Contributor

Choose a reason for hiding this comment

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

could we open up an issue for this?

x/ibc/02-client/keeper/client.go Outdated Show resolved Hide resolved
x/ibc/02-client/keeper/client_test.go Outdated Show resolved Hide resolved
x/ibc/07-tendermint/update.go Outdated Show resolved Hide resolved
x/ibc/07-tendermint/update.go Outdated Show resolved Hide resolved
x/ibc/07-tendermint/update.go Show resolved Hide resolved
x/ibc/07-tendermint/update_test.go Outdated Show resolved Hide resolved
x/ibc/07-tendermint/update_test.go Show resolved Hide resolved
x/ibc/07-tendermint/update_test.go Outdated Show resolved Hide resolved
AdityaSripal and others added 2 commits July 31, 2020 13:21
Co-authored-by: colin axner <25233464+colin-axner@users.noreply.github.com>
Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
Copy link
Contributor

@colin-axner colin-axner left a comment

Choose a reason for hiding this comment

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

left some more nits and suggestions

x/ibc/07-tendermint/types/errors.go Outdated Show resolved Hide resolved
x/ibc/07-tendermint/update.go Outdated Show resolved Hide resolved
x/ibc/07-tendermint/update.go Outdated Show resolved Hide resolved
x/ibc/07-tendermint/update.go Show resolved Hide resolved
x/ibc/07-tendermint/update.go Outdated Show resolved Hide resolved
x/ibc/07-tendermint/update.go Show resolved Hide resolved
x/ibc/02-client/keeper/client.go Show resolved Hide resolved
x/ibc/07-tendermint/update.go Outdated Show resolved Hide resolved
x/ibc/07-tendermint/update.go Outdated Show resolved Hide resolved
x/ibc/07-tendermint/update.go Outdated Show resolved Hide resolved
@colin-axner
Copy link
Contributor

Following merge of this pr I'm pretty sure we can migrate client state entirely, consensusState and headers will have to wait for tendemint update. No fields in client state rely on tendermint except Fraction, but an initial migration already showed we have to define our own Fraction anyways

Copy link
Contributor

@colin-axner colin-axner left a comment

Choose a reason for hiding this comment

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

LGTM - amazing work!

@colin-axner
Copy link
Contributor

I think the following changes should still be done

  • updating spec
  • removing unnecessary header parts from ibc-testing and the tm utils testing in the 07-tendermint/types
  • adding tests to check update functionality using testing pkg

But since this pr is now the blocking factor for client state migration, they should be done in followup pr's

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, one minor query, agreed on follow-ups

Root commitmentexported.Root `json:"root" yaml:"root"`
Height uint64 `json:"height" yaml:"height"`
NextValidatorsHash tmbytes.HexBytes `json:"next_validators_hash"` // validators hash for the next block
ValidatorSet *tmtypes.ValidatorSet `json:"validator_set" yaml:"validator_set"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed, this can be done in a follow-up.

@@ -71,9 +71,16 @@ func (k Keeper) UpdateClient(ctx sdk.Context, clientID string, header exported.H

switch clientType {
case exported.Tendermint:
trustedConsState, found := k.GetClientConsensusStateLTE(ctx, clientID, header.GetHeight())
Copy link
Contributor

Choose a reason for hiding this comment

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

This is probably alright, although I wonder if we want to allow the transaction to provide an explicit past height to update from - though in most cases the most recent height will be best, as we have here

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

@fedekunze fedekunze merged commit 9b61e09 into master Aug 4, 2020
@fedekunze fedekunze deleted the aditya/remove-last-header branch August 4, 2020 09:05
larry0x pushed a commit to larry0x/cosmos-sdk that referenced this pull request May 22, 2023
* implement features, fix tendermint tests

* allow test headers to pass in custom nextvalidatorset

* allow updates to previous heights and test

* remove unnecessary testing feature

* fix client tests

* fix ibc tests, and updating consensus state

* fix ibc-transfer tests

* appease linter

* Apply suggestions from code review

Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>

* add chainID test case

* fix expPass value

* Apply suggestions from code review

Co-authored-by: colin axner <25233464+colin-axner@users.noreply.github.com>
Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>

* address rest of @colin-axner review

* fix bug and errors

* Apply suggestions from code review

Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>

* address rest of @colin-axner review

* implement updating before frozen height

Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
Co-authored-by: colin axner <25233464+colin-axner@users.noreply.github.com>
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.

ClientState in x/ibc/07 diverges from that in ICS 07
4 participants