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

Add comment on x/auth hacky migration script #9132

Merged
merged 2 commits into from
Apr 16, 2021
Merged
Changes from all commits
Commits
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
30 changes: 30 additions & 0 deletions x/auth/legacy/v043/store.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
// Package v043 creates in-place store migrations for fixing tracking
// delegations with vesting accounts.
// ref: https://github.com/cosmos/cosmos-sdk/issues/8601
// ref: https://github.com/cosmos/cosmos-sdk/issues/8812
//
// The migration script modifies x/auth state, hence lives in the `x/auth/legacy`
// folder. However, it needs access to staking and bank state. To avoid
// cyclic dependencies, we cannot import those 2 keepers in this file. To solve
// this, we use the baseapp router to do inter-module querying, by importing
// the `baseapp.QueryRouter grpc.Server`. This is really hacky.
//
// PLEASE DO NOT REPLICATE THIS PATTERN IN YOUR OWN APP.
//
// Proposals to refactor this file have been made in:
// https://github.com/cosmos/cosmos-sdk/issues/9070
// The preferred solution is to use inter-module communication (ADR-033), and
// this file will be refactored to use ADR-033 once it's ready.
package v043

import (
Expand Down Expand Up @@ -27,6 +44,8 @@ const (
balancesPath = "/cosmos.bank.v1beta1.Query/AllBalances"
)

// We use the baseapp.QueryRouter here to do inter-module state querying.
// PLEASE DO NOT REPLICATE THIS PATTERN IN YOUR OWN APP.
func migrateVestingAccounts(ctx sdk.Context, account types.AccountI, queryServer grpc.Server) (types.AccountI, error) {
bondDenom, err := getBondDenom(ctx, queryServer)

Expand Down Expand Up @@ -111,6 +130,8 @@ func resetVestingDelegatedBalances(evacct exported.VestingAccount) (exported.Ves
}
}

// We use the baseapp.QueryRouter here to do inter-module state querying.
// PLEASE DO NOT REPLICATE THIS PATTERN IN YOUR OWN APP.
func getDelegatorDelegationsSum(ctx sdk.Context, address string, queryServer grpc.Server) (sdk.Coins, error) {
querier, ok := queryServer.(*baseapp.GRPCQueryRouter)
if !ok {
Expand Down Expand Up @@ -153,6 +174,8 @@ func getDelegatorDelegationsSum(ctx sdk.Context, address string, queryServer grp
return res, nil
}

// We use the baseapp.QueryRouter here to do inter-module state querying.
// PLEASE DO NOT REPLICATE THIS PATTERN IN YOUR OWN APP.
func getDelegatorUnbondingDelegationsSum(ctx sdk.Context, address, bondDenom string, queryServer grpc.Server) (sdk.Coins, error) {
querier, ok := queryServer.(*baseapp.GRPCQueryRouter)
if !ok {
Expand Down Expand Up @@ -197,6 +220,8 @@ func getDelegatorUnbondingDelegationsSum(ctx sdk.Context, address, bondDenom str
return res, nil
}

// We use the baseapp.QueryRouter here to do inter-module state querying.
// PLEASE DO NOT REPLICATE THIS PATTERN IN YOUR OWN APP.
func getBalance(ctx sdk.Context, address string, queryServer grpc.Server) (sdk.Coins, error) {
querier, ok := queryServer.(*baseapp.GRPCQueryRouter)
if !ok {
Expand Down Expand Up @@ -229,6 +254,8 @@ func getBalance(ctx sdk.Context, address string, queryServer grpc.Server) (sdk.C
return balance.Balances, nil
}

// We use the baseapp.QueryRouter here to do inter-module state querying.
// PLEASE DO NOT REPLICATE THIS PATTERN IN YOUR OWN APP.
func getBondDenom(ctx sdk.Context, queryServer grpc.Server) (string, error) {
querier, ok := queryServer.(*baseapp.GRPCQueryRouter)
if !ok {
Expand Down Expand Up @@ -264,6 +291,9 @@ func getBondDenom(ctx sdk.Context, queryServer grpc.Server) (string, error) {
// MigrateAccount migrates vesting account to make the DelegatedVesting and DelegatedFree fields correctly
// track delegations.
// References: https://github.com/cosmos/cosmos-sdk/issues/8601, https://github.com/cosmos/cosmos-sdk/issues/8812
//
// We use the baseapp.QueryRouter here to do inter-module state querying.
// PLEASE DO NOT REPLICATE THIS PATTERN IN YOUR OWN APP.
func MigrateAccount(ctx sdk.Context, account types.AccountI, queryServer grpc.Server) (types.AccountI, error) {
return migrateVestingAccounts(ctx, account, queryServer)
}