pull/8/head
Minh Doan 7 years ago
parent 689a06d577
commit 8e36f57fd5
  1. 10
      consensus/consensus.go

@ -38,12 +38,11 @@ type Consensus struct {
// BlockHeader to run consensus on // BlockHeader to run consensus on
blockHeader []byte blockHeader []byte
// Shard Id which this node belongs to // Shard Id which this node belongs to
ShardIDShardID uint32 ShardID uint32
// global consensus mutex // global consensus mutex
mutex sync.Mutex mutex sync.Mutex
// Validator specific fields // Validator specific fields
// Blocks received but not done with consensus yet // Blocks received but not done with consensus yet
blocksReceived map[uint32]*BlockConsensusStatus blocksReceived map[uint32]*BlockConsensusStatus
@ -90,6 +89,7 @@ const (
CHALLENGE_DONE CHALLENGE_DONE
RESPONSE_DONE RESPONSE_DONE
) )
// 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{
@ -131,11 +131,11 @@ func NewConsensus(ip, port, ShardID string, peers []p2p.Peer, leader p2p.Peer) C
consensus.Log.Crit("Regex Compilation Failed", "err", err, "consensus", consensus) consensus.Log.Crit("Regex Compilation Failed", "err", err, "consensus", consensus)
} }
consensus.consensusId = 0 consensus.consensusId = 0
myShardIDShardID, err := strconv.Atoi(ShardID) myShardID, err := strconv.Atoi(ShardID)
if err != nil { if err != nil {
panic("Unparseable shard Id" + ShardID) panic("Unparseable shard Id" + ShardID)
} }
consensus.ShardIDShardID = uint32(myShardIDShardID) consensus.ShardID = uint32(myShardID)
// For validators // For validators
consensus.blocksReceived = make(map[uint32]*BlockConsensusStatus) consensus.blocksReceived = make(map[uint32]*BlockConsensusStatus)
@ -176,5 +176,5 @@ func (consensus *Consensus) String() string {
} else { } else {
duty = "VLD" // validator duty = "VLD" // validator
} }
return fmt.Sprintf("[%s, %s, %v, %v, %s]", duty, consensus.priKey, consensus.ShardIDShardID, consensus.nodeId, consensus.state) return fmt.Sprintf("[%s, %s, %v, %v, %s]", duty, consensus.priKey, consensus.ShardID, consensus.nodeId, consensus.state)
} }

Loading…
Cancel
Save