Leader verifies validator's signatures and collect responses by node id

pull/55/head
Rongjian Lan 6 years ago
parent da7959f9e3
commit 4e2e26261a
  1. 8
      consensus/consensus.go
  2. 26
      consensus/consensus_leader.go

@ -21,8 +21,8 @@ type Consensus struct {
commitments map[uint16]kyber.Point
// Commits collected from validators.
bitmap *crypto.Mask
// Signatures collected from validators
responses map[string]string
// Responses collected from validators
responses map[uint16]kyber.Scalar
// map of nodeId to validator Peer object
validators map[uint16]p2p.Peer
// Leader
@ -89,7 +89,7 @@ func NewConsensus(ip, port, ShardID string, peers []p2p.Peer, leader p2p.Peer) *
consensus.commitments = make(map[uint16]kyber.Point)
consensus.validators = make(map[uint16]p2p.Peer)
consensus.responses = make(map[string]string)
consensus.responses = make(map[uint16]kyber.Scalar)
consensus.leader = leader
for _, peer := range peers {
@ -160,7 +160,7 @@ func (consensus *Consensus) getValidatorPeers() []p2p.Peer {
func (consensus *Consensus) ResetState() {
consensus.state = FINISHED
consensus.commitments = make(map[uint16]kyber.Point)
consensus.responses = make(map[string]string)
consensus.responses = make(map[uint16]kyber.Scalar)
consensus.secret = nil
}

@ -271,7 +271,7 @@ func (consensus *Consensus) processResponseMessage(payload []byte) {
offset += 32
// 2 byte validator id
validatorId := string(payload[offset : offset+2])
validatorId := binary.BigEndian.Uint16(payload[offset : offset+2])
offset += 2
// 32 byte response
@ -283,12 +283,6 @@ func (consensus *Consensus) processResponseMessage(payload []byte) {
offset += 64
//#### END: Read payload data
// TODO: make use of the data. This is just to avoid the unused variable warning
_ = consensusId
_ = blockHash
_ = response
_ = signature
shouldProcess := true
consensus.mutex.Lock()
// check consensus Id
@ -302,12 +296,24 @@ func (consensus *Consensus) processResponseMessage(payload []byte) {
return
}
// Verify signature
value, ok := consensus.validators[validatorId]
if !ok {
consensus.Log.Warn("Received message from unrecognized validator", "validatorId", validatorId, "consensus", consensus)
return
}
if schnorr.Verify(crypto.Ed25519Curve, value.PubKey, payload[:offset-64], signature) != nil {
consensus.Log.Warn("Received message with invalid signature", "validatorKey", consensus.leader.PubKey, "consensus", consensus)
return
}
// proceed only when the message is not received before
_, ok := consensus.responses[validatorId]
_, ok = consensus.responses[validatorId]
shouldProcess = shouldProcess && !ok
if shouldProcess {
consensus.responses[validatorId] = validatorId
//consensus.Log.Debug("Number of responses received", "consensusId", consensus.consensusId, "count", len(consensus.responses))
scalar := crypto.Ed25519Curve.Scalar()
scalar.UnmarshalBinary(response)
consensus.responses[validatorId] = scalar
}
consensus.mutex.Unlock()

Loading…
Cancel
Save