github.com/cosmos/cosmos-sdk@v0.50.10/x/distribution/migrations/v3/migrate.go (about)

     1  package v3
     2  
     3  import (
     4  	"cosmossdk.io/core/store"
     5  	sdkmath "cosmossdk.io/math"
     6  
     7  	"github.com/cosmos/cosmos-sdk/codec"
     8  	sdk "github.com/cosmos/cosmos-sdk/types"
     9  	"github.com/cosmos/cosmos-sdk/x/distribution/exported"
    10  	"github.com/cosmos/cosmos-sdk/x/distribution/types"
    11  )
    12  
    13  const (
    14  	ModuleName = "distribution"
    15  )
    16  
    17  var ParamsKey = []byte{0x09}
    18  
    19  // MigrateStore migrates the x/distribution module state from the consensus version 2 to
    20  // version 3. Specifically, it takes the parameters that are currently stored
    21  // and managed by the x/params module and stores them directly into the x/distribution
    22  // module state.
    23  func MigrateStore(ctx sdk.Context, storeService store.KVStoreService, legacySubspace exported.Subspace, cdc codec.BinaryCodec) error {
    24  	store := storeService.OpenKVStore(ctx)
    25  	var currParams types.Params
    26  	legacySubspace.GetParamSet(ctx, &currParams)
    27  
    28  	// reset unused params
    29  	currParams.BaseProposerReward = sdkmath.LegacyZeroDec()
    30  	currParams.BonusProposerReward = sdkmath.LegacyZeroDec()
    31  
    32  	if err := currParams.ValidateBasic(); err != nil {
    33  		return err
    34  	}
    35  
    36  	bz, err := cdc.Marshal(&currParams)
    37  	if err != nil {
    38  		return err
    39  	}
    40  
    41  	return store.Set(ParamsKey, bz)
    42  }