-
Notifications
You must be signed in to change notification settings - Fork 215
Invalid signers cache #6873
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
Invalid signers cache #6873
Changes from 1 commit
b329c94
03edfe7
d34dde1
50d43da
4665ec6
8e7319a
95dde91
40304bc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -150,6 +150,12 @@ func (sr *subroundEndRound) receivedInvalidSignersInfo(_ context.Context, cnsDta | |
| return false | ||
| } | ||
|
|
||
| invalidSignersHash := sr.Hasher().Compute(string(cnsDta.InvalidSigners)) | ||
| invalidSignersCache := sr.InvalidSignersCache() | ||
| if invalidSignersCache.HasInvalidSigners(string(invalidSignersHash)) { | ||
| return false | ||
| } | ||
|
|
||
| err := sr.verifyInvalidSigners(cnsDta.InvalidSigners) | ||
| if err != nil { | ||
| log.Trace("receivedInvalidSignersInfo.verifyInvalidSigners", "error", err.Error()) | ||
|
|
@@ -158,6 +164,8 @@ func (sr *subroundEndRound) receivedInvalidSignersInfo(_ context.Context, cnsDta | |
|
|
||
| log.Debug("step 3: invalid signers info has been evaluated") | ||
|
|
||
| invalidSignersCache.AddInvalidSigners(string(invalidSignersHash)) | ||
|
|
||
| sr.PeerHonestyHandler().ChangeScore( | ||
| messageSender, | ||
| spos.GetConsensusTopicID(sr.ShardCoordinator()), | ||
|
|
@@ -501,24 +509,23 @@ func (sr *subroundEndRound) handleInvalidSignersOnAggSigFail() ([]byte, []byte, | |
| invalidPubKeys, err := sr.verifyNodesOnAggSigFail(ctx) | ||
| cancel() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not related to the changes from this PR, but this cancel() doesn't seem right to call it after the "intensive". Maybe move it up 1 line and call it on a defer? |
||
| if err != nil { | ||
| log.Debug("doEndRoundJobByNode.verifyNodesOnAggSigFail", "error", err.Error()) | ||
| log.Debug("handleInvalidSignersOnAggSigFail.verifyNodesOnAggSigFail", "error", err.Error()) | ||
| return nil, nil, err | ||
| } | ||
|
|
||
| _, err = sr.getFullMessagesForInvalidSigners(invalidPubKeys) | ||
| invalidSigners, err := sr.getFullMessagesForInvalidSigners(invalidPubKeys) | ||
| if err != nil { | ||
| log.Debug("doEndRoundJobByNode.getFullMessagesForInvalidSigners", "error", err.Error()) | ||
| log.Debug("handleInvalidSignersOnAggSigFail.getFullMessagesForInvalidSigners", "error", err.Error()) | ||
| return nil, nil, err | ||
| } | ||
|
|
||
| // TODO: handle invalid signers broadcast without flooding the network | ||
| // if len(invalidSigners) > 0 { | ||
| // sr.createAndBroadcastInvalidSigners(invalidSigners) | ||
| // } | ||
| if len(invalidSigners) > 0 { | ||
| sr.createAndBroadcastInvalidSigners(invalidSigners) | ||
| } | ||
|
|
||
| bitmap, sig, err := sr.computeAggSigOnValidNodes() | ||
raduchis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if err != nil { | ||
| log.Debug("doEndRoundJobByNode.computeAggSigOnValidNodes", "error", err.Error()) | ||
| log.Debug("handleInvalidSignersOnAggSigFail.computeAggSigOnValidNodes", "error", err.Error()) | ||
| return nil, nil, err | ||
| } | ||
|
|
||
|
|
@@ -646,6 +653,9 @@ func (sr *subroundEndRound) createAndBroadcastInvalidSigners(invalidSigners []by | |
| invalidSigners, | ||
| ) | ||
|
|
||
| invalidSignersHash := sr.Hasher().Compute(string(invalidSigners)) | ||
| sr.InvalidSignersCache().AddInvalidSigners(string(invalidSignersHash)) | ||
|
|
||
| err = sr.BroadcastMessenger().BroadcastConsensusMessage(cnsMsg) | ||
| if err != nil { | ||
| log.Debug("doEndRoundJob.BroadcastConsensusMessage", "error", err.Error()) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| package spos | ||
|
|
||
| import "sync" | ||
|
|
||
| type invalidSignersCache struct { | ||
| sync.RWMutex | ||
| invalidSignersMap map[string]struct{} | ||
|
||
| } | ||
|
|
||
| // NewInvalidSignersCache returns a new instance of invalidSignersCache | ||
| func NewInvalidSignersCache() *invalidSignersCache { | ||
| return &invalidSignersCache{ | ||
| invalidSignersMap: make(map[string]struct{}), | ||
| } | ||
| } | ||
|
|
||
| // AddInvalidSigners adds the provided hash into the internal map if it does not exist | ||
| func (cache *invalidSignersCache) AddInvalidSigners(hash string) { | ||
| if len(hash) == 0 { | ||
| return | ||
| } | ||
|
|
||
| cache.Lock() | ||
| defer cache.Unlock() | ||
|
|
||
| cache.invalidSignersMap[hash] = struct{}{} | ||
| } | ||
|
|
||
| // HasInvalidSigners check whether the provided hash exists in int internal map or not | ||
|
||
| func (cache *invalidSignersCache) HasInvalidSigners(hash string) bool { | ||
| cache.RLock() | ||
| defer cache.RUnlock() | ||
|
|
||
| _, has := cache.invalidSignersMap[hash] | ||
| return has | ||
| } | ||
|
|
||
| // Reset clears the internal map | ||
|
||
| func (cache *invalidSignersCache) Reset() { | ||
| cache.Lock() | ||
| defer cache.Unlock() | ||
|
|
||
| cache.invalidSignersMap = make(map[string]struct{}) | ||
| } | ||
|
|
||
| // IsInterfaceNil returns true if there is no value under the interface | ||
| func (cache *invalidSignersCache) IsInterfaceNil() bool { | ||
| return cache == nil | ||
| } | ||
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.
if there are different number of invalidSigners: first time 2: A and B, and in on a second message it gets only A, it seems that the message will be propagated 2 times?