Add collective sig message and broadcasting it after prepare phase of cosi

pull/61/head
Rongjian Lan 6 years ago
parent c519f495ca
commit e0c250561d
  1. 2
      blockchain/block.go
  2. 18
      consensus/consensus_leader.go

@ -23,7 +23,7 @@ type Block struct {
ShardId uint32 ShardId uint32
Hash [32]byte Hash [32]byte
// Signature... // Signature...
bitmap []byte // Contains which validator signed the block. Bitmap []byte // Contains which validator signed the block.
Signature [66]byte // Schnorr collective signature Signature [66]byte // Schnorr collective signature
} }

@ -247,15 +247,26 @@ func (consensus *Consensus) processResponseMessage(payload []byte) {
log.Error("Failed to aggregate responses") log.Error("Failed to aggregate responses")
return return
} }
collectiveSig, err := crypto.Sign(crypto.Ed25519Curve, consensus.aggregatedCommitment, aggResponse, consensus.bitmap) collectiveSigAndBitmap, err := crypto.Sign(crypto.Ed25519Curve, consensus.aggregatedCommitment, aggResponse, consensus.bitmap)
if err != nil { if err != nil {
log.Error("Failed to create collective signature") log.Error("Failed to create collective signature")
return return
} else { } else {
log.Info("CollectiveSig created.", "size", len(collectiveSig)) log.Info("CollectiveSig and Bitmap created.", "size", len(collectiveSigAndBitmap))
} }
// Start the second round of Cosi
collectiveSig := [64]byte{}
copy(collectiveSig[:], collectiveSigAndBitmap[:64])
bitmap := collectiveSigAndBitmap[64:]
msgToSend := consensus.constructCollectiveSigMessage(collectiveSig, bitmap)
p2p.BroadcastMessage(consensus.getValidatorPeers(), msgToSend)
// Set state to CHALLENGE_DONE
consensus.state = COLLECTIVE_SIG_DONE
consensus.Log.Debug("Consensus reached with signatures.", "numOfSignatures", len(consensus.responses)) consensus.Log.Debug("Consensus reached with signatures.", "numOfSignatures", len(consensus.responses))
// Reset state to FINISHED, and clear other data. // Reset state to FINISHED, and clear other data.
consensus.ResetState() consensus.ResetState()
@ -273,7 +284,8 @@ func (consensus *Consensus) processResponseMessage(payload []byte) {
// Sign the block // Sign the block
// TODO(RJ): populate bitmap // TODO(RJ): populate bitmap
copy(blockHeaderObj.Signature[:], collectiveSig) copy(blockHeaderObj.Signature[:], collectiveSig[:])
copy(blockHeaderObj.Bitmap[:], bitmap)
consensus.OnConsensusDone(&blockHeaderObj) consensus.OnConsensusDone(&blockHeaderObj)
// TODO: @ricl these logic are irrelevant to consensus, move them to another file, say profiler. // TODO: @ricl these logic are irrelevant to consensus, move them to another file, say profiler.

Loading…
Cancel
Save