Skip to content

Commit

Permalink
Merge pull request #5024 from multiversx/remove-numNodes-trie-functio…
Browse files Browse the repository at this point in the history
…nality

Remove `GetNumNodes` trie functionality
  • Loading branch information
iulianpascalau authored Feb 24, 2023
2 parents c69e883 + 1f8be7b commit 3c57b72
Show file tree
Hide file tree
Showing 11 changed files with 0 additions and 141 deletions.
10 changes: 0 additions & 10 deletions common/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,6 @@ import (
"github.com/multiversx/mx-chain-go/trie/statistics"
)

// NumNodesDTO represents the DTO structure that will hold the number of nodes split by category and other
// trie structure relevant data such as maximum number of trie levels including the roothash node and all leaves
type NumNodesDTO struct {
Leaves int
Extensions int
Branches int
MaxLevel int
}

// TrieIteratorChannels defines the channels that are being used when iterating the trie nodes
type TrieIteratorChannels struct {
LeavesChan chan core.KeyValueHolder
Expand All @@ -40,7 +31,6 @@ type Trie interface {
GetOldRoot() []byte
GetSerializedNodes([]byte, uint64) ([][]byte, uint64, error)
GetSerializedNode([]byte) ([]byte, error)
GetNumNodes() NumNodesDTO
GetAllLeavesOnChannel(allLeavesChan *TrieIteratorChannels, ctx context.Context, rootHash []byte, keyBuilder KeyBuilder) error
GetAllHashes() ([][]byte, error)
GetProof(key []byte) ([][]byte, []byte, error)
Expand Down
18 changes: 0 additions & 18 deletions integrationTests/state/stateTrieSync/stateTrieSync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,6 @@ func testNodeRequestInterceptTrieNodesWithMessenger(t *testing.T, version int) {
_ = resolverTrie.Update([]byte(strconv.Itoa(i)), []byte(strconv.Itoa(i)))
}

nodes := resolverTrie.GetNumNodes()
log.Info("trie nodes",
"total", nodes.Branches+nodes.Extensions+nodes.Leaves,
"branches", nodes.Branches,
"extensions", nodes.Extensions,
"leaves", nodes.Leaves,
"max level", nodes.MaxLevel,
)

_ = resolverTrie.Commit()
rootHash, _ := resolverTrie.RootHash()

Expand Down Expand Up @@ -231,15 +222,6 @@ func testNodeRequestInterceptTrieNodesWithMessengerNotSyncingShouldErr(t *testin
_ = resolverTrie.Update([]byte(strconv.Itoa(i)), []byte(strconv.Itoa(i)))
}

nodes := resolverTrie.GetNumNodes()
log.Info("trie nodes",
"total", nodes.Branches+nodes.Extensions+nodes.Leaves,
"branches", nodes.Branches,
"extensions", nodes.Extensions,
"leaves", nodes.Leaves,
"max level", nodes.MaxLevel,
)

_ = resolverTrie.Commit()
rootHash, _ := resolverTrie.RootHash()

Expand Down
10 changes: 0 additions & 10 deletions testscommon/trie/trieStub.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ type TrieStub struct {
VerifyProofCalled func(rootHash []byte, key []byte, proof [][]byte) (bool, error)
GetStorageManagerCalled func() common.StorageManager
GetSerializedNodeCalled func(bytes []byte) ([]byte, error)
GetNumNodesCalled func() common.NumNodesDTO
GetOldRootCalled func() []byte
CloseCalled func() error
}
Expand Down Expand Up @@ -185,15 +184,6 @@ func (ts *TrieStub) GetSerializedNode(bytes []byte) ([]byte, error) {
return nil, nil
}

// GetNumNodes -
func (ts *TrieStub) GetNumNodes() common.NumNodesDTO {
if ts.GetNumNodesCalled != nil {
return ts.GetNumNodesCalled()
}

return common.NumNodesDTO{}
}

// GetOldRoot -
func (ts *TrieStub) GetOldRoot() []byte {
if ts.GetOldRootCalled != nil {
Expand Down
28 changes: 0 additions & 28 deletions trie/branchNode.go
Original file line number Diff line number Diff line change
Expand Up @@ -855,34 +855,6 @@ func (bn *branchNode) getAllHashes(db common.DBWriteCacher) ([][]byte, error) {
return hashes, nil
}

func (bn *branchNode) getNumNodes() common.NumNodesDTO {
if check.IfNil(bn) {
return common.NumNodesDTO{}
}

currentNumNodes := common.NumNodesDTO{
Branches: 1,
}

for _, n := range bn.children {
if check.IfNil(n) {
continue
}

childNumNodes := n.getNumNodes()
currentNumNodes.Branches += childNumNodes.Branches
currentNumNodes.Leaves += childNumNodes.Leaves
currentNumNodes.Extensions += childNumNodes.Extensions
if childNumNodes.MaxLevel > currentNumNodes.MaxLevel {
currentNumNodes.MaxLevel = childNumNodes.MaxLevel
}
}

currentNumNodes.MaxLevel++

return currentNumNodes
}

func (bn *branchNode) getNextHashAndKey(key []byte) (bool, []byte, []byte) {
if len(key) == 0 || check.IfNil(bn) {
return false, nil, nil
Expand Down
9 changes: 0 additions & 9 deletions trie/branchNode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1319,15 +1319,6 @@ func TestBranchNode_getNextHashAndKeyNilNode(t *testing.T) {
assert.Nil(t, nextKey)
}

func TestBranchNode_GetNumNodesNilSelfShouldErr(t *testing.T) {
t.Parallel()

var bn *branchNode
numNodes := bn.getNumNodes()

assert.Equal(t, common.NumNodesDTO{}, numNodes)
}

func TestBranchNode_SizeInBytes(t *testing.T) {
t.Parallel()

Expand Down
12 changes: 0 additions & 12 deletions trie/extensionNode.go
Original file line number Diff line number Diff line change
Expand Up @@ -601,18 +601,6 @@ func (en *extensionNode) getChildren(db common.DBWriteCacher) ([]node, error) {
return nextNodes, nil
}

func (en *extensionNode) getNumNodes() common.NumNodesDTO {
if check.IfNil(en) {
return common.NumNodesDTO{}
}

childNumNodes := en.child.getNumNodes()
childNumNodes.Extensions++
childNumNodes.MaxLevel++

return childNumNodes
}

func (en *extensionNode) isValid() bool {
if len(en.EncodedChild) == 0 && en.child == nil {
return false
Expand Down
9 changes: 0 additions & 9 deletions trie/extensionNode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -987,15 +987,6 @@ func TestExtensionNode_getNextHashAndKeyNilNode(t *testing.T) {
assert.Nil(t, nextKey)
}

func TestExtensionNode_GetNumNodesNilSelfShouldErr(t *testing.T) {
t.Parallel()

var en *extensionNode
numNodes := en.getNumNodes()

assert.Equal(t, common.NumNodesDTO{}, numNodes)
}

func TestExtensionNode_SizeInBytes(t *testing.T) {
t.Parallel()

Expand Down
1 change: 0 additions & 1 deletion trie/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ type node interface {
getAllLeavesOnChannel(chan core.KeyValueHolder, common.KeyBuilder, common.DBWriteCacher, marshal.Marshalizer, chan struct{}, context.Context) error
getAllHashes(db common.DBWriteCacher) ([][]byte, error)
getNextHashAndKey([]byte) (bool, []byte, []byte)
getNumNodes() common.NumNodesDTO
getValue() []byte

commitDirty(level byte, maxTrieLevelInMemory uint, originDb common.DBWriteCacher, targetDb common.DBWriteCacher) error
Expand Down
7 changes: 0 additions & 7 deletions trie/leafNode.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,13 +413,6 @@ func (ln *leafNode) getChildren(_ common.DBWriteCacher) ([]node, error) {
return nil, nil
}

func (ln *leafNode) getNumNodes() common.NumNodesDTO {
return common.NumNodesDTO{
Leaves: 1,
MaxLevel: 1,
}
}

func (ln *leafNode) isValid() bool {
return len(ln.Value) > 0
}
Expand Down
13 changes: 0 additions & 13 deletions trie/patriciaMerkleTrie.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,19 +604,6 @@ func (tr *patriciaMerkleTrie) VerifyProof(rootHash []byte, key []byte, proof [][
return false, nil
}

// GetNumNodes will return the trie nodes statistics DTO
func (tr *patriciaMerkleTrie) GetNumNodes() common.NumNodesDTO {
tr.mutOperation.Lock()
defer tr.mutOperation.Unlock()

n := tr.root
if check.IfNil(n) {
return common.NumNodesDTO{}
}

return n.getNumNodes()
}

// GetStorageManager returns the storage manager for the trie
func (tr *patriciaMerkleTrie) GetStorageManager() common.StorageManager {
tr.mutOperation.Lock()
Expand Down
24 changes: 0 additions & 24 deletions trie/patriciaMerkleTrie_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -883,15 +883,6 @@ func dumpTrieContents(tr common.Trie, values [][]byte) {
}
}

func TestPatriciaMerkleTrie_GetNumNodesNilRootShouldReturnEmpty(t *testing.T) {
t.Parallel()

tr := emptyTrie()

numNodes := tr.GetNumNodes()
assert.Equal(t, common.NumNodesDTO{}, numNodes)
}

func TestPatriciaMerkleTrie_GetTrieStats(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -921,21 +912,6 @@ func TestPatriciaMerkleTrie_GetTrieStats(t *testing.T) {
assert.Equal(t, uint32(3), stats.MaxTrieDepth)
}

func TestPatriciaMerkleTrie_GetNumNodes(t *testing.T) {
t.Parallel()

tr := emptyTrie()
_ = tr.Update([]byte("eod"), []byte("reindeer"))
_ = tr.Update([]byte("god"), []byte("puppy"))
_ = tr.Update([]byte("eggod"), []byte("cat"))

numNodes := tr.GetNumNodes()
assert.Equal(t, 5, numNodes.MaxLevel)
assert.Equal(t, 3, numNodes.Leaves)
assert.Equal(t, 2, numNodes.Extensions)
assert.Equal(t, 2, numNodes.Branches)
}

func TestPatriciaMerkleTrie_GetOldRoot(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit 3c57b72

Please sign in to comment.