-
Notifications
You must be signed in to change notification settings - Fork 640
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
refactor: simplify optional tendermint pruning migrations #2862
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e3bc60c
refactor: use client keeper instead of store keeper in optional tm mi…
colin-axner 95b7488
Merge branch 'main' of github.com:cosmos/ibc-go into colin/2845-simpl…
colin-axner b5e3ad8
chore: move tm migrations to its own pkg
colin-axner 8c6f6ef
chore: rename PruneTendermintConsensusStates to PruneExpiredConsensus…
colin-axner d294c1d
imp: add total pruned consensus states as a return argument
colin-axner 78b3b49
Merge branch 'main' into colin/2845-simplify-optional-tm-migrations
colin-axner d83c882
fix: test build
colin-axner 1c75176
Merge branch 'colin/2845-simplify-optional-tm-migrations' of github.c…
colin-axner 8b3c290
Merge branch 'main' into colin/2845-simplify-optional-tm-migrations
colin-axner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
modules/light-clients/07-tendermint/migrations/expected_keepers.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package migrations | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/tendermint/tendermint/libs/log" | ||
|
||
"github.com/cosmos/ibc-go/v6/modules/core/exported" | ||
) | ||
|
||
// ClientKeeper expected account IBC client keeper | ||
type ClientKeeper interface { | ||
GetClientState(ctx sdk.Context, clientID string) (exported.ClientState, bool) | ||
IterateClientStates(ctx sdk.Context, prefix []byte, cb func(string, exported.ClientState) bool) | ||
ClientStore(ctx sdk.Context, clientID string) sdk.KVStore | ||
Logger(ctx sdk.Context) log.Logger | ||
} |
46 changes: 46 additions & 0 deletions
46
modules/light-clients/07-tendermint/migrations/migrations.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package migrations | ||
|
||
import ( | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
|
||
clienttypes "github.com/cosmos/ibc-go/v6/modules/core/02-client/types" | ||
"github.com/cosmos/ibc-go/v6/modules/core/exported" | ||
ibctm "github.com/cosmos/ibc-go/v6/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, sdkerrors.Wrapf(clienttypes.ErrClientNotFound, "clientID %s", clientID) | ||
} | ||
|
||
tmClientState, ok := clientState.(*ibctm.ClientState) | ||
if !ok { | ||
return 0, sdkerrors.Wrap(clienttypes.ErrInvalidClient, "client state is not tendermint even though client id contains 07-tendermint") | ||
} | ||
|
||
totalPruned += ibctm.PruneAllExpiredConsensusStates(ctx, clientStore, cdc, tmClientState) | ||
} | ||
|
||
clientLogger := clientKeeper.Logger(ctx) | ||
clientLogger.Info("pruned expired tendermint consensus states", "total", totalPruned) | ||
|
||
return totalPruned, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be worth returning
totalPruned
here for chains to have the ability to act on the number pruned from the store?We could always make it as a future improvement
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense to me!