Skip to content

Commit 3b841dd

Browse files
committed
fix alloc root
1 parent 2a08b72 commit 3b841dd

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ func (Allocation) TableName() string {
9191
func (a *Allocation) GetTrie() *wmpt.WeightedMerkleTrie {
9292
trie := Repo.getTrie(a.ID)
9393
if trie == nil {
94-
if a.AllocationRoot == "" {
94+
if a.FileMetaRoot == "" {
9595
trie = wmpt.New(nil, datastore.GetBlockStore())
9696
} else {
97-
decodedRoot, _ := hex.DecodeString(a.AllocationRoot)
97+
decodedRoot, _ := hex.DecodeString(a.FileMetaRoot)
9898
trie = wmpt.New(wmpt.NewHashNode(decodedRoot, a.NumBlocks), datastore.GetBlockStore())
9999
}
100100
Repo.setTrie(a.ID, trie)

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,8 +1087,8 @@ func (fsh *StorageHandler) CommitWriteV2(ctx context.Context, r *http.Request) (
10871087
"Invalid chain size. expected:%v got %v", connectionObj.Size, writeMarker.ChainSize)
10881088
}
10891089

1090-
allocationRoot := hex.EncodeToString(trie.Root())
1091-
fileMetaRoot := allocationRoot
1090+
fileMetaRoot := hex.EncodeToString(trie.Root())
1091+
allocationRoot := encryption.Hash(fileMetaRoot + allocationID)
10921092
if allocationRoot != writeMarker.AllocationRoot {
10931093
result.AllocationRoot = allocationObj.AllocationRoot
10941094
if latestWriteMarkerEntity != nil {
@@ -1122,6 +1122,7 @@ func (fsh *StorageHandler) CommitWriteV2(ctx context.Context, r *http.Request) (
11221122
db := datastore.GetStore().GetTransaction(ctx)
11231123
writemarkerEntity.Latest = true
11241124
if err = db.Create(writemarkerEntity).Error; err != nil {
1125+
logging.Logger.Error("write_marker_error", zap.String("allocation_id", allocationID), zap.Error(err))
11251126
return nil, common.NewError("write_marker_error", "Error persisting the write marker")
11261127
}
11271128
allocationObj.AllocationRoot = allocationRoot
@@ -2020,8 +2021,8 @@ func (fsh *StorageHandler) Rollback(ctx context.Context, r *http.Request) (*blob
20202021
}
20212022
if trie != nil {
20222023
var node wmpt.Node
2023-
if len(allocationRoot) > 0 {
2024-
decodedRoot, _ := hex.DecodeString(allocationRoot)
2024+
if len(fileMetaRoot) > 0 {
2025+
decodedRoot, _ := hex.DecodeString(fileMetaRoot)
20252026
node = wmpt.NewHashNode(decodedRoot, alloc.NumBlocks)
20262027
}
20272028
trie.RollbackTrie(node)

0 commit comments

Comments
 (0)