Skip to content
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

fixes for multikey mode, send proof from random managed key #6764

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 35 additions & 3 deletions consensus/spos/bls/v2/subroundEndRound.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/hex"
"fmt"
"math/bits"
"math/rand"
"sync"
"time"

Expand Down Expand Up @@ -100,7 +101,7 @@ func (sr *subroundEndRound) receivedProof(proof consensus.ProofHandler) {
sr.mutProcessingEndRound.Lock()
defer sr.mutProcessingEndRound.Unlock()

if sr.IsJobDone(sr.SelfPubKey(), sr.Current()) {
if sr.IsSelfJobDone(sr.Current()) {
return
}
if !sr.IsConsensusDataSet() {
Expand Down Expand Up @@ -555,18 +556,49 @@ func (sr *subroundEndRound) createAndBroadcastProof(signature []byte, bitmap []b
IsStartOfEpoch: sr.GetHeader().IsStartOfEpochBlock(),
}

err := sr.BroadcastMessenger().BroadcastEquivalentProof(headerProof, []byte(sr.SelfPubKey()))
sender := sr.getEquivalentProofSender()
err := sr.BroadcastMessenger().BroadcastEquivalentProof(headerProof, []byte(sender))
if err != nil {
return err
}

log.Debug("step 3: block header proof has been sent",
"PubKeysBitmap", bitmap,
"AggregateSignature", signature)
"AggregateSignature", signature,
"proof sender", hex.EncodeToString([]byte(sender)))

return nil
}

func (sr *subroundEndRound) getEquivalentProofSender() string {
if sr.IsNodeInConsensusGroup(sr.SelfPubKey()) {
return sr.SelfPubKey() // single key mode
}

return sr.getRandomManagedKeyProofSender()
}

func (sr *subroundEndRound) getRandomManagedKeyProofSender() string {
// in multikey mode, we randomly select one managed key for the proof
consensusKeysManagedByCurrentNode := make([]string, 0)
for _, validator := range sr.ConsensusGroup() {
if !sr.IsKeyManagedBySelf([]byte(validator)) {
continue
}

consensusKeysManagedByCurrentNode = append(consensusKeysManagedByCurrentNode, validator)
}

if len(consensusKeysManagedByCurrentNode) == 0 {
return sr.SelfPubKey() // fallback return self pub key, should never happen
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could happen if we allow observers or waiting nodes to send proofs as well

}

randIdx := rand.Intn(len(consensusKeysManagedByCurrentNode))
randManagedKey := consensusKeysManagedByCurrentNode[randIdx]

return randManagedKey
}

func (sr *subroundEndRound) createAndBroadcastInvalidSigners(invalidSigners []byte) {
if !sr.ShouldConsiderSelfKeyInConsensus() {
return
Expand Down