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

Modular IBC Client #7028

Merged
merged 13 commits into from
Aug 14, 2020
Merged

Modular IBC Client #7028

merged 13 commits into from
Aug 14, 2020

Conversation

AdityaSripal
Copy link
Member

Description

closes: #6064


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 Aug 12, 2020

Codecov Report

Merging #7028 into master will increase coverage by 0.00%.
The diff coverage is 38.67%.

@@           Coverage Diff           @@
##           master    #7028   +/-   ##
=======================================
  Coverage   61.97%   61.98%           
=======================================
  Files         520      520           
  Lines       32041    32015   -26     
=======================================
- Hits        19856    19843   -13     
+ Misses      10552    10542   -10     
+ Partials     1633     1630    -3     

@AdityaSripal AdityaSripal mentioned this pull request Aug 12, 2020
9 tasks
@AdityaSripal AdityaSripal changed the title Modular Client Modular IBC Client Aug 12, 2020
consensusHeight = uint64(ctx.BlockHeight())
default:
return nil, sdkerrors.Wrapf(types.ErrInvalidClientType, "unsupported client type (%s)", msg.GetClientType())
consState := msg.GetConsensusState()
if consState == nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure that returning an error is good? I for eg the localhost client would return nil here. I'd just set the consensusHeight = 0 in this case

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 a good point. @cwgoes thoughts? Is it likely that clients outside of localhost would not have consensus states?

Copy link
Member Author

Choose a reason for hiding this comment

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

Went with fede's suggestion

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.

Looking good. Left a few comments 👍

x/ibc/02-client/handler.go Outdated Show resolved Hide resolved
x/ibc/02-client/keeper/encoding.go Outdated Show resolved Hide resolved

// Retrieve trusted consensus states for each Header in misbehaviour
// and unmarshal from clientStore
consBytes1 := clientStore.Get(host.KeyConsensusState(tmEvidence.Header1.TrustedHeight))
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 you add a few more spacing between lines? it's too packed lol

Copy link
Contributor

Choose a reason for hiding this comment

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

also use GetConsensusState helper func

Copy link
Member Author

@AdityaSripal AdityaSripal Aug 13, 2020

Choose a reason for hiding this comment

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

I can't because I'm using the prefix.Store which only implements Get and Set, I think this is preferable to giving the specific clients access to the client.Keeper

Copy link
Contributor

Choose a reason for hiding this comment

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

see my comment on update.go, but the helper function I was referring to is in 07-tendermint/types/store.go not the client keeper

x/ibc/09-localhost/types/msgs.go Show resolved Hide resolved
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.

first pass LGTM, this will greatly reduce the complexity in 02-client 💯

x/ibc/02-client/exported/exported.go Outdated Show resolved Hide resolved
x/ibc/02-client/handler.go Outdated Show resolved Hide resolved
consensusHeight = uint64(ctx.BlockHeight())
default:
return nil, sdkerrors.Wrapf(types.ErrInvalidClientType, "unsupported client type (%s)", msg.GetClientType())
consState := msg.GetConsensusState()
if consState == nil {
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 a good point. @cwgoes thoughts? Is it likely that clients outside of localhost would not have consensus states?

x/ibc/02-client/handler.go Outdated Show resolved Hide resolved
@@ -69,34 +66,7 @@ func (k Keeper) UpdateClient(ctx sdk.Context, clientID string, header exported.H
err error
)

switch clientType {
case exported.Tendermint:
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️

x/ibc/02-client/keeper/encoding.go Outdated Show resolved Hide resolved
x/ibc/02-client/keeper/encoding.go Show resolved Hide resolved
@@ -72,6 +72,26 @@ func (cs ClientState) GetProofSpecs() []*ics23.ProofSpec {
return nil
}

// CheckValidityAndUpdateState updates the localhost client
// It only needs access to the context
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: only do line breaks when the line goes to far to the right, not per idea. This is pretty standard across the SDK and I find it easier to read/look at because it is standard

tmConsState, ok := consState.(*types.ConsensusState)
if !ok {
// Get trusted consensus state and unmarshal from clientStore
consBytes := clientStore.Get(host.KeyConsensusState(tmHeader.TrustedHeight))
Copy link
Contributor

Choose a reason for hiding this comment

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

use helper function GetConsensusState

Copy link
Collaborator

Choose a reason for hiding this comment

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

++

Copy link
Member Author

Choose a reason for hiding this comment

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

I can't because I'm using the prefix.Store which only handles Get and Set, I think this is preferable to giving the specific clients access to the client.Keeper

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 confused? I was referring to the helper in x/ibc/07-tendermint/types/store.go

// GetConsensusState retrieves the consensus state from the client prefixed
// store. An error is returned if the consensus state does not exist.
func GetConsensusState(store sdk.KVStore, cdc codec.BinaryMarshaler, height uint64) (*ConsensusState, error) {

This isn't giving access to the keeper

Copy link
Member Author

Choose a reason for hiding this comment

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

😮 I did not realize that function existed!! That's a lot cleaner! Thanks @colin-axner !!


// Retrieve trusted consensus states for each Header in misbehaviour
// and unmarshal from clientStore
consBytes1 := clientStore.Get(host.KeyConsensusState(tmEvidence.Header1.TrustedHeight))
Copy link
Contributor

Choose a reason for hiding this comment

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

also use GetConsensusState helper func

@AdityaSripal AdityaSripal marked this pull request as ready for review August 13, 2020 23:00
@@ -35,7 +35,7 @@ var DefaultConsensusParams = &abci.ConsensusParams{
},
Evidence: &abci.EvidenceParams{
MaxAgeNumBlocks: 302400,
MaxAgeDuration: 1814400,
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 used to be nanoseconds

ageDuration := currentTimestamp.Sub(infractionTime)
ageBlocks := uint64(infractionHeight) - height
ageDuration := ctx.BlockTime().Sub(infractionTime)
ageBlocks := int64(cs.LatestHeight) - infractionHeight
Copy link
Member Author

Choose a reason for hiding this comment

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

ageBlocks was being incorrectly calculated, fixed now.

suite.now,
false,
},
{
"rejected misbehaviour due to expired age",
"rejected misbehaviour due to expired age duration",
Copy link
Member Author

Choose a reason for hiding this comment

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

Tested incorrectly, fixed now

Comment on lines +90 to +91
(ageDuration > consensusParams.Evidence.MaxAgeDuration ||
ageBlocks > consensusParams.Evidence.MaxAgeNumBlocks) {
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 must be OR not AND

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 clean! thanks @AdityaSripal

@fedekunze fedekunze merged commit 3735b18 into master Aug 14, 2020
@fedekunze fedekunze deleted the aditya-modular-client branch August 14, 2020 08:47
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.

This pr is a huge improvement 🎉 . I left some nits, but my main request is that we use the GetConsensusState helper function in 07-tendermint/types/store.go. I think there was some confusion on what I meant with my initial review comment, but there exists redundant code and it will be much easier for others to read

localhosttypes "github.com/cosmos/cosmos-sdk/x/ibc/09-localhost/types"
)

func (suite *ClientTestSuite) TestHandleCreateClientLocalHost() {
Copy link
Contributor

Choose a reason for hiding this comment

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

it would have been nice to note that since suite.SetupTest() is not being ran, test case state changes are persisted through each test meaning test case ordering matters. This could be confusing for later developers who modify this test or copy its structure.


clientState, ok := suite.chainA.App.IBCKeeper.ClientKeeper.GetClientState(suite.chainA.GetContext(), tc.clientID)
suite.Require().True(ok, "could not retrieve clientState")
suite.Require().NotNil(clientState, "clientstate is nil")
Copy link
Contributor

Choose a reason for hiding this comment

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

checking the clientState.(type) would have been nice here as well to ensure the correct client state was created for the clientID

func (chain *TestChain) CreateTMClient(counterparty *TestChain, clientID string) error {
// construct MsgCreateClient using counterparty
msg := ibctmtypes.NewMsgCreateClient(
func (chain *TestChain) ConstructMsgCreateClient(counterparty *TestChain, clientID string) clientexported.MsgCreateClient {
Copy link
Contributor

Choose a reason for hiding this comment

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

some godoc here would have been nice or a different name since this creates specifically a tendermint client


// Retrieve trusted consensus states for each Header in misbehaviour
// and unmarshal from clientStore
consBytes1 := clientStore.Get(host.KeyConsensusState(tmEvidence.Header1.TrustedHeight))
Copy link
Contributor

Choose a reason for hiding this comment

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

see my comment on update.go, but the helper function I was referring to is in 07-tendermint/types/store.go not the client keeper

ageDuration > consensusParams.Evidence.MaxAgeDuration &&
ageBlocks > uint64(consensusParams.Evidence.MaxAgeNumBlocks) {
(ageDuration > consensusParams.Evidence.MaxAgeDuration ||
ageBlocks > consensusParams.Evidence.MaxAgeNumBlocks) {
return nil, sdkerrors.Wrapf(clienttypes.ErrInvalidEvidence,
"age duration (%s) and age blocks (%d) are greater than max consensus params for duration (%s) and block (%d)",
Copy link
Contributor

Choose a reason for hiding this comment

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

this error message should be updated to reflect the logic change


import (
"bytes"
fmt "fmt"
Copy link
Contributor

Choose a reason for hiding this comment

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

?

}
if tc.expPass {
suite.Require().NoError(err, "valid test case %d failed: %s", i, tc.name)
suite.Require().NotNil(clientState, "valid test case %d failed: %s", i, tc.name)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: when using suite.Run since the case name is passed in and printed out upon an error, I like to leave these error messages blank unless providing useful notes on why it might have failed

@@ -69,34 +66,7 @@ func (k Keeper) UpdateClient(ctx sdk.Context, clientID string, header exported.H
err error
)

Copy link
Contributor

Choose a reason for hiding this comment

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

It's a little strange the the client keeper has UpdateClient and CheckMisbehaviourAndUpdateState. We should update these to be consistent? These funcs also do checks on the client state

@AdityaSripal AdityaSripal mentioned this pull request Aug 18, 2020
9 tasks
mergify bot added a commit that referenced this pull request Aug 19, 2020
* use cleaner helper function

* fix error strings

* lint

* typos

Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>
Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
larry0x pushed a commit to larry0x/cosmos-sdk that referenced this pull request May 22, 2023
* start modular client work

* fix panic

* reuse keeper marshal methods

* readd TODO

* add nil checks for misbehaviour

* address reviews

* address rest of reviews and fix builds

* fixed tests

* address rest of reviews

* fix expired blocks bug

* fix expired bug
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.

x/ibc Make 02-client more modular
3 participants