2020-05-20 20:57:53 +01:00
|
|
|
// Copyright (C) 2020 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2021-02-19 14:42:10 +00:00
|
|
|
package overlay_test
|
2020-05-20 20:57:53 +01:00
|
|
|
|
|
|
|
import (
|
2021-01-18 14:33:13 +00:00
|
|
|
"fmt"
|
2020-05-20 20:57:53 +01:00
|
|
|
"testing"
|
2020-08-04 21:28:46 +01:00
|
|
|
"time"
|
2020-05-20 20:57:53 +01:00
|
|
|
|
2021-10-27 11:58:29 +01:00
|
|
|
"github.com/stretchr/testify/assert"
|
2020-05-20 20:57:53 +01:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2021-04-22 14:43:56 +01:00
|
|
|
"storj.io/common/pb"
|
2021-10-27 11:58:29 +01:00
|
|
|
"storj.io/common/storj"
|
2020-05-20 20:57:53 +01:00
|
|
|
"storj.io/common/testcontext"
|
2021-10-27 11:58:29 +01:00
|
|
|
"storj.io/common/testrand"
|
2020-05-20 20:57:53 +01:00
|
|
|
"storj.io/storj/private/testplanet"
|
2021-04-22 14:43:56 +01:00
|
|
|
"storj.io/storj/private/teststorj"
|
2021-10-27 11:58:29 +01:00
|
|
|
"storj.io/storj/satellite"
|
2020-05-20 20:57:53 +01:00
|
|
|
"storj.io/storj/satellite/overlay"
|
2021-10-27 11:58:29 +01:00
|
|
|
"storj.io/storj/satellite/satellitedb/satellitedbtest"
|
2021-01-18 14:33:13 +00:00
|
|
|
"storj.io/storj/storagenode"
|
2020-05-20 20:57:53 +01:00
|
|
|
)
|
|
|
|
|
2020-12-31 18:43:13 +00:00
|
|
|
func TestDQNodesLastSeenBefore(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
2021-03-23 18:31:08 +00:00
|
|
|
SatelliteCount: 1, StorageNodeCount: 3,
|
2020-12-31 18:43:13 +00:00
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
2021-02-10 13:58:05 +00:00
|
|
|
planet.Satellites[0].Overlay.DQStrayNodes.Loop.Pause()
|
|
|
|
|
|
|
|
node1 := planet.StorageNodes[0]
|
|
|
|
node2 := planet.StorageNodes[1]
|
2021-03-23 18:31:08 +00:00
|
|
|
node3 := planet.StorageNodes[2]
|
2021-02-10 13:58:05 +00:00
|
|
|
node1.Contact.Chore.Pause(ctx)
|
|
|
|
node2.Contact.Chore.Pause(ctx)
|
2021-03-23 18:31:08 +00:00
|
|
|
node3.Contact.Chore.Pause(ctx)
|
2020-12-31 18:43:13 +00:00
|
|
|
|
|
|
|
cache := planet.Satellites[0].Overlay.DB
|
|
|
|
|
2021-02-10 13:58:05 +00:00
|
|
|
// initial check that node1 is not disqualified
|
|
|
|
n1Info, err := cache.Get(ctx, node1.ID())
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Nil(t, n1Info.Disqualified)
|
|
|
|
|
2021-03-23 18:31:08 +00:00
|
|
|
// initial check that node2 is not disqualified
|
|
|
|
n2Info, err := cache.Get(ctx, node2.ID())
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Nil(t, n2Info.Disqualified)
|
|
|
|
|
|
|
|
// gracefully exit node3
|
2021-02-10 13:58:05 +00:00
|
|
|
req := &overlay.ExitStatusRequest{
|
2021-03-23 18:31:08 +00:00
|
|
|
NodeID: node3.ID(),
|
2021-02-10 13:58:05 +00:00
|
|
|
ExitInitiatedAt: time.Now(),
|
|
|
|
ExitLoopCompletedAt: time.Now(),
|
|
|
|
ExitFinishedAt: time.Now(),
|
|
|
|
}
|
|
|
|
|
|
|
|
dossier, err := cache.UpdateExitStatus(ctx, req)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, dossier.ExitStatus.ExitFinishedAt)
|
|
|
|
|
2021-03-23 18:31:08 +00:00
|
|
|
// check that limit works, set limit = 1
|
|
|
|
// run twice to DQ nodes 1 and 2
|
|
|
|
for i := 0; i < 2; i++ {
|
2022-10-12 18:56:15 +01:00
|
|
|
_, n, err := cache.DQNodesLastSeenBefore(ctx, time.Now(), 1)
|
2021-03-23 18:31:08 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, n, 1)
|
|
|
|
}
|
2021-02-10 13:58:05 +00:00
|
|
|
|
|
|
|
n1Info, err = cache.Get(ctx, node1.ID())
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, n1Info.Disqualified)
|
|
|
|
n1DQTime := n1Info.Disqualified
|
|
|
|
|
2021-03-23 18:31:08 +00:00
|
|
|
n2Info, err = cache.Get(ctx, node2.ID())
|
2020-12-31 18:43:13 +00:00
|
|
|
require.NoError(t, err)
|
2021-03-23 18:31:08 +00:00
|
|
|
require.NotNil(t, n2Info.Disqualified)
|
|
|
|
n2DQTime := n2Info.Disqualified
|
2020-12-31 18:43:13 +00:00
|
|
|
|
2021-03-23 18:31:08 +00:00
|
|
|
// there should be no more nodes for DQ
|
|
|
|
// use higher limit to double check that DQ times
|
|
|
|
// for nodes 1 and 2 have not changed
|
2022-10-12 18:56:15 +01:00
|
|
|
_, n, err := cache.DQNodesLastSeenBefore(ctx, time.Now(), 100)
|
2021-03-15 20:48:36 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, n, 0)
|
2020-12-31 18:43:13 +00:00
|
|
|
|
2021-03-23 18:31:08 +00:00
|
|
|
// double check that node 3 is not DQ
|
|
|
|
n3Info, err := cache.Get(ctx, node3.ID())
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Nil(t, n3Info.Disqualified)
|
|
|
|
|
|
|
|
// double check dq times not updated
|
2021-02-10 13:58:05 +00:00
|
|
|
n1Info, err = cache.Get(ctx, node1.ID())
|
2020-12-31 18:43:13 +00:00
|
|
|
require.NoError(t, err)
|
2021-03-23 18:31:08 +00:00
|
|
|
require.NotNil(t, n1Info.Disqualified)
|
2021-11-08 20:51:04 +00:00
|
|
|
require.Equal(t, n1DQTime, n1Info.Reputation.Status.Disqualified)
|
2021-03-23 18:31:08 +00:00
|
|
|
|
|
|
|
n2Info, err = cache.Get(ctx, node2.ID())
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, n2Info.Disqualified)
|
2021-11-08 20:51:04 +00:00
|
|
|
require.Equal(t, n2DQTime, n2Info.Reputation.Status.Disqualified)
|
2020-12-31 18:43:13 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-04-22 14:43:56 +01:00
|
|
|
// In the event of a new node failing the satellite's initial pingback, its last_contact_success
|
|
|
|
// is set to '0001-01-01 00:00:00+00'. The DQ stray nodes chore DQs nodes where last_contact_success < now() - 30d.
|
|
|
|
// Make sure these nodes are not DQd with stray nodes.
|
|
|
|
func TestDQStrayNodesFailedPingback(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1, StorageNodeCount: 0,
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
sat := planet.Satellites[0]
|
|
|
|
sat.Overlay.DQStrayNodes.Loop.Pause()
|
|
|
|
oc := sat.DB.OverlayCache()
|
|
|
|
|
|
|
|
testID := teststorj.NodeIDFromString("test")
|
|
|
|
checkIn := overlay.NodeCheckInInfo{
|
|
|
|
NodeID: testID,
|
|
|
|
IsUp: false,
|
|
|
|
Address: &pb.NodeAddress{
|
|
|
|
Address: "1.2.3.4",
|
|
|
|
},
|
|
|
|
Version: &pb.NodeVersion{
|
|
|
|
Version: "v0.0.0",
|
|
|
|
CommitHash: "",
|
|
|
|
Timestamp: time.Time{},
|
|
|
|
Release: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
require.NoError(t, oc.UpdateCheckIn(ctx, checkIn, time.Now(), sat.Config.Overlay.Node))
|
|
|
|
|
|
|
|
d, err := oc.Get(ctx, testID)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, time.Time{}, d.Reputation.LastContactSuccess.UTC())
|
2021-11-08 20:51:04 +00:00
|
|
|
require.Nil(t, d.Reputation.Status.Disqualified)
|
2021-04-22 14:43:56 +01:00
|
|
|
|
|
|
|
sat.Overlay.DQStrayNodes.Loop.TriggerWait()
|
|
|
|
|
|
|
|
d, err = oc.Get(ctx, testID)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, time.Time{}, d.Reputation.LastContactSuccess.UTC())
|
2021-11-08 20:51:04 +00:00
|
|
|
require.Nil(t, d.Reputation.Status.Disqualified)
|
2021-04-22 14:43:56 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-01-18 14:33:13 +00:00
|
|
|
func TestOperatorConfig(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1, StorageNodeCount: 2, Reconfigure: testplanet.Reconfigure{
|
|
|
|
StorageNode: func(index int, config *storagenode.Config) {
|
|
|
|
config.Operator.Wallet = fmt.Sprintf("0x%d123456789012345678901234567890123456789", index)
|
|
|
|
config.Operator.WalletFeatures = []string{fmt.Sprintf("test_%d", index)}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
nodeA := planet.StorageNodes[0]
|
|
|
|
nodeB := planet.StorageNodes[1]
|
|
|
|
nodeA.Contact.Chore.Pause(ctx)
|
|
|
|
nodeB.Contact.Chore.Pause(ctx)
|
|
|
|
|
|
|
|
cache := planet.Satellites[0].DB.OverlayCache()
|
|
|
|
|
|
|
|
for _, node := range []*testplanet.StorageNode{nodeA, nodeB} {
|
|
|
|
nodeInfo, err := cache.Get(ctx, node.ID())
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, node.Config.Operator.Email, nodeInfo.Operator.Email)
|
|
|
|
require.Equal(t, node.Config.Operator.Wallet, nodeInfo.Operator.Wallet)
|
|
|
|
require.Equal(t, []string(node.Config.Operator.WalletFeatures), nodeInfo.Operator.WalletFeatures)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2021-10-27 11:58:29 +01:00
|
|
|
|
|
|
|
func TestDBDisqualifyNode(t *testing.T) {
|
|
|
|
satellitedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db satellite.DB) {
|
|
|
|
overlayDB := db.OverlayCache()
|
|
|
|
now := time.Now().Truncate(time.Second).UTC()
|
|
|
|
|
|
|
|
cases := []struct {
|
|
|
|
Name string
|
|
|
|
NodeID storj.NodeID
|
|
|
|
DisqualifiedAt time.Time
|
|
|
|
Reason overlay.DisqualificationReason
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
Name: "Unknown",
|
|
|
|
NodeID: testrand.NodeID(),
|
|
|
|
DisqualifiedAt: now,
|
|
|
|
Reason: overlay.DisqualificationReasonUnknown,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "Audit Failure",
|
|
|
|
NodeID: testrand.NodeID(),
|
|
|
|
DisqualifiedAt: now,
|
|
|
|
Reason: overlay.DisqualificationReasonAuditFailure,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "Suspension",
|
|
|
|
NodeID: testrand.NodeID(),
|
|
|
|
DisqualifiedAt: now,
|
|
|
|
Reason: overlay.DisqualificationReasonSuspension,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "Node Offline",
|
|
|
|
NodeID: testrand.NodeID(),
|
|
|
|
DisqualifiedAt: now,
|
|
|
|
Reason: overlay.DisqualificationReasonNodeOffline,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, testcase := range cases {
|
|
|
|
t.Run(testcase.Name, func(t *testing.T) {
|
|
|
|
checkIn := overlay.NodeCheckInInfo{
|
|
|
|
NodeID: testcase.NodeID,
|
|
|
|
Address: &pb.NodeAddress{
|
|
|
|
Transport: 1,
|
|
|
|
Address: "127.0.0.1:0",
|
|
|
|
},
|
|
|
|
IsUp: true,
|
|
|
|
Version: &pb.NodeVersion{
|
|
|
|
Version: "v0.0.0",
|
|
|
|
CommitHash: "",
|
|
|
|
Timestamp: now,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
err := overlayDB.UpdateCheckIn(ctx, checkIn, now, overlay.NodeSelectionConfig{})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-10-11 17:13:29 +01:00
|
|
|
_, err = overlayDB.DisqualifyNode(ctx, testcase.NodeID, testcase.DisqualifiedAt, testcase.Reason)
|
2021-10-27 11:58:29 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
info, err := overlayDB.Get(ctx, testcase.NodeID)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, info.Disqualified)
|
|
|
|
assert.Equal(t, testcase.DisqualifiedAt, info.Disqualified.UTC())
|
|
|
|
assert.Equal(t, testcase.Reason, *info.DisqualificationReason)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|