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

Investigate if only single lockup exists per owner+duration+denom pair #2142

Closed
Tracked by #4622
mattverse opened this issue Jul 19, 2022 · 0 comments
Closed
Tracked by #4622

Comments

@mattverse
Copy link
Member

mattverse commented Jul 19, 2022

Background

The current lockup module "assumes" that we have a single lockup in AddToExistingLock(which is when we're trying to add coins to existing locks) and add coins to the first lock out of the given array.

func (k Keeper) AddToExistingLock(ctx sdk.Context, owner sdk.AccAddress, coin sdk.Coin, duration time.Duration) ([]types.PeriodLock, error) {
	locks := k.GetAccountLockedDurationNotUnlockingOnly(ctx, owner, coin.Denom, duration)
	// if existing lock with same duration and denom exists, just add there
	if len(locks) > 0 {
		lock := locks[0]
		_, err := k.AddTokensToLockByID(ctx, lock.ID, owner, coin)
		if err != nil {
			return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, err.Error())
		}
	}
	return locks, nil
}

We want to ensure this is a safe, by changing len(locks) = 1 from the current simple check len(locks) > 0.

In order to make this change, we first need to make sure that only a single lockup exists per owner + duration + denom pair, and then change this logical gate to check that len(locks) = 1

cref: #1979 (comment)

Acceptance Criteria

  • Investigate and make sure that only a single lockup exists per owner + duration + denom pair in the current state, make sure there's no edge cases in being able to make multiple locks per owner + duration + denom pair
  • Change checks in AddToExistingLock to be len(locks) = 1 from len(locks) > 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

4 participants