From 38d8d2ee6fd41d9237d89d44e37a7de74286595f Mon Sep 17 00:00:00 2001 From: istae <14264581+istae@users.noreply.github.com> Date: Wed, 11 Sep 2024 19:22:52 +0300 Subject: [PATCH] fix: reset epoch timestamp when the reserve is reset (#4816) --- pkg/storer/internal/reserve/reserve.go | 7 ++++++- pkg/storer/internal/reserve/reserve_test.go | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/storer/internal/reserve/reserve.go b/pkg/storer/internal/reserve/reserve.go index 4e7bfed506a..417bc19a566 100644 --- a/pkg/storer/internal/reserve/reserve.go +++ b/pkg/storer/internal/reserve/reserve.go @@ -518,9 +518,14 @@ func (r *Reserve) Reset(ctx context.Context) error { size := r.Size() + err := r.st.Run(ctx, func(s transaction.Store) error { return s.IndexStore().Delete(&EpochItem{}) }) + if err != nil { + return err + } + bRitems := make([]*BatchRadiusItem, 0, size) - err := r.st.IndexStore().Iterate(storage.Query{ + err = r.st.IndexStore().Iterate(storage.Query{ Factory: func() storage.Item { return &BatchRadiusItem{} }, }, func(res storage.Result) (bool, error) { bRitems = append(bRitems, res.Entry.(*BatchRadiusItem)) diff --git a/pkg/storer/internal/reserve/reserve_test.go b/pkg/storer/internal/reserve/reserve_test.go index ad7dd13d019..cc6a1e8814c 100644 --- a/pkg/storer/internal/reserve/reserve_test.go +++ b/pkg/storer/internal/reserve/reserve_test.go @@ -824,6 +824,8 @@ func TestReset(t *testing.T) { } assert.Equal(t, c, total) + checkStore(t, ts.IndexStore(), &reserve.EpochItem{}, false) + err = r.Reset(context.Background()) if err != nil { t.Fatal(err) @@ -851,6 +853,8 @@ func TestReset(t *testing.T) { } assert.Equal(t, c, 0) + checkStore(t, ts.IndexStore(), &reserve.EpochItem{}, true) + for _, c := range chs { h, err := c.Stamp().Hash() if err != nil {