diff --git a/pkg/p2p/libp2p/internal/handshake/handshake.go b/pkg/p2p/libp2p/internal/handshake/handshake.go index 9da141c12f5..a1d7cb2d587 100644 --- a/pkg/p2p/libp2p/internal/handshake/handshake.go +++ b/pkg/p2p/libp2p/internal/handshake/handshake.go @@ -30,7 +30,7 @@ const ( // ProtocolName is the text of the name of the handshake protocol. ProtocolName = "handshake" // ProtocolVersion is the current handshake protocol version. - ProtocolVersion = "12.0.0" + ProtocolVersion = "13.0.0" // StreamName is the name of the stream used for handshake purposes. StreamName = "handshake" // MaxWelcomeMessageLength is maximum number of characters allowed in the welcome message. diff --git a/pkg/storer/migration/all_steps.go b/pkg/storer/migration/all_steps.go index 674e08c1143..dec09640e0f 100644 --- a/pkg/storer/migration/all_steps.go +++ b/pkg/storer/migration/all_steps.go @@ -25,6 +25,7 @@ func AfterInitSteps( 4: step_04(sharkyPath, sharkyNoOfShards, st, logger), 5: step_05(st, logger), 6: step_06(st, logger), + 7: resetReserveEpochTimestamp(st), } } diff --git a/pkg/storer/migration/export_test.go b/pkg/storer/migration/export_test.go index 383d9abcce5..06dc27731a9 100644 --- a/pkg/storer/migration/export_test.go +++ b/pkg/storer/migration/export_test.go @@ -5,9 +5,10 @@ package migration var ( - Step_01 = step_01 - Step_02 = step_02 - Step_04 = step_04 - Step_05 = step_05 - Step_06 = step_06 + Step_01 = step_01 + Step_02 = step_02 + Step_04 = step_04 + Step_05 = step_05 + Step_06 = step_06 + ResetEpochTimestamp = resetReserveEpochTimestamp ) diff --git a/pkg/storer/migration/resetEpochTimestamp.go b/pkg/storer/migration/resetEpochTimestamp.go new file mode 100644 index 00000000000..11c42ba7616 --- /dev/null +++ b/pkg/storer/migration/resetEpochTimestamp.go @@ -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{}) + }) + } +} diff --git a/pkg/storer/migration/resetEpochTimestamp_test.go b/pkg/storer/migration/resetEpochTimestamp_test.go new file mode 100644 index 00000000000..f965da458c2 --- /dev/null +++ b/pkg/storer/migration/resetEpochTimestamp_test.go @@ -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") + } +}