From 902adcfc57eb8773f9874e8645ee2ae645848ded Mon Sep 17 00:00:00 2001 From: Tyrone Date: Fri, 6 May 2022 10:25:07 +1000 Subject: [PATCH 1/2] Add `on_chain` field on `/file/stats/` endpoint (#669) --- .../blobbercore/handler/storage_handler.go | 1 + code/go/0chain.net/blobbercore/stats/filestats.go | 1 + .../go/0chain.net/blobbercore/writemarker/entity.go | 4 ++++ .../blobbercore/writemarker/entity_test.go | 13 +++++++++++++ 4 files changed, 19 insertions(+) create mode 100644 code/go/0chain.net/blobbercore/writemarker/entity_test.go diff --git a/code/go/0chain.net/blobbercore/handler/storage_handler.go b/code/go/0chain.net/blobbercore/handler/storage_handler.go index 8da235ff7..a6952cafe 100644 --- a/code/go/0chain.net/blobbercore/handler/storage_handler.go +++ b/code/go/0chain.net/blobbercore/handler/storage_handler.go @@ -393,6 +393,7 @@ func (fsh *StorageHandler) GetFileStats(ctx context.Context, r *http.Request) (i wm, _ := writemarker.GetWriteMarkerEntity(ctx, fileref.WriteMarker) if wm != nil && fileStats != nil { fileStats.WriteMarkerRedeemTxn = wm.CloseTxnID + fileStats.OnChain = wm.OnChain() } var statsMap map[string]interface{} statsBytes, _ := json.Marshal(fileStats) diff --git a/code/go/0chain.net/blobbercore/stats/filestats.go b/code/go/0chain.net/blobbercore/stats/filestats.go index 543b5b430..437254bd4 100644 --- a/code/go/0chain.net/blobbercore/stats/filestats.go +++ b/code/go/0chain.net/blobbercore/stats/filestats.go @@ -19,6 +19,7 @@ type FileStats struct { FailedChallenges int64 `gorm:"column:num_of_failed_challenges" json:"num_of_failed_challenges"` LastChallengeResponseTxn string `gorm:"column:last_challenge_txn;size:64" json:"last_challenge_txn"` WriteMarkerRedeemTxn string `gorm:"-" json:"write_marker_txn"` + OnChain bool `gorm:"-" json:"on_chain"` datastore.ModelWithTS } diff --git a/code/go/0chain.net/blobbercore/writemarker/entity.go b/code/go/0chain.net/blobbercore/writemarker/entity.go index 16f1db7da..11fc3f7f9 100644 --- a/code/go/0chain.net/blobbercore/writemarker/entity.go +++ b/code/go/0chain.net/blobbercore/writemarker/entity.go @@ -106,6 +106,10 @@ func (wm *WriteMarkerEntity) UpdateStatus(ctx context.Context, status WriteMarke return } +func (wm *WriteMarkerEntity) OnChain() bool { + return wm.Status == Committed +} + // GetWriteMarkerEntity get WriteMarkerEntity from postgres func GetWriteMarkerEntity(ctx context.Context, allocation_root string) (*WriteMarkerEntity, error) { db := datastore.GetStore().GetTransaction(ctx) diff --git a/code/go/0chain.net/blobbercore/writemarker/entity_test.go b/code/go/0chain.net/blobbercore/writemarker/entity_test.go new file mode 100644 index 000000000..924c9c1f6 --- /dev/null +++ b/code/go/0chain.net/blobbercore/writemarker/entity_test.go @@ -0,0 +1,13 @@ +package writemarker + +import ( + "github.com/stretchr/testify/assert" + "testing" +) + +func TestWriteMarkerEntity_OnChain(t *testing.T) { + assert.False(t, (&WriteMarkerEntity{Status: Accepted}).OnChain()) + assert.False(t, (&WriteMarkerEntity{Status: Failed}).OnChain()) + assert.True(t, (&WriteMarkerEntity{Status: Committed}).OnChain()) + assert.False(t, (&WriteMarkerEntity{}).OnChain()) // unspecified +} From 8ce0eacccf36dd98ef46b26f18a4afff18216ce1 Mon Sep 17 00:00:00 2001 From: Sumit <103603196+sum-it08@users.noreply.github.com> Date: Mon, 9 May 2022 21:01:43 +0530 Subject: [PATCH 2/2] - challenge struct updated (#648) --- code/go/0chain.net/validatorcore/storage/challenge_handler.go | 4 ++-- code/go/0chain.net/validatorcore/storage/models.go | 2 +- code/go/0chain.net/validatorcore/storage/protocol.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/code/go/0chain.net/validatorcore/storage/challenge_handler.go b/code/go/0chain.net/validatorcore/storage/challenge_handler.go index 2222e2350..cb3c35e50 100644 --- a/code/go/0chain.net/validatorcore/storage/challenge_handler.go +++ b/code/go/0chain.net/validatorcore/storage/challenge_handler.go @@ -79,7 +79,7 @@ func ChallengeHandler(ctx context.Context, r *http.Request) (interface{}, error) } Logger.Error("Validation Failed - Error verifying the challenge", zap.Any("challenge_id", challengeObj.ID), zap.Error(err)) - validationTicket.BlobberID = challengeObj.Blobber.ID + validationTicket.BlobberID = challengeObj.BlobberID validationTicket.ChallengeID = challengeObj.ID validationTicket.Result = false validationTicket.MessageCode = errCode @@ -94,7 +94,7 @@ func ChallengeHandler(ctx context.Context, r *http.Request) (interface{}, error) return &validationTicket, nil } - validationTicket.BlobberID = challengeObj.Blobber.ID + validationTicket.BlobberID = challengeObj.BlobberID validationTicket.ChallengeID = challengeObj.ID validationTicket.Result = true validationTicket.MessageCode = "success" diff --git a/code/go/0chain.net/validatorcore/storage/models.go b/code/go/0chain.net/validatorcore/storage/models.go index 59ca96e83..7160bedd8 100644 --- a/code/go/0chain.net/validatorcore/storage/models.go +++ b/code/go/0chain.net/validatorcore/storage/models.go @@ -351,8 +351,8 @@ type Challenge struct { Validators []*StorageNode `json:"validators"` RandomNumber int64 `json:"seed"` AllocationID string `json:"allocation_id"` - Blobber *StorageNode `json:"blobber"` AllocationRoot string `json:"allocation_root"` + BlobberID string `json:"blobber_id"` } type ValidationTicket struct { diff --git a/code/go/0chain.net/validatorcore/storage/protocol.go b/code/go/0chain.net/validatorcore/storage/protocol.go index 9d91977e4..db6a87ed7 100644 --- a/code/go/0chain.net/validatorcore/storage/protocol.go +++ b/code/go/0chain.net/validatorcore/storage/protocol.go @@ -110,7 +110,7 @@ func (sp *ValidatorProtocolImpl) VerifyChallengeTransaction(ctx context.Context, return nil, common.NewError("invalid_challenge", "Validator is not part of the challenge") } - if challengeObj.Blobber.ID != blobberID { + if challengeObj.BlobberID != blobberID { return nil, common.NewError("invalid_challenge", "Challenge is meant for a different blobber") }