Skip to content

Commit

Permalink
fix RootRecord
Browse files Browse the repository at this point in the history
  • Loading branch information
catShaark committed Oct 6, 2022
1 parent 33ceaf3 commit ca2ac94
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions mutable_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,7 @@ func (tree *MutableTree) GetImmutable(version int64) (*ImmutableTree, error) {

tree.mtx.Lock()
defer tree.mtx.Unlock()
fmt.Println(rootHash)
if len(rootHash) == 0 {
tree.versions[version] = true
return &ImmutableTree{
Expand Down Expand Up @@ -878,6 +879,7 @@ func (tree *MutableTree) SaveVersion() ([]byte, int64, error) {
// There can still be orphans, for example if the root is the node being
// removed.
logger.Debug("SAVE EMPTY TREE %v\n", version)
fmt.Println("save empty")
if err := tree.ndb.SaveOrphans(version, tree.orphans); err != nil {
return nil, 0, err
}
Expand Down
5 changes: 4 additions & 1 deletion nodedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,9 @@ func (ndb *nodeDB) SaveEmptyRoot(version int64) error {

// RootRecord join a root's hash and nodekey, this joined []byte is save in the entry for that root
func RootRecord(hash []byte, nodeKey []byte) []byte {
if len(hash) == 0 || len(nodeKey) == 0 {
return []byte{}
}
bz := make([]byte, hashSize+nodeKeySize)
copy(bz[:32], hash)
copy(bz[32:], nodeKey)
Expand All @@ -966,7 +969,7 @@ func RootRecord(hash []byte, nodeKey []byte) []byte {

func DecodeRootRecord(rootRecord []byte) (hash []byte, nodeKey []byte) {
if len(rootRecord) != hashSize+nodeKeySize {
return nil, nil
return []byte{}, []byte{}
}
return rootRecord[:32], rootRecord[32:]

Expand Down

0 comments on commit ca2ac94

Please sign in to comment.