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

Minor fixes for ibc tendermint #7916

Merged
merged 6 commits into from
Nov 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions x/ibc/light-clients/07-tendermint/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,4 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
(*exported.Misbehaviour)(nil),
&Misbehaviour{},
)
registry.RegisterImplementations(
(*exported.Header)(nil),
&Header{},
)
}
8 changes: 2 additions & 6 deletions x/ibc/light-clients/07-tendermint/types/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,16 @@ func (h Header) ClientType() string {

// GetHeight returns the current height. It returns 0 if the tendermint
// header is nil.
// NOTE: the header.Header is checked to be non nil in ValidateBasic.
func (h Header) GetHeight() exported.Height {
if h.Header == nil {
return clienttypes.ZeroHeight()
}
version := clienttypes.ParseChainID(h.Header.ChainID)
return clienttypes.NewHeight(version, uint64(h.Header.Height))
}

// GetTime returns the current block timestamp. It returns a zero time if
// the tendermint header is nil.
// NOTE: the header.Header is checked to be non nil in ValidateBasic.
func (h Header) GetTime() time.Time {
if h.Header == nil {
return time.Time{}
}
return h.Header.Time
}

Expand Down
6 changes: 0 additions & 6 deletions x/ibc/light-clients/07-tendermint/types/header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,11 @@ import (
func (suite *TendermintTestSuite) TestGetHeight() {
header := suite.chainA.LastHeader
suite.Require().NotEqual(uint64(0), header.GetHeight())

header.Header = nil
suite.Require().Equal(clienttypes.ZeroHeight(), header.GetHeight())
}

func (suite *TendermintTestSuite) TestGetTime() {
header := suite.chainA.LastHeader
suite.Require().NotEqual(time.Time{}, header.GetTime())

header.Header = nil
suite.Require().Equal(time.Time{}, header.GetTime())
}

func (suite *TendermintTestSuite) TestHeaderValidateBasic() {
Expand Down
11 changes: 10 additions & 1 deletion x/ibc/light-clients/07-tendermint/types/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ import (
// in client state that must be the same across all valid Tendermint clients for the new chain.
// VerifyUpgrade will return an error if:
// - the upgradedClient is not a Tendermint ClientState
// - the lastest height of the client state does not have the same version number or has a greater
// height than the committed client.
// - the height of upgraded client is not greater than that of current client
// - the latest height of the new client does not match the height in committed client
// - the latest height of the new client does not match or is greater than the height in committed client
// - any Tendermint chain specified parameter in upgraded client such as ChainID, UnbondingPeriod,
// and ProofSpecs do not match parameters set by committed client
func (cs ClientState) VerifyUpgradeAndUpdateState(
Expand All @@ -40,6 +42,13 @@ func (cs ClientState) VerifyUpgradeAndUpdateState(
cs.GetLatestHeight().GetVersionNumber(), upgradeHeight.GetVersionNumber())
}

// UpgradeHeight must be greater than or equal to current client state height
if cs.GetLatestHeight().GetVersionHeight() > upgradeHeight.GetVersionHeight() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't sure if they could be equal but it sounds logical to me that the latest client state must be less than or equal to the upgrade height?

return nil, nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidHeight, "version height at which upgrade occurs must be greater than or equal to current client height (%d > %d)",
cs.GetLatestHeight().GetVersionHeight(), upgradeHeight.GetVersionHeight(),
)
}

if !upgradedClient.GetLatestHeight().GT(cs.GetLatestHeight()) {
return nil, nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidHeight, "upgraded client height %s must be greater than current client height %s",
upgradedClient.GetLatestHeight(), cs.GetLatestHeight())
Expand Down
26 changes: 26 additions & 0 deletions x/ibc/light-clients/07-tendermint/types/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,32 @@ func (suite *TendermintTestSuite) TestVerifyUpgrade() {
},
expPass: false,
},
{
name: "unsuccessful upgrade: upgrade height version height is less than the current client version height",
setup: func() {

upgradedClient = types.NewClientState("newChainId", types.DefaultTrustLevel, trustingPeriod, ubdPeriod+trustingPeriod, maxClockDrift, newClientHeight, commitmenttypes.GetSDKSpecs(), upgradePath, false, false)

// upgrade Height is at next block
upgradeHeight = clienttypes.NewHeight(10, uint64(suite.chainB.GetContext().BlockHeight()-1))

// zero custom fields and store in upgrade store
suite.chainB.App.UpgradeKeeper.SetUpgradedClient(suite.chainB.GetContext(), int64(upgradeHeight.GetVersionHeight()), upgradedClient)

// commit upgrade store changes and update clients

suite.coordinator.CommitBlock(suite.chainB)
err := suite.coordinator.UpdateClient(suite.chainA, suite.chainB, clientA, exported.Tendermint)
suite.Require().NoError(err)

cs, found := suite.chainA.App.IBCKeeper.ClientKeeper.GetClientState(suite.chainA.GetContext(), clientA)
suite.Require().True(found)

proofUpgrade, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedClientKey(int64(upgradeHeight.GetVersionHeight())), cs.GetLatestHeight().GetVersionHeight())
},
expPass: false,
},

{
name: "unsuccessful upgrade: chain-specified parameters do not match committed client",
setup: func() {
Expand Down