-
Notifications
You must be signed in to change notification settings - Fork 215
Proofs pool improvements #6878
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Proofs pool improvements #6878
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
35f8e8a
remove sort operation from proofs pool insert
ssd04 91fd46e
added proofs cache buckets
ssd04 7066189
add parallel cleanup
ssd04 147c0d3
proofs cache benchmarks
ssd04 c21c78c
added bucket size to config
ssd04 5704d4e
Merge branch 'feat/andromeda-fixes' into fix-proofs-pool-insert
ssd04 3a1a9e2
fix after review
ssd04 e03e7a1
remove concurrency from cleanup
ssd04 b2fc09a
fix after review: keep only one cache
ssd04 ac7f4ab
Merge branch 'feat/andromeda-fixes' into fix-proofs-pool-insert
sstanculeanu b759ac8
Merge branch 'feat/andromeda-fixes' into fix-proofs-pool-insert
sstanculeanu 3cb4bce
Merge branch 'feat/andromeda-fixes' into fix-proofs-pool-insert
sstanculeanu 57532ba
Merge branch 'feat/andromeda-fixes' into fix-proofs-pool-insert
sstanculeanu 36ae586
Merge branch 'feat/andromeda-fixes' into fix-proofs-pool-insert
sstanculeanu 4ea5d8e
use range buckets instead of stack buckets
ssd04 21fd3ea
fixes after review
ssd04 210f52b
Merge branch 'feat/andromeda-fixes' into fix-proofs-pool-insert
sstanculeanu acf47c7
use simple map instead of sync.Map
ssd04 ecd4e54
delete map entry while iterating
ssd04 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,15 +14,15 @@ type proofNonceMapping struct { | |
|
|
||
| type proofsCache struct { | ||
| mutProofsCache sync.RWMutex | ||
| proofsByNonceBuckets []*proofNonceBucket | ||
| bucketSize int | ||
| proofsByNonceBuckets sync.Map | ||
| bucketSize uint64 | ||
| proofsByHash map[string]data.HeaderProofHandler | ||
| } | ||
|
|
||
| func newProofsCache(bucketSize int) *proofsCache { | ||
| return &proofsCache{ | ||
| proofsByNonceBuckets: make([]*proofNonceBucket, 0), | ||
| bucketSize: bucketSize, | ||
| proofsByNonceBuckets: sync.Map{}, | ||
| bucketSize: uint64(bucketSize), | ||
| proofsByHash: make(map[string]data.HeaderProofHandler), | ||
| } | ||
| } | ||
|
|
@@ -52,27 +52,18 @@ func (pc *proofsCache) addProof(proof data.HeaderProofHandler) { | |
| pc.proofsByHash[string(proof.GetHeaderHash())] = proof | ||
| } | ||
|
|
||
| func (pc *proofsCache) insertProofByNonce(proof data.HeaderProofHandler) { | ||
| if len(pc.proofsByNonceBuckets) == 0 { | ||
| pc.insertInNewBucket(proof) | ||
| return | ||
| } | ||
|
|
||
| headBucket := pc.proofsByNonceBuckets[0] | ||
|
|
||
| if headBucket.isFull() { | ||
| pc.insertInNewBucket(proof) | ||
| return | ||
| } | ||
|
|
||
| headBucket.insert(proof) | ||
| // getBucketKey will return bucket key as lower bound window value | ||
| func (pc *proofsCache) getBucketKey(index uint64) uint64 { | ||
| return (index / pc.bucketSize) * pc.bucketSize | ||
| } | ||
|
|
||
| func (pc *proofsCache) insertInNewBucket(proof data.HeaderProofHandler) { | ||
| bucket := newProofBucket(pc.bucketSize) | ||
| bucket.insert(proof) | ||
| func (pc *proofsCache) insertProofByNonce(proof data.HeaderProofHandler) { | ||
| bucketKey := pc.getBucketKey(proof.GetHeaderNonce()) | ||
|
|
||
| bucket, _ := pc.proofsByNonceBuckets.LoadOrStore(bucketKey, newProofBucket()) | ||
|
|
||
| pc.proofsByNonceBuckets = append([]*proofNonceBucket{bucket}, pc.proofsByNonceBuckets...) | ||
| b := bucket.(*proofNonceBucket) | ||
| b.insert(proof) | ||
| } | ||
|
|
||
| func (pc *proofsCache) cleanupProofsBehindNonce(nonce uint64) { | ||
|
|
@@ -83,22 +74,28 @@ func (pc *proofsCache) cleanupProofsBehindNonce(nonce uint64) { | |
| pc.mutProofsCache.Lock() | ||
| defer pc.mutProofsCache.Unlock() | ||
|
|
||
| buckets := make([]*proofNonceBucket, 0) | ||
| bucketsToDelete := make([]uint64, 0) | ||
|
|
||
| pc.proofsByNonceBuckets.Range(func(key, value interface{}) bool { | ||
| bucketKey := key.(uint64) | ||
| bucket := value.(*proofNonceBucket) | ||
|
|
||
| for _, bucket := range pc.proofsByNonceBuckets { | ||
| if nonce > bucket.maxNonce { | ||
| pc.cleanupProofsInBucket(bucket) | ||
| continue | ||
| bucketsToDelete = append(bucketsToDelete, bucketKey) | ||
| pc.proofsByNonceBuckets.Delete(key) | ||
| } | ||
|
|
||
| buckets = append(buckets, bucket) | ||
| } | ||
| return true | ||
| }) | ||
|
|
||
| pc.proofsByNonceBuckets = buckets | ||
| for _, key := range bucketsToDelete { | ||
| pc.proofsByNonceBuckets.Delete(key) | ||
|
||
| } | ||
| } | ||
|
|
||
| func (pc *proofsCache) cleanupProofsInBucket(bucket *proofNonceBucket) { | ||
| for _, proofInfo := range bucket.proofsByNonce { | ||
| delete(pc.proofsByHash, proofInfo.headerHash) | ||
| for _, headerHash := range bucket.proofsByNonce { | ||
| delete(pc.proofsByHash, headerHash) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
proofNonceMapping struct not used anymore
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 deleted it