Some checks failed
CodeQL / Analyze (push) Waiting to run
Docker Build & Push Simapp (main) / docker-build (push) Waiting to run
golangci-lint / lint (push) Waiting to run
Tests / Code Coverage / build (amd64) (push) Waiting to run
Tests / Code Coverage / build (arm64) (push) Waiting to run
Tests / Code Coverage / unit-tests (map[additional-args:-tags="test_e2e" name:e2e path:./e2e]) (push) Waiting to run
Tests / Code Coverage / unit-tests (map[name:08-wasm path:./modules/light-clients/08-wasm]) (push) Waiting to run
Tests / Code Coverage / unit-tests (map[name:ibc-go path:.]) (push) Waiting to run
Deploy to GitHub Pages / Deploy to GitHub Pages (push) Has been cancelled
Buf-Push / push (push) Has been cancelled
46 lines
1.7 KiB
Go
46 lines
1.7 KiB
Go
package migrations
|
|
|
|
import (
|
|
errorsmod "cosmossdk.io/errors"
|
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
clienttypes "github.com/cosmos/ibc-go/v10/modules/core/02-client/types"
|
|
"github.com/cosmos/ibc-go/v10/modules/core/exported"
|
|
ibctm "github.com/cosmos/ibc-go/v10/modules/light-clients/07-tendermint"
|
|
)
|
|
|
|
// PruneExpiredConsensusStates prunes all expired tendermint consensus states. This function
|
|
// may optionally be called during in-place store migrations. The ibc store key must be provided.
|
|
func PruneExpiredConsensusStates(ctx sdk.Context, cdc codec.BinaryCodec, clientKeeper ClientKeeper) (int, error) {
|
|
var clientIDs []string
|
|
clientKeeper.IterateClientStates(ctx, []byte(exported.Tendermint), func(clientID string, _ exported.ClientState) bool {
|
|
clientIDs = append(clientIDs, clientID)
|
|
return false
|
|
})
|
|
|
|
// keep track of the total consensus states pruned so chains can
|
|
// understand how much space is saved when the migration is run
|
|
var totalPruned int
|
|
|
|
for _, clientID := range clientIDs {
|
|
clientStore := clientKeeper.ClientStore(ctx, clientID)
|
|
|
|
clientState, ok := clientKeeper.GetClientState(ctx, clientID)
|
|
if !ok {
|
|
return 0, errorsmod.Wrapf(clienttypes.ErrClientNotFound, "clientID %s", clientID)
|
|
}
|
|
|
|
tmClientState, ok := clientState.(*ibctm.ClientState)
|
|
if !ok {
|
|
return 0, errorsmod.Wrap(clienttypes.ErrInvalidClient, "client state is not tendermint even though client id contains 07-tendermint")
|
|
}
|
|
|
|
totalPruned += ibctm.PruneAllExpiredConsensusStates(ctx, clientStore, cdc, tmClientState)
|
|
}
|
|
|
|
clientKeeper.Logger(ctx).Info("pruned expired tendermint consensus states", "total", totalPruned)
|
|
|
|
return totalPruned, nil
|
|
}
|