-
Notifications
You must be signed in to change notification settings - Fork 338
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: bump handshake version and reset reserve epoch timestamp (#4903)
- Loading branch information
Showing
5 changed files
with
82 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright 2024 The Swarm Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package migration | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/ethersphere/bee/v2/pkg/storer/internal/reserve" | ||
"github.com/ethersphere/bee/v2/pkg/storer/internal/transaction" | ||
) | ||
|
||
// resetReserveEpochTimestamp is a migration that resets the epoch timestamp of the reserve | ||
// so that peers in the network can resync chunks. | ||
func resetReserveEpochTimestamp(st transaction.Storage) func() error { | ||
return func() error { | ||
return st.Run(context.Background(), func(s transaction.Store) error { | ||
return s.IndexStore().Delete(&reserve.EpochItem{}) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright 2024 The Swarm Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package migration_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/ethersphere/bee/v2/pkg/sharky" | ||
"github.com/ethersphere/bee/v2/pkg/storage/inmemstore" | ||
"github.com/ethersphere/bee/v2/pkg/storer/internal/reserve" | ||
"github.com/ethersphere/bee/v2/pkg/storer/internal/transaction" | ||
localmigration "github.com/ethersphere/bee/v2/pkg/storer/migration" | ||
"github.com/ethersphere/bee/v2/pkg/swarm" | ||
"github.com/ethersphere/bee/v2/pkg/util/testutil" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_ResetEpochTimestamp(t *testing.T) { | ||
t.Parallel() | ||
|
||
sharkyDir := t.TempDir() | ||
sharkyStore, err := sharky.New(&dirFS{basedir: sharkyDir}, 1, swarm.SocMaxChunkSize) | ||
assert.NoError(t, err) | ||
store := inmemstore.New() | ||
storage := transaction.NewStorage(sharkyStore, store) | ||
testutil.CleanupCloser(t, storage) | ||
|
||
err = storage.Run(context.Background(), func(s transaction.Store) error { | ||
return s.IndexStore().Put(&reserve.EpochItem{Timestamp: uint64(time.Now().Second())}) | ||
}) | ||
require.NoError(t, err) | ||
|
||
has, err := storage.IndexStore().Has(&reserve.EpochItem{}) | ||
require.NoError(t, err) | ||
if !has { | ||
t.Fatal("epoch item should exist") | ||
} | ||
|
||
err = localmigration.ResetEpochTimestamp(storage)() | ||
require.NoError(t, err) | ||
|
||
has, err = storage.IndexStore().Has(&reserve.EpochItem{}) | ||
require.NoError(t, err) | ||
if has { | ||
t.Fatal("epoch item should be deleted") | ||
} | ||
} |