Skip to content

Commit

Permalink
Merge branch 'staging' into feature/transaction-nonce
Browse files Browse the repository at this point in the history
  • Loading branch information
dabasov committed May 9, 2022
2 parents 72c1f99 + 8ce0eac commit f640cc9
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions code/go/0chain.net/blobbercore/handler/storage_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions code/go/0chain.net/blobbercore/stats/filestats.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 4 additions & 0 deletions code/go/0chain.net/blobbercore/writemarker/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions code/go/0chain.net/blobbercore/writemarker/entity_test.go
Original file line number Diff line number Diff line change
@@ -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
}
4 changes: 2 additions & 2 deletions code/go/0chain.net/validatorcore/storage/challenge_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion code/go/0chain.net/validatorcore/storage/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion code/go/0chain.net/validatorcore/storage/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down

0 comments on commit f640cc9

Please sign in to comment.