storagenode: use minimum time in the order for expiration (#2504)
This commit is contained in:
parent
910e4744ad
commit
d616be8ae0
@ -115,7 +115,7 @@ func (planet *Planet) newStorageNodes(count int, whitelistedSatellites storj.Nod
|
||||
Storage2: piecestore.Config{
|
||||
ExpirationGracePeriod: 0,
|
||||
MaxConcurrentRequests: 100,
|
||||
OrderLimitGracePeriod: time.Hour * 24,
|
||||
OrderLimitGracePeriod: time.Hour,
|
||||
Sender: orders.SenderConfig{
|
||||
Interval: time.Hour,
|
||||
Timeout: time.Hour,
|
||||
|
@ -49,7 +49,7 @@ func TestCollector(t *testing.T) {
|
||||
collections := 0
|
||||
serialsPresent := 0
|
||||
|
||||
// imagine we are 16 days in the future
|
||||
// imagine we are 30 minutes in the future
|
||||
for _, storageNode := range planet.StorageNodes {
|
||||
pieceinfos := storageNode.DB.PieceInfo()
|
||||
usedSerials := storageNode.DB.UsedSerials()
|
||||
@ -63,14 +63,9 @@ func TestCollector(t *testing.T) {
|
||||
}
|
||||
|
||||
// collect all the data
|
||||
err = storageNode.Collector.Collect(ctx, time.Now().Add(16*24*time.Hour))
|
||||
err = storageNode.Collector.Collect(ctx, time.Now().Add(30*time.Minute))
|
||||
require.NoError(t, err)
|
||||
|
||||
// verify that we deleted everything
|
||||
used, err = pieceinfos.SpaceUsed(ctx)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, int64(0), used)
|
||||
|
||||
// ensure we haven't deleted used serials
|
||||
err = usedSerials.IterateAll(ctx, func(_ storj.NodeID, _ storj.SerialNumber, _ time.Time) {
|
||||
serialsPresent++
|
||||
@ -85,12 +80,12 @@ func TestCollector(t *testing.T) {
|
||||
|
||||
serialsPresent = 0
|
||||
|
||||
// imagine we are 48 days in the future
|
||||
// imagine we are 2 hours in the future
|
||||
for _, storageNode := range planet.StorageNodes {
|
||||
usedSerials := storageNode.DB.UsedSerials()
|
||||
|
||||
// collect all the data
|
||||
err = storageNode.Collector.Collect(ctx, time.Now().Add(48*24*time.Hour))
|
||||
err = storageNode.Collector.Collect(ctx, time.Now().Add(2*time.Hour))
|
||||
require.NoError(t, err)
|
||||
|
||||
// ensure we have deleted used serials
|
||||
@ -103,5 +98,30 @@ func TestCollector(t *testing.T) {
|
||||
}
|
||||
|
||||
require.Equal(t, 0, serialsPresent)
|
||||
|
||||
serialsPresent = 0
|
||||
|
||||
// imagine we are 10 days in the future
|
||||
for _, storageNode := range planet.StorageNodes {
|
||||
pieceinfos := storageNode.DB.PieceInfo()
|
||||
usedSerials := storageNode.DB.UsedSerials()
|
||||
|
||||
// collect all the data
|
||||
err = storageNode.Collector.Collect(ctx, time.Now().Add(10*24*time.Hour))
|
||||
require.NoError(t, err)
|
||||
|
||||
// verify that we deleted everything
|
||||
used, err := pieceinfos.SpaceUsed(ctx)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, int64(0), used)
|
||||
|
||||
// ensure we have deleted used serials
|
||||
err = usedSerials.IterateAll(ctx, func(id storj.NodeID, serial storj.SerialNumber, expiration time.Time) {
|
||||
serialsPresent++
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
collections++
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ func (endpoint *Endpoint) VerifyOrderLimit(ctx context.Context, limit *pb.OrderL
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
|
||||
// sanity checks
|
||||
now := time.Now()
|
||||
switch {
|
||||
case limit.Limit < 0:
|
||||
return ErrProtocol.New("order limit is negative")
|
||||
@ -42,7 +43,7 @@ func (endpoint *Endpoint) VerifyOrderLimit(ctx context.Context, limit *pb.OrderL
|
||||
return ErrProtocol.New("piece expired: %v", limit.PieceExpiration)
|
||||
case endpoint.IsExpired(limit.OrderExpiration):
|
||||
return ErrProtocol.New("order expired: %v", limit.OrderExpiration)
|
||||
case time.Now().Sub(limit.OrderCreation) > endpoint.config.OrderLimitGracePeriod:
|
||||
case now.Sub(limit.OrderCreation) > endpoint.config.OrderLimitGracePeriod:
|
||||
return ErrProtocol.New("order created too long ago: %v", limit.OrderCreation)
|
||||
case limit.SatelliteId.IsZero():
|
||||
return ErrProtocol.New("missing satellite id")
|
||||
@ -76,11 +77,16 @@ func (endpoint *Endpoint) VerifyOrderLimit(ctx context.Context, limit *pb.OrderL
|
||||
return ErrVerifyUntrusted.Wrap(err)
|
||||
}
|
||||
|
||||
// TODO: use min of piece and order expiration instead
|
||||
serialExpiration, err := ptypes.Timestamp(limit.OrderExpiration)
|
||||
if err != nil {
|
||||
return ErrInternal.Wrap(err)
|
||||
}
|
||||
|
||||
// Expire the serial earlier if the grace period is smaller than the serial expiration.
|
||||
if graceExpiration := now.Add(endpoint.config.OrderLimitGracePeriod); graceExpiration.Before(serialExpiration) {
|
||||
serialExpiration = graceExpiration
|
||||
}
|
||||
|
||||
if err := endpoint.usedSerials.Add(ctx, limit.SatelliteId, limit.SerialNumber, serialExpiration); err != nil {
|
||||
return ErrVerifyDuplicateRequest.Wrap(err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user