fix comments and add TODO

pull/8/head
Minh Doan 7 years ago
parent 1d0f62ff00
commit ca404d2d71
  1. 16
      consensus/consensus.go
  2. 3
      log/doc.go
  3. 1
      log/format.go
  4. 2
      log/logger.go
  5. 4
      log/root.go

@ -36,7 +36,7 @@ type Consensus struct {
// BlockHeader to run consensus on
blockHeader []byte
// Shard Id which this node belongs to
ShardId uint32
ShardIDShardID uint32
// Signal channel for starting a new consensus process
ReadySignal chan int
@ -80,8 +80,10 @@ func (state ConsensusState) String() string {
return names[state]
}
// Create a new Consensus object
func NewConsensus(ip, port, shardId string, peers []p2p.Peer, leader p2p.Peer) Consensus {
// NewConsensus creates a new Consensus object
// TODO(minhdoan): Maybe convert it into just New
// FYI, see https://golang.org/doc/effective_go.html?#package-names
func NewConsensus(ip, port, ShardID string, peers []p2p.Peer, leader p2p.Peer) Consensus {
// The first Ip, port passed will be leader.
consensus := Consensus{}
peer := p2p.Peer{Port: port, Ip: ip}
@ -104,11 +106,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.consensusId = 0
myShardId, err := strconv.Atoi(shardId)
myShardIDShardID, err := strconv.Atoi(ShardID)
if err != nil {
panic("Unparseable shard Id" + shardId)
panic("Unparseable shard Id" + ShardID)
}
consensus.ShardId = uint32(myShardId)
consensus.ShardIDShardID = uint32(myShardIDShardID)
// For now use socket address as 16 byte Id
// TODO: populate with correct Id
@ -146,5 +148,5 @@ func (consensus *Consensus) String() string {
} else {
duty = "VLD" // validator
}
return fmt.Sprintf("[%s, %s, %v, %v]", duty, consensus.priKey, consensus.ShardId, consensus.nodeId)
return fmt.Sprintf("[%s, %s, %v, %v]", duty, consensus.priKey, consensus.ShardIDShardID, consensus.nodeId)
}

@ -1,3 +1,5 @@
package log
/*
Package log15 provides an opinionated, simple toolkit for best-practice logging that is
both human and machine readable. It is modeled after the standard library's io and net/http
@ -330,4 +332,3 @@ The Name
https://xkcd.com/927/
*/
package log

@ -50,6 +50,7 @@ var fieldPadding = make(map[string]int)
// fieldPaddingLock is a global mutex protecting the field padding map.
var fieldPaddingLock sync.RWMutex
// Format interface.
type Format interface {
Format(r *Record) []byte
}

@ -14,8 +14,10 @@ const msgKey = "msg"
const errorKey = "LOG15_ERROR"
const skipLevel = 2
// Lvl type.
type Lvl int
// Constants.
const (
LvlCrit Lvl = iota
LvlError

@ -5,8 +5,10 @@ import (
)
var (
root = &logger{[]interface{}{}, new(swapHandler)}
root = &logger{[]interface{}{}, new(swapHandler)}
// StdoutHandler handles stdout
StdoutHandler = StreamHandler(os.Stdout, LogfmtFormat())
// StderrHandler handles stderr
StderrHandler = StreamHandler(os.Stderr, LogfmtFormat())
)

Loading…
Cancel
Save