-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Modular IBC Client #7028
Conversation
Codecov Report
@@ 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 |
x/ibc/02-client/handler.go
Outdated
consensusHeight = uint64(ctx.BlockHeight()) | ||
default: | ||
return nil, sdkerrors.Wrapf(types.ErrInvalidClientType, "unsupported client type (%s)", msg.GetClientType()) | ||
consState := msg.GetConsensusState() | ||
if consState == 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.
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
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.
this is a good point. @cwgoes thoughts? Is it likely that clients outside of localhost would not have consensus states?
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.
Went with fede's suggestion
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.
Looking good. Left a few comments 👍
|
||
// Retrieve trusted consensus states for each Header in misbehaviour | ||
// and unmarshal from clientStore | ||
consBytes1 := clientStore.Get(host.KeyConsensusState(tmEvidence.Header1.TrustedHeight)) |
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, can you add a few more spacing between lines? it's too packed lol
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.
also use GetConsensusState
helper func
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 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
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.
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
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.
first pass LGTM, this will greatly reduce the complexity in 02-client 💯
x/ibc/02-client/handler.go
Outdated
consensusHeight = uint64(ctx.BlockHeight()) | ||
default: | ||
return nil, sdkerrors.Wrapf(types.ErrInvalidClientType, "unsupported client type (%s)", msg.GetClientType()) | ||
consState := msg.GetConsensusState() | ||
if consState == 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.
this is a good point. @cwgoes thoughts? Is it likely that clients outside of localhost would not have consensus states?
@@ -69,34 +66,7 @@ func (k Keeper) UpdateClient(ctx sdk.Context, clientID string, header exported.H | |||
err error | |||
) | |||
|
|||
switch clientType { | |||
case exported.Tendermint: |
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.
❤️
@@ -72,6 +72,26 @@ func (cs ClientState) GetProofSpecs() []*ics23.ProofSpec { | |||
return nil | |||
} | |||
|
|||
// CheckValidityAndUpdateState updates the localhost client | |||
// It only needs access to the context |
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: 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)) |
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.
use helper function GetConsensusState
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.
++
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 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
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'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
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 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)) |
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.
also use GetConsensusState
helper func
…into aditya-modular-client
@@ -35,7 +35,7 @@ var DefaultConsensusParams = &abci.ConsensusParams{ | |||
}, | |||
Evidence: &abci.EvidenceParams{ | |||
MaxAgeNumBlocks: 302400, | |||
MaxAgeDuration: 1814400, |
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.
THis used to be nanoseconds
ageDuration := currentTimestamp.Sub(infractionTime) | ||
ageBlocks := uint64(infractionHeight) - height | ||
ageDuration := ctx.BlockTime().Sub(infractionTime) | ||
ageBlocks := int64(cs.LatestHeight) - infractionHeight |
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.
ageBlocks was being incorrectly calculated, fixed now.
suite.now, | ||
false, | ||
}, | ||
{ | ||
"rejected misbehaviour due to expired age", | ||
"rejected misbehaviour due to expired age duration", |
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.
Tested incorrectly, fixed now
(ageDuration > consensusParams.Evidence.MaxAgeDuration || | ||
ageBlocks > consensusParams.Evidence.MaxAgeNumBlocks) { |
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.
This must be OR not AND
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 clean! thanks @AdityaSripal
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.
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() { |
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.
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") |
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.
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 { |
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.
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)) |
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.
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)", |
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.
this error message should be updated to reflect the logic change
|
||
import ( | ||
"bytes" | ||
fmt "fmt" |
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.
?
} | ||
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) |
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: 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 | |||
) | |||
|
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.
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
* 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>
* 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
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.
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