Skip to content

Commit

Permalink
fix after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
BeniaminDrasovean committed Nov 27, 2024
1 parent d106713 commit 804ea57
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 50 deletions.
1 change: 1 addition & 0 deletions trie/extensionNode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-core-go/core/throttler"
"github.com/multiversx/mx-chain-go/common"
"github.com/multiversx/mx-chain-go/common/errChan"
"github.com/multiversx/mx-chain-go/state/hashesCollector"
"github.com/multiversx/mx-chain-go/storage/cache"
Expand Down
11 changes: 4 additions & 7 deletions trie/patriciaMerkleTrie.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type patriciaMerkleTrie struct {
batchManager common.TrieBatchManager
goroutinesThrottler core.Throttler
trieOperationInProgress *atomic.Flag
trieMutex sync.RWMutex
updateTrieMutex sync.RWMutex

maxTrieLevelInMemory uint
chanClose chan struct{}
Expand Down Expand Up @@ -101,7 +101,7 @@ func NewTrie(
batchManager: trieBatchManager.NewTrieBatchManager(),
goroutinesThrottler: trieThrottler,
trieOperationInProgress: &atomic.Flag{},
trieMutex: sync.RWMutex{},
updateTrieMutex: sync.RWMutex{},
}, nil
}

Expand Down Expand Up @@ -178,8 +178,8 @@ func (tr *patriciaMerkleTrie) Delete(key []byte) {
}

func (tr *patriciaMerkleTrie) updateTrie() error {
tr.trieMutex.Lock()
defer tr.trieMutex.Unlock()
tr.updateTrieMutex.Lock()
defer tr.updateTrieMutex.Unlock()

batch, err := tr.batchManager.MarkTrieUpdateInProgress()
if err != nil {
Expand Down Expand Up @@ -301,9 +301,6 @@ func (tr *patriciaMerkleTrie) getRootHash() ([]byte, error) {
return common.EmptyTrieHash, nil
}

tr.trieMutex.Lock()
defer tr.trieMutex.Unlock()

hash := rootNode.getHash()
if hash != nil {
return hash, nil
Expand Down
77 changes: 34 additions & 43 deletions trie/patriciaMerkleTrie_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ func TestPatriciaMerkleTrie_ConcurrentOperations(t *testing.T) {
numOperations := 1000
wg := sync.WaitGroup{}
wg.Add(numOperations)
numFunctions := 7
numFunctions := 14

initialRootHash, _ := tr.RootHash()

Expand Down Expand Up @@ -985,48 +985,39 @@ func TestPatriciaMerkleTrie_ConcurrentOperations(t *testing.T) {
rootHashHolder := holders.NewRootHashHolder(initialRootHash, epoch)
_, err := tr.RecreateFromEpoch(rootHashHolder)
assert.Nil(t, err)
//case 7:
// _ = tr.ToString()
//case 8:
// _ = tr.GetObsoleteHashes()
//case 9:
// _, err := tr.GetDirtyHashes()
// assert.Nil(t, err)
//case 10:
// _, err := tr.GetSerializedNode(initialRootHash)
// assert.Nil(t, err)
//case 11:
// size1KB := uint64(1024 * 1024)
// _, _, err := tr.GetSerializedNodes(initialRootHash, size1KB)
// assert.Nil(t, err)
//case 12:
// trieIteratorChannels := &common.TrieIteratorChannels{
// LeavesChan: make(chan core.KeyValueHolder, 1000),
// ErrChan: errChan.NewErrChanWrapper(),
// }
//
// err := tr.GetAllLeavesOnChannel(
// trieIteratorChannels,
// context.Background(),
// initialRootHash,
// keyBuilder.NewKeyBuilder(),
// parsers.NewMainTrieLeafParser(),
// )
// assert.Nil(t, err)
//case 13:
// _, _, _ = tr.GetProof(initialRootHash, initialRootHash) // this might error due to concurrent operations that change the roothash
//case 14:
// // extremely hard to compute an existing hash due to concurrent changes.
// _, _ = tr.VerifyProof([]byte("dog"), []byte("puppy"), [][]byte{[]byte("proof1")}) // this might error due to concurrent operations that change the roothash
//case 15:
// sm := tr.GetStorageManager()
// assert.NotNil(t, sm)
//case 16:
// _ = tr.GetOldRoot()
//case 17:
// trieStatsHandler := tr.(common.TrieStats)
// _, err := trieStatsHandler.GetTrieStats("address", initialRootHash)
// assert.Nil(t, err)
case 7:
_, err := tr.GetSerializedNode(initialRootHash)
assert.Nil(t, err)
case 8:
size1KB := uint64(1024 * 1024)
_, _, err := tr.GetSerializedNodes(initialRootHash, size1KB)
assert.Nil(t, err)
case 9:
trieIteratorChannels := &common.TrieIteratorChannels{
LeavesChan: make(chan core.KeyValueHolder, 1000),
ErrChan: errChan.NewErrChanWrapper(),
}

err := tr.GetAllLeavesOnChannel(
trieIteratorChannels,
context.Background(),
initialRootHash,
keyBuilder.NewKeyBuilder(),
parsers.NewMainTrieLeafParser(),
)
assert.Nil(t, err)
case 10:
_, _, _ = tr.GetProof(initialRootHash, initialRootHash) // this might error due to concurrent operations that change the roothash
case 11:
// extremely hard to compute an existing hash due to concurrent changes.
_, _ = tr.VerifyProof([]byte("dog"), []byte("puppy"), [][]byte{[]byte("proof1")}) // this might error due to concurrent operations that change the roothash
case 12:
sm := tr.GetStorageManager()
assert.NotNil(t, sm)
case 13:
trieStatsHandler := tr.(common.TrieStats)
_, err := trieStatsHandler.GetTrieStats("address", initialRootHash)
assert.Nil(t, err)
default:
assert.Fail(t, fmt.Sprintf("invalid numFunctions value %d, operation: %d", numFunctions, operation))
}
Expand Down

0 comments on commit 804ea57

Please sign in to comment.