change FINISHED to Finished

pull/75/head
Minh Doan 6 years ago
parent c7908e8821
commit 37a9d84216
  1. 2
      consensus/consensus.go
  2. 14
      consensus/consensus_leader.go
  3. 10
      consensus/consensus_state.go

@ -184,7 +184,7 @@ func (consensus *Consensus) GetValidatorPeers() []p2p.Peer {
// Reset the state of the consensus // Reset the state of the consensus
func (consensus *Consensus) ResetState() { func (consensus *Consensus) ResetState() {
consensus.state = FINISHED consensus.state = Finished
consensus.commitments = &map[uint16]kyber.Point{} consensus.commitments = &map[uint16]kyber.Point{}
consensus.finalCommitments = &map[uint16]kyber.Point{} consensus.finalCommitments = &map[uint16]kyber.Point{}
consensus.responses = &map[uint16]kyber.Scalar{} consensus.responses = &map[uint16]kyber.Scalar{}

@ -31,7 +31,7 @@ func (consensus *Consensus) WaitForNewBlock(blockChannel chan blockchain.Block)
// TODO: think about potential race condition // TODO: think about potential race condition
startTime = time.Now() startTime = time.Now()
consensus.Log.Debug("STARTING CONSENSUS", "consensus", consensus, "startTime", startTime) consensus.Log.Debug("STARTING CONSENSUS", "consensus", consensus, "startTime", startTime)
for consensus.state == FINISHED { for consensus.state == Finished {
// time.Sleep(500 * time.Millisecond) // time.Sleep(500 * time.Millisecond)
consensus.startConsensus(&newBlock) consensus.startConsensus(&newBlock)
break break
@ -61,7 +61,7 @@ func (consensus *Consensus) ProcessMessageLeader(message []byte) {
case proto_consensus.FinalCommit: case proto_consensus.FinalCommit:
consensus.processCommitMessage(payload, FinalChallengeDone) consensus.processCommitMessage(payload, FinalChallengeDone)
case proto_consensus.FinalResponse: case proto_consensus.FinalResponse:
consensus.processResponseMessage(payload, FINISHED) consensus.processResponseMessage(payload, Finished)
default: default:
consensus.Log.Error("Unexpected message type", "msgType", msgType, "consensus", consensus) consensus.Log.Error("Unexpected message type", "msgType", msgType, "consensus", consensus)
} }
@ -286,7 +286,7 @@ func (consensus *Consensus) processResponseMessage(payload []byte, targetState C
commitments := consensus.commitments // targetState == CollectiveSigDone commitments := consensus.commitments // targetState == CollectiveSigDone
responses := consensus.responses responses := consensus.responses
bitmap := consensus.bitmap bitmap := consensus.bitmap
if targetState == FINISHED { if targetState == Finished {
commitments = consensus.finalCommitments commitments = consensus.finalCommitments
responses = consensus.finalResponses responses = consensus.finalResponses
bitmap = consensus.finalBitmap bitmap = consensus.finalBitmap
@ -335,7 +335,7 @@ func (consensus *Consensus) processResponseMessage(payload []byte, targetState C
return return
} }
aggregatedCommitment := consensus.aggregatedCommitment aggregatedCommitment := consensus.aggregatedCommitment
if targetState == FINISHED { if targetState == Finished {
aggregatedCommitment = consensus.aggregatedFinalCommitment aggregatedCommitment = consensus.aggregatedFinalCommitment
} }
@ -352,10 +352,10 @@ func (consensus *Consensus) processResponseMessage(payload []byte, targetState C
copy(collectiveSig[:], collectiveSigAndBitmap[:64]) copy(collectiveSig[:], collectiveSigAndBitmap[:64])
bitmap := collectiveSigAndBitmap[64:] bitmap := collectiveSigAndBitmap[64:]
// Set state to CollectiveSigDone or FINISHED // Set state to CollectiveSigDone or Finished
consensus.state = targetState consensus.state = targetState
if consensus.state != FINISHED { if consensus.state != Finished {
// Start the second round of Cosi // Start the second round of Cosi
msgToSend := consensus.constructCollectiveSigMessage(collectiveSig, bitmap) msgToSend := consensus.constructCollectiveSigMessage(collectiveSig, bitmap)
@ -363,7 +363,7 @@ func (consensus *Consensus) processResponseMessage(payload []byte, targetState C
consensus.commitByLeader(false) consensus.commitByLeader(false)
} else { } else {
consensus.Log.Debug("Consensus reached with signatures.", "numOfSignatures", len(*responses)) consensus.Log.Debug("Consensus reached with signatures.", "numOfSignatures", len(*responses))
// Reset state to FINISHED, and clear other data. // Reset state to Finished, and clear other data.
consensus.ResetState() consensus.ResetState()
consensus.consensusID++ consensus.consensusID++
consensus.Log.Debug("HOORAY!!! CONSENSUS REACHED!!!", "consensusID", consensus.consensusID) consensus.Log.Debug("HOORAY!!! CONSENSUS REACHED!!!", "consensusID", consensus.consensusID)

@ -2,13 +2,13 @@ package consensus
// Consensus state enum for both leader and validator // Consensus state enum for both leader and validator
// States for leader: // States for leader:
// FINISHED, AnnounceDone, ChallengeDone // Finished, AnnounceDone, ChallengeDone
// States for validator: // States for validator:
// FINISHED, CommitDone, ResponseDone // Finished, CommitDone, ResponseDone
type ConsensusState int type ConsensusState int
const ( const (
FINISHED ConsensusState = iota // initial state or state after previous consensus is done. Finished ConsensusState = iota // initial state or state after previous consensus is done.
AnnounceDone AnnounceDone
CommitDone CommitDone
ChallengeDone ChallengeDone
@ -22,7 +22,7 @@ const (
// Returns string name for the ConsensusState enum // Returns string name for the ConsensusState enum
func (state ConsensusState) String() string { func (state ConsensusState) String() string {
names := [...]string{ names := [...]string{
"FINISHED", "Finished",
"AnnounceDone", "AnnounceDone",
"CommitDone", "CommitDone",
"ChallengeDone", "ChallengeDone",
@ -32,7 +32,7 @@ func (state ConsensusState) String() string {
"FinalChallengeDone", "FinalChallengeDone",
"FinalResponseDone"} "FinalResponseDone"}
if state < FINISHED || state > FinalResponseDone { if state < Finished || state > FinalResponseDone {
return "Unknown" return "Unknown"
} }
return names[state] return names[state]

Loading…
Cancel
Save