Skip to content

Commit

Permalink
check start time
Browse files Browse the repository at this point in the history
  • Loading branch information
Hitenjain14 committed Aug 15, 2023
1 parent cb1f9c2 commit 5a4acd6
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 10 deletions.
15 changes: 8 additions & 7 deletions code/go/0chain.net/blobbercore/allocation/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,14 @@ type Allocation struct {
RepairerID string `gorm:"column:repairer_id;size:64;not null"`
Expiration common.Timestamp `gorm:"column:expiration_date;not null"`
// AllocationRoot allcation_root of last write_marker
AllocationRoot string `gorm:"column:allocation_root;size:64;not null;default:''"`
FileMetaRoot string `gorm:"column:file_meta_root;size:64;not null;default:''"`
BlobberSize int64 `gorm:"column:blobber_size;not null;default:0"`
BlobberSizeUsed int64 `gorm:"column:blobber_size_used;not null;default:0"`
LatestRedeemedWM string `gorm:"column:latest_redeemed_write_marker;size:64"`
IsRedeemRequired bool `gorm:"column:is_redeem_required"`
TimeUnit time.Duration `gorm:"column:time_unit;not null;default:172800000000000"`
AllocationRoot string `gorm:"column:allocation_root;size:64;not null;default:''"`
FileMetaRoot string `gorm:"column:file_meta_root;size:64;not null;default:''"`
BlobberSize int64 `gorm:"column:blobber_size;not null;default:0"`
BlobberSizeUsed int64 `gorm:"column:blobber_size_used;not null;default:0"`
LatestRedeemedWM string `gorm:"column:latest_redeemed_write_marker;size:64"`
IsRedeemRequired bool `gorm:"column:is_redeem_required"`
TimeUnit time.Duration `gorm:"column:time_unit;not null;default:172800000000000"`
StartTime common.Timestamp `gorm:"column:start_time;not null"`
// Ending and cleaning
CleanedUp bool `gorm:"column:cleaned_up;not null;default:false"`
Finalized bool `gorm:"column:finalized;not null;default:false"`
Expand Down
1 change: 1 addition & 0 deletions code/go/0chain.net/blobbercore/allocation/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func FetchAllocationFromEventsDB(ctx context.Context, allocationID string, alloc
a.Finalized = sa.Finalized
a.TimeUnit = sa.TimeUnit
a.FileOptions = sa.FileOptions
a.StartTime = sa.StartTime

m := map[string]interface{}{
"allocation_id": a.ID,
Expand Down
5 changes: 4 additions & 1 deletion code/go/0chain.net/blobbercore/readmarker/readmarker.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,11 @@ func (rm *ReadMarkerEntity) VerifyMarker(ctx context.Context, sa *allocation.All
return common.NewError("read_marker_validation_failed", "Read Marker clientID does not match request clientID")
}

if rm.LatestRM.Timestamp < sa.StartTime {
return common.NewError("read_marker_validation_failed", "Readmarker timestamp is before the allocation start time")
}

if rm.LatestRM.Timestamp > sa.Expiration {
zLogger.Logger.Error("Readmarker is for an expired allocation", zap.Any("rm", rm))
return common.NewError("read_marker_validation_failed", "Readmarker is for an expired allocation")
}

Expand Down
7 changes: 6 additions & 1 deletion code/go/0chain.net/blobbercore/writemarker/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/0chain/blobber/code/go/0chain.net/core/chain"
"github.com/0chain/blobber/code/go/0chain.net/core/common"
"github.com/0chain/blobber/code/go/0chain.net/core/encryption"
"github.com/0chain/blobber/code/go/0chain.net/core/logging"
. "github.com/0chain/blobber/code/go/0chain.net/core/logging"
"github.com/0chain/blobber/code/go/0chain.net/core/node"
"github.com/0chain/blobber/code/go/0chain.net/core/transaction"
Expand Down Expand Up @@ -81,10 +82,14 @@ func (wme *WriteMarkerEntity) VerifyMarker(ctx context.Context, dbAllocation *al
if clientID == "" || clientID != wme.WM.ClientID || clientID != co.ClientID || co.ClientID != wme.WM.ClientID {
return common.NewError("write_marker_validation_failed", "Write Marker is not by the same client who uploaded")
}
logging.Logger.Info("WriteMarkerEntity.VerifyMarker", zap.Any("startTime", dbAllocation.StartTime))
if wme.WM.Timestamp < dbAllocation.StartTime {
return common.NewError("write_marker_validation_failed", "Write Marker timestamp is before the allocation start time")
}

currTime := common.Now()
// blobber clock is allowed to be 10 seconds behind the current time
if wme.WM.Timestamp > currTime+10 {
if wme.WM.Timestamp > currTime+60 {
return common.NewError("write_marker_validation_failed", "Write Marker timestamp is in the future")
}

Expand Down
1 change: 1 addition & 0 deletions code/go/0chain.net/core/transaction/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ type StorageAllocation struct {
TimeUnit time.Duration `json:"time_unit"`
WritePool uint64 `json:"write_pool"`
FileOptions uint16 `json:"file_options"`
StartTime common.Timestamp `json:"start_time"`

DataShards int64 `json:"data_shards"`
ParityShards int64 `json:"parity_shards"`
Expand Down
3 changes: 2 additions & 1 deletion goose/migrations/001_blobber_meta.sql
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ CREATE TABLE public.allocations (
time_unit bigint DEFAULT '172800000000000'::bigint NOT NULL,
cleaned_up boolean DEFAULT false NOT NULL,
finalized boolean DEFAULT false NOT NULL,
file_options integer DEFAULT 63 NOT NULL
file_options integer DEFAULT 63 NOT NULL,
start_time bigint NOT NULL
);


Expand Down

0 comments on commit 5a4acd6

Please sign in to comment.