Skip to content

Commit

Permalink
Revert "CNS-692: fix stale at bug in fixation + fix unit tests"
Browse files Browse the repository at this point in the history
This reverts commit 68e419a.
  • Loading branch information
oren-lava committed Nov 16, 2023
1 parent 219dba1 commit 07fce32
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion x/fixationstore/fixationstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion x/fixationstore/fixationstore_migrations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type mockEntry1to2 struct {
}

func mockGetStaleBlock(ctx sdk.Context) uint64 {
return 1440
return 1500
}

func TestMigrate1to2(t *testing.T) {
Expand Down
14 changes: 7 additions & 7 deletions x/fixationstore/fixationstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
}

Expand Down Expand Up @@ -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},
}

Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -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},
Expand Down
2 changes: 1 addition & 1 deletion x/fixationstore/types/fixation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
16 changes: 9 additions & 7 deletions x/subscription/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
}

Expand Down

0 comments on commit 07fce32

Please sign in to comment.