Aggregate responses and create schnorr multi-sig

pull/55/head
Rongjian Lan 6 years ago
parent 4e2e26261a
commit 762b6ec219
  1. 4
      consensus/consensus.go
  2. 20
      consensus/consensus_leader.go

@ -18,7 +18,9 @@ import (
type Consensus struct {
state ConsensusState
// Commits collected from validators. A map from node Id to its commitment
commitments map[uint16]kyber.Point
commitments map[uint16]kyber.Point
aggregatedCommitment kyber.Point
// Commits collected from validators.
bitmap *crypto.Mask
// Responses collected from validators

@ -221,6 +221,7 @@ func (consensus *Consensus) constructChallengeMessage() []byte {
// 32 byte challenge
buffer.Write(getChallenge(aggCommitment, consensus.bitmap.AggregatePublic, buffer.Bytes()[:36])) // message contains consensus id and block hash for now.
consensus.aggregatedCommitment = aggCommitment
// 64 byte of signature on previous data
signature := consensus.signMessage(buffer.Bytes())
@ -325,6 +326,23 @@ func (consensus *Consensus) processResponseMessage(payload []byte) {
if len(consensus.responses) >= (2*len(consensus.validators))/3+1 && consensus.state != FINISHED {
consensus.mutex.Lock()
if len(consensus.responses) >= (2*len(consensus.validators))/3+1 && consensus.state != FINISHED {
// Aggregate responses
responses := make([]kyber.Scalar, 0)
for _, val := range consensus.responses {
responses = append(responses, val)
}
aggResponse, err := crypto.AggregateResponses(crypto.Ed25519Curve, responses)
if err != nil {
log.Error("Failed to aggregate responses")
return
}
collectiveSign, err := crypto.Sign(crypto.Ed25519Curve, consensus.aggregatedCommitment, aggResponse, consensus.bitmap)
if err != nil {
log.Error("Failed to create collective signature")
return
}
_ = collectiveSign // TODO: put the collective signature into block and broadcast
consensus.Log.Debug("Consensus reached with signatures.", "numOfSignatures", len(consensus.responses))
// Reset state to FINISHED, and clear other data.
consensus.ResetState()
@ -335,7 +353,7 @@ func (consensus *Consensus) processResponseMessage(payload []byte) {
// For now, we used the stored whole block already stored in consensus.blockHeader
txDecoder := gob.NewDecoder(bytes.NewReader(consensus.blockHeader))
var blockHeaderObj blockchain.Block
err := txDecoder.Decode(&blockHeaderObj)
err = txDecoder.Decode(&blockHeaderObj)
if err != nil {
consensus.Log.Debug("failed to construct the new block after consensus")
}

Loading…
Cancel
Save