Skip to content

Commit

Permalink
fix!: patch barberry vesting bug (backport)
Browse files Browse the repository at this point in the history
  • Loading branch information
crypin committed Jun 8, 2023
1 parent 930bff8 commit d56a3cd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions x/auth/legacy/v043/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,8 @@ func TestMigrateVestingAccounts(t *testing.T) {

delayedAccount := types.NewPeriodicVestingAccount(baseAccount, vestedCoins, startTime, periods)

ctx = ctx.WithBlockTime(time.Unix(1601042400, 0))

app.AccountKeeper.SetAccount(ctx, delayedAccount)

// delegation of the original vesting, failed because of no spendable balances
Expand Down
8 changes: 8 additions & 0 deletions x/auth/vesting/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ func (s msgServer) CreatePeriodicVestingAccount(goCtx context.Context, msg *type
return nil, err
}

if bk.BlockedAddr(to) {
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to receive funds", msg.ToAddress)
}

if acc := ak.GetAccount(ctx, to); acc != nil {
return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "account %s already exists", msg.ToAddress)
}
Expand All @@ -124,6 +128,10 @@ func (s msgServer) CreatePeriodicVestingAccount(goCtx context.Context, msg *type
totalCoins = totalCoins.Add(period.Amount...)
}

if err := bk.IsSendEnabledCoins(ctx, totalCoins...); err != nil {
return nil, err
}

baseAccount := ak.NewAccountWithAddress(ctx, to)

acc := types.NewPeriodicVestingAccount(baseAccount.(*authtypes.BaseAccount), totalCoins.Sort(), msg.StartTime, msg.VestingPeriods)
Expand Down
8 changes: 8 additions & 0 deletions x/auth/vesting/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ func (msg MsgCreatePeriodicVestingAccount) ValidateBasic() error {
}

for i, period := range msg.VestingPeriods {
if !period.Amount.IsValid() {
return sdkerrors.ErrInvalidCoins.Wrap(period.Amount.String())
}

if !period.Amount.IsAllPositive() {
return sdkerrors.ErrInvalidCoins.Wrap(period.Amount.String())
}

if period.Length < 1 {
return fmt.Errorf("invalid period length of %d in period %d, length must be greater than 0", period.Length, i)
}
Expand Down

0 comments on commit d56a3cd

Please sign in to comment.