Skip to content

Commit a7e6c0e

Browse files
committed
use stakingkeeper for consensusstate
1 parent e31966a commit a7e6c0e

File tree

5 files changed

+40
-5
lines changed

5 files changed

+40
-5
lines changed

testutil/keeper/expectations.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ func GetMocksForMakeConsumerGenesis(ctx sdk.Context, mocks *MockedKeepers,
5252
) []*gomock.Call {
5353
return []*gomock.Call{
5454
mocks.MockStakingKeeper.EXPECT().UnbondingTime(gomock.Any()).Return(unbondingTimeToInject, nil).Times(1),
55-
mocks.MockClientKeeper.EXPECT().GetSelfConsensusState(gomock.Any(),
56-
clienttypes.GetSelfHeight(ctx)).Return(&ibctmtypes.ConsensusState{}, nil).Times(1),
5755
}
5856
}
5957

testutil/keeper/mocks.go

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x/ccv/provider/keeper/consumer_lifecycle.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,11 +434,12 @@ func (k Keeper) MakeConsumerGenesis(
434434
clientState.TrustingPeriod = trustPeriod
435435
clientState.UnbondingPeriod = providerUnbondingPeriod
436436

437-
consState, err := k.clientKeeper.GetSelfConsensusState(ctx, height)
437+
consState, err := k.getSelfConsensusState(ctx, height)
438+
438439
if err != nil {
439440
return gen, errorsmod.Wrapf(clienttypes.ErrConsensusStateNotFound, "error %s getting self consensus state for: %s", err, height)
440441
}
441-
tmConsState = consState.(*ibctmtypes.ConsensusState)
442+
tmConsState = consState
442443
} else {
443444
// connection ID provided
444445
preCCV = true
@@ -504,6 +505,26 @@ func (k Keeper) MakeConsumerGenesis(
504505
return gen, nil
505506
}
506507

508+
// This is copied from the client keeper in ibc v8, since this function was removed in ibc v9
509+
func (k Keeper) getSelfConsensusState(ctx sdk.Context, height clienttypes.Height) (*ibctmtypes.ConsensusState, error) {
510+
// check that height revision matches chainID revision
511+
revision := clienttypes.ParseChainID(ctx.ChainID())
512+
if revision != height.GetRevisionNumber() {
513+
return nil, errorsmod.Wrapf(clienttypes.ErrInvalidHeight, "chainID revision number does not match height revision number: expected %d, got %d", revision, height.GetRevisionNumber())
514+
}
515+
histInfo, err := k.stakingKeeper.GetHistoricalInfo(ctx, int64(height.RevisionHeight))
516+
if err != nil {
517+
return nil, errorsmod.Wrapf(err, "height %d", height.RevisionHeight)
518+
}
519+
520+
consensusState := &ibctmtypes.ConsensusState{
521+
Timestamp: histInfo.Header.Time,
522+
Root: commitmenttypes.NewMerkleRoot(histInfo.Header.GetAppHash()),
523+
NextValidatorsHash: histInfo.Header.NextValidatorsHash,
524+
}
525+
return consensusState, nil
526+
}
527+
507528
// StopAndPrepareForConsumerRemoval sets the phase of the chain to stopped and prepares to get the state of the
508529
// chain removed after unbonding period elapses
509530
func (k Keeper) StopAndPrepareForConsumerRemoval(ctx sdk.Context, consumerId string) error {

x/ccv/provider/keeper/consumer_lifecycle_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ func TestCreateConsumerClient(t *testing.T) {
560560
providerKeeper.SetConsumerPhase(ctx, CONSUMER_ID, providertypes.CONSUMER_PHASE_LAUNCHED)
561561

562562
// Expect none of the client creation related calls to happen
563-
mocks.MockClientKeeper.EXPECT().CreateClient(gomock.Any(), gomock.Any(), gomock.Any()).Times(0)
563+
mocks.MockClientKeeper.EXPECT().CreateClient(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Times(0)
564564
},
565565
expClientCreated: false,
566566
},

x/ccv/types/expected_keepers.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ type StakingKeeper interface {
6868
StakingTokenSupply(ctx context.Context) (math.Int, error)
6969
BondedRatio(ctx context.Context) (math.LegacyDec, error)
7070
TotalBondedTokens(ctx context.Context) (math.Int, error)
71+
GetHistoricalInfo(ctx context.Context, height int64) (stakingtypes.HistoricalInfo, error)
7172
}
7273

7374
// SlashingKeeper defines the contract expected to perform ccv slashing

0 commit comments

Comments
 (0)