-
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 6 commits
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,14 +150,21 @@ func (sr *subroundEndRound) receivedInvalidSignersInfo(_ context.Context, cnsDta | |
| return false | ||
| } | ||
|
|
||
| err := sr.verifyInvalidSigners(cnsDta.InvalidSigners) | ||
| invalidSignersCache := sr.InvalidSignersCache() | ||
| if invalidSignersCache.HasInvalidSigners(cnsDta.BlockHeaderHash, cnsDta.InvalidSigners) { | ||
| return false | ||
| } | ||
|
|
||
| invalidSignersPubKeys, err := sr.verifyInvalidSigners(cnsDta.InvalidSigners) | ||
| if err != nil { | ||
| log.Trace("receivedInvalidSignersInfo.verifyInvalidSigners", "error", err.Error()) | ||
| return false | ||
| } | ||
|
|
||
| log.Debug("step 3: invalid signers info has been evaluated") | ||
|
|
||
| invalidSignersCache.AddInvalidSigners(cnsDta.BlockHeaderHash, cnsDta.InvalidSigners, invalidSignersPubKeys) | ||
|
|
||
| sr.PeerHonestyHandler().ChangeScore( | ||
| messageSender, | ||
| spos.GetConsensusTopicID(sr.ShardCoordinator()), | ||
|
|
@@ -167,32 +174,37 @@ func (sr *subroundEndRound) receivedInvalidSignersInfo(_ context.Context, cnsDta | |
| return true | ||
| } | ||
|
|
||
| func (sr *subroundEndRound) verifyInvalidSigners(invalidSigners []byte) error { | ||
| func (sr *subroundEndRound) verifyInvalidSigners(invalidSigners []byte) ([]string, error) { | ||
| messages, err := sr.MessageSigningHandler().Deserialize(invalidSigners) | ||
| if err != nil { | ||
| return err | ||
| return nil, err | ||
| } | ||
|
|
||
| pubKeys := make([]string, 0, len(messages)) | ||
| for _, msg := range messages { | ||
| err = sr.verifyInvalidSigner(msg) | ||
| if err != nil { | ||
| return err | ||
| pubKey, errVerify := sr.verifyInvalidSigner(msg) | ||
| if errVerify != nil { | ||
| return nil, errVerify | ||
|
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. Thus, here we break & return, all good? 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. yes, it means we were not able to verify if the provided invalid signers indeed had invalid signatures |
||
| } | ||
|
|
||
| if len(pubKey) > 0 { | ||
| pubKeys = append(pubKeys, pubKey) | ||
|
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. So we only collect the public keys of the good signers? And if there's any invalid one, we collect nothing. Should we find a better name for the function e.g. 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 really, this method checks whether the invalid signers provided an invalid signature.. so this appends the invalid signers that we confirmed they had an invalid signature |
||
| } | ||
| } | ||
|
|
||
| return nil | ||
| return pubKeys, nil | ||
| } | ||
|
|
||
| func (sr *subroundEndRound) verifyInvalidSigner(msg p2p.MessageP2P) error { | ||
| func (sr *subroundEndRound) verifyInvalidSigner(msg p2p.MessageP2P) (string, error) { | ||
| err := sr.MessageSigningHandler().Verify(msg) | ||
| if err != nil { | ||
| return err | ||
| return "", err | ||
|
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. Note to ourselves - this is the raw byte pubkey, not the hex-encoded one (from what I understand). No change needed. 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. correct |
||
| } | ||
|
|
||
| cnsMsg := &consensus.Message{} | ||
| err = sr.Marshalizer().Unmarshal(cnsMsg, msg.Data()) | ||
| if err != nil { | ||
| return err | ||
| return "", err | ||
| } | ||
|
|
||
| err = sr.SigningHandler().VerifySingleSignature(cnsMsg.PubKey, cnsMsg.BlockHeaderHash, cnsMsg.SignatureShare) | ||
|
|
@@ -203,9 +215,11 @@ func (sr *subroundEndRound) verifyInvalidSigner(msg p2p.MessageP2P) error { | |
| "error", err.Error(), | ||
| ) | ||
| sr.applyBlacklistOnNode(msg.Peer()) | ||
|
|
||
| return string(cnsMsg.PubKey), nil | ||
| } | ||
|
|
||
| return nil | ||
| return "", nil | ||
| } | ||
|
|
||
| func (sr *subroundEndRound) applyBlacklistOnNode(peer core.PeerID) { | ||
|
|
@@ -501,24 +515,23 @@ func (sr *subroundEndRound) handleInvalidSignersOnAggSigFail() ([]byte, []byte, | |
| invalidPubKeys, err := sr.verifyNodesOnAggSigFail(ctx) | ||
| cancel() | ||
|
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, invalidPubKeys) | ||
| } | ||
|
|
||
| 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 | ||
| } | ||
|
|
||
|
|
@@ -618,7 +631,7 @@ func (sr *subroundEndRound) getRandomManagedKeyProofSender() string { | |
| return randManagedKey | ||
| } | ||
|
|
||
| func (sr *subroundEndRound) createAndBroadcastInvalidSigners(invalidSigners []byte) { | ||
| func (sr *subroundEndRound) createAndBroadcastInvalidSigners(invalidSigners []byte, invalidSignersPubKeys []string) { | ||
| if !sr.ShouldConsiderSelfKeyInConsensus() { | ||
| return | ||
| } | ||
|
|
@@ -646,6 +659,8 @@ func (sr *subroundEndRound) createAndBroadcastInvalidSigners(invalidSigners []by | |
| invalidSigners, | ||
| ) | ||
|
|
||
| sr.InvalidSignersCache().AddInvalidSigners(sr.GetData(), invalidSigners, invalidSignersPubKeys) | ||
|
|
||
| err = sr.BroadcastMessenger().BroadcastConsensusMessage(cnsMsg) | ||
| if err != nil { | ||
| log.Debug("doEndRoundJob.BroadcastConsensusMessage", "error", err.Error()) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.