-
Notifications
You must be signed in to change notification settings - Fork 199
/
baseTrieSync.go
64 lines (51 loc) · 1.38 KB
/
baseTrieSync.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package trie
import (
"sync"
"time"
)
type baseSyncTrie struct {
mutStatistics sync.RWMutex
numTrieNodes uint64
numLeaves uint64
numBytes uint64
duration time.Duration
}
func (bst *baseSyncTrie) updateStats(bytesToAdd uint64, element node) {
_, isLeaf := element.(*leafNode)
bst.mutStatistics.Lock()
bst.numBytes += bytesToAdd
bst.numTrieNodes++
if isLeaf {
bst.numLeaves++
}
bst.mutStatistics.Unlock()
}
func (bst *baseSyncTrie) setSyncDuration(duration time.Duration) {
bst.mutStatistics.Lock()
bst.duration = duration
bst.mutStatistics.Unlock()
}
// NumLeaves return the total number of leaves for the provided trie
func (bst *baseSyncTrie) NumLeaves() uint64 {
bst.mutStatistics.RLock()
defer bst.mutStatistics.RUnlock()
return bst.numLeaves
}
// NumBytes returns the total number of bytes for the provided trie
func (bst *baseSyncTrie) NumBytes() uint64 {
bst.mutStatistics.RLock()
defer bst.mutStatistics.RUnlock()
return bst.numBytes
}
// NumTrieNodes returns the total number of trie for the provided trie
func (bst *baseSyncTrie) NumTrieNodes() uint64 {
bst.mutStatistics.RLock()
defer bst.mutStatistics.RUnlock()
return bst.numTrieNodes
}
// Duration returns the total sync duration for the provided trie
func (bst *baseSyncTrie) Duration() time.Duration {
bst.mutStatistics.RLock()
defer bst.mutStatistics.RUnlock()
return bst.duration
}