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

Proposer equivalent proof for previous block #6428

Draft
wants to merge 2 commits into
base: feat/equivalent-messages
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions consensus/spos/bls/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,3 +366,8 @@ func (sr *subroundStartRound) ChangeEpoch(epoch uint32) {
func (sr *subroundStartRound) IndexRoundIfNeeded(pubKeys []string) {
sr.indexRoundIfNeeded(pubKeys)
}

// SetEquivalentProofForPreviousBlock -
func (sr *subroundStartRound) SetEquivalentProofForPreviousBlock(bitmap []byte, epoch uint32) error {
return sr.setEquivalentProofForPreviousBlock(bitmap, epoch)
}
38 changes: 38 additions & 0 deletions consensus/spos/bls/subroundStartRound.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ func (sr *subroundStartRound) initCurrentRound() bool {

sr.AppStatusHandler().SetStringValue(common.MetricConsensusRoundState, "")

// get previous bitmap before generating next consensus group
previousBitmap := sr.GenerateBitmap(SrSignature)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

handle scenario on start of epoch block where the consensus group will still be selected based on previous model


err := sr.generateNextConsensusGroup(sr.RoundHandler().Index())
if err != nil {
log.Debug("initCurrentRound.generateNextConsensusGroup",
Expand Down Expand Up @@ -202,6 +205,21 @@ func (sr *subroundStartRound) initCurrentRound() bool {
}
}

// if leader, check aggregated signature here, before cleaning up the collected
// signature shares
currentEpoch := uint32(0)
currentHeader := sr.Blockchain().GetCurrentBlockHeader()
if !check.IfNil(currentHeader) {
currentEpoch = currentHeader.GetEpoch()
}

if isLeader && sr.EnableEpochsHandler().IsFlagEnabledInEpoch(common.EquivalentMessagesFlag, currentEpoch) {
err = sr.setEquivalentProofForPreviousBlock(previousBitmap, currentEpoch)
if err != nil {
return false
}
}

err = sr.SigningHandler().Reset(pubKeys)
if err != nil {
log.Debug("initCurrentRound.Reset", "error", err.Error())
Expand Down Expand Up @@ -231,6 +249,26 @@ func (sr *subroundStartRound) initCurrentRound() bool {
return true
}

func (sr *subroundStartRound) setEquivalentProofForPreviousBlock(bitmap []byte, epoch uint32) error {
aggSig, err := sr.SigningHandler().AggregateSigs(bitmap, epoch)
if err != nil {
log.Debug("setEquivalentProofForPreviousBlock.AggregateSigs", "error", err.Error())
return err
}

proof := data.HeaderProof{
AggregatedSignature: aggSig,
PubKeysBitmap: bitmap,
}

currentHeaderHash := sr.Blockchain().GetCurrentBlockHeaderHash()

sr.worker.SetValidEquivalentProof(currentHeaderHash, proof)
sr.Blockchain().SetCurrentHeaderProof(proof)

return nil
}

func (sr *subroundStartRound) computeNumManagedKeysInConsensusGroup(pubKeys []string) int {
numMultiKeysInConsensusGroup := 0
for _, pk := range pubKeys {
Expand Down
Loading
Loading