Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/refactor-trie-set-hash' into ref…
Browse files Browse the repository at this point in the history
…actor-trie-commit
  • Loading branch information
BeniaminDrasovean committed Dec 16, 2024
2 parents 22912c9 + 438ccc8 commit 4d5f3e2
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 42 deletions.
2 changes: 2 additions & 0 deletions state/accountsDB.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,8 @@ func (adb *AccountsDB) removeCodeAndDataTrie(acnt vmcommon.AccountHandler) error
return nil
}

// TODO find a method to remove the data trie and mark all the removed hashes for pruning.
// There can be a lot of hashes to be removed, so take into consideration the mem usage and the time needed to remove them.
return adb.removeCode(baseAcc)
}

Expand Down
5 changes: 4 additions & 1 deletion trie/baseNode.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package trie

import (
"sync"

"github.com/multiversx/mx-chain-core-go/hashing"
"github.com/multiversx/mx-chain-core-go/marshal"
"sync"
)

type baseNode struct {
Expand All @@ -15,6 +16,8 @@ type baseNode struct {
}

func (bn *baseNode) getHash() []byte {
//TODO add mutex protection for all methods

bn.mutex.RLock()
defer bn.mutex.RUnlock()

Expand Down
6 changes: 4 additions & 2 deletions trie/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
vmcommon "github.com/multiversx/mx-chain-vm-common-go"
)

type node interface {
type baseTrieNode interface {
getHash() []byte
setGivenHash([]byte)
setDirty(bool)
Expand All @@ -21,9 +21,11 @@ type node interface {
setMarshalizer(marshal.Marshalizer)
getHasher() hashing.Hasher
setHasher(hashing.Hasher)
}

type node interface {
baseTrieNode
setHash(goRoutinesManager common.TrieGoroutinesManager)

getCollapsed() (node, error) // a collapsed node is a node that instead of the children holds the children hashes
getEncodedNode() ([]byte, error)
hashNode() ([]byte, error)
Expand Down
38 changes: 0 additions & 38 deletions trie/modifiedChildren.go

This file was deleted.

2 changes: 1 addition & 1 deletion trie/patriciaMerkleTrie.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func (tr *patriciaMerkleTrie) insertBatch(sortedDataForInsertion []core.TrieData
}

rootNode := tr.GetRootNode()
if rootNode == nil {
if check.IfNil(rootNode) {
newRoot, err := newLeafNode(sortedDataForInsertion[0], tr.marshalizer, tr.hasher)
if err != nil {
return err
Expand Down
2 changes: 2 additions & 0 deletions trie/rootManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"github.com/multiversx/mx-chain-core-go/core/check"
)

// TODO: add unit tests

type rootManager struct {
root node
oldHashes [][]byte
Expand Down

0 comments on commit 4d5f3e2

Please sign in to comment.