Skip to content

Commit

Permalink
change workingtree start leaf count
Browse files Browse the repository at this point in the history
  • Loading branch information
sh-cha committed Nov 21, 2024
1 parent e0b0e01 commit c71228a
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion executor/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ func Migration0191(db types.DB) error {
}

nextSequence := uint64(1)
changeWorkingTree := false
err = merkleDB.PrefixedIterate(merkletypes.WorkingTreeKey, nil, func(key, value []byte) (bool, error) {
if len(key) != len(merkletypes.WorkingTreeKey)+1+8 {
return false, nil
Expand All @@ -114,7 +115,23 @@ func Migration0191(db types.DB) error {
return true, err
}

if workingTree.Done && workingTree.LeafCount != 0 && nextSequence == workingTree.StartLeafIndex {
if workingTree.Done && workingTree.LeafCount != 0 {
if nextSequence != workingTree.StartLeafIndex {
changeWorkingTree = true
}

if changeWorkingTree {
workingTree.StartLeafIndex = nextSequence
workingTreeBz, err := json.Marshal(workingTree)
if err != nil {
return true, err
}
err = merkleDB.Set(key, workingTreeBz)
if err != nil {
return true, err
}
}

data, err := json.Marshal(executortypes.TreeExtraData{
BlockNumber: types.MustUint64ToInt64(version),
})
Expand Down Expand Up @@ -146,6 +163,7 @@ func Migration0191(db types.DB) error {
if err != nil {
return true, err
}

fmt.Printf("finalized tree index: %d, start leaf index: %d, leaf count: %d, block height: %d\n", finalizedTreeInfo.TreeIndex, finalizedTreeInfo.StartLeafIndex, finalizedTreeInfo.LeafCount, version)
nextSequence = workingTree.StartLeafIndex + workingTree.LeafCount
}
Expand Down

0 comments on commit c71228a

Please sign in to comment.