Skip to content

Commit

Permalink
chore: Rename ResetAllLocks (backport #1951) (#2032)
Browse files Browse the repository at this point in the history
* refactor ref method (#1951)

(cherry picked from commit 1517e65)

# Conflicts:
#	x/lockup/keeper/bench_test.go

* Fix merge conflict

Co-authored-by: Matt, Park <[email protected]>
Co-authored-by: mattverse <[email protected]>
  • Loading branch information
3 people authored Jul 12, 2022
1 parent bd32316 commit 2f136d8
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
4 changes: 2 additions & 2 deletions x/lockup/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (
// state.
func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) {
k.SetLastLockID(ctx, genState.LastLockId)
if err := k.ResetAllLocks(ctx, genState.Locks); err != nil {
if err := k.InitializeAllLocks(ctx, genState.Locks); err != nil {
return
}
if err := k.ResetAllSyntheticLocks(ctx, genState.SyntheticLocks); err != nil {
if err := k.InitializeAllSyntheticLocks(ctx, genState.SyntheticLocks); err != nil {
return
}
}
Expand Down
10 changes: 6 additions & 4 deletions x/lockup/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,14 @@ func TestInitGenesis(t *testing.T) {
coins = app.LockupKeeper.GetAccountLockedCoins(ctx, acc2)
require.Equal(t, coins.String(), sdk.NewInt64Coin("foo", 5000000).String())

// TODO: module account balance is kept by bank keeper and no need to check here
// coins = app.LockupKeeper.GetModuleBalance(ctx)
// require.Equal(t, coins.String(), sdk.NewInt64Coin("foo", 30000000).String())

lastLockId := app.LockupKeeper.GetLastLockID(ctx)
require.Equal(t, lastLockId, uint64(10))

acc := app.LockupKeeper.GetPeriodLocksAccumulation(ctx, types.QueryCondition{
Denom: "foo",
Duration: time.Second,
})
require.Equal(t, sdk.NewInt(30000000), acc)
}

func TestExportGenesis(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion x/lockup/keeper/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func benchmarkResetLogic(numLockups int, b *testing.B) {
b.StartTimer()
b.ReportAllocs()
// distribute coins from gauges to lockup owners
_ = app.LockupKeeper.ResetAllLocks(ctx, locks)
_ = app.LockupKeeper.InitializeAllLocks(ctx, locks)
}

func BenchmarkResetLogicMedium(b *testing.B) {
Expand Down
12 changes: 6 additions & 6 deletions x/lockup/keeper/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,10 +413,10 @@ func (k Keeper) ExtendLockup(ctx sdk.Context, lockID uint64, owner sdk.AccAddres
return nil
}

// ResetAllLocks takes a set of locks, and initializes state to be storing
// InitializeAllLocks takes a set of locks, and initializes state to be storing
// them all correctly. This utilizes batch optimizations to improve efficiency,
// as this becomes a bottleneck at chain initialization & upgrades.
func (k Keeper) ResetAllLocks(ctx sdk.Context, locks []types.PeriodLock) error {
func (k Keeper) InitializeAllLocks(ctx sdk.Context, locks []types.PeriodLock) error {
// index by coin.Denom, them duration -> amt
// We accumulate the accumulation store entries separately,
// to avoid hitting the myriad of slowdowns in the SDK iterator creation process.
Expand All @@ -428,7 +428,7 @@ func (k Keeper) ResetAllLocks(ctx sdk.Context, locks []types.PeriodLock) error {
msg := fmt.Sprintf("Reset %d lock refs, cur lock ID %d", i, lock.ID)
ctx.Logger().Info(msg)
}
err := k.setLockAndResetLockRefs(ctx, lock)
err := k.setLockAndAddLockRefs(ctx, lock)
if err != nil {
return err
}
Expand Down Expand Up @@ -476,7 +476,7 @@ func (k Keeper) ResetAllLocks(ctx sdk.Context, locks []types.PeriodLock) error {
return nil
}

func (k Keeper) ResetAllSyntheticLocks(ctx sdk.Context, syntheticLocks []types.SyntheticLock) error {
func (k Keeper) InitializeAllSyntheticLocks(ctx sdk.Context, syntheticLocks []types.SyntheticLock) error {
// index by coin.Denom, them duration -> amt
// We accumulate the accumulation store entries separately,
// to avoid hitting the myriad of slowdowns in the SDK iterator creation process.
Expand Down Expand Up @@ -612,9 +612,9 @@ func (k Keeper) setLock(ctx sdk.Context, lock types.PeriodLock) error {
return nil
}

// setLockAndResetLockRefs sets the lock, and resets all of its lock references
// setLockAndAddLockRefs sets the lock, and resets all of its lock references
// This puts the lock into a 'clean' state, aside from the AccumulationStore.
func (k Keeper) setLockAndResetLockRefs(ctx sdk.Context, lock types.PeriodLock) error {
func (k Keeper) setLockAndAddLockRefs(ctx sdk.Context, lock types.PeriodLock) error {
err := k.setLock(ctx, lock)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion x/lockup/keeper/synthetic_lock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func (suite *KeeperTestSuite) TestResetAllSyntheticLocks() {
suite.Require().Len(locks, 1)
suite.Require().Equal(locks[0].Coins, coins)

suite.App.LockupKeeper.ResetAllSyntheticLocks(suite.Ctx, []types.SyntheticLock{
suite.App.LockupKeeper.InitializeAllSyntheticLocks(suite.Ctx, []types.SyntheticLock{
{
UnderlyingLockId: 1,
SynthDenom: "synthstakestakedtovalidator1",
Expand Down

0 comments on commit 2f136d8

Please sign in to comment.