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
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
2020-12-17 22:07:06 +00:00
|
|
|
"go.uber.org/zap"
|
2020-05-20 20:57:53 +01:00
|
|
|
|
|
|
|
"storj.io/common/testcontext"
|
|
|
|
"storj.io/storj/private/testplanet"
|
2020-12-17 22:07:06 +00:00
|
|
|
"storj.io/storj/satellite"
|
2020-05-20 20:57:53 +01:00
|
|
|
"storj.io/storj/satellite/overlay"
|
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++ {
|
|
|
|
n, err := cache.DQNodesLastSeenBefore(ctx, time.Now(), 1)
|
|
|
|
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
|
|
|
|
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)
|
|
|
|
require.Equal(t, n1DQTime, n1Info.Reputation.Disqualified)
|
|
|
|
|
|
|
|
n2Info, err = cache.Get(ctx, node2.ID())
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, n2Info.Disqualified)
|
|
|
|
require.Equal(t, n2DQTime, n2Info.Reputation.Disqualified)
|
2020-12-31 18:43:13 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-05-20 20:57:53 +01:00
|
|
|
func TestUpdateStats(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
2020-12-17 22:07:06 +00:00
|
|
|
SatelliteCount: 1, StorageNodeCount: 1,
|
|
|
|
Reconfigure: testplanet.Reconfigure{
|
|
|
|
Satellite: func(log *zap.Logger, index int, config *satellite.Config) {
|
|
|
|
config.Overlay.Node.AuditCount = 2
|
|
|
|
},
|
|
|
|
},
|
2020-05-20 20:57:53 +01:00
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
2020-12-17 22:07:06 +00:00
|
|
|
node := planet.StorageNodes[0]
|
|
|
|
node.Contact.Chore.Pause(ctx)
|
2020-07-08 15:28:49 +01:00
|
|
|
|
2020-05-20 20:57:53 +01:00
|
|
|
cache := planet.Satellites[0].DB.OverlayCache()
|
|
|
|
|
2020-12-17 22:07:06 +00:00
|
|
|
// 1 audit -> unvetted
|
2020-08-26 21:26:10 +01:00
|
|
|
updateReq := &overlay.UpdateRequest{
|
2020-12-17 22:07:06 +00:00
|
|
|
NodeID: node.ID(),
|
|
|
|
AuditOutcome: overlay.AuditOffline,
|
|
|
|
AuditsRequiredForVetting: planet.Satellites[0].Config.Overlay.Node.AuditCount,
|
|
|
|
AuditHistory: testAuditHistoryConfig(),
|
2020-08-26 21:26:10 +01:00
|
|
|
}
|
|
|
|
nodeStats, err := cache.UpdateStats(ctx, updateReq, time.Now())
|
2020-05-20 20:57:53 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
assert.Nil(t, nodeStats.VettedAt)
|
|
|
|
assert.EqualValues(t, 1, nodeStats.AuditCount)
|
|
|
|
|
2020-12-17 22:07:06 +00:00
|
|
|
// 2 audits -> vetted
|
|
|
|
updateReq.NodeID = node.ID()
|
2020-10-23 16:27:39 +01:00
|
|
|
updateReq.AuditOutcome = overlay.AuditOffline
|
2020-08-26 21:26:10 +01:00
|
|
|
nodeStats, err = cache.UpdateStats(ctx, updateReq, time.Now())
|
2020-05-20 20:57:53 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
assert.NotNil(t, nodeStats.VettedAt)
|
|
|
|
assert.EqualValues(t, 2, nodeStats.AuditCount)
|
|
|
|
|
2020-12-17 22:07:06 +00:00
|
|
|
// Don't overwrite node's vetted_at timestamp
|
|
|
|
updateReq.NodeID = node.ID()
|
2020-08-26 21:26:10 +01:00
|
|
|
updateReq.AuditOutcome = overlay.AuditSuccess
|
|
|
|
nodeStats2, err := cache.UpdateStats(ctx, updateReq, time.Now())
|
2020-05-20 20:57:53 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
assert.NotNil(t, nodeStats2.VettedAt)
|
|
|
|
assert.Equal(t, nodeStats.VettedAt, nodeStats2.VettedAt)
|
|
|
|
assert.EqualValues(t, 3, nodeStats2.AuditCount)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBatchUpdateStats(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1, StorageNodeCount: 2,
|
2020-12-17 22:07:06 +00:00
|
|
|
Reconfigure: testplanet.Reconfigure{
|
|
|
|
Satellite: func(log *zap.Logger, index int, config *satellite.Config) {
|
|
|
|
config.Overlay.Node.AuditCount = 2
|
|
|
|
},
|
|
|
|
},
|
2020-05-20 20:57:53 +01:00
|
|
|
}, 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)
|
2020-07-08 15:28:49 +01:00
|
|
|
|
2020-05-20 20:57:53 +01:00
|
|
|
cache := planet.Satellites[0].DB.OverlayCache()
|
2020-12-17 22:07:06 +00:00
|
|
|
numAudits := planet.Satellites[0].Config.Overlay.Node.AuditCount
|
2020-05-20 20:57:53 +01:00
|
|
|
batchSize := 2
|
|
|
|
|
2020-12-17 22:07:06 +00:00
|
|
|
// unvetted
|
|
|
|
updateReqA := &overlay.UpdateRequest{NodeID: nodeA.ID(), AuditOutcome: overlay.AuditOffline, AuditsRequiredForVetting: numAudits, AuditHistory: testAuditHistoryConfig()}
|
|
|
|
updateReqB := &overlay.UpdateRequest{NodeID: nodeB.ID(), AuditOutcome: overlay.AuditSuccess, AuditsRequiredForVetting: numAudits, AuditHistory: testAuditHistoryConfig()}
|
2020-05-20 20:57:53 +01:00
|
|
|
updateReqs := []*overlay.UpdateRequest{updateReqA, updateReqB}
|
2020-08-26 21:26:10 +01:00
|
|
|
failed, err := cache.BatchUpdateStats(ctx, updateReqs, batchSize, time.Now())
|
2020-05-20 20:57:53 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
assert.Len(t, failed, 0)
|
|
|
|
|
|
|
|
nA, err := cache.Get(ctx, nodeA.ID())
|
|
|
|
require.NoError(t, err)
|
|
|
|
assert.Nil(t, nA.Reputation.VettedAt)
|
|
|
|
assert.EqualValues(t, 1, nA.Reputation.AuditCount)
|
|
|
|
|
|
|
|
nB, err := cache.Get(ctx, nodeB.ID())
|
|
|
|
require.NoError(t, err)
|
|
|
|
assert.Nil(t, nB.Reputation.VettedAt)
|
|
|
|
assert.EqualValues(t, 1, nB.Reputation.AuditCount)
|
|
|
|
|
2020-12-17 22:07:06 +00:00
|
|
|
// vetted
|
|
|
|
updateReqA = &overlay.UpdateRequest{NodeID: nodeA.ID(), AuditOutcome: overlay.AuditOffline, AuditsRequiredForVetting: numAudits, AuditHistory: testAuditHistoryConfig()}
|
|
|
|
updateReqB = &overlay.UpdateRequest{NodeID: nodeB.ID(), AuditOutcome: overlay.AuditFailure, AuditsRequiredForVetting: numAudits, AuditHistory: testAuditHistoryConfig()}
|
2020-05-20 20:57:53 +01:00
|
|
|
updateReqs = []*overlay.UpdateRequest{updateReqA, updateReqB}
|
2020-08-26 21:26:10 +01:00
|
|
|
failed, err = cache.BatchUpdateStats(ctx, updateReqs, batchSize, time.Now())
|
2020-05-20 20:57:53 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
assert.Len(t, failed, 0)
|
|
|
|
|
|
|
|
nA, err = cache.Get(ctx, nodeA.ID())
|
|
|
|
require.NoError(t, err)
|
2020-12-17 22:07:06 +00:00
|
|
|
assert.NotNil(t, nA.Reputation.VettedAt)
|
2020-05-20 20:57:53 +01:00
|
|
|
assert.EqualValues(t, 2, nA.Reputation.AuditCount)
|
|
|
|
|
|
|
|
nB, err = cache.Get(ctx, nodeB.ID())
|
|
|
|
require.NoError(t, err)
|
|
|
|
assert.NotNil(t, nB.Reputation.VettedAt)
|
|
|
|
assert.EqualValues(t, 2, nB.Reputation.AuditCount)
|
|
|
|
|
2020-12-17 22:07:06 +00:00
|
|
|
// don't overwrite timestamp
|
|
|
|
updateReqA = &overlay.UpdateRequest{NodeID: nodeA.ID(), AuditOutcome: overlay.AuditSuccess, AuditsRequiredForVetting: numAudits, AuditHistory: testAuditHistoryConfig()}
|
|
|
|
updateReqB = &overlay.UpdateRequest{NodeID: nodeB.ID(), AuditOutcome: overlay.AuditSuccess, AuditsRequiredForVetting: numAudits, AuditHistory: testAuditHistoryConfig()}
|
2020-05-20 20:57:53 +01:00
|
|
|
updateReqs = []*overlay.UpdateRequest{updateReqA, updateReqB}
|
2020-08-26 21:26:10 +01:00
|
|
|
failed, err = cache.BatchUpdateStats(ctx, updateReqs, batchSize, time.Now())
|
2020-05-20 20:57:53 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
assert.Len(t, failed, 0)
|
|
|
|
|
2020-12-17 22:07:06 +00:00
|
|
|
nA2, err := cache.Get(ctx, nodeA.ID())
|
2020-05-20 20:57:53 +01:00
|
|
|
require.NoError(t, err)
|
2020-12-17 22:07:06 +00:00
|
|
|
assert.NotNil(t, nA2.Reputation.VettedAt)
|
|
|
|
assert.Equal(t, nA.Reputation.VettedAt, nA2.Reputation.VettedAt)
|
|
|
|
assert.EqualValues(t, 3, nA2.Reputation.AuditCount)
|
2020-05-20 20:57:53 +01:00
|
|
|
|
|
|
|
nB2, err := cache.Get(ctx, nodeB.ID())
|
|
|
|
require.NoError(t, err)
|
|
|
|
assert.NotNil(t, nB2.Reputation.VettedAt)
|
|
|
|
assert.Equal(t, nB.Reputation.VettedAt, nB2.Reputation.VettedAt)
|
|
|
|
assert.EqualValues(t, 3, nB2.Reputation.AuditCount)
|
|
|
|
})
|
|
|
|
}
|
2020-08-04 21:28:46 +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)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|