Skip to content

Commit b2fc09a

Browse files
committed
fix after review: keep only one cache
1 parent e03e7a1 commit b2fc09a

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

dataRetriever/dataPool/proofsCache/proofsCache.go

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@ type proofNonceMapping struct {
1212
}
1313

1414
type proofsCache struct {
15-
mutProofsByNonce sync.RWMutex
15+
mutProofsCache sync.RWMutex
1616
proofsByNonceBuckets []*proofNonceBucket
1717
bucketSize int
18-
19-
proofsByHash map[string]data.HeaderProofHandler
20-
mutProofsByHash sync.RWMutex
18+
proofsByHash map[string]data.HeaderProofHandler
2119
}
2220

2321
func newProofsCache(bucketSize int) *proofsCache {
@@ -29,8 +27,8 @@ func newProofsCache(bucketSize int) *proofsCache {
2927
}
3028

3129
func (pc *proofsCache) getProofByHash(headerHash []byte) (data.HeaderProofHandler, error) {
32-
pc.mutProofsByHash.RLock()
33-
defer pc.mutProofsByHash.RUnlock()
30+
pc.mutProofsCache.RLock()
31+
defer pc.mutProofsCache.RUnlock()
3432

3533
proof, ok := pc.proofsByHash[string(headerHash)]
3634
if !ok {
@@ -45,17 +43,15 @@ func (pc *proofsCache) addProof(proof data.HeaderProofHandler) {
4543
return
4644
}
4745

46+
pc.mutProofsCache.Lock()
47+
defer pc.mutProofsCache.Unlock()
48+
4849
pc.insertProofByNonce(proof)
4950

50-
pc.mutProofsByHash.Lock()
5151
pc.proofsByHash[string(proof.GetHeaderHash())] = proof
52-
pc.mutProofsByHash.Unlock()
5352
}
5453

5554
func (pc *proofsCache) insertProofByNonce(proof data.HeaderProofHandler) {
56-
pc.mutProofsByNonce.Lock()
57-
defer pc.mutProofsByNonce.Unlock()
58-
5955
if len(pc.proofsByNonceBuckets) == 0 {
6056
pc.insertInNewBucket(proof)
6157
return
@@ -83,8 +79,8 @@ func (pc *proofsCache) cleanupProofsBehindNonce(nonce uint64) {
8379
return
8480
}
8581

86-
pc.mutProofsByNonce.Lock()
87-
defer pc.mutProofsByNonce.Unlock()
82+
pc.mutProofsCache.Lock()
83+
defer pc.mutProofsCache.Unlock()
8884

8985
buckets := make([]*proofNonceBucket, 0)
9086

@@ -101,9 +97,6 @@ func (pc *proofsCache) cleanupProofsBehindNonce(nonce uint64) {
10197
}
10298

10399
func (pc *proofsCache) cleanupProofsInBucket(bucket *proofNonceBucket) {
104-
pc.mutProofsByHash.Lock()
105-
defer pc.mutProofsByHash.Unlock()
106-
107100
for _, proofInfo := range bucket.proofsByNonce {
108101
delete(pc.proofsByHash, proofInfo.headerHash)
109102
}

0 commit comments

Comments
 (0)