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 10 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
2 changes: 1 addition & 1 deletion proto/cosmos/upgrade/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,5 @@ message QueryUpgradedConsensusStateRequest {
// QueryUpgradedConsensusStateResponse is the response type for the Query/UpgradedConsensusState
// RPC method.
message QueryUpgradedConsensusStateResponse {
google.protobuf.Any upgraded_consensus_state = 1;
bytes upgraded_consensus_state = 1;
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 proto-breaking. Could we just add a new field instead? Or else we can also bump to v1beta2

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 can do whichever you prefer. The old fields would just be unused if I added a new field. It would also be unusable since I cannot fulfill the UnpackInterfaces function since there won't be a interface to unpack into. I presume I'd have to change this for the Upgrade Plan as well or does only the Query definitions matter?

Copy link
Contributor

Choose a reason for hiding this comment

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

Not bumping to v1beta2 would be ideal. If the old field is not used anymore, I would say let's go for reserved, like here

See https://developers.google.com/protocol-buffers/docs/proto#updating

Non-required fields can be removed, as long as the field number is not used again in your updated message type. You may want to rename the field instead, perhaps adding the prefix "OBSOLETE_", or make the field number reserved, so that future users of your .proto can't accidentally reuse the number.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sweet, thanks for catching this. Updated it, let me know if anything is wrong

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The proto-breakage check still says breaking, but I presume this is fine?

Do I need the reserved "option"; part?

}
2 changes: 1 addition & 1 deletion proto/cosmos/upgrade/v1beta1/upgrade.proto
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ message Plan {
// 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 = 5 [(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