Skip to content

Commit ca8b639

Browse files
committed
add recover log in validator
1 parent 6031712 commit ca8b639

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package allocation
22

33
import (
44
"context"
5+
"database/sql"
56
"encoding/json"
67
"fmt"
78
"path/filepath"
@@ -10,6 +11,7 @@ import (
1011
"sync/atomic"
1112

1213
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/config"
14+
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/datastore"
1315
"github.com/0chain/common/core/util/wmpt"
1416
"gorm.io/gorm"
1517

@@ -109,11 +111,30 @@ func (nf *NewDir) ApplyChangeV2(ctx context.Context, allocationRoot, clientPubKe
109111
return 0, common.NewError("invalid_parent_path", "parent path is not a directory")
110112
}
111113
newRef := reference.NewDirectoryRef()
114+
newRef.LookupHash = reference.GetReferenceLookup(nf.AllocationID, nf.Path)
115+
var refResult struct {
116+
ID int64
117+
}
118+
err := datastore.GetStore().WithNewTransaction(func(ctx context.Context) error {
119+
tx := datastore.GetStore().GetTransaction(ctx)
120+
return tx.Model(&reference.Ref{}).Select("id").Where("lookup_hash = ?", newRef.LookupHash).Take(&refResult).Error
121+
}, &sql.TxOptions{
122+
ReadOnly: true,
123+
})
124+
if err != nil && err != gorm.ErrRecordNotFound {
125+
return 0, err
126+
}
127+
if refResult.ID > 0 {
128+
collector.LockTransaction()
129+
defer collector.UnlockTransaction()
130+
txn := datastore.GetStore().GetTransaction(ctx)
131+
err = txn.Exec("UPDATE refs SET custom_meta=? WHERE lookup_hash=?", nf.CustomMeta, newRef.LookupHash).Error
132+
return 0, err
133+
}
112134
newRef.AllocationID = nf.AllocationID
113135
newRef.Path = nf.Path
114136
newRef.Name = filepath.Base(nf.Path)
115137
newRef.ParentPath = parentPath
116-
newRef.LookupHash = reference.GetReferenceLookup(nf.AllocationID, nf.Path)
117138
newRef.CreatedAt = ts
118139
newRef.UpdatedAt = ts
119140
newRef.AllocationRoot = allocationRoot

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,12 @@ func (cr *ChallengeRequest) verifyBlockNum(challengeObj *Challenge) error {
321321
}
322322

323323
func (cr *ChallengeRequest) VerifyChallenge(challengeObj *Challenge, allocationObj *Allocation) error {
324-
logging.Logger.Info("Verifying object path", zap.String("challenge_id", challengeObj.ID), zap.Int64("seed", challengeObj.RandomNumber))
324+
logging.Logger.Info("Verifying object path", zap.String("challenge_id", challengeObj.ID), zap.Int64("seed", challengeObj.RandomNumber), zap.Int("storage_version", cr.StorageVersion))
325+
defer func() {
326+
if r := recover(); r != nil {
327+
logging.Logger.Error("Panic in VerifyChallenge", zap.Any("recover", r), zap.Stack("recover_stack"))
328+
}
329+
}()
325330
if cr.ObjPath != nil && cr.StorageVersion == 0 {
326331
err := cr.ObjPath.Verify(challengeObj.AllocationID, challengeObj.RandomNumber)
327332
if err != nil {

0 commit comments

Comments
 (0)