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 IBC logic from x/upgrade #8673

Merged
merged 47 commits into from
Mar 1, 2021
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
e65921b
add zeroed custom fields check to tm client
colin-axner Feb 23, 2021
64b59fd
remove custom fields function from x/upgrade and fix tests
colin-axner Feb 23, 2021
1234383
use []byte in x/upgrade, move abci to 02-client
colin-axner Feb 23, 2021
c5c0d26
remove x/ibc from types
colin-axner Feb 23, 2021
31ca56d
whoops, delete testing files
colin-axner Feb 23, 2021
9ea85b8
fix upgrade tests
colin-axner Feb 24, 2021
3449f66
fix tm tests
colin-axner Feb 24, 2021
01cc2d7
fix tests
colin-axner Feb 24, 2021
975133b
Merge branch 'master' of github.com:cosmos/cosmos-sdk into colin/rm-i…
colin-axner Feb 24, 2021
21fb511
update CHANGELOG
colin-axner Feb 24, 2021
862dc37
revert proto breakage, use reserved field cc @amaurym
colin-axner Feb 24, 2021
1d5bdd5
Merge branch 'master' into colin/rm-ibc-from-upgrade
colin-axner Feb 24, 2021
dd180e8
add IBC Upgrade Proposal type
colin-axner Feb 25, 2021
99f8a76
remove IBC from upgrade types
colin-axner Feb 25, 2021
973cef5
add IBC upgrade logic to 02-client
colin-axner Feb 25, 2021
c47f4ce
Merge branch 'colin/rm-ibc-from-upgrade' of github.com:cosmos/cosmos-…
colin-axner Feb 25, 2021
c9e515b
fix all tests for x/upgrade
colin-axner Feb 25, 2021
1590837
Add CLI for IBC Upgrade Proposal
colin-axner Feb 25, 2021
a2959f6
Merge branch 'master' of github.com:cosmos/cosmos-sdk into colin/rm-i…
colin-axner Feb 25, 2021
5295e58
Update x/ibc/core/02-client/types/proposal_test.go
colin-axner Feb 25, 2021
b136626
Merge branch 'colin/rm-ibc-from-upgrade' of github.com:cosmos/cosmos-…
colin-axner Feb 25, 2021
49924c8
add gRPC for upgraded client state
colin-axner Feb 25, 2021
d05fba1
test fixes
colin-axner Feb 25, 2021
d86f0b0
add HandleUpgradeProposal tests
colin-axner Feb 26, 2021
96bc1c8
update docs and remove unnecessary code
colin-axner Feb 26, 2021
28fb256
Merge branch 'master' into colin/rm-ibc-from-upgrade
colin-axner Feb 26, 2021
b1fc663
self review bug and test fixes
colin-axner Feb 26, 2021
715dd42
Merge branch 'colin/rm-ibc-from-upgrade' of github.com:cosmos/cosmos-…
colin-axner Feb 26, 2021
2b2e0b0
neatness
colin-axner Feb 26, 2021
a0ff9e3
Merge branch 'master' into colin/rm-ibc-from-upgrade
colin-axner Feb 26, 2021
7b281f4
construct empty rest handler
colin-axner Feb 26, 2021
75edb27
Merge branch 'master' into colin/rm-ibc-from-upgrade
colin-axner Feb 26, 2021
d771d4f
fix tests
colin-axner Feb 26, 2021
e9597c1
Merge branch 'colin/rm-ibc-from-upgrade' of github.com:cosmos/cosmos-…
colin-axner Feb 26, 2021
07670fc
fix stringer tests
colin-axner Feb 26, 2021
d3ecf9e
Update docs/core/proto-docs.md
colin-axner Mar 1, 2021
2a6adb0
add key in ibc store tracking ibc upgrade heights
colin-axner Mar 1, 2021
0b51095
Merge branch 'colin/rm-ibc-from-upgrade' of github.com:cosmos/cosmos-…
colin-axner Mar 1, 2021
d40e695
update abci and tests
colin-axner Mar 1, 2021
7906b28
Merge branch 'master' into colin/rm-ibc-from-upgrade
colin-axner Mar 1, 2021
0404d4e
Merge branch 'master' into colin/rm-ibc-from-upgrade
colin-axner Mar 1, 2021
9dbcbe1
Merge branch 'master' into colin/rm-ibc-from-upgrade
colin-axner Mar 1, 2021
73fefb9
Merge branch 'master' of github.com:cosmos/cosmos-sdk into colin/rm-i…
colin-axner Mar 1, 2021
abc4ebb
Merge branch 'colin/rm-ibc-from-upgrade' of github.com:cosmos/cosmos-…
colin-axner Mar 1, 2021
95cb360
revert key storage after discussion with @AdityaSripal
colin-axner Mar 1, 2021
5e20b2f
clear IBC states on cancelled upgrades
colin-axner Mar 1, 2021
57f2c8d
Merge branch 'master' into colin/rm-ibc-from-upgrade
colin-axner Mar 1, 2021
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/distribution) [\#8473](https://github.com/cosmos/cosmos-sdk/pull/8473) On genesis init, if the distribution module account balance, coming from bank module state, does not match the one in distribution module state, the initialization will panic.
* (client/keys) [\#8500](https://github.com/cosmos/cosmos-sdk/pull/8500) `InfoImporter` interface is removed from legacy keybase.
* [\#8629](https://github.com/cosmos/cosmos-sdk/pull/8629) Deprecated `SetFullFundraiserPath` from `Config` in favor of `SetPurpose` and `SetCoinType`.
* (x/upgrade) [\#8673](https://github.com/cosmos/cosmos-sdk/pull/8673) Remove x/ibc imports from x/upgrade by replacing plan.UpgradedClient with a `[]byte` instead of using an `Any`. IBC upgrade begin blocker logic moved to the IBC module.

### State Machine Breaking

Expand Down
4 changes: 2 additions & 2 deletions docs/core/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -7507,7 +7507,7 @@ Plan specifies information about a planned upgrade and when it should occur.
| `time` | [google.protobuf.Timestamp](#google.protobuf.Timestamp) | | The time after which the upgrade must be performed. Leave set to its zero value to use a pre-defined Height instead. |
| `height` | [int64](#int64) | | The height at which the upgrade must be performed. Only used if Time is not set. |
| `info` | [string](#string) | | Any application specific upgrade info to be included on-chain such as a git commit that validators could automatically upgrade to |
| `upgraded_client_state` | [google.protobuf.Any](#google.protobuf.Any) | | IBC-enabled chains can opt-in to including the upgraded client state in its upgrade plan This will make the chain commit to the correct upgraded (self) client state before the upgrade occurs, so that connecting chains can verify that the new upgraded client is valid by verifying a proof on the previous version of the chain. This will allow IBC connections to persist smoothly across planned chain upgrades |
| `upgraded_client_state` | [bytes](#bytes) | | IBC-enabled chains can opt-in to including the upgraded client state in its upgrade plan This will make the chain commit to the correct upgraded (self) client state before the upgrade occurs, so that connecting chains can verify that the new upgraded client is valid by verifying a proof on the previous version of the chain. This will allow IBC connections to persist smoothly across planned chain upgrades |
colin-axner marked this conversation as resolved.
Show resolved Hide resolved



Expand Down Expand Up @@ -7632,7 +7632,7 @@ RPC method.

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `upgraded_consensus_state` | [google.protobuf.Any](#google.protobuf.Any) | | |
| `upgraded_consensus_state` | [bytes](#bytes) | | |



Expand Down
5 changes: 4 additions & 1 deletion proto/cosmos/upgrade/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,8 @@ message QueryUpgradedConsensusStateRequest {
// QueryUpgradedConsensusStateResponse is the response type for the Query/UpgradedConsensusState
// RPC method.
message QueryUpgradedConsensusStateResponse {
google.protobuf.Any upgraded_consensus_state = 1;
reserved 1;
reserved "option";
colin-axner marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
reserved "option";

You can remove this. This is to reserve a field name. Since you're using the same field name in the new field, there's no need to reserve anything.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good to know, thanks. I'm waiting on a confirmation from @AdityaSripal, but I think the direction with this pr might be to remove IBC entirely:

  • create a duplicate proposal type in IBC that wraps an upgrade plan, then call ScheduleUpgrade from within IBC
  • handle IBC related logic in IBC

This would make this field obsolete. Any preference for how to deprecate QueryUpgradedConsensusStateResponse? And for Plan I guess reserving the field and name would be sufficient

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool. Yes, reserving both field number and name should be enough.


bytes upgraded_consensus_state = 2;
Copy link
Collaborator

Choose a reason for hiding this comment

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

why this was changed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry for not documenting it, but I believe the reason why is because then the upgrade module would have a dependency on the IBC module which we wanted to completely avoid. In order to return the correct Any, the upgrade module would need to understand what an IBC consensus state is, thus creating a dependency on the IBC module

Is there an issue with the new behaviour?

Copy link
Collaborator

Choose a reason for hiding this comment

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

It breaks the API. It seams that you were not correctly using this function - because Any was not used.

Copy link
Contributor Author

@colin-axner colin-axner Aug 4, 2021

Choose a reason for hiding this comment

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

This is just a convenience function for the cli. Relayers who perform the client upgrade functionality do ABCI queries to obtain the proofs necessary

}
5 changes: 4 additions & 1 deletion proto/cosmos/upgrade/v1beta1/upgrade.proto
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,15 @@ message Plan {
// such as a git commit that validators could automatically upgrade to
string info = 4;

reserved 5;
reserved "option";

// IBC-enabled chains can opt-in to including the upgraded client state in its upgrade plan
// This will make the chain commit to the correct upgraded (self) client state before the upgrade occurs,
// so that connecting chains can verify that the new upgraded client is valid by verifying a proof on the
// previous version of the chain.
// This will allow IBC connections to persist smoothly across planned chain upgrades
google.protobuf.Any upgraded_client_state = 5 [(gogoproto.moretags) = "yaml:\"upgraded_client_state\""];
bytes upgraded_client_state = 6 [(gogoproto.moretags) = "yaml:\"upgraded_client_state\""];
}

// SoftwareUpgradeProposal is a gov Content type for initiating a software
Expand Down
2 changes: 1 addition & 1 deletion simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func NewSimApp(

// Create IBC Keeper
app.IBCKeeper = ibckeeper.NewKeeper(
appCodec, keys[ibchost.StoreKey], app.GetSubspace(ibchost.ModuleName), app.StakingKeeper, scopedIBCKeeper,
appCodec, keys[ibchost.StoreKey], app.GetSubspace(ibchost.ModuleName), app.StakingKeeper, app.UpgradeKeeper, scopedIBCKeeper,
)

app.AuthzKeeper = authzkeeper.NewKeeper(keys[authztypes.StoreKey], appCodec, app.BaseApp.MsgServiceRouter())
Expand Down
22 changes: 21 additions & 1 deletion x/ibc/core/02-client/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,31 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/ibc/core/02-client/keeper"
"github.com/cosmos/cosmos-sdk/x/ibc/core/exported"
ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/light-clients/07-tendermint/types"
)

// BeginBlocker updates an existing localhost client with the latest block height.
func BeginBlocker(ctx sdk.Context, k keeper.Keeper) {
_, found := k.GetClientState(ctx, exported.Localhost)
plan, found := k.GetUpgradePlan(ctx)
if found {
// Once we are at the last block this chain will commit, set the upgraded consensus state
// so that IBC clients can use the last NextValidatorsHash as a trusted kernel for verifying
// headers on the next version of the chain.
// Set the time to the last block time of the current chain.
// In order for a client to upgrade successfully, the first block of the new chain must be committed
// within the trusting period of the last block time on this chain.
if plan.IsIBCPlan() && ctx.BlockHeight() == plan.Height-1 {
upgradedConsState := &ibctmtypes.ConsensusState{
Timestamp: ctx.BlockTime(),
NextValidatorsHash: ctx.BlockHeader().NextValidatorsHash,
}
bz := k.MustMarshalConsensusState(upgradedConsState)

k.SetUpgradedConsensusState(ctx, plan.Height, bz)
}
}

_, found = k.GetClientState(ctx, exported.Localhost)
if !found {
return
}
Expand Down
33 changes: 33 additions & 0 deletions x/ibc/core/02-client/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ import (
"testing"

"github.com/stretchr/testify/suite"
abci "github.com/tendermint/tendermint/abci/types"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

client "github.com/cosmos/cosmos-sdk/x/ibc/core/02-client"
"github.com/cosmos/cosmos-sdk/x/ibc/core/02-client/types"
"github.com/cosmos/cosmos-sdk/x/ibc/core/exported"
ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/light-clients/07-tendermint/types"
localhosttypes "github.com/cosmos/cosmos-sdk/x/ibc/light-clients/09-localhost/types"
ibctesting "github.com/cosmos/cosmos-sdk/x/ibc/testing"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
)

type ClientTestSuite struct {
Expand Down Expand Up @@ -58,3 +62,32 @@ func (suite *ClientTestSuite) TestBeginBlocker() {
prevHeight = localHostClient.GetLatestHeight().(types.Height)
}
}

func (suite *ClientTestSuite) TestBeginBlockerConsensusState() {
cs := []byte("IBC client state")
plan := &upgradetypes.Plan{
Name: "test",
Height: suite.chainA.GetContext().BlockHeight() + 1,
UpgradedClientState: cs,
}
store := suite.chainA.GetContext().KVStore(suite.chainA.App.GetKey(upgradetypes.StoreKey))
bz := suite.chainA.App.AppCodec().MustMarshalBinaryBare(plan)
store.Set(upgradetypes.PlanKey(), bz)

suite.T().Log("Verify that chain committed to consensus state on the last height it will commit")
colin-axner marked this conversation as resolved.
Show resolved Hide resolved
nextValsHash := []byte("nextValsHash")
newCtx := suite.chainA.GetContext().WithBlockHeader(tmproto.Header{
Height: suite.chainA.GetContext().BlockHeight(),
NextValidatorsHash: nextValsHash,
})

req := abci.RequestBeginBlock{Header: newCtx.BlockHeader()}
suite.chainA.App.BeginBlock(req)

// plan Height is at ctx.BlockHeight+1
consState, err := suite.chainA.App.UpgradeKeeper.GetUpgradedConsensusState(newCtx, suite.chainA.GetContext().BlockHeight()+1)
suite.Require().NoError(err)
bz, err = types.MarshalConsensusState(suite.chainA.App.AppCodec(), &ibctmtypes.ConsensusState{Timestamp: newCtx.BlockTime(), NextValidatorsHash: nextValsHash})
suite.Require().NoError(err)
suite.Require().Equal(bz, consState)
}
54 changes: 21 additions & 33 deletions x/ibc/core/02-client/keeper/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ func (suite *KeeperTestSuite) TestUpgradeClient() {
lastHeight exported.Height
clientA string
proofUpgradedClient, proofUpgradedConsState []byte
upgradedClientBz, upgradedConsStateBz []byte
err error
)

testCases := []struct {
Expand All @@ -240,18 +242,12 @@ func (suite *KeeperTestSuite) TestUpgradeClient() {
{
name: "successful upgrade",
setup: func() {

upgradedClient = ibctmtypes.NewClientState("newChainId", ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod+trustingPeriod, maxClockDrift, newClientHeight, commitmenttypes.GetSDKSpecs(), ibctesting.UpgradePath, false, false)
upgradedConsState = &ibctmtypes.ConsensusState{
NextValidatorsHash: []byte("nextValsHash"),
}

// last Height is at next block
lastHeight = clienttypes.NewHeight(0, uint64(suite.chainB.GetContext().BlockHeight()+1))

// zero custom fields and store in upgrade store
suite.chainB.App.UpgradeKeeper.SetUpgradedClient(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedClient)
suite.chainB.App.UpgradeKeeper.SetUpgradedConsensusState(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedConsState)
suite.chainB.App.UpgradeKeeper.SetUpgradedClient(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedClientBz)
suite.chainB.App.UpgradeKeeper.SetUpgradedConsensusState(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedConsStateBz)

// commit upgrade store changes and update clients

Expand All @@ -270,18 +266,12 @@ func (suite *KeeperTestSuite) TestUpgradeClient() {
{
name: "client state not found",
setup: func() {

upgradedClient = ibctmtypes.NewClientState("newChainId", ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod+trustingPeriod, maxClockDrift, newClientHeight, commitmenttypes.GetSDKSpecs(), ibctesting.UpgradePath, false, false)
upgradedConsState = &ibctmtypes.ConsensusState{
NextValidatorsHash: []byte("nextValsHash"),
}

// last Height is at next block
lastHeight = clienttypes.NewHeight(0, uint64(suite.chainB.GetContext().BlockHeight()+1))

// zero custom fields and store in upgrade store
suite.chainB.App.UpgradeKeeper.SetUpgradedClient(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedClient)
suite.chainB.App.UpgradeKeeper.SetUpgradedConsensusState(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedConsState)
suite.chainB.App.UpgradeKeeper.SetUpgradedClient(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedClientBz)
suite.chainB.App.UpgradeKeeper.SetUpgradedConsensusState(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedConsStateBz)

// commit upgrade store changes and update clients

Expand All @@ -302,18 +292,12 @@ func (suite *KeeperTestSuite) TestUpgradeClient() {
{
name: "client state frozen",
setup: func() {

upgradedClient = ibctmtypes.NewClientState("newChainId", ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod+trustingPeriod, maxClockDrift, newClientHeight, commitmenttypes.GetSDKSpecs(), ibctesting.UpgradePath, false, false)
upgradedConsState = &ibctmtypes.ConsensusState{
NextValidatorsHash: []byte("nextValsHash"),
}

// last Height is at next block
lastHeight = clienttypes.NewHeight(0, uint64(suite.chainB.GetContext().BlockHeight()+1))

// zero custom fields and store in upgrade store
suite.chainB.App.UpgradeKeeper.SetUpgradedClient(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedClient)
suite.chainB.App.UpgradeKeeper.SetUpgradedConsensusState(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedConsState)
suite.chainB.App.UpgradeKeeper.SetUpgradedClient(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedClientBz)
suite.chainB.App.UpgradeKeeper.SetUpgradedConsensusState(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedConsStateBz)

// commit upgrade store changes and update clients

Expand All @@ -338,18 +322,12 @@ func (suite *KeeperTestSuite) TestUpgradeClient() {
{
name: "tendermint client VerifyUpgrade fails",
setup: func() {

upgradedClient = ibctmtypes.NewClientState("newChainId", ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod+trustingPeriod, maxClockDrift, newClientHeight, commitmenttypes.GetSDKSpecs(), ibctesting.UpgradePath, false, false)
upgradedConsState = &ibctmtypes.ConsensusState{
NextValidatorsHash: []byte("nextValsHash"),
}

// last Height is at next block
lastHeight = clienttypes.NewHeight(0, uint64(suite.chainB.GetContext().BlockHeight()+1))

// zero custom fields and store in upgrade store
suite.chainB.App.UpgradeKeeper.SetUpgradedClient(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedClient)
suite.chainB.App.UpgradeKeeper.SetUpgradedConsensusState(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedConsState)
suite.chainB.App.UpgradeKeeper.SetUpgradedClient(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedClientBz)
suite.chainB.App.UpgradeKeeper.SetUpgradedConsensusState(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedConsStateBz)

// change upgradedClient client-specified parameters
upgradedClient = ibctmtypes.NewClientState("wrongchainID", ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, newClientHeight, commitmenttypes.GetSDKSpecs(), ibctesting.UpgradePath, true, true)
Expand All @@ -371,13 +349,23 @@ func (suite *KeeperTestSuite) TestUpgradeClient() {
for _, tc := range testCases {
tc := tc
clientA, _ = suite.coordinator.SetupClients(suite.chainA, suite.chainB, exported.Tendermint)
upgradedClient = ibctmtypes.NewClientState("newChainId", ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod+trustingPeriod, maxClockDrift, newClientHeight, commitmenttypes.GetSDKSpecs(), ibctesting.UpgradePath, false, false)
upgradedClient = upgradedClient.ZeroCustomFields()
upgradedClientBz, err = types.MarshalClientState(suite.chainA.App.AppCodec(), upgradedClient)
suite.Require().NoError(err)

upgradedConsState = &ibctmtypes.ConsensusState{
NextValidatorsHash: []byte("nextValsHash"),
}
upgradedConsStateBz, err = types.MarshalConsensusState(suite.chainA.App.AppCodec(), upgradedConsState)
suite.Require().NoError(err)

tc.setup()

// Call ZeroCustomFields on upgraded clients to clear any client-chosen parameters in test-case upgradedClient
upgradedClient = upgradedClient.ZeroCustomFields()

err := suite.chainA.App.IBCKeeper.ClientKeeper.UpgradeClient(suite.chainA.GetContext(), clientA, upgradedClient, upgradedConsState, proofUpgradedClient, proofUpgradedConsState)
err = suite.chainA.App.IBCKeeper.ClientKeeper.UpgradeClient(suite.chainA.GetContext(), clientA, upgradedClient, upgradedConsState, proofUpgradedClient, proofUpgradedConsState)

if tc.expPass {
suite.Require().NoError(err, "verify upgrade failed on valid case: %s", tc.name)
Expand Down
14 changes: 13 additions & 1 deletion x/ibc/core/02-client/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ type Keeper struct {
cdc codec.BinaryMarshaler
paramSpace paramtypes.Subspace
stakingKeeper types.StakingKeeper
upgradeKeeper types.UpgradeKeeper
}

// NewKeeper creates a new NewKeeper instance
func NewKeeper(cdc codec.BinaryMarshaler, key sdk.StoreKey, paramSpace paramtypes.Subspace, sk types.StakingKeeper) Keeper {
func NewKeeper(cdc codec.BinaryMarshaler, key sdk.StoreKey, paramSpace paramtypes.Subspace, sk types.StakingKeeper, uk types.UpgradeKeeper) Keeper {
// set KeyTable if it has not already been set
if !paramSpace.HasKeyTable() {
paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable())
Expand All @@ -42,6 +43,7 @@ func NewKeeper(cdc codec.BinaryMarshaler, key sdk.StoreKey, paramSpace paramtype
cdc: cdc,
paramSpace: paramSpace,
stakingKeeper: sk,
upgradeKeeper: uk,
}
}

Expand Down Expand Up @@ -327,6 +329,16 @@ func (k Keeper) ValidateSelfClient(ctx sdk.Context, clientState exported.ClientS
return nil
}

// GetUpgradePlan executes the upgrade keeper GetUpgradePlan function.
func (k Keeper) GetUpgradePlan(ctx sdk.Context) (plan upgradetypes.Plan, havePlan bool) {
return k.upgradeKeeper.GetUpgradePlan(ctx)
}

// GetUpgradedConsensusState executes the upgrade keeper SetUpgradedConsensusState function.
func (k Keeper) SetUpgradedConsensusState(ctx sdk.Context, planHeight int64, bz []byte) error {
return k.upgradeKeeper.SetUpgradedConsensusState(ctx, planHeight, bz)
}

// IterateClients provides an iterator over all stored light client State
// objects. For each State object, cb will be called. If the cb returns true,
// the iterator will close and stop.
Expand Down
7 changes: 7 additions & 0 deletions x/ibc/core/02-client/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
)

// StakingKeeper expected staking keeper
type StakingKeeper interface {
GetHistoricalInfo(ctx sdk.Context, height int64) (stakingtypes.HistoricalInfo, bool)
UnbondingTime(ctx sdk.Context) time.Duration
}

// UpgradeKeeper expected upgrade keeper
type UpgradeKeeper interface {
GetUpgradePlan(ctx sdk.Context) (plan upgradetypes.Plan, havePlan bool)
SetUpgradedConsensusState(ctx sdk.Context, planHeight int64, bz []byte) error
}
5 changes: 3 additions & 2 deletions x/ibc/core/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ type Keeper struct {
// NewKeeper creates a new ibc Keeper
func NewKeeper(
cdc codec.BinaryMarshaler, key sdk.StoreKey, paramSpace paramtypes.Subspace,
stakingKeeper clienttypes.StakingKeeper, scopedKeeper capabilitykeeper.ScopedKeeper,
stakingKeeper clienttypes.StakingKeeper, upgradeKeeper clienttypes.UpgradeKeeper,
scopedKeeper capabilitykeeper.ScopedKeeper,
) *Keeper {
clientKeeper := clientkeeper.NewKeeper(cdc, key, paramSpace, stakingKeeper)
clientKeeper := clientkeeper.NewKeeper(cdc, key, paramSpace, stakingKeeper, upgradeKeeper)
connectionKeeper := connectionkeeper.NewKeeper(cdc, key, clientKeeper)
portKeeper := portkeeper.NewKeeper(scopedKeeper)
channelKeeper := channelkeeper.NewKeeper(cdc, key, clientKeeper, connectionKeeper, portKeeper, scopedKeeper)
Expand Down
Loading