Skip to content

Commit

Permalink
fixes for multikey mode, send proof from random managed key
Browse files Browse the repository at this point in the history
  • Loading branch information
sstanculeanu committed Jan 31, 2025
1 parent 3e24cfe commit 4278333
Showing 1 changed file with 35 additions and 3 deletions.
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
}

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

return randManagedKey
}

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

0 comments on commit 4278333

Please sign in to comment.