Skip to content

Commit 23445a1

Browse files
authored
chore: bump handshake version and reset reserve epoch timestamp (#4903)
1 parent a276067 commit 23445a1

File tree

5 files changed

+82
-6
lines changed

5 files changed

+82
-6
lines changed

pkg/p2p/libp2p/internal/handshake/handshake.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const (
3030
// ProtocolName is the text of the name of the handshake protocol.
3131
ProtocolName = "handshake"
3232
// ProtocolVersion is the current handshake protocol version.
33-
ProtocolVersion = "12.0.0"
33+
ProtocolVersion = "13.0.0"
3434
// StreamName is the name of the stream used for handshake purposes.
3535
StreamName = "handshake"
3636
// MaxWelcomeMessageLength is maximum number of characters allowed in the welcome message.

pkg/storer/migration/all_steps.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ func AfterInitSteps(
2525
4: step_04(sharkyPath, sharkyNoOfShards, st, logger),
2626
5: step_05(st, logger),
2727
6: step_06(st, logger),
28+
7: resetReserveEpochTimestamp(st),
2829
}
2930
}
3031

pkg/storer/migration/export_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
package migration
66

77
var (
8-
Step_01 = step_01
9-
Step_02 = step_02
10-
Step_04 = step_04
11-
Step_05 = step_05
12-
Step_06 = step_06
8+
Step_01 = step_01
9+
Step_02 = step_02
10+
Step_04 = step_04
11+
Step_05 = step_05
12+
Step_06 = step_06
13+
ResetEpochTimestamp = resetReserveEpochTimestamp
1314
)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2024 The Swarm Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package migration
6+
7+
import (
8+
"context"
9+
10+
"github.com/ethersphere/bee/v2/pkg/storer/internal/reserve"
11+
"github.com/ethersphere/bee/v2/pkg/storer/internal/transaction"
12+
)
13+
14+
// resetReserveEpochTimestamp is a migration that resets the epoch timestamp of the reserve
15+
// so that peers in the network can resync chunks.
16+
func resetReserveEpochTimestamp(st transaction.Storage) func() error {
17+
return func() error {
18+
return st.Run(context.Background(), func(s transaction.Store) error {
19+
return s.IndexStore().Delete(&reserve.EpochItem{})
20+
})
21+
}
22+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright 2024 The Swarm Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package migration_test
6+
7+
import (
8+
"context"
9+
"testing"
10+
"time"
11+
12+
"github.com/ethersphere/bee/v2/pkg/sharky"
13+
"github.com/ethersphere/bee/v2/pkg/storage/inmemstore"
14+
"github.com/ethersphere/bee/v2/pkg/storer/internal/reserve"
15+
"github.com/ethersphere/bee/v2/pkg/storer/internal/transaction"
16+
localmigration "github.com/ethersphere/bee/v2/pkg/storer/migration"
17+
"github.com/ethersphere/bee/v2/pkg/swarm"
18+
"github.com/ethersphere/bee/v2/pkg/util/testutil"
19+
"github.com/stretchr/testify/assert"
20+
"github.com/stretchr/testify/require"
21+
)
22+
23+
func Test_ResetEpochTimestamp(t *testing.T) {
24+
t.Parallel()
25+
26+
sharkyDir := t.TempDir()
27+
sharkyStore, err := sharky.New(&dirFS{basedir: sharkyDir}, 1, swarm.SocMaxChunkSize)
28+
assert.NoError(t, err)
29+
store := inmemstore.New()
30+
storage := transaction.NewStorage(sharkyStore, store)
31+
testutil.CleanupCloser(t, storage)
32+
33+
err = storage.Run(context.Background(), func(s transaction.Store) error {
34+
return s.IndexStore().Put(&reserve.EpochItem{Timestamp: uint64(time.Now().Second())})
35+
})
36+
require.NoError(t, err)
37+
38+
has, err := storage.IndexStore().Has(&reserve.EpochItem{})
39+
require.NoError(t, err)
40+
if !has {
41+
t.Fatal("epoch item should exist")
42+
}
43+
44+
err = localmigration.ResetEpochTimestamp(storage)()
45+
require.NoError(t, err)
46+
47+
has, err = storage.IndexStore().Has(&reserve.EpochItem{})
48+
require.NoError(t, err)
49+
if has {
50+
t.Fatal("epoch item should be deleted")
51+
}
52+
}

0 commit comments

Comments
 (0)