From 2f136d8c1326730d19a8a7960a0a990abf4bdde6 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Tue, 12 Jul 2022 20:52:04 +0900 Subject: [PATCH] chore: Rename `ResetAllLocks` (backport #1951) (#2032) * refactor ref method (#1951) (cherry picked from commit 1517e651c8af8417009f6a2392833265106b7d64) # Conflicts: # x/lockup/keeper/bench_test.go * Fix merge conflict Co-authored-by: Matt, Park <45252226+mattverse@users.noreply.github.com> Co-authored-by: mattverse --- x/lockup/genesis.go | 4 ++-- x/lockup/genesis_test.go | 10 ++++++---- x/lockup/keeper/bench_test.go | 2 +- x/lockup/keeper/lock.go | 12 ++++++------ x/lockup/keeper/synthetic_lock_test.go | 2 +- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/x/lockup/genesis.go b/x/lockup/genesis.go index a2ac061c042..7b681b0346f 100644 --- a/x/lockup/genesis.go +++ b/x/lockup/genesis.go @@ -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 } } diff --git a/x/lockup/genesis_test.go b/x/lockup/genesis_test.go index 8370c5725f0..caad09fcd70 100644 --- a/x/lockup/genesis_test.go +++ b/x/lockup/genesis_test.go @@ -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) { diff --git a/x/lockup/keeper/bench_test.go b/x/lockup/keeper/bench_test.go index 1391f846538..99a1008282d 100644 --- a/x/lockup/keeper/bench_test.go +++ b/x/lockup/keeper/bench_test.go @@ -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) { diff --git a/x/lockup/keeper/lock.go b/x/lockup/keeper/lock.go index a1445723b53..3d43af871cd 100644 --- a/x/lockup/keeper/lock.go +++ b/x/lockup/keeper/lock.go @@ -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. @@ -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 } @@ -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. @@ -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 diff --git a/x/lockup/keeper/synthetic_lock_test.go b/x/lockup/keeper/synthetic_lock_test.go index 2f57927ad22..4e59d095590 100644 --- a/x/lockup/keeper/synthetic_lock_test.go +++ b/x/lockup/keeper/synthetic_lock_test.go @@ -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",