Skip to content

Commit c1f964a

Browse files
authored
Merge branch 'sprint-1.18' into fix/auth-prefix
2 parents 2a11580 + 22ca751 commit c1f964a

File tree

8 files changed

+30
-22
lines changed

8 files changed

+30
-22
lines changed

code/go/0chain.net/blobbercore/allocation/protocol.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func FetchAllocationFromEventsDB(ctx context.Context, allocationID string, alloc
113113
a.StartTime = sa.StartTime
114114
a.StorageVersion = uint8(sa.StorageVersion)
115115
a.OwnerSigningPublicKey = sa.OwnerSigningPublicKey
116-
logging.Logger.Info("OwnerSigningPublicKey", zap.String("OwnerSigningPublicKey", a.OwnerSigningPublicKey), zap.String("allocation_id", a.ID))
116+
logging.Logger.Info("OwnerSigningPublicKey", zap.String("OwnerSigningPublicKey", a.OwnerSigningPublicKey), zap.String("allocation_id", a.ID), zap.String("allocation_tx", a.Tx))
117117

118118
m := map[string]interface{}{
119119
"allocation_id": a.ID,
@@ -141,7 +141,7 @@ func FetchAllocationFromEventsDB(ctx context.Context, allocationID string, alloc
141141
return a, nil
142142
}
143143

144-
logging.Logger.Info("Saving the allocation to DB", zap.String("allocation_id", a.ID))
144+
logging.Logger.Info("Saving the allocation to DB", zap.String("allocation_id", a.ID), zap.String("allocation_tx", a.Tx))
145145

146146
if !isExist {
147147
err = Repo.Save(ctx, a)
@@ -174,6 +174,7 @@ func FetchAllocationFromEventsDB(ctx context.Context, allocationID string, alloc
174174
alloc.StartTime = a.StartTime
175175
alloc.BlobberSize = a.BlobberSize
176176
alloc.OwnerSigningPublicKey = a.OwnerSigningPublicKey
177+
logging.Logger.Info("updatingAllocation", zap.String("allocation_id", a.ID), zap.String("allocation_tx", a.Tx))
177178
}
178179
err = Repo.UpdateAllocation(ctx, a, updateMap, updateOption)
179180
}

code/go/0chain.net/blobbercore/allocation/repository.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ func (r *Repository) GetByTx(ctx context.Context, allocationID, txHash string) (
135135
Allocation: a,
136136
}
137137
return a, nil
138+
} else if a != nil {
139+
logging.Logger.Debug("allocation_cache_miss", zap.String("allocation_id", allocationID), zap.String("tx_hash", txHash), zap.String("cached_tx_hash", a.Tx))
138140
}
139141

140142
alloc := &Allocation{}
@@ -260,7 +262,6 @@ func (r *Repository) Commit(tx *datastore.EnhancedDB) {
260262
return
261263
}
262264
for _, txnCache := range cache {
263-
alloc := r.getAllocFromGlobalCache(txnCache.Allocation.ID)
264265
mapLock.Lock()
265266
mut, ok := r.allocLock[txnCache.Allocation.ID]
266267
if !ok {
@@ -269,11 +270,13 @@ func (r *Repository) Commit(tx *datastore.EnhancedDB) {
269270
}
270271
mapLock.Unlock()
271272
mut.Lock()
273+
alloc := r.getAllocFromGlobalCache(txnCache.Allocation.ID)
272274
if alloc != nil {
273275
for _, update := range txnCache.AllocationUpdates {
274276
update(alloc)
275277
}
276278
if len(txnCache.AllocationUpdates) > 0 {
279+
logging.Logger.Debug("committing_allocation", zap.String("allocation_id", alloc.ID), zap.String("tx", alloc.Tx))
277280
r.setAllocToGlobalCache(alloc)
278281
}
279282
}

code/go/0chain.net/blobbercore/challenge/protocol.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ func (cr *ChallengeEntity) LoadValidationTickets(ctx context.Context) error {
8383
// unlocking it as it will be locked for longer time and handler.CommitWrite
8484
// will fail.
8585
allocMu := lock.GetMutex(allocation.Allocation{}.TableName(), cr.AllocationID)
86+
logging.Logger.Debug("[challenge]load: ", zap.String("challenge_id", cr.ChallengeID), zap.String("allocation_id", cr.AllocationID))
8687
allocMu.RLock()
8788

8889
allocationObj, err := allocation.Repo.GetAllocationFromDB(ctx, cr.AllocationID)
@@ -105,15 +106,14 @@ func (cr *ChallengeEntity) LoadValidationTickets(ctx context.Context) error {
105106
var (
106107
postData map[string]any
107108
)
108-
109109
if allocationObj.IsStorageV2() {
110110
postData, err = cr.getPostDataV2(ctx, allocationObj)
111111
} else {
112112
postData, err = cr.getPostData(ctx, allocationObj)
113113
}
114114
allocMu.RUnlock()
115115
if err != nil {
116-
logging.Logger.Error("[challenge]load: ", zap.String("challenge_id", cr.ChallengeID), zap.Error(err))
116+
logging.Logger.Error("[challenge]load: ", zap.String("challenge_id", cr.ChallengeID), zap.String("allocation_id", cr.AllocationID), zap.Error(err))
117117
cr.CancelChallenge(ctx, err)
118118
return err
119119
}
@@ -294,7 +294,7 @@ func (cr *ChallengeEntity) SaveChallengeResult(ctx context.Context, t *coreTxn.T
294294
func (cr *ChallengeEntity) getPostDataV2(ctx context.Context, allocationObj *allocation.Allocation) (map[string]any, error) {
295295
trie := allocationObj.GetTrie()
296296
copyTrie := wmpt.New(trie.CopyRoot(filestore.COLLAPSE_DEPTH), datastore.GetBlockStore())
297-
297+
logging.Logger.Info("[challenge]getPostDataV2: ", zap.String("allocation_id", cr.AllocationID))
298298
var (
299299
blockNum = int64(0)
300300
postData = make(map[string]interface{})
@@ -307,7 +307,7 @@ func (cr *ChallengeEntity) getPostDataV2(ctx context.Context, allocationObj *all
307307
blockNum = r.Int63n(int64(copyTrie.Weight()))
308308
blockNum++
309309
cr.BlockNum = blockNum
310-
logging.Logger.Info("[challenge]rand: ", zap.Uint64("trie.NumBlocks", trie.Weight()), zap.Any("blockNum", blockNum), zap.Any("challenge_id", cr.ChallengeID), zap.Any("random_seed", cr.RandomNumber))
310+
logging.Logger.Info("[challenge]rand: ", zap.Uint64("trie.NumBlocks", trie.Weight()), zap.Any("blockNum", blockNum), zap.Any("challenge_id", cr.ChallengeID), zap.Any("random_seed", cr.RandomNumber), zap.String("allocation_id", cr.AllocationID))
311311
key, objectProof, err := copyTrie.GetBlockProof(uint64(blockNum))
312312
if err != nil {
313313
return nil, err
@@ -353,6 +353,8 @@ func (cr *ChallengeEntity) getPostDataV2(ctx context.Context, allocationObj *all
353353
zap.Int64("file size", ref.Size),
354354
zap.String("file path", ref.Path),
355355
zap.Int64("proof gen time", proofGenTime),
356+
zap.String("allocation_id", cr.AllocationID),
357+
zap.String("challenge_id", cr.ChallengeID),
356358
)
357359
postData["challenge_proof"] = challengeResponse
358360
objectSize = ref.Size
@@ -385,6 +387,7 @@ func (cr *ChallengeEntity) getPostDataV2(ctx context.Context, allocationObj *all
385387

386388
return nil, err
387389
}
390+
logging.Logger.Debug("[challenge]getPostDataV2Return ", zap.Any("blockNum", blockNum), zap.String("allocation_id", cr.AllocationID))
388391
return postData, nil
389392
}
390393

code/go/0chain.net/blobbercore/handler/handler_common.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import (
44
"context"
55
"errors"
66
"fmt"
7-
"github.com/0chain/gosdk/core/client"
87
"net/http"
98
"time"
109

10+
"github.com/0chain/gosdk/core/client"
11+
1112
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/allocation"
1213
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/blobberhttp"
1314
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/writemarker"
@@ -142,12 +143,12 @@ func WithStatusConnectionForWM(handler common.StatusCodeResponderF) common.Statu
142143

143144
mutex := lock.GetMutex(allocation.Allocation{}.TableName(), allocationID)
144145
Logger.Info("Locking allocation", zap.String("allocation_id", allocationID))
146+
mutex.Lock()
147+
defer mutex.Unlock()
145148
wmSet := writemarker.SetCommittingMarker(allocationID, true)
146149
if !wmSet {
147150
return nil, http.StatusBadRequest, common.NewError("pending_markers", "Committing marker set failed")
148151
}
149-
mutex.Lock()
150-
defer mutex.Unlock()
151152
ctx = GetMetaDataStore().CreateTransaction(ctx)
152153
tx := GetMetaDataStore().GetTransaction(ctx)
153154
resp, statusCode, err = handler(ctx, r)
@@ -161,6 +162,7 @@ func WithStatusConnectionForWM(handler common.StatusCodeResponderF) common.Statu
161162
}
162163
writemarker.SetCommittingMarker(allocationID, false)
163164
}
165+
Logger.Debug("Unlocking allocation", zap.String("allocation_id", allocationID))
164166
}()
165167

166168
if err != nil {

code/go/0chain.net/blobbercore/handler/object_operation_handler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ func (fsh *StorageHandler) CommitWrite(ctx context.Context, r *http.Request) (*b
622622
return nil, common.NewError("blacklisted_client", "Client is blacklisted: "+clientID)
623623
}
624624

625-
allocationObj, err := fsh.verifyAllocation(ctx, allocationId, allocationTx, false)
625+
allocationObj, err := fsh.verifyAllocation(ctx, allocationId, allocationTx, true)
626626
if err != nil {
627627
return nil, common.NewError("invalid_parameters", "Invalid allocation id passed."+err.Error())
628628
}
@@ -912,7 +912,7 @@ func (fsh *StorageHandler) CommitWriteV2(ctx context.Context, r *http.Request) (
912912
return nil, common.NewError("blacklisted_client", "Client is blacklisted: "+clientID)
913913
}
914914

915-
allocationObj, err := fsh.verifyAllocation(ctx, allocationId, allocationTx, false)
915+
allocationObj, err := fsh.verifyAllocation(ctx, allocationId, allocationTx, true)
916916
if err != nil {
917917
return nil, common.NewError("invalid_parameters", "Invalid allocation id passed."+err.Error())
918918
}

code/go/0chain.net/blobbercore/handler/storage_handler.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,7 @@ func (fsh *StorageHandler) GetReferencePathV2(ctx context.Context, r *http.Reque
589589
case result := <-resCh:
590590
return result, nil
591591
case err := <-errCh:
592+
logging.Logger.Error("GetReferencePathV2", zap.Error(err))
592593
return nil, err
593594
}
594595

@@ -708,10 +709,11 @@ func (fsh *StorageHandler) getReferencePathV2(ctx context.Context, r *http.Reque
708709
return
709710
}
710711
allocMu := lock.GetMutex(allocation.Allocation{}.TableName(), allocationId)
712+
logging.Logger.Debug("getReferencePathV2Lock", zap.String("allocation_id", allocationId))
711713
allocMu.RLock()
712714
defer allocMu.RUnlock()
713715
now := time.Now()
714-
716+
logging.Logger.Debug("getTrie", zap.String("allocation_id", allocationId))
715717
trie := allocationObj.GetTrie()
716718
if trie == nil {
717719
errCh <- common.NewError("invalid_parameters", "Trie not found for allocation.")

code/go/0chain.net/blobbercore/writemarker/worker.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,16 @@ func SetupWorkers(ctx context.Context) {
115115
}
116116

117117
func redeemWriteMarker(md *markerData) error {
118-
ctx := datastore.GetStore().CreateTransaction(context.TODO())
118+
timeoutCtx, cancel := context.WithTimeout(context.Background(), 180*time.Second)
119+
defer cancel()
120+
ctx := datastore.GetStore().CreateTransaction(timeoutCtx)
119121
db := datastore.GetStore().GetTransaction(ctx)
120122
allocationID := md.allocationID
121123
shouldRollback := false
122124
start := time.Now()
123125
logging.Logger.Info("redeeming_write_marker", zap.String("allocationID", allocationID))
124126
allocMu := lock.GetMutex(allocation.Allocation{}.TableName(), allocationID)
125127
allocMu.RLock()
126-
defer allocMu.RUnlock()
127128
defer func() {
128129
if shouldRollback {
129130
if rollbackErr := db.Rollback().Error; rollbackErr != nil {
@@ -135,8 +136,8 @@ func redeemWriteMarker(md *markerData) error {
135136
} else {
136137
deleteMarkerData(allocationID)
137138
}
139+
allocMu.RUnlock()
138140
}()
139-
140141
alloc, err := allocation.Repo.GetAllocationFromDB(ctx, allocationID)
141142
if err != nil {
142143
logging.Logger.Error("Error redeeming the write marker.", zap.Any("allocation", allocationID), zap.Any("wm", allocationID), zap.Any("error", err))
@@ -153,7 +154,6 @@ func redeemWriteMarker(md *markerData) error {
153154
shouldRollback = true
154155
return nil
155156
}
156-
157157
wm, err := GetWriteMarkerEntity(ctx, alloc.ID, alloc.AllocationRoot)
158158
if err != nil {
159159
logging.Logger.Error("Error redeeming the write marker.", zap.Any("allocation", allocationID), zap.Any("wm", alloc.AllocationRoot), zap.Any("error", err))
@@ -163,7 +163,6 @@ func redeemWriteMarker(md *markerData) error {
163163
shouldRollback = true
164164
return err
165165
}
166-
167166
err = wm.RedeemMarker(ctx, alloc.LastRedeemedSeq+1)
168167
if err != nil {
169168
elapsedTime := time.Since(start)
@@ -178,7 +177,6 @@ func redeemWriteMarker(md *markerData) error {
178177
shouldRollback = true
179178
return err
180179
}
181-
182180
err = allocation.Repo.UpdateAllocationRedeem(ctx, allocationID, wm.WM.AllocationRoot, alloc, wm.Sequence)
183181
if err != nil {
184182
logging.Logger.Error("Error redeeming the write marker. Allocation latest wm redeemed update failed",
@@ -188,7 +186,6 @@ func redeemWriteMarker(md *markerData) error {
188186
go tryAgain(md)
189187
return err
190188
}
191-
192189
err = db.Commit().Error
193190
if err != nil {
194191
logging.Logger.Error("Error committing the writemarker redeem",

code/go/0chain.net/validatorcore/storage/models.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,13 +484,13 @@ func (cr *ChallengeRequest) verifyObjectProof(latestWM *writemarker.WriteMarker,
484484
hashData := fmt.Sprintf("%s:%s:%s:%s", cr.Meta.ActualFileHash, cr.Meta.ValidationRoot, cr.Meta.FixedMerkleRoot, blobberID)
485485
validationRootHash := encryption.Hash(hashData)
486486
var verify bool
487-
if cr.Meta.SignatureVersion == 1 {
487+
if len(cr.Meta.ValidationRootSignature) == 128 {
488488
verify, err = encryption.VerifyEd25519(ownerSigningPublicKey, cr.Meta.ValidationRootSignature, validationRootHash)
489489
} else {
490490
verify, err = encryption.Verify(ownerPublicKey, cr.Meta.ValidationRootSignature, validationRootHash)
491491
}
492492
if err != nil {
493-
logging.Logger.Error("Failed to verify the validation root signature", zap.Error(err), zap.String("validation_root", cr.Meta.ValidationRoot), zap.String("validation_root_signature", cr.Meta.ValidationRootSignature), zap.String("owner_public_key", ownerPublicKey))
493+
logging.Logger.Error("Failed to verify the validation root signature", zap.Error(err), zap.String("validation_root", cr.Meta.ValidationRoot), zap.String("validation_root_signature", cr.Meta.ValidationRootSignature), zap.String("owner_public_key", ownerPublicKey), zap.String("allocation_id", latestWM.AllocationID))
494494
return common.NewError("invalid_object_proof", "Failed to verify the validation root signature. "+err.Error())
495495
}
496496
if !verify {

0 commit comments

Comments
 (0)