-
Notifications
You must be signed in to change notification settings - Fork 215
Proofs pool upsert #6887
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
+275
−204
Merged
Proofs pool upsert #6887
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
719e2d3
added proof pool Upsert and IsProofEqual operations
ssd04 cae63bb
check proof in pool on shard data check
ssd04 70c9e7c
adapt tests and imports
ssd04 38a4296
rename is proof in pool equal to
ssd04 68af497
remove todo
ssd04 28842ea
fix epoch start reference
ssd04 c32da77
fixes after review
ssd04 f0c08f0
remove diplicated check
ssd04 7a601e8
Merge branch 'feat/andromeda-fixes' into proofs-pool-upsert
ssd04 ca5d50c
fix linter issue
ssd04 130cb55
remove duplicated add prev proof operations
ssd04 c650026
Merge branch 'feat/andromeda-fixes' into proofs-pool-upsert
AdoAdoAdo 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| package proofscache | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "fmt" | ||
| "sync" | ||
|
|
||
|
|
@@ -43,22 +44,40 @@ func NewProofsPool(cleanupNonceDelta uint64, bucketSize int) *proofsPool { | |
| } | ||
| } | ||
|
|
||
| // AddProof will add the provided proof to the pool | ||
| // UpsertProof will add the provided proof to the pool. If there is already an existing proof, | ||
| // it will overwrite it. | ||
| func (pp *proofsPool) UpsertProof( | ||
| headerProof data.HeaderProofHandler, | ||
| ) bool { | ||
| if check.IfNilReflect(headerProof) { | ||
| return false | ||
| } | ||
|
|
||
| return pp.addProof(headerProof) | ||
| } | ||
|
|
||
| // AddProof will add the provided proof to the pool, if it's not already in the pool. | ||
| // It will return true if the proof was added to the pool. | ||
| func (pp *proofsPool) AddProof( | ||
| headerProof data.HeaderProofHandler, | ||
| ) bool { | ||
| if check.IfNil(headerProof) { | ||
| return false | ||
| } | ||
|
|
||
| shardID := headerProof.GetHeaderShardId() | ||
| headerHash := headerProof.GetHeaderHash() | ||
|
|
||
| hasProof := pp.HasProof(shardID, headerHash) | ||
| hasProof := pp.HasProof(headerProof.GetHeaderShardId(), headerProof.GetHeaderHash()) | ||
| if hasProof { | ||
| return false | ||
| } | ||
|
|
||
| return pp.addProof(headerProof) | ||
| } | ||
|
|
||
| func (pp *proofsPool) addProof( | ||
| headerProof data.HeaderProofHandler, | ||
| ) bool { | ||
| shardID := headerProof.GetHeaderShardId() | ||
|
|
||
| pp.mutCache.Lock() | ||
| proofsPerShard, ok := pp.cache[shardID] | ||
| if !ok { | ||
|
|
@@ -85,6 +104,27 @@ func (pp *proofsPool) AddProof( | |
| return true | ||
| } | ||
|
|
||
| // IsProofInPoolEqualTo will check if the provided proof is equal with the already existing proof in the pool | ||
| func (pp *proofsPool) IsProofInPoolEqualTo(headerProof data.HeaderProofHandler) bool { | ||
| if check.IfNilReflect(headerProof) { | ||
|
||
| return false | ||
| } | ||
|
|
||
| existingProof, err := pp.GetProof(headerProof.GetHeaderShardId(), headerProof.GetHeaderHash()) | ||
| if err != nil { | ||
| return false | ||
| } | ||
|
|
||
| if !bytes.Equal(existingProof.GetAggregatedSignature(), headerProof.GetAggregatedSignature()) { | ||
| return false | ||
| } | ||
| if !bytes.Equal(existingProof.GetPubKeysBitmap(), headerProof.GetPubKeysBitmap()) { | ||
| return false | ||
| } | ||
|
|
||
| return true | ||
| } | ||
|
|
||
| func (pp *proofsPool) callAddedProofSubscribers(headerProof data.HeaderProofHandler) { | ||
| pp.mutAddedProofSubscribers.RLock() | ||
| defer pp.mutAddedProofSubscribers.RUnlock() | ||
|
|
||
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
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
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
Oops, something went wrong.
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.
check.IfNil instead for proofs IsInterfaceNil was added for the HeaderProofHandler