From 07fce32a4026f7e100025200d0940177f8bbcc52 Mon Sep 17 00:00:00 2001 From: oren-lava Date: Thu, 16 Nov 2023 10:57:46 +0200 Subject: [PATCH] Revert "CNS-692: fix stale at bug in fixation + fix unit tests" This reverts commit 68e419a1d7349e8afbb41461d3095d5fa93c2b32. --- x/fixationstore/fixationstore.go | 2 +- x/fixationstore/fixationstore_migrations_test.go | 2 +- x/fixationstore/fixationstore_test.go | 14 +++++++------- x/fixationstore/types/fixation.go | 2 +- x/subscription/keeper/keeper.go | 16 +++++++++------- 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/x/fixationstore/fixationstore.go b/x/fixationstore/fixationstore.go index d235a0618e..3cc59697c9 100644 --- a/x/fixationstore/fixationstore.go +++ b/x/fixationstore/fixationstore.go @@ -801,7 +801,7 @@ func (fs *FixationStore) putEntry(ctx sdk.Context, entry types.Entry) { entry.StaleAt = block + fs.getStaleBlocks(ctx) key := encodeForTimer(entry.SafeIndex(), entry.Block, timerStaleEntry) - fs.tstore.AddTimerByBlockHeight(ctx, entry.StaleAt+1, key, []byte{}) + fs.tstore.AddTimerByBlockHeight(ctx, entry.StaleAt, key, []byte{}) } fs.setEntry(ctx, entry) diff --git a/x/fixationstore/fixationstore_migrations_test.go b/x/fixationstore/fixationstore_migrations_test.go index 89d900d3bf..7529c6b5ae 100644 --- a/x/fixationstore/fixationstore_migrations_test.go +++ b/x/fixationstore/fixationstore_migrations_test.go @@ -27,7 +27,7 @@ type mockEntry1to2 struct { } func mockGetStaleBlock(ctx sdk.Context) uint64 { - return 1440 + return 1500 } func TestMigrate1to2(t *testing.T) { diff --git a/x/fixationstore/fixationstore_test.go b/x/fixationstore/fixationstore_test.go index 9adeb42158..518d7e16d0 100644 --- a/x/fixationstore/fixationstore_test.go +++ b/x/fixationstore/fixationstore_test.go @@ -448,7 +448,7 @@ func TestDelThenAddEntry(t *testing.T) { {op: "getvers", name: "to check 6 versions", count: 6}, // aadvance to trigger stales {op: "block", name: "advance to block3", count: block3 - block2 - 50}, - {op: "block", name: "advance until stale", count: int64(mockGetStaleBlock(sdk.Context{}) + 1)}, + {op: "block", name: "advance until stale", count: int64(mockGetStaleBlock(sdk.Context{}))}, {op: "getvers", name: "to check 1 version", count: 1}, } @@ -507,7 +507,7 @@ func TestDelEntrySameFuture(t *testing.T) { {op: "block", name: "advance to block1", count: block1 - block0}, // now entry #2 is latest, and deleted {op: "get", name: "entry #1 should fail", fail: true}, - {op: "block", name: "advance until entry #1 stale", count: int64(mockGetStaleBlock(sdk.Context{}) + 1)}, + {op: "block", name: "advance until entry #1 stale", count: int64(mockGetStaleBlock(sdk.Context{}))}, {op: "getvers", name: "to check 1 version", count: 0}, } @@ -616,10 +616,10 @@ func TestRemoveStaleEntries(t *testing.T) { block3 := block2 + int64(10) block4 := block3 + int64(10) block5 := int64(100) - block6 := block5 + int64(mockGetStaleBlock(sdk.Context{})) + 1 - block7 := block6 + int64(mockGetStaleBlock(sdk.Context{}))/2 + 1 - block8 := block7 + int64(mockGetStaleBlock(sdk.Context{}))/2 + 2 - block9 := block8 + int64(mockGetStaleBlock(sdk.Context{}))/2 + 3 + block6 := block5 + int64(mockGetStaleBlock(sdk.Context{})) + block7 := block6 + int64(mockGetStaleBlock(sdk.Context{}))/2 + block8 := block7 + int64(mockGetStaleBlock(sdk.Context{}))/2 + 1 + block9 := block8 + int64(mockGetStaleBlock(sdk.Context{}))/2 + 2 playbook := []fixationTemplate{ {op: "append", name: "entry #1", count: block0, coin: 0}, @@ -675,7 +675,7 @@ func TestIllegalPutLatestEntry(t *testing.T) { func TestRemoveLastEntry(t *testing.T) { block0 := int64(10) block1 := block0 + int64(10) - block2 := block1 + int64(mockGetStaleBlock(sdk.Context{})) + 1 + block2 := block1 + int64(mockGetStaleBlock(sdk.Context{})) playbook := []fixationTemplate{ {op: "append", name: "entry #1", count: block0, coin: 0}, diff --git a/x/fixationstore/types/fixation.go b/x/fixationstore/types/fixation.go index 9c748d2357..4c3f86208d 100644 --- a/x/fixationstore/types/fixation.go +++ b/x/fixationstore/types/fixation.go @@ -46,7 +46,7 @@ func (entry Entry) SafeIndex() SafeIndex { // has passed its stale_at time (more than STALE_ENTRY_TIME since deletion). func (entry Entry) IsStaleBy(block uint64) bool { if entry.GetRefcount() == 0 { - if entry.StaleAt < block { + if entry.StaleAt <= block { return true } } diff --git a/x/subscription/keeper/keeper.go b/x/subscription/keeper/keeper.go index ec178f652e..6b439e89d0 100644 --- a/x/subscription/keeper/keeper.go +++ b/x/subscription/keeper/keeper.go @@ -59,6 +59,9 @@ func NewKeeper( ps = ps.WithKeyTable(types.ParamKeyTable()) } + fs := *fixationStoreKeeper.NewFixationStore(storeKey, types.SubsFixationPrefix) + cuTracker := *fixationStoreKeeper.NewFixationStore(storeKey, types.CuTrackerFixationPrefix) + keeper := &Keeper{ cdc: cdc, storeKey: storeKey, @@ -71,26 +74,25 @@ func NewKeeper( projectsKeeper: projectsKeeper, plansKeeper: plansKeeper, dualstakingKeeper: dualstakingKeeper, + + subsFS: fs, + cuTrackerFS: cuTracker, } subsTimerCallback := func(ctx sdk.Context, subkey, _ []byte) { keeper.advanceMonth(ctx, subkey) } + keeper.subsTS = *timerStoreKeeper.NewTimerStore(storeKey, types.SubsTimerPrefix). + WithCallbackByBlockTime(subsTimerCallback) + cuTrackerCallback := func(ctx sdk.Context, cuTrackerTimerKey []byte, cuTrackerTimerData []byte) { keeper.RewardAndResetCuTracker(ctx, cuTrackerTimerKey, cuTrackerTimerData) } - keeper.subsTS = *timerStoreKeeper.NewTimerStore(storeKey, types.SubsTimerPrefix). - WithCallbackByBlockTime(subsTimerCallback) - keeper.cuTrackerTS = *timerStoreKeeper.NewTimerStore(storeKey, types.CuTrackerTimerPrefix). WithCallbackByBlockHeight(cuTrackerCallback) - keeper.cuTrackerFS = *fixationStoreKeeper.NewFixationStore(storeKey, types.CuTrackerFixationPrefix) - - keeper.subsFS = *fixationStoreKeeper.NewFixationStore(storeKey, types.SubsFixationPrefix) - return keeper }