Add bitmap and signature for blocks; populate signature for block

pull/61/head
Rongjian Lan 6 years ago
parent 7cfa59eddf
commit b7a7aa339c
  1. 4
      blockchain/block.go
  2. 8
      consensus/consensus_leader.go

@ -22,6 +22,8 @@ type Block struct {
ShardId uint32
Hash [32]byte
// Signature...
bitmap []byte // Contains which validator signed the block.
Signature [66]byte // Schnorr collective signature
}
// Serialize serializes the block
@ -96,7 +98,7 @@ func NewBlock(transactions []*Transaction, prevBlockHash [32]byte, shardId uint3
for _, tx := range transactions {
txIds = append(txIds, tx.ID)
}
block := &Block{time.Now().Unix(), prevBlockHash, numTxs, txIds, transactions, shardId, [32]byte{}}
block := &Block{Timestamp: time.Now().Unix(), PrevBlockHash: prevBlockHash, NumTransactions: numTxs, TransactionIds: txIds, Transactions: transactions, ShardId: shardId, Hash: [32]byte{}}
copy(block.Hash[:], block.CalculateBlockHash()[:])
return block

@ -339,11 +339,13 @@ func (consensus *Consensus) processResponseMessage(payload []byte) {
return
}
collectiveSign, err := crypto.Sign(crypto.Ed25519Curve, consensus.aggregatedCommitment, aggResponse, consensus.bitmap)
if err != nil {
log.Error("Failed to create collective signature")
return
} else {
log.Info("CollectiveSig created.", "size", len(collectiveSign))
}
_ = 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.
@ -359,6 +361,10 @@ func (consensus *Consensus) processResponseMessage(payload []byte) {
if err != nil {
consensus.Log.Debug("failed to construct the new block after consensus")
}
// Sign the block
// TODO(RJ): populate bitmap
copy(blockHeaderObj.Signature[:], collectiveSign)
consensus.OnConsensusDone(&blockHeaderObj)
// TODO: @ricl these logic are irrelevant to consensus, move them to another file, say profiler.

Loading…
Cancel
Save