2019-06-21 17:27:19 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package audit_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2019-06-24 23:04:06 +01:00
|
|
|
"github.com/stretchr/testify/assert"
|
2019-06-21 17:27:19 +01:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"go.uber.org/zap"
|
2019-06-24 23:04:06 +01:00
|
|
|
|
2019-12-27 11:48:47 +00:00
|
|
|
"storj.io/common/memory"
|
|
|
|
"storj.io/common/pb"
|
|
|
|
"storj.io/common/storj"
|
|
|
|
"storj.io/common/testcontext"
|
|
|
|
"storj.io/common/testrand"
|
2019-11-14 19:46:15 +00:00
|
|
|
"storj.io/storj/private/testplanet"
|
2019-06-21 17:27:19 +01:00
|
|
|
"storj.io/storj/satellite"
|
2019-07-28 06:55:36 +01:00
|
|
|
"storj.io/storj/satellite/audit"
|
2021-04-21 13:42:57 +01:00
|
|
|
"storj.io/storj/satellite/metabase"
|
2019-07-28 06:55:36 +01:00
|
|
|
"storj.io/storj/satellite/overlay"
|
2021-06-23 00:09:39 +01:00
|
|
|
"storj.io/storj/satellite/reputation"
|
2019-06-21 17:27:19 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// TestDisqualificationTooManyFailedAudits does the following:
|
2020-12-05 16:01:42 +00:00
|
|
|
// - Create a failed audit report for a storagenode
|
|
|
|
// - Record the audit report several times and check that the node isn't
|
|
|
|
// disqualified until the audit reputation reaches the cut-off value.
|
2019-06-21 17:27:19 +01:00
|
|
|
func TestDisqualificationTooManyFailedAudits(t *testing.T) {
|
|
|
|
var (
|
2020-04-13 22:38:33 +01:00
|
|
|
auditDQCutOff = 0.4
|
2019-06-21 17:27:19 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1, StorageNodeCount: 1, Reconfigure: testplanet.Reconfigure{
|
|
|
|
Satellite: func(log *zap.Logger, index int, config *satellite.Config) {
|
2021-06-23 00:09:39 +01:00
|
|
|
config.Reputation.AuditLambda = 1
|
|
|
|
config.Reputation.AuditWeight = 1
|
|
|
|
config.Reputation.AuditDQ = auditDQCutOff
|
2019-06-21 17:27:19 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
var (
|
2019-07-22 20:10:04 +01:00
|
|
|
satellitePeer = planet.Satellites[0]
|
|
|
|
nodeID = planet.StorageNodes[0].ID()
|
2019-10-09 15:06:58 +01:00
|
|
|
report = audit.Report{
|
2019-06-21 17:27:19 +01:00
|
|
|
Fails: storj.NodeIDList{nodeID},
|
|
|
|
}
|
|
|
|
)
|
2019-09-11 23:37:01 +01:00
|
|
|
satellitePeer.Audit.Worker.Loop.Pause()
|
2019-06-21 17:27:19 +01:00
|
|
|
|
2019-07-22 20:10:04 +01:00
|
|
|
dossier, err := satellitePeer.Overlay.Service.Get(ctx, nodeID)
|
2019-06-21 17:27:19 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-06-23 00:09:39 +01:00
|
|
|
require.Nil(t, dossier.Disqualified)
|
2019-06-21 17:27:19 +01:00
|
|
|
|
2021-06-23 00:09:39 +01:00
|
|
|
_, err = satellitePeer.Audit.Reporter.RecordAudits(ctx, audit.Report{
|
|
|
|
Successes: storj.NodeIDList{nodeID},
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
reputationInfo, err := satellitePeer.Reputation.Service.Get(ctx, nodeID)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
prevReputation := calcReputation(reputationInfo)
|
2019-06-21 17:27:19 +01:00
|
|
|
|
|
|
|
// Report the audit failure until the node gets disqualified due to many
|
2019-09-11 23:37:01 +01:00
|
|
|
// failed audits.
|
2019-06-21 17:27:19 +01:00
|
|
|
iterations := 1
|
|
|
|
for ; ; iterations++ {
|
2020-12-14 12:54:22 +00:00
|
|
|
_, err := satellitePeer.Audit.Reporter.RecordAudits(ctx, report)
|
2019-06-21 17:27:19 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-06-23 00:09:39 +01:00
|
|
|
reputationInfo, err := satellitePeer.Reputation.Service.Get(ctx, nodeID)
|
2019-06-21 17:27:19 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-06-23 00:09:39 +01:00
|
|
|
reputation := calcReputation(reputationInfo)
|
2019-06-21 17:27:19 +01:00
|
|
|
require.Truef(t, prevReputation >= reputation,
|
|
|
|
"(%d) expected reputation to remain or decrease (previous >= current): %f >= %f",
|
|
|
|
iterations, prevReputation, reputation,
|
|
|
|
)
|
|
|
|
|
|
|
|
if reputation <= auditDQCutOff || reputation == prevReputation {
|
2021-06-23 00:09:39 +01:00
|
|
|
require.NotNilf(t, reputationInfo.Disqualified,
|
2019-06-21 17:27:19 +01:00
|
|
|
"Disqualified (%d) - cut-off: %f, prev. reputation: %f, current reputation: %f",
|
|
|
|
iterations, auditDQCutOff, prevReputation, reputation,
|
|
|
|
)
|
|
|
|
|
2021-06-23 00:09:39 +01:00
|
|
|
require.True(t, time.Since(*reputationInfo.Disqualified) >= 0,
|
2019-06-21 17:27:19 +01:00
|
|
|
"Disqualified should be in the past",
|
|
|
|
)
|
|
|
|
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2021-06-23 00:09:39 +01:00
|
|
|
require.Nil(t, reputationInfo.Disqualified, "Disqualified")
|
2019-06-21 17:27:19 +01:00
|
|
|
prevReputation = reputation
|
|
|
|
}
|
|
|
|
|
|
|
|
require.True(t, iterations > 1, "the number of iterations must be at least 2")
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-06-23 00:09:39 +01:00
|
|
|
func calcReputation(dossier *reputation.Info) float64 {
|
2019-06-21 17:27:19 +01:00
|
|
|
var (
|
2021-06-23 00:09:39 +01:00
|
|
|
alpha = dossier.AuditReputationAlpha
|
|
|
|
beta = dossier.AuditReputationBeta
|
2019-06-21 17:27:19 +01:00
|
|
|
)
|
|
|
|
return alpha / (alpha + beta)
|
|
|
|
}
|
2019-06-24 23:04:06 +01:00
|
|
|
|
|
|
|
func TestDisqualifiedNodesGetNoDownload(t *testing.T) {
|
2019-06-26 11:38:51 +01:00
|
|
|
// Uploads random data.
|
|
|
|
// Mark a node as disqualified.
|
|
|
|
// Check we don't get it when we require order limit.
|
2019-06-24 23:04:06 +01:00
|
|
|
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 1,
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
2019-07-22 20:10:04 +01:00
|
|
|
satellitePeer := planet.Satellites[0]
|
|
|
|
uplinkPeer := planet.Uplinks[0]
|
2019-09-11 23:37:01 +01:00
|
|
|
satellitePeer.Audit.Worker.Loop.Pause()
|
2019-06-24 23:04:06 +01:00
|
|
|
|
2019-06-26 11:38:51 +01:00
|
|
|
testData := testrand.Bytes(8 * memory.KiB)
|
2019-06-24 23:04:06 +01:00
|
|
|
|
2019-09-11 23:37:01 +01:00
|
|
|
err := uplinkPeer.Upload(ctx, satellitePeer, "testbucket", "test/path", testData)
|
2019-06-24 23:04:06 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-08-28 16:55:59 +01:00
|
|
|
bucket := metabase.BucketLocation{ProjectID: uplinkPeer.Projects[0].ID, BucketName: "testbucket"}
|
2019-06-24 23:04:06 +01:00
|
|
|
|
2020-12-14 12:54:22 +00:00
|
|
|
segments, err := satellitePeer.Metainfo.Metabase.TestingAllSegments(ctx)
|
2019-06-24 23:04:06 +01:00
|
|
|
require.NoError(t, err)
|
2020-12-14 12:54:22 +00:00
|
|
|
require.Equal(t, 1, len(segments))
|
2020-05-26 09:05:43 +01:00
|
|
|
|
2020-12-14 12:54:22 +00:00
|
|
|
segment := segments[0]
|
|
|
|
disqualifiedNode := segment.Pieces[0].StorageNode
|
2019-06-24 23:04:06 +01:00
|
|
|
|
2021-07-14 00:30:06 +01:00
|
|
|
err = satellitePeer.Reputation.Service.TestDisqualifyNode(ctx, disqualifiedNode)
|
2020-01-03 00:00:18 +00:00
|
|
|
require.NoError(t, err)
|
2019-06-24 23:04:06 +01:00
|
|
|
|
2021-05-13 14:31:55 +01:00
|
|
|
limits, _, err := satellitePeer.Orders.Service.CreateGetOrderLimits(ctx, bucket, segment, 0)
|
2019-06-24 23:04:06 +01:00
|
|
|
require.NoError(t, err)
|
2020-12-14 12:54:22 +00:00
|
|
|
assert.Len(t, limits, len(segment.Pieces)-1)
|
2019-06-24 23:04:06 +01:00
|
|
|
|
|
|
|
for _, orderLimit := range limits {
|
2019-07-22 20:10:04 +01:00
|
|
|
assert.False(t, isDisqualified(t, ctx, satellitePeer, orderLimit.Limit.StorageNodeId))
|
2019-06-24 23:04:06 +01:00
|
|
|
assert.NotEqual(t, orderLimit.Limit.StorageNodeId, disqualifiedNode)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDisqualifiedNodesGetNoUpload(t *testing.T) {
|
|
|
|
|
|
|
|
// - mark a node as disqualified
|
|
|
|
// - check that we have an error if we try to create a segment using all storage nodes
|
|
|
|
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 1,
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
2019-07-22 20:10:04 +01:00
|
|
|
satellitePeer := planet.Satellites[0]
|
2019-06-24 23:04:06 +01:00
|
|
|
disqualifiedNode := planet.StorageNodes[0]
|
2019-09-11 23:37:01 +01:00
|
|
|
satellitePeer.Audit.Worker.Loop.Pause()
|
2019-06-24 23:04:06 +01:00
|
|
|
|
2021-07-14 00:30:06 +01:00
|
|
|
err := satellitePeer.Reputation.Service.TestDisqualifyNode(ctx, disqualifiedNode.ID())
|
2020-01-03 00:00:18 +00:00
|
|
|
require.NoError(t, err)
|
2019-06-24 23:04:06 +01:00
|
|
|
|
|
|
|
request := overlay.FindStorageNodesRequest{
|
2020-05-07 12:54:48 +01:00
|
|
|
RequestedCount: 4,
|
|
|
|
ExcludedIDs: nil,
|
|
|
|
MinimumVersion: "", // semver or empty
|
2019-06-24 23:04:06 +01:00
|
|
|
}
|
2020-05-06 14:05:31 +01:00
|
|
|
nodes, err := satellitePeer.Overlay.Service.FindStorageNodesForUpload(ctx, request)
|
2019-06-24 23:04:06 +01:00
|
|
|
assert.True(t, overlay.ErrNotEnoughNodes.Has(err))
|
|
|
|
|
|
|
|
assert.Len(t, nodes, 3)
|
|
|
|
for _, node := range nodes {
|
2020-03-28 14:56:05 +00:00
|
|
|
assert.False(t, isDisqualified(t, ctx, satellitePeer, node.ID))
|
|
|
|
assert.NotEqual(t, node.ID, disqualifiedNode)
|
2019-06-24 23:04:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-06-25 18:10:22 +01:00
|
|
|
func TestDisqualifiedNodeRemainsDisqualified(t *testing.T) {
|
|
|
|
|
|
|
|
// - mark a node as disqualified
|
2020-01-03 00:00:18 +00:00
|
|
|
// - give it high audit rate
|
2019-06-25 18:10:22 +01:00
|
|
|
// - check that the node remains disqualified
|
|
|
|
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 1,
|
2021-07-14 00:30:06 +01:00
|
|
|
Reconfigure: testplanet.Reconfigure{
|
|
|
|
Satellite: func(log *zap.Logger, index int, config *satellite.Config) {
|
|
|
|
config.Overlay.Node.MinimumDiskSpace = 10 * memory.MB
|
|
|
|
config.Reputation.AuditLambda = 0 // forget about history
|
|
|
|
config.Reputation.AuditWeight = 1
|
|
|
|
config.Reputation.AuditDQ = 0 // make sure new reputation scores are larger than the DQ thresholds
|
|
|
|
config.Reputation.SuspensionGracePeriod = time.Hour
|
|
|
|
config.Reputation.SuspensionDQEnabled = true
|
|
|
|
},
|
|
|
|
},
|
2019-06-25 18:10:22 +01:00
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
2019-07-22 20:10:04 +01:00
|
|
|
satellitePeer := planet.Satellites[0]
|
2019-09-11 23:37:01 +01:00
|
|
|
satellitePeer.Audit.Worker.Loop.Pause()
|
2019-06-25 18:10:22 +01:00
|
|
|
|
|
|
|
disqualifiedNode := planet.StorageNodes[0]
|
2021-07-14 00:30:06 +01:00
|
|
|
err := satellitePeer.Reputation.Service.TestDisqualifyNode(ctx, disqualifiedNode.ID())
|
2020-01-03 00:00:18 +00:00
|
|
|
require.NoError(t, err)
|
2019-06-25 18:10:22 +01:00
|
|
|
|
2019-09-19 19:37:31 +01:00
|
|
|
info := overlay.NodeCheckInInfo{
|
|
|
|
NodeID: disqualifiedNode.ID(),
|
|
|
|
IsUp: true,
|
|
|
|
Address: &pb.NodeAddress{
|
|
|
|
Address: "1.2.3.4",
|
|
|
|
},
|
|
|
|
Version: &pb.NodeVersion{
|
|
|
|
Version: "v0.0.0",
|
|
|
|
CommitHash: "",
|
|
|
|
Timestamp: time.Time{},
|
|
|
|
Release: false,
|
|
|
|
},
|
|
|
|
}
|
2020-03-10 22:05:01 +00:00
|
|
|
err = satellitePeer.DB.OverlayCache().UpdateCheckIn(ctx, info, time.Now(), overlay.NodeSelectionConfig{})
|
2019-06-25 18:10:22 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-07-22 20:10:04 +01:00
|
|
|
assert.True(t, isDisqualified(t, ctx, satellitePeer, disqualifiedNode.ID()))
|
2021-07-14 00:30:06 +01:00
|
|
|
err = satellitePeer.Reputation.Service.ApplyAudit(ctx, disqualifiedNode.ID(), reputation.AuditSuccess)
|
2019-06-25 18:10:22 +01:00
|
|
|
require.NoError(t, err)
|
2019-07-22 20:10:04 +01:00
|
|
|
assert.True(t, isDisqualified(t, ctx, satellitePeer, disqualifiedNode.ID()))
|
2019-06-25 18:10:22 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-03-27 14:46:40 +00:00
|
|
|
func isDisqualified(t *testing.T, ctx *testcontext.Context, satellite *testplanet.Satellite, nodeID storj.NodeID) bool {
|
2019-06-24 23:04:06 +01:00
|
|
|
node, err := satellite.Overlay.Service.Get(ctx, nodeID)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
return node.Disqualified != nil
|
|
|
|
}
|