Skip to content

Commit

Permalink
Merge pull request #260 from terra-money/revert-259-upgrade/v0.47.x
Browse files Browse the repository at this point in the history
Revert "feat: upgrade terra to v0.47.x"
  • Loading branch information
emidev98 committed Aug 18, 2023
2 parents 6cf2102 + df3702c commit eea8a01
Show file tree
Hide file tree
Showing 17 changed files with 48 additions and 882 deletions.
File renamed without changes.
19 changes: 2 additions & 17 deletions proto/cosmos/vesting/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ service Msg {
//
// Since: cosmos-sdk 0.46
rpc CreatePeriodicVestingAccount(MsgCreatePeriodicVestingAccount) returns (MsgCreatePeriodicVestingAccountResponse);
// DonateAllVestingTokens defines a method that enables donating all vesting
// tokens to community pool
rpc DonateAllVestingTokens(MsgDonateAllVestingTokens) returns (MsgDonateAllVestingTokensResponse);
}

// MsgCreateVestingAccount defines a message that enables creating a vesting
Expand Down Expand Up @@ -79,7 +76,7 @@ message MsgCreatePermanentLockedAccount {
// Since: cosmos-sdk 0.46
message MsgCreatePermanentLockedAccountResponse {}

// MsgCreatePeriodicVestingAccount defines a message that enables creating a vesting
// MsgCreateVestingAccount defines a message that enables creating a vesting
// account.
//
// Since: cosmos-sdk 0.46
Expand All @@ -96,20 +93,8 @@ message MsgCreatePeriodicVestingAccount {
repeated Period vesting_periods = 4 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
}

// MsgCreatePeriodicVestingAccountResponse defines the Msg/CreatePeriodicVestingAccount
// MsgCreateVestingAccountResponse defines the Msg/CreatePeriodicVestingAccount
// response type.
//
// Since: cosmos-sdk 0.46
message MsgCreatePeriodicVestingAccountResponse {}

// MsgDonateAllVestingTokens defines a message that enables donating all vesting
// token to community pool.
message MsgDonateAllVestingTokens {
option (gogoproto.equal) = false;

string from_address = 1 [(gogoproto.moretags) = "yaml:\"from_address\""];
}

// MsgDonateAllVestingTokensResponse defines the Msg/MsgDonateAllVestingTokens
// response type.
message MsgDonateAllVestingTokensResponse {}
4 changes: 4 additions & 0 deletions scripts/protocgen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ cd ..
# move proto files to the right places
cp -r github.com/cosmos/cosmos-sdk/* ./
rm -rf github.com

go mod tidy

./scripts/protocgen-pulsar.sh
2 changes: 1 addition & 1 deletion simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ func NewSimApp(
encodingConfig.TxConfig,
),
auth.NewAppModule(appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts, app.GetSubspace(authtypes.ModuleName)),
vesting.NewAppModule(app.AccountKeeper, app.BankKeeper, app.DistrKeeper, app.StakingKeeper),
vesting.NewAppModule(app.AccountKeeper, app.BankKeeper),
bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper, app.GetSubspace(banktypes.ModuleName)),
capability.NewAppModule(appCodec, *app.CapabilityKeeper, false),
crisis.NewAppModule(app.CrisisKeeper, skipGenesisInvariants, app.GetSubspace(crisistypes.ModuleName)),
Expand Down
8 changes: 4 additions & 4 deletions x/auth/migrations/v2/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ func TestMigrateVestingAccounts(t *testing.T) {
3666666670000,
3666666670000,
0,
1601042400,
1601042400 + 1,
},
{
"periodic vesting account, all has vested",
Expand Down Expand Up @@ -430,7 +430,7 @@ func TestMigrateVestingAccounts(t *testing.T) {
3666666670000,
0,
3666666670000,
1601042400 + 31536000 + 15897600 + 15897600,
1601042400 + 31536000 + 15897600 + 15897600 + 1,
},
{
"periodic vesting account, first period has vested",
Expand Down Expand Up @@ -476,7 +476,7 @@ func TestMigrateVestingAccounts(t *testing.T) {
3666666670000,
3666666670000 - 1833333335000,
1833333335000,
1601042400 + 31536000,
1601042400 + 31536000 + 1,
},
{
"periodic vesting account, first 2 period has vested",
Expand Down Expand Up @@ -522,7 +522,7 @@ func TestMigrateVestingAccounts(t *testing.T) {
3666666670000,
3666666670000 - 1833333335000 - 916666667500,
1833333335000 + 916666667500,
1601042400 + 31536000 + 15638400,
1601042400 + 31536000 + 15638400 + 1,
},
{
"vesting account has unbonding delegations in place",
Expand Down
56 changes: 13 additions & 43 deletions x/auth/vesting/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ func GetTxCmd() *cobra.Command {
NewMsgCreateVestingAccountCmd(),
NewMsgCreatePermanentLockedAccountCmd(),
NewMsgCreatePeriodicVestingAccountCmd(),
NewMsgDonateAllVestingTokensCmd(),
)

return txCmd
Expand Down Expand Up @@ -142,20 +141,19 @@ func NewMsgCreatePeriodicVestingAccountCmd() *cobra.Command {
Where periods.json contains:
An array of coin strings and unix epoch times for coins to vest
{
"start_time": 1625204910,
"periods":[
{
"coins": "10test",
"length_seconds":2592000
},
{
"coins": "10test",
"length_seconds":2592000 //30 days
}
]
}
`,
{ "start_time": 1625204910,
"periods":[
{
"coins": "10test",
"length_seconds":2592000 //30 days
},
{
"coins": "10test",
"length_seconds":2592000 //30 days
},
]
}
`,
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
Expand Down Expand Up @@ -209,31 +207,3 @@ func NewMsgCreatePeriodicVestingAccountCmd() *cobra.Command {

return cmd
}

// NewMsgDonateAllVestingTokensCmd returns a CLI command handler for creating a
// MsgDonateAllVestingTokens transaction.
func NewMsgDonateAllVestingTokensCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "donate-all-vesting-tokens",
Short: "Donate all vesting tokens of a vesting account to community pool.",
Long: `Donate all vesting tokens of a vesting account to community pool.
The account must not have any delegated vesting tokens to prevent complex
vesting logic changes. After donation, the account will be changed to normal
"BaseAccount".`,
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

msg := types.NewMsgDonateAllVestingTokens(clientCtx.GetFromAddress())

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}

flags.AddTxFlagsToCmd(cmd)

return cmd
}
39 changes: 0 additions & 39 deletions x/auth/vesting/handler.go

This file was deleted.

26 changes: 3 additions & 23 deletions x/auth/vesting/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"cosmossdk.io/core/appmodule"

"github.com/cosmos/cosmos-sdk/x/auth/keeper"

"github.com/cosmos/cosmos-sdk/x/auth/vesting/client/cli"
"github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
)
Expand Down Expand Up @@ -81,22 +80,13 @@ type AppModule struct {

accountKeeper keeper.AccountKeeper
bankKeeper types.BankKeeper
distrKeeper types.DistrKeeper
stakingKeeper types.StakingKeeper
}

func NewAppModule(
ak keeper.AccountKeeper,
bk types.BankKeeper,
dk types.DistrKeeper,
sk types.StakingKeeper,
) AppModule {
func NewAppModule(ak keeper.AccountKeeper, bk types.BankKeeper) AppModule {
return AppModule{
AppModuleBasic: AppModuleBasic{},
accountKeeper: ak,
bankKeeper: bk,
distrKeeper: dk,
stakingKeeper: sk,
}
}

Expand All @@ -113,15 +103,7 @@ func (AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {}

// RegisterServices registers module services.
func (am AppModule) RegisterServices(cfg module.Configurator) {
types.RegisterMsgServer(
cfg.MsgServer(),
NewMsgServerImpl(
am.accountKeeper,
am.bankKeeper,
am.distrKeeper,
am.stakingKeeper,
),
)
types.RegisterMsgServer(cfg.MsgServer(), NewMsgServerImpl(am.accountKeeper, am.bankKeeper))
}

// InitGenesis performs a no-op.
Expand Down Expand Up @@ -152,8 +134,6 @@ type VestingInputs struct {

AccountKeeper keeper.AccountKeeper
BankKeeper types.BankKeeper
// DistrKeeper types.DistrKeeper
StakingKeeper types.StakingKeeper
}

type VestingOutputs struct {
Expand All @@ -163,7 +143,7 @@ type VestingOutputs struct {
}

func ProvideModule(in VestingInputs) VestingOutputs {
m := NewAppModule(in.AccountKeeper, in.BankKeeper, nil, in.StakingKeeper)
m := NewAppModule(in.AccountKeeper, in.BankKeeper)

return VestingOutputs{Module: m}
}
89 changes: 2 additions & 87 deletions x/auth/vesting/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package vesting

import (
"context"
"fmt"
"math"

"github.com/armon/go-metrics"

Expand All @@ -12,26 +10,18 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/keeper"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/auth/vesting/exported"
"github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
)

type msgServer struct {
keeper.AccountKeeper
types.BankKeeper
types.DistrKeeper
types.StakingKeeper
}

// NewMsgServerImpl returns an implementation of the vesting MsgServer interface,
// wrapping the corresponding AccountKeeper and BankKeeper.
func NewMsgServerImpl(
k keeper.AccountKeeper,
bk types.BankKeeper,
dk types.DistrKeeper,
sk types.StakingKeeper,
) types.MsgServer {
return &msgServer{AccountKeeper: k, BankKeeper: bk, DistrKeeper: dk, StakingKeeper: sk}
func NewMsgServerImpl(k keeper.AccountKeeper, bk types.BankKeeper) types.MsgServer {
return &msgServer{AccountKeeper: k, BankKeeper: bk}
}

var _ types.MsgServer = msgServer{}
Expand Down Expand Up @@ -203,78 +193,3 @@ func (s msgServer) CreatePeriodicVestingAccount(goCtx context.Context, msg *type

return &types.MsgCreatePeriodicVestingAccountResponse{}, nil
}

func (s msgServer) DonateAllVestingTokens(goCtx context.Context, msg *types.MsgDonateAllVestingTokens) (*types.MsgDonateAllVestingTokensResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

ak := s.AccountKeeper
dk := s.DistrKeeper
sk := s.StakingKeeper

from, err := sdk.AccAddressFromBech32(msg.FromAddress)
if err != nil {
return nil, err
}

acc := ak.GetAccount(ctx, from)
if acc == nil {
return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "account %s not exists", msg.FromAddress)
}

// get all delegations of an account and undust those that have less than 1 uluna
delegations := sk.GetDelegatorDelegations(ctx, acc.GetAddress(), math.MaxUint16)
for _, delegation := range delegations {
validatorAddr, err := sdk.ValAddressFromBech32(delegation.ValidatorAddress)
if err != nil {
return nil, err
}
validator, found := sk.GetValidator(ctx, validatorAddr)
if !found {
return nil, fmt.Errorf("validator not found")
}
// Try to delete the dust delegation
_, removedTokens := sk.RemoveValidatorTokensAndShares(ctx, validator, delegation.Shares)
// If the delegation is not dust, return an error and stop the donation flow
if !removedTokens.IsZero() {
return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "account %s has a non-zero staking entry", msg.FromAddress)
}

// Remove the dust delegation shares from the validator
err = sk.RemoveDelegation(ctx, delegation)
if err != nil {
return nil, err
}
}

// check whether an account has any other type of staking entries
if len(sk.GetUnbondingDelegations(ctx, acc.GetAddress(), 1)) != 0 ||
len(sk.GetRedelegations(ctx, acc.GetAddress(), 1)) != 0 {
return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "account %s has staking entry", msg.FromAddress)
}

vestingAcc, ok := acc.(exported.VestingAccount)
if !ok {
return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "account %s is not a vesting account", msg.FromAddress)
}

vestingCoins := vestingAcc.GetVestingCoins(ctx.BlockTime())
if vestingCoins.IsZero() {
return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "account %s has no vesting tokens", msg.FromAddress)
}

// Change the account as normal account
ak.SetAccount(ctx,
authtypes.NewBaseAccount(
acc.GetAddress(),
acc.GetPubKey(),
acc.GetAccountNumber(),
acc.GetSequence(),
),
)

if err := dk.FundCommunityPool(ctx, vestingCoins, from); err != nil {
return nil, err
}

return &types.MsgDonateAllVestingTokensResponse{}, nil
}
Loading

0 comments on commit eea8a01

Please sign in to comment.