Browse Source

change logger to log15

pull/9/head
Jae Kwon 10 years ago
parent
commit
0bfb389b35
35 changed files with 189 additions and 251 deletions
  1. +7
    -5
      alert/alert.go
  2. +2
    -6
      alert/log.go
  3. +3
    -1
      binary/bit_array.go
  4. +2
    -2
      binary/bit_array_test.go
  5. +2
    -6
      binary/log.go
  6. +16
    -14
      binary/reflect.go
  7. +10
    -10
      block/store.go
  8. +5
    -4
      cmd/daemon.go
  9. +2
    -2
      cmd/log.go
  10. +0
    -44
      common/logging.go
  11. +2
    -6
      common/panic.go
  12. +7
    -0
      common/string.go
  13. +2
    -2
      config/config.go
  14. +2
    -6
      consensus/log.go
  15. +7
    -9
      consensus/reactor.go
  16. +19
    -19
      consensus/state.go
  17. +0
    -1
      consensus/vote_set.go
  18. +2
    -6
      mempool/log.go
  19. +5
    -4
      mempool/reactor.go
  20. +15
    -15
      p2p/addrbook.go
  21. +21
    -20
      p2p/connection.go
  22. +7
    -7
      p2p/listener.go
  23. +2
    -6
      p2p/log.go
  24. +3
    -3
      p2p/peer.go
  25. +3
    -3
      p2p/pex_reactor.go
  26. +7
    -7
      p2p/switch.go
  27. +2
    -1
      p2p/switch_test.go
  28. +2
    -6
      p2p/upnp/log.go
  29. +13
    -11
      p2p/upnp/probe.go
  30. +3
    -2
      rpc/http_handler.go
  31. +3
    -2
      rpc/http_server.go
  32. +2
    -6
      rpc/log.go
  33. +7
    -7
      state/genesis.go
  34. +2
    -6
      state/log.go
  35. +2
    -2
      state/state.go

+ 7
- 5
alert/alert.go View File

@ -2,9 +2,11 @@ package alert
import ( import (
"fmt" "fmt"
"github.com/sfreiberg/gotwilio"
"time" "time"
"github.com/sfreiberg/gotwilio"
. "github.com/tendermint/tendermint/common"
. "github.com/tendermint/tendermint/config" . "github.com/tendermint/tendermint/config"
) )
@ -35,7 +37,7 @@ func Alert(message string) {
func sendTwilio(message string) { func sendTwilio(message string) {
defer func() { defer func() {
if err := recover(); err != nil { if err := recover(); err != nil {
log.Error("sendTwilio error: %v", err)
log.Error(Fmt("sendTwilio error: %v", err))
} }
}() }()
if len(message) > 50 { if len(message) > 50 {
@ -44,14 +46,14 @@ func sendTwilio(message string) {
twilio := gotwilio.NewTwilioClient(Config.Alert.TwilioSid, Config.Alert.TwilioToken) twilio := gotwilio.NewTwilioClient(Config.Alert.TwilioSid, Config.Alert.TwilioToken)
res, exp, err := twilio.SendSMS(Config.Alert.TwilioFrom, Config.Alert.TwilioTo, message, "", "") res, exp, err := twilio.SendSMS(Config.Alert.TwilioFrom, Config.Alert.TwilioTo, message, "", "")
if exp != nil || err != nil { if exp != nil || err != nil {
log.Error("sendTwilio error: %v %v %v", res, exp, err)
log.Error(Fmt("sendTwilio error: %v %v %v", res, exp, err))
} }
} }
func sendEmail(message string) { func sendEmail(message string) {
defer func() { defer func() {
if err := recover(); err != nil { if err := recover(); err != nil {
log.Error("sendEmail error: %v", err)
log.Error(Fmt("sendEmail error: %v", err))
} }
}() }()
subject := message subject := message
@ -60,6 +62,6 @@ func sendEmail(message string) {
} }
err := SendEmail(subject, message, Config.Alert.EmailRecipients) err := SendEmail(subject, message, Config.Alert.EmailRecipients)
if err != nil { if err != nil {
log.Error("sendEmail error: %v\n%v", err, message)
log.Error(Fmt("sendEmail error: %v\n%v", err, message))
} }
} }

+ 2
- 6
alert/log.go View File

@ -1,11 +1,7 @@
package alert package alert
import ( import (
"github.com/op/go-logging"
"gopkg.in/inconshreveable/log15.v2"
) )
var log = logging.MustGetLogger("alert")
func SetAlertLogger(l *logging.Logger) {
log = l
}
var log = log15.New("module", "alert")

common/bit_array.go → binary/bit_array.go View File


common/bit_array_test.go → binary/bit_array_test.go View File


+ 2
- 6
binary/log.go View File

@ -1,11 +1,7 @@
package binary package binary
import ( import (
"github.com/op/go-logging"
"gopkg.in/inconshreveable/log15.v2"
) )
var log = logging.MustGetLogger("binary")
func SetBinaryLogger(l *logging.Logger) {
log = l
}
var log = log15.New("module", "binary")

+ 16
- 14
binary/reflect.go View File

@ -6,6 +6,8 @@ import (
"io" "io"
"reflect" "reflect"
"sync" "sync"
. "github.com/tendermint/tendermint/common"
) )
type TypeInfo struct { type TypeInfo struct {
@ -113,7 +115,7 @@ func readReflect(rv reflect.Value, rt reflect.Type, r Unreader, n *int64, err *e
// Read TypeByte prefix // Read TypeByte prefix
if typeInfo.HasTypeByte { if typeInfo.HasTypeByte {
typeByte := ReadByte(r, n, err) typeByte := ReadByte(r, n, err)
log.Debug("Read TypeByte: %X", typeByte)
log.Debug("Read typebyte", "typeByte", typeByte)
if typeByte != typeInfo.TypeByte { if typeByte != typeInfo.TypeByte {
*err = errors.New(fmt.Sprintf("Expected TypeByte of %X but got %X", typeInfo.TypeByte, typeByte)) *err = errors.New(fmt.Sprintf("Expected TypeByte of %X but got %X", typeInfo.TypeByte, typeByte))
return return
@ -126,12 +128,12 @@ func readReflect(rv reflect.Value, rt reflect.Type, r Unreader, n *int64, err *e
if elemRt.Kind() == reflect.Uint8 { if elemRt.Kind() == reflect.Uint8 {
// Special case: Byteslices // Special case: Byteslices
byteslice := ReadByteSlice(r, n, err) byteslice := ReadByteSlice(r, n, err)
log.Debug("Read byteslice: %X", byteslice)
log.Debug("Read byteslice", "bytes", byteslice)
rv.Set(reflect.ValueOf(byteslice)) rv.Set(reflect.ValueOf(byteslice))
} else { } else {
// Read length // Read length
length := int(ReadUvarint(r, n, err)) length := int(ReadUvarint(r, n, err))
log.Debug("Read length: %v", length)
log.Debug(Fmt("Read length: %v", length))
sliceRv := reflect.MakeSlice(rt, length, length) sliceRv := reflect.MakeSlice(rt, length, length)
// Read elems // Read elems
for i := 0; i < length; i++ { for i := 0; i < length; i++ {
@ -154,57 +156,57 @@ func readReflect(rv reflect.Value, rt reflect.Type, r Unreader, n *int64, err *e
case reflect.String: case reflect.String:
str := ReadString(r, n, err) str := ReadString(r, n, err)
log.Debug("Read string: %v", str)
log.Debug(Fmt("Read string: %v", str))
rv.SetString(str) rv.SetString(str)
case reflect.Int64: case reflect.Int64:
num := ReadUint64(r, n, err) num := ReadUint64(r, n, err)
log.Debug("Read num: %v", num)
log.Debug(Fmt("Read num: %v", num))
rv.SetInt(int64(num)) rv.SetInt(int64(num))
case reflect.Int32: case reflect.Int32:
num := ReadUint32(r, n, err) num := ReadUint32(r, n, err)
log.Debug("Read num: %v", num)
log.Debug(Fmt("Read num: %v", num))
rv.SetInt(int64(num)) rv.SetInt(int64(num))
case reflect.Int16: case reflect.Int16:
num := ReadUint16(r, n, err) num := ReadUint16(r, n, err)
log.Debug("Read num: %v", num)
log.Debug(Fmt("Read num: %v", num))
rv.SetInt(int64(num)) rv.SetInt(int64(num))
case reflect.Int8: case reflect.Int8:
num := ReadUint8(r, n, err) num := ReadUint8(r, n, err)
log.Debug("Read num: %v", num)
log.Debug(Fmt("Read num: %v", num))
rv.SetInt(int64(num)) rv.SetInt(int64(num))
case reflect.Int: case reflect.Int:
num := ReadUvarint(r, n, err) num := ReadUvarint(r, n, err)
log.Debug("Read num: %v", num)
log.Debug(Fmt("Read num: %v", num))
rv.SetInt(int64(num)) rv.SetInt(int64(num))
case reflect.Uint64: case reflect.Uint64:
num := ReadUint64(r, n, err) num := ReadUint64(r, n, err)
log.Debug("Read num: %v", num)
log.Debug(Fmt("Read num: %v", num))
rv.SetUint(uint64(num)) rv.SetUint(uint64(num))
case reflect.Uint32: case reflect.Uint32:
num := ReadUint32(r, n, err) num := ReadUint32(r, n, err)
log.Debug("Read num: %v", num)
log.Debug(Fmt("Read num: %v", num))
rv.SetUint(uint64(num)) rv.SetUint(uint64(num))
case reflect.Uint16: case reflect.Uint16:
num := ReadUint16(r, n, err) num := ReadUint16(r, n, err)
log.Debug("Read num: %v", num)
log.Debug(Fmt("Read num: %v", num))
rv.SetUint(uint64(num)) rv.SetUint(uint64(num))
case reflect.Uint8: case reflect.Uint8:
num := ReadUint8(r, n, err) num := ReadUint8(r, n, err)
log.Debug("Read num: %v", num)
log.Debug(Fmt("Read num: %v", num))
rv.SetUint(uint64(num)) rv.SetUint(uint64(num))
case reflect.Uint: case reflect.Uint:
num := ReadUvarint(r, n, err) num := ReadUvarint(r, n, err)
log.Debug("Read num: %v", num)
log.Debug(Fmt("Read num: %v", num))
rv.SetUint(uint64(num)) rv.SetUint(uint64(num))
default: default:


+ 10
- 10
block/store.go View File

@ -53,7 +53,7 @@ func (bs *BlockStore) LoadBlock(height uint) *Block {
var err error var err error
meta := ReadBinary(&BlockMeta{}, bs.GetReader(calcBlockMetaKey(height)), &n, &err).(*BlockMeta) meta := ReadBinary(&BlockMeta{}, bs.GetReader(calcBlockMetaKey(height)), &n, &err).(*BlockMeta)
if err != nil { if err != nil {
Panicf("Error reading block meta: %v", err)
panic(Fmt("Error reading block meta: %v", err))
} }
bytez := []byte{} bytez := []byte{}
for i := uint(0); i < meta.Parts.Total; i++ { for i := uint(0); i < meta.Parts.Total; i++ {
@ -62,7 +62,7 @@ func (bs *BlockStore) LoadBlock(height uint) *Block {
} }
block := ReadBinary(&Block{}, bytes.NewReader(bytez), &n, &err).(*Block) block := ReadBinary(&Block{}, bytes.NewReader(bytez), &n, &err).(*Block)
if err != nil { if err != nil {
Panicf("Error reading block: %v", err)
panic(Fmt("Error reading block: %v", err))
} }
return block return block
} }
@ -72,7 +72,7 @@ func (bs *BlockStore) LoadBlockPart(height uint, index uint) *Part {
var err error var err error
part := ReadBinary(&Part{}, bs.GetReader(calcBlockPartKey(height, index)), &n, &err).(*Part) part := ReadBinary(&Part{}, bs.GetReader(calcBlockPartKey(height, index)), &n, &err).(*Part)
if err != nil { if err != nil {
Panicf("Error reading block part: %v", err)
panic(Fmt("Error reading block part: %v", err))
} }
return part return part
} }
@ -82,7 +82,7 @@ func (bs *BlockStore) LoadBlockMeta(height uint) *BlockMeta {
var err error var err error
meta := ReadBinary(&BlockMeta{}, bs.GetReader(calcBlockMetaKey(height)), &n, &err).(*BlockMeta) meta := ReadBinary(&BlockMeta{}, bs.GetReader(calcBlockMetaKey(height)), &n, &err).(*BlockMeta)
if err != nil { if err != nil {
Panicf("Error reading block meta: %v", err)
panic(Fmt("Error reading block meta: %v", err))
} }
return meta return meta
} }
@ -92,7 +92,7 @@ func (bs *BlockStore) LoadBlockValidation(height uint) *Validation {
var err error var err error
validation := ReadBinary(&Validation{}, bs.GetReader(calcBlockValidationKey(height)), &n, &err).(*Validation) validation := ReadBinary(&Validation{}, bs.GetReader(calcBlockValidationKey(height)), &n, &err).(*Validation)
if err != nil { if err != nil {
Panicf("Error reading validation: %v", err)
panic(Fmt("Error reading validation: %v", err))
} }
return validation return validation
} }
@ -100,10 +100,10 @@ func (bs *BlockStore) LoadBlockValidation(height uint) *Validation {
func (bs *BlockStore) SaveBlock(block *Block, blockParts *PartSet) { func (bs *BlockStore) SaveBlock(block *Block, blockParts *PartSet) {
height := block.Height height := block.Height
if height != bs.height+1 { if height != bs.height+1 {
Panicf("BlockStore can only save contiguous blocks. Wanted %v, got %v", bs.height+1, height)
panic(Fmt("BlockStore can only save contiguous blocks. Wanted %v, got %v", bs.height+1, height))
} }
if !blockParts.IsComplete() { if !blockParts.IsComplete() {
Panicf("BlockStore can only save complete block part sets")
panic(Fmt("BlockStore can only save complete block part sets"))
} }
// Save block meta // Save block meta
@ -129,7 +129,7 @@ func (bs *BlockStore) SaveBlock(block *Block, blockParts *PartSet) {
func (bs *BlockStore) saveBlockPart(height uint, index uint, part *Part) { func (bs *BlockStore) saveBlockPart(height uint, index uint, part *Part) {
if height != bs.height+1 { if height != bs.height+1 {
Panicf("BlockStore can only save contiguous blocks. Wanted %v, got %v", bs.height+1, height)
panic(Fmt("BlockStore can only save contiguous blocks. Wanted %v, got %v", bs.height+1, height))
} }
partBytes := BinaryBytes(part) partBytes := BinaryBytes(part)
bs.db.Set(calcBlockPartKey(height, index), partBytes) bs.db.Set(calcBlockPartKey(height, index), partBytes)
@ -176,7 +176,7 @@ type BlockStoreStateJSON struct {
func (bsj BlockStoreStateJSON) Save(db db_.DB) { func (bsj BlockStoreStateJSON) Save(db db_.DB) {
bytes, err := json.Marshal(bsj) bytes, err := json.Marshal(bsj)
if err != nil { if err != nil {
Panicf("Could not marshal state bytes: %v", err)
panic(Fmt("Could not marshal state bytes: %v", err))
} }
db.Set(blockStoreKey, bytes) db.Set(blockStoreKey, bytes)
} }
@ -191,7 +191,7 @@ func LoadBlockStoreStateJSON(db db_.DB) BlockStoreStateJSON {
bsj := BlockStoreStateJSON{} bsj := BlockStoreStateJSON{}
err := json.Unmarshal(bytes, &bsj) err := json.Unmarshal(bytes, &bsj)
if err != nil { if err != nil {
Panicf("Could not unmarshal bytes: %X", bytes)
panic(Fmt("Could not unmarshal bytes: %X", bytes))
} }
return bsj return bsj
} }

+ 5
- 4
cmd/daemon.go View File

@ -6,6 +6,7 @@ import (
"github.com/tendermint/tendermint/block" "github.com/tendermint/tendermint/block"
"github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/config"
. "github.com/tendermint/tendermint/common"
"github.com/tendermint/tendermint/consensus" "github.com/tendermint/tendermint/consensus"
db_ "github.com/tendermint/tendermint/db" db_ "github.com/tendermint/tendermint/db"
mempool_ "github.com/tendermint/tendermint/mempool" mempool_ "github.com/tendermint/tendermint/mempool"
@ -87,7 +88,7 @@ func (n *Node) Stop() {
// Add a Listener to accept inbound peer connections. // Add a Listener to accept inbound peer connections.
func (n *Node) AddListener(l p2p.Listener) { func (n *Node) AddListener(l p2p.Listener) {
log.Info("Added %v", l)
log.Info(Fmt("Added %v", l))
n.lz = append(n.lz, l) n.lz = append(n.lz, l)
n.book.AddOurAddress(l.ExternalAddress()) n.book.AddOurAddress(l.ExternalAddress())
} }
@ -125,11 +126,11 @@ func daemon() {
if config.Config.SeedNode != "" { if config.Config.SeedNode != "" {
peer, err := n.sw.DialPeerWithAddress(p2p.NewNetAddressString(config.Config.SeedNode)) peer, err := n.sw.DialPeerWithAddress(p2p.NewNetAddressString(config.Config.SeedNode))
if err != nil { if err != nil {
log.Error("Error dialing seed: %v", err)
log.Error(Fmt("Error dialing seed: %v", err))
//n.book.MarkAttempt(addr) //n.book.MarkAttempt(addr)
return return
} else { } else {
log.Info("Connected to seed: %v", peer)
log.Info(Fmt("Connected to seed: %v", peer))
} }
} }
@ -149,7 +150,7 @@ func trapSignal(cb func()) {
signal.Notify(c, os.Interrupt) signal.Notify(c, os.Interrupt)
go func() { go func() {
for sig := range c { for sig := range c {
log.Info("captured %v, exiting..", sig)
log.Info(Fmt("captured %v, exiting..", sig))
cb() cb()
os.Exit(1) os.Exit(1)
} }


+ 2
- 2
cmd/log.go View File

@ -1,7 +1,7 @@
package main package main
import ( import (
"github.com/op/go-logging"
"gopkg.in/inconshreveable/log15.v2"
) )
var log = logging.MustGetLogger("main")
var log = log15.New("module", "main")

+ 0
- 44
common/logging.go View File

@ -1,44 +0,0 @@
package common
import (
stdlog "log"
"os"
"github.com/op/go-logging"
)
var Log = logging.MustGetLogger("main")
func init() {
// Customize the output format
logging.SetFormatter(logging.MustStringFormatter("[%{level:.4s}] %{shortfile:-20s} %{message}"))
// Setup one stdout and one syslog backend.
logBackend := logging.NewLogBackend(os.Stderr, "", stdlog.LstdFlags)
logBackend.Color = true
syslogBackend, err := logging.NewSyslogBackend("")
if err != nil {
panic(err)
}
// Combine them both into one logging backend.
logging.SetBackend(logBackend, syslogBackend)
// Test
/*
Log.Debug("debug")
Log.Info("info")
Log.Notice("notice")
Log.Warning("warning")
Log.Error("error")
*/
}
var Debug = Log.Debug
var Info = Log.Info
var Notice = Log.Notice
var Warning = Log.Warning
var Warn = Log.Warning
var Error = Log.Error
var Critical = Log.Critical

+ 2
- 6
common/panic.go View File

@ -5,11 +5,7 @@ import (
"os" "os"
) )
func Panicf(s string, args ...interface{}) {
panic(fmt.Sprintf(s, args...))
}
func Exitf(s string, args ...interface{}) {
fmt.Printf(s+"\n", args...)
func Exit(s string) {
fmt.Printf(s)
os.Exit(1) os.Exit(1)
} }

+ 7
- 0
common/string.go View File

@ -0,0 +1,7 @@
package common
import (
"fmt"
)
var Fmt = fmt.Sprintf

+ 2
- 2
config/config.go View File

@ -151,11 +151,11 @@ func ParseFlags(args []string) {
Config = ConfigType{} Config = ConfigType{}
err = json.Unmarshal(configBytes, &Config) err = json.Unmarshal(configBytes, &Config)
if err != nil { if err != nil {
Exitf("Invalid configuration file %s: %v", configFile, err)
Exit(Fmt("Invalid configuration file %s: %v", configFile, err))
} }
err = Config.validate() err = Config.validate()
if err != nil { if err != nil {
Exitf("Invalid configuration file %s: %v", configFile, err)
Exit(Fmt("Invalid configuration file %s: %v", configFile, err))
} }
// try to parse arg flags, which can override file configuration. // try to parse arg flags, which can override file configuration.


+ 2
- 6
consensus/log.go View File

@ -1,11 +1,7 @@
package consensus package consensus
import ( import (
"github.com/op/go-logging"
"gopkg.in/inconshreveable/log15.v2"
) )
var log = logging.MustGetLogger("consensus")
func SetConsensusLogger(l *logging.Logger) {
log = l
}
var log = log15.New("module", "consensus")

+ 7
- 9
consensus/reactor.go View File

@ -113,12 +113,10 @@ func (conR *ConsensusReactor) Receive(chId byte, peer *p2p.Peer, msgBytes []byte
ps := peer.Data.Get(peerStateKey).(*PeerState) ps := peer.Data.Get(peerStateKey).(*PeerState)
_, msg_, err := DecodeMessage(msgBytes) _, msg_, err := DecodeMessage(msgBytes)
if err != nil { if err != nil {
log.Warning("[%X] RECEIVE %v: %v ERROR: %v", chId, peer.Connection().RemoteAddress, msg_, err)
log.Warning("[%X] RECEIVE BYTES: %X", chId, msgBytes)
log.Warn("Error decoding message", "channel", chId, "peer", peer, "msg", msg_, "error", err, "bytes", msgBytes)
return return
} }
log.Debug("[%X] RECEIVE %v: %v", chId, peer.Connection().RemoteAddress, msg_)
log.Debug("[%X] RECEIVE BYTES: %X", chId, msgBytes)
log.Debug("RECEIVE", "channel", chId, "peer", peer, "msg", msg_, "bytes", msgBytes)
switch chId { switch chId {
case StateCh: case StateCh:
@ -175,7 +173,7 @@ func (conR *ConsensusReactor) Receive(chId byte, peer *p2p.Peer, msgBytes []byte
added, index, err := conR.conS.AddVote(address, vote) added, index, err := conR.conS.AddVote(address, vote)
if err != nil { if err != nil {
// Probably an invalid signature. Bad peer. // Probably an invalid signature. Bad peer.
log.Warning("Error attempting to add vote: %v", err)
log.Warn(Fmt("Error attempting to add vote: %v", err))
} }
// Initialize Prevotes/Precommits/Commits if needed // Initialize Prevotes/Precommits/Commits if needed
ps.EnsureVoteBitArrays(rs.Height, rs.Validators.Size()) ps.EnsureVoteBitArrays(rs.Height, rs.Validators.Size())
@ -198,7 +196,7 @@ func (conR *ConsensusReactor) Receive(chId byte, peer *p2p.Peer, msgBytes []byte
} }
if err != nil { if err != nil {
log.Warning("Error in Receive(): %v", err)
log.Warn(Fmt("Error in Receive(): %v", err))
} }
} }
@ -254,7 +252,7 @@ OUTER_LOOP:
for { for {
// Manage disconnects from self or peer. // Manage disconnects from self or peer.
if peer.IsStopped() || conR.IsStopped() { if peer.IsStopped() || conR.IsStopped() {
log.Info("Stopping gossipDataRoutine for %v.", peer)
log.Info(Fmt("Stopping gossipDataRoutine for %v.", peer))
return return
} }
rs := conR.conS.GetRoundState() rs := conR.conS.GetRoundState()
@ -319,7 +317,7 @@ OUTER_LOOP:
for { for {
// Manage disconnects from self or peer. // Manage disconnects from self or peer.
if peer.IsStopped() || conR.IsStopped() { if peer.IsStopped() || conR.IsStopped() {
log.Info("Stopping gossipVotesRoutine for %v.", peer)
log.Info(Fmt("Stopping gossipVotesRoutine for %v.", peer))
return return
} }
rs := conR.conS.GetRoundState() rs := conR.conS.GetRoundState()
@ -641,7 +639,7 @@ const (
// TODO: check for unnecessary extra bytes at the end. // TODO: check for unnecessary extra bytes at the end.
func DecodeMessage(bz []byte) (msgType byte, msg interface{}, err error) { func DecodeMessage(bz []byte) (msgType byte, msg interface{}, err error) {
n := new(int64) n := new(int64)
// log.Debug("decoding msg bytes: %X", bz)
// log.Debug(Fmt("decoding msg bytes: %X", bz))
msgType = bz[0] msgType = bz[0]
r := bytes.NewReader(bz) r := bytes.NewReader(bz)
switch msgType { switch msgType {


+ 19
- 19
consensus/state.go View File

@ -253,7 +253,7 @@ func (cs *ConsensusState) stepTransitionRoutine() {
// we're running in a separate goroutine, which avoids deadlocks. // we're running in a separate goroutine, which avoids deadlocks.
rs := cs.getRoundState() rs := cs.getRoundState()
round, roundStartTime, roundDuration, _, elapsedRatio := calcRoundInfo(rs.StartTime) round, roundStartTime, roundDuration, _, elapsedRatio := calcRoundInfo(rs.StartTime)
log.Debug("Called scheduleNextAction. round:%v roundStartTime:%v elapsedRatio:%v", round, roundStartTime, elapsedRatio)
log.Debug("Scheduling next action", "round", round, "roundStartTime", roundStartTime, "elapsedRatio", elapsedRatio)
switch rs.Step { switch rs.Step {
case RoundStepNewHeight: case RoundStepNewHeight:
// We should run RoundActionPropose when rs.StartTime passes. // We should run RoundActionPropose when rs.StartTime passes.
@ -306,7 +306,7 @@ ACTION_LOOP:
height, round, action := roundAction.Height, roundAction.Round, roundAction.Action height, round, action := roundAction.Height, roundAction.Round, roundAction.Action
rs := cs.GetRoundState() rs := cs.GetRoundState()
log.Info("Running round action A:%X %v", action, rs.StringShort())
log.Info("Running round action", "action", action, "height", rs.Height, "round", rs.Round, "step", rs.Step, "startTime", rs.StartTime)
// Continue if action is not relevant // Continue if action is not relevant
if height != rs.Height { if height != rs.Height {
@ -394,8 +394,8 @@ ACTION_LOOP:
func (cs *ConsensusState) updateToState(state *state.State) { func (cs *ConsensusState) updateToState(state *state.State) {
// Sanity check state. // Sanity check state.
if cs.Height > 0 && cs.Height != state.LastBlockHeight { if cs.Height > 0 && cs.Height != state.LastBlockHeight {
Panicf("updateToState() expected state height of %v but found %v",
cs.Height, state.LastBlockHeight)
panic(Fmt("updateToState() expected state height of %v but found %v",
cs.Height, state.LastBlockHeight))
} }
// Reset fields based on state. // Reset fields based on state.
@ -586,7 +586,7 @@ func (cs *ConsensusState) RunActionPrevote(height uint, round uint) {
cs.mtx.Lock() cs.mtx.Lock()
defer cs.mtx.Unlock() defer cs.mtx.Unlock()
if cs.Height != height || cs.Round != round { if cs.Height != height || cs.Round != round {
Panicf("RunActionPrevote(%v/%v), expected %v/%v", height, round, cs.Height, cs.Round)
panic(Fmt("RunActionPrevote(%v/%v), expected %v/%v", height, round, cs.Height, cs.Round))
} }
defer func() { defer func() {
cs.Step = RoundStepPrevote cs.Step = RoundStepPrevote
@ -601,7 +601,7 @@ func (cs *ConsensusState) RunActionPrevote(height uint, round uint) {
// If ProposalBlock is nil, prevote nil. // If ProposalBlock is nil, prevote nil.
if cs.ProposalBlock == nil { if cs.ProposalBlock == nil {
log.Warning("ProposalBlock is nil")
log.Warn("ProposalBlock is nil")
cs.signAddVote(VoteTypePrevote, nil, PartSetHeader{}) cs.signAddVote(VoteTypePrevote, nil, PartSetHeader{})
return return
} }
@ -610,7 +610,7 @@ func (cs *ConsensusState) RunActionPrevote(height uint, round uint) {
err := cs.stageBlock(cs.ProposalBlock, cs.ProposalBlockParts) err := cs.stageBlock(cs.ProposalBlock, cs.ProposalBlockParts)
if err != nil { if err != nil {
// ProposalBlock is invalid, prevote nil. // ProposalBlock is invalid, prevote nil.
log.Warning("ProposalBlock is invalid: %v", err)
log.Warn(Fmt("ProposalBlock is invalid: %v", err))
cs.signAddVote(VoteTypePrevote, nil, PartSetHeader{}) cs.signAddVote(VoteTypePrevote, nil, PartSetHeader{})
return return
} }
@ -626,7 +626,7 @@ func (cs *ConsensusState) RunActionPrecommit(height uint, round uint) {
cs.mtx.Lock() cs.mtx.Lock()
defer cs.mtx.Unlock() defer cs.mtx.Unlock()
if cs.Height != height || cs.Round != round { if cs.Height != height || cs.Round != round {
Panicf("RunActionPrecommit(%v/%v), expected %v/%v", height, round, cs.Height, cs.Round)
panic(Fmt("RunActionPrecommit(%v/%v), expected %v/%v", height, round, cs.Height, cs.Round))
} }
defer func() { defer func() {
cs.Step = RoundStepPrecommit cs.Step = RoundStepPrecommit
@ -661,7 +661,7 @@ func (cs *ConsensusState) RunActionPrecommit(height uint, round uint) {
// Validate the block. // Validate the block.
if err := cs.stageBlock(cs.ProposalBlock, cs.ProposalBlockParts); err != nil { if err := cs.stageBlock(cs.ProposalBlock, cs.ProposalBlockParts); err != nil {
// Prevent zombies. // Prevent zombies.
log.Warning("+2/3 prevoted for an invalid block: %v", err)
log.Warn(Fmt("+2/3 prevoted for an invalid block: %v", err))
return return
} }
cs.LockedBlock = cs.ProposalBlock cs.LockedBlock = cs.ProposalBlock
@ -686,7 +686,7 @@ func (cs *ConsensusState) RunActionCommit(height uint) {
cs.mtx.Lock() cs.mtx.Lock()
defer cs.mtx.Unlock() defer cs.mtx.Unlock()
if cs.Height != height { if cs.Height != height {
Panicf("RunActionCommit(%v), expected %v", height, cs.Height)
panic(Fmt("RunActionCommit(%v), expected %v", height, cs.Height))
} }
defer func() { defer func() {
cs.Step = RoundStepCommit cs.Step = RoundStepCommit
@ -745,7 +745,7 @@ func (cs *ConsensusState) TryFinalizeCommit(height uint) bool {
defer cs.mtx.Unlock() defer cs.mtx.Unlock()
if cs.Height != height { if cs.Height != height {
Panicf("TryFinalizeCommit(%v), expected %v", height, cs.Height)
panic(Fmt("TryFinalizeCommit(%v), expected %v", height, cs.Height))
} }
if cs.Step == RoundStepCommit && if cs.Step == RoundStepCommit &&
@ -754,19 +754,19 @@ func (cs *ConsensusState) TryFinalizeCommit(height uint) bool {
// Sanity check // Sanity check
if cs.ProposalBlock == nil { if cs.ProposalBlock == nil {
Panicf("Expected ProposalBlock to exist")
panic(Fmt("Expected ProposalBlock to exist"))
} }
hash, header, _ := cs.Commits.TwoThirdsMajority() hash, header, _ := cs.Commits.TwoThirdsMajority()
if !cs.ProposalBlock.HashesTo(hash) { if !cs.ProposalBlock.HashesTo(hash) {
Panicf("Expected ProposalBlock to hash to commit hash")
panic(Fmt("Expected ProposalBlock to hash to commit hash"))
} }
if !cs.ProposalBlockParts.HasHeader(header) { if !cs.ProposalBlockParts.HasHeader(header) {
Panicf("Expected ProposalBlockParts header to be commit header")
panic(Fmt("Expected ProposalBlockParts header to be commit header"))
} }
err := cs.stageBlock(cs.ProposalBlock, cs.ProposalBlockParts) err := cs.stageBlock(cs.ProposalBlock, cs.ProposalBlockParts)
if err == nil { if err == nil {
log.Debug("Finalizing commit of block: %v", cs.ProposalBlock)
log.Debug(Fmt("Finalizing commit of block: %v", cs.ProposalBlock))
// Increment height. // Increment height.
cs.updateToState(cs.stagedState) cs.updateToState(cs.stagedState)
// cs.Step is now RoundStepNewHeight or RoundStepNewRound // cs.Step is now RoundStepNewHeight or RoundStepNewRound
@ -775,7 +775,7 @@ func (cs *ConsensusState) TryFinalizeCommit(height uint) bool {
} else { } else {
// Prevent zombies. // Prevent zombies.
// TODO: Does this ever happen? // TODO: Does this ever happen?
Panicf("+2/3 committed an invalid block: %v", err)
panic(Fmt("+2/3 committed an invalid block: %v", err))
} }
} }
return false return false
@ -910,7 +910,7 @@ func (cs *ConsensusState) addVote(address []byte, vote *Vote) (added bool, index
added, index, err = cs.Commits.Add(address, vote) added, index, err = cs.Commits.Add(address, vote)
if added && cs.Commits.HasTwoThirdsMajority() && cs.CommitTime.IsZero() { if added && cs.Commits.HasTwoThirdsMajority() && cs.CommitTime.IsZero() {
cs.CommitTime = time.Now() cs.CommitTime = time.Now()
log.Debug("Set CommitTime to %v", cs.CommitTime)
log.Debug(Fmt("Set CommitTime to %v", cs.CommitTime))
if cs.Step < RoundStepCommit { if cs.Step < RoundStepCommit {
cs.queueAction(RoundAction{cs.Height, cs.Round, RoundActionCommit}) cs.queueAction(RoundAction{cs.Height, cs.Round, RoundActionCommit})
} else { } else {
@ -974,7 +974,7 @@ func (cs *ConsensusState) saveCommitVoteBlock(block *Block, blockParts *PartSet)
// The proposal must be valid. // The proposal must be valid.
if err := cs.stageBlock(block, blockParts); err != nil { if err := cs.stageBlock(block, blockParts); err != nil {
// Prevent zombies. // Prevent zombies.
log.Warning("+2/3 precommitted an invalid block: %v", err)
log.Warn(Fmt("+2/3 precommitted an invalid block: %v", err))
return return
} }
@ -1022,7 +1022,7 @@ func calcRound(startTime time.Time) uint {
panic("Could not calc round, should not happen") panic("Could not calc round, should not happen")
} }
if R > math.MaxInt32 { if R > math.MaxInt32 {
Panicf("Could not calc round, round overflow: %v", R)
panic(Fmt("Could not calc round, round overflow: %v", R))
} }
if R < 0 { if R < 0 {
return 0 return 0


+ 0
- 1
consensus/vote_set.go View File

@ -9,7 +9,6 @@ import (
. "github.com/tendermint/tendermint/account" . "github.com/tendermint/tendermint/account"
. "github.com/tendermint/tendermint/binary" . "github.com/tendermint/tendermint/binary"
. "github.com/tendermint/tendermint/block" . "github.com/tendermint/tendermint/block"
. "github.com/tendermint/tendermint/common"
"github.com/tendermint/tendermint/state" "github.com/tendermint/tendermint/state"
) )


+ 2
- 6
mempool/log.go View File

@ -1,11 +1,7 @@
package mempool package mempool
import ( import (
"github.com/op/go-logging"
"gopkg.in/inconshreveable/log15.v2"
) )
var log = logging.MustGetLogger("mempool")
func SetMempoolLogger(l *logging.Logger) {
log = l
}
var log = log15.New("module", "mempool")

+ 5
- 4
mempool/reactor.go View File

@ -7,6 +7,7 @@ import (
. "github.com/tendermint/tendermint/binary" . "github.com/tendermint/tendermint/binary"
. "github.com/tendermint/tendermint/block" . "github.com/tendermint/tendermint/block"
. "github.com/tendermint/tendermint/common"
"github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/p2p"
) )
@ -70,10 +71,10 @@ func (pexR *MempoolReactor) RemovePeer(peer *p2p.Peer, reason interface{}) {
func (memR *MempoolReactor) Receive(chId byte, src *p2p.Peer, msgBytes []byte) { func (memR *MempoolReactor) Receive(chId byte, src *p2p.Peer, msgBytes []byte) {
_, msg_, err := DecodeMessage(msgBytes) _, msg_, err := DecodeMessage(msgBytes)
if err != nil { if err != nil {
log.Warning("Error decoding message: %v", err)
log.Warn(Fmt("Error decoding message: %v", err))
return return
} }
log.Info("MempoolReactor received %v", msg_)
log.Info(Fmt("MempoolReactor received %v", msg_))
switch msg_.(type) { switch msg_.(type) {
case *TxMessage: case *TxMessage:
@ -81,10 +82,10 @@ func (memR *MempoolReactor) Receive(chId byte, src *p2p.Peer, msgBytes []byte) {
err := memR.Mempool.AddTx(msg.Tx) err := memR.Mempool.AddTx(msg.Tx)
if err != nil { if err != nil {
// Bad, seen, or conflicting tx. // Bad, seen, or conflicting tx.
log.Debug("Could not add tx %v", msg.Tx)
log.Debug(Fmt("Could not add tx %v", msg.Tx))
return return
} else { } else {
log.Debug("Added valid tx %V", msg.Tx)
log.Debug(Fmt("Added valid tx %V", msg.Tx))
} }
// Share tx. // Share tx.
// We use a simple shotgun approach for now. // We use a simple shotgun approach for now.


+ 15
- 15
p2p/addrbook.go View File

@ -327,7 +327,7 @@ func (a *AddrBook) saveToFile(filePath string) {
jsonBytes, err := json.MarshalIndent(aJSON, "", "\t") jsonBytes, err := json.MarshalIndent(aJSON, "", "\t")
_, err = w.Write(jsonBytes) _, err = w.Write(jsonBytes)
if err != nil { if err != nil {
log.Error("Failed to save AddrBook to file %v: %v", filePath, err)
log.Error(Fmt("Failed to save AddrBook to file %v: %v", filePath, err))
} }
} }
@ -377,7 +377,7 @@ out:
for { for {
select { select {
case <-dumpAddressTicker.C: case <-dumpAddressTicker.C:
log.Debug("Saving book to file (%v)", a.Size())
log.Debug(Fmt("Saving book to file (%v)", a.Size()))
a.saveToFile(a.filePath) a.saveToFile(a.filePath)
case <-a.quit: case <-a.quit:
break out break out
@ -405,7 +405,7 @@ func (a *AddrBook) getBucket(bucketType byte, bucketIdx int) map[string]*knownAd
func (a *AddrBook) addToNewBucket(ka *knownAddress, bucketIdx int) bool { func (a *AddrBook) addToNewBucket(ka *knownAddress, bucketIdx int) bool {
// Sanity check // Sanity check
if ka.isOld() { if ka.isOld() {
log.Warning("Cannot add address already in old bucket to a new bucket: %v", ka)
log.Warn(Fmt("Cannot add address already in old bucket to a new bucket: %v", ka))
return false return false
} }
@ -439,11 +439,11 @@ func (a *AddrBook) addToNewBucket(ka *knownAddress, bucketIdx int) bool {
func (a *AddrBook) addToOldBucket(ka *knownAddress, bucketIdx int) bool { func (a *AddrBook) addToOldBucket(ka *knownAddress, bucketIdx int) bool {
// Sanity check // Sanity check
if ka.isNew() { if ka.isNew() {
log.Warning("Cannot add new address to old bucket: %v", ka)
log.Warn(Fmt("Cannot add new address to old bucket: %v", ka))
return false return false
} }
if len(ka.Buckets) != 0 { if len(ka.Buckets) != 0 {
log.Warning("Cannot add already old address to another old bucket: %v", ka)
log.Warn(Fmt("Cannot add already old address to another old bucket: %v", ka))
return false return false
} }
@ -474,7 +474,7 @@ func (a *AddrBook) addToOldBucket(ka *knownAddress, bucketIdx int) bool {
func (a *AddrBook) removeFromBucket(ka *knownAddress, bucketType byte, bucketIdx int) { func (a *AddrBook) removeFromBucket(ka *knownAddress, bucketType byte, bucketIdx int) {
if ka.BucketType != bucketType { if ka.BucketType != bucketType {
log.Warning("Bucket type mismatch: %v", ka)
log.Warn(Fmt("Bucket type mismatch: %v", ka))
return return
} }
bucket := a.getBucket(bucketType, bucketIdx) bucket := a.getBucket(bucketType, bucketIdx)
@ -516,7 +516,7 @@ func (a *AddrBook) pickOldest(bucketType byte, bucketIdx int) *knownAddress {
func (a *AddrBook) addAddress(addr, src *NetAddress) { func (a *AddrBook) addAddress(addr, src *NetAddress) {
if !addr.Routable() { if !addr.Routable() {
log.Warning("Cannot add non-routable address %v", addr)
log.Warn(Fmt("Cannot add non-routable address %v", addr))
return return
} }
if _, ok := a.ourAddrs[addr.String()]; ok { if _, ok := a.ourAddrs[addr.String()]; ok {
@ -547,7 +547,7 @@ func (a *AddrBook) addAddress(addr, src *NetAddress) {
bucket := a.calcNewBucket(addr, src) bucket := a.calcNewBucket(addr, src)
a.addToNewBucket(ka, bucket) a.addToNewBucket(ka, bucket)
log.Info("Added new address %s for a total of %d addresses", addr, a.size())
log.Info(Fmt("Added new address %s for a total of %d addresses", addr, a.size()))
} }
// Make space in the new buckets by expiring the really bad entries. // Make space in the new buckets by expiring the really bad entries.
@ -556,7 +556,7 @@ func (a *AddrBook) expireNew(bucketIdx int) {
for addrStr, ka := range a.addrNew[bucketIdx] { for addrStr, ka := range a.addrNew[bucketIdx] {
// If an entry is bad, throw it away // If an entry is bad, throw it away
if ka.isBad() { if ka.isBad() {
log.Info("expiring bad address %v", addrStr)
log.Info(Fmt("expiring bad address %v", addrStr))
a.removeFromBucket(ka, bucketTypeNew, bucketIdx) a.removeFromBucket(ka, bucketTypeNew, bucketIdx)
return return
} }
@ -573,11 +573,11 @@ func (a *AddrBook) expireNew(bucketIdx int) {
func (a *AddrBook) moveToOld(ka *knownAddress) { func (a *AddrBook) moveToOld(ka *knownAddress) {
// Sanity check // Sanity check
if ka.isOld() { if ka.isOld() {
log.Warning("Cannot promote address that is already old %v", ka)
log.Warn(Fmt("Cannot promote address that is already old %v", ka))
return return
} }
if len(ka.Buckets) == 0 { if len(ka.Buckets) == 0 {
log.Warning("Cannot promote address that isn't in any new buckets %v", ka)
log.Warn(Fmt("Cannot promote address that isn't in any new buckets %v", ka))
return return
} }
@ -602,13 +602,13 @@ func (a *AddrBook) moveToOld(ka *knownAddress) {
if !added { if !added {
added := a.addToNewBucket(oldest, freedBucket) added := a.addToNewBucket(oldest, freedBucket)
if !added { if !added {
log.Warning("Could not migrate oldest %v to freedBucket %v", oldest, freedBucket)
log.Warn(Fmt("Could not migrate oldest %v to freedBucket %v", oldest, freedBucket))
} }
} }
// Finally, add to bucket again. // Finally, add to bucket again.
added = a.addToOldBucket(ka, oldBucketIdx) added = a.addToOldBucket(ka, oldBucketIdx)
if !added { if !added {
log.Warning("Could not re-add ka %v to oldBucketIdx %v", ka, oldBucketIdx)
log.Warn(Fmt("Could not re-add ka %v to oldBucketIdx %v", ka, oldBucketIdx))
} }
} }
} }
@ -755,7 +755,7 @@ func (ka *knownAddress) markGood() {
func (ka *knownAddress) addBucketRef(bucketIdx int) int { func (ka *knownAddress) addBucketRef(bucketIdx int) int {
for _, bucket := range ka.Buckets { for _, bucket := range ka.Buckets {
if bucket == bucketIdx { if bucket == bucketIdx {
log.Warning("Bucket already exists in ka.Buckets: %v", ka)
log.Warn(Fmt("Bucket already exists in ka.Buckets: %v", ka))
return -1 return -1
} }
} }
@ -771,7 +771,7 @@ func (ka *knownAddress) removeBucketRef(bucketIdx int) int {
} }
} }
if len(buckets) != len(ka.Buckets)-1 { if len(buckets) != len(ka.Buckets)-1 {
log.Warning("bucketIdx not found in ka.Buckets: %v", ka)
log.Warn(Fmt("bucketIdx not found in ka.Buckets: %v", ka))
return -1 return -1
} }
ka.Buckets = buckets ka.Buckets = buckets


+ 21
- 20
p2p/connection.go View File

@ -11,9 +11,9 @@ import (
"time" "time"
flow "code.google.com/p/mxk/go1/flowcontrol" flow "code.google.com/p/mxk/go1/flowcontrol"
"github.com/op/go-logging"
. "github.com/tendermint/tendermint/binary" . "github.com/tendermint/tendermint/binary"
. "github.com/tendermint/tendermint/common" . "github.com/tendermint/tendermint/common"
"gopkg.in/inconshreveable/log15.v2"
) )
const ( const (
@ -123,7 +123,7 @@ func NewMConnection(conn net.Conn, chDescs []*ChannelDescriptor, onReceive recei
// .Start() begins multiplexing packets to and from "channels". // .Start() begins multiplexing packets to and from "channels".
func (c *MConnection) Start() { func (c *MConnection) Start() {
if atomic.CompareAndSwapUint32(&c.started, 0, 1) { if atomic.CompareAndSwapUint32(&c.started, 0, 1) {
log.Debug("Starting %v", c)
log.Debug(Fmt("Starting %v", c))
go c.sendRoutine() go c.sendRoutine()
go c.recvRoutine() go c.recvRoutine()
} }
@ -131,7 +131,7 @@ func (c *MConnection) Start() {
func (c *MConnection) Stop() { func (c *MConnection) Stop() {
if atomic.CompareAndSwapUint32(&c.stopped, 0, 1) { if atomic.CompareAndSwapUint32(&c.stopped, 0, 1) {
log.Debug("Stopping %v", c)
log.Debug(Fmt("Stopping %v", c))
close(c.quit) close(c.quit)
c.conn.Close() c.conn.Close()
c.flushTimer.Stop() c.flushTimer.Stop()
@ -153,7 +153,7 @@ func (c *MConnection) flush() {
err := c.bufWriter.Flush() err := c.bufWriter.Flush()
if err != nil { if err != nil {
if atomic.LoadUint32(&c.stopped) != 1 { if atomic.LoadUint32(&c.stopped) != 1 {
log.Warning("MConnection flush failed: %v", err)
log.Warn(Fmt("MConnection flush failed: %v", err))
} }
} }
} }
@ -182,13 +182,12 @@ func (c *MConnection) Send(chId byte, msg interface{}) bool {
return false return false
} }
log.Debug("[%X] SEND %v: %v", chId, c.RemoteAddress, msg)
log.Debug(" Bytes: %X", BinaryBytes(msg))
log.Debug("Send", "channel", chId, "connection", c, "msg", msg, "bytes", BinaryBytes(msg))
// Send message to channel. // Send message to channel.
channel, ok := c.channelsIdx[chId] channel, ok := c.channelsIdx[chId]
if !ok { if !ok {
log.Error("Cannot send bytes, unknown channel %X", chId)
log.Error(Fmt("Cannot send bytes, unknown channel %X", chId))
return false return false
} }
@ -210,12 +209,12 @@ func (c *MConnection) TrySend(chId byte, msg interface{}) bool {
return false return false
} }
log.Debug("[%X] TRYSEND %v: %v", chId, c.RemoteAddress, msg)
log.Debug(Fmt("[%X] TRYSEND %v: %v", chId, c.RemoteAddress, msg))
// Send message to channel. // Send message to channel.
channel, ok := c.channelsIdx[chId] channel, ok := c.channelsIdx[chId]
if !ok { if !ok {
log.Error("Cannot send bytes, unknown channel %X", chId)
log.Error(Fmt("Cannot send bytes, unknown channel %X", chId))
return false return false
} }
@ -238,7 +237,7 @@ func (c *MConnection) CanSend(chId byte) bool {
channel, ok := c.channelsIdx[chId] channel, ok := c.channelsIdx[chId]
if !ok { if !ok {
log.Error("Unknown channel %X", chId)
log.Error(Fmt("Unknown channel %X", chId))
return false return false
} }
return channel.canSend() return channel.canSend()
@ -287,7 +286,7 @@ FOR_LOOP:
break FOR_LOOP break FOR_LOOP
} }
if err != nil { if err != nil {
log.Warning("%v failed @ sendRoutine:\n%v", c, err)
log.Warn(Fmt("%v failed @ sendRoutine:\n%v", c, err))
c.Stop() c.Stop()
break FOR_LOOP break FOR_LOOP
} }
@ -342,7 +341,7 @@ func (c *MConnection) sendMsgPacket() bool {
// Make & send a msgPacket from this channel // Make & send a msgPacket from this channel
n, err := leastChannel.writeMsgPacketTo(c.bufWriter) n, err := leastChannel.writeMsgPacketTo(c.bufWriter)
if err != nil { if err != nil {
log.Warning("Failed to write msgPacket. Error: %v", err)
log.Warn(Fmt("Failed to write msgPacket. Error: %v", err))
c.stopForError(err) c.stopForError(err)
return true return true
} }
@ -369,20 +368,22 @@ FOR_LOOP:
c.recvMonitor.Update(int(n)) c.recvMonitor.Update(int(n))
if err != nil { if err != nil {
if atomic.LoadUint32(&c.stopped) != 1 { if atomic.LoadUint32(&c.stopped) != 1 {
log.Warning("%v failed @ recvRoutine with err: %v", c, err)
log.Warn(Fmt("%v failed @ recvRoutine with err: %v", c, err))
c.Stop() c.Stop()
} }
break FOR_LOOP break FOR_LOOP
} }
// Peek into bufReader for debugging // Peek into bufReader for debugging
if log.IsEnabledFor(logging.DEBUG) {
log.Debug("%v", log15.Lazy{func() string {
numBytes := c.bufReader.Buffered() numBytes := c.bufReader.Buffered()
bytes, err := c.bufReader.Peek(MinInt(numBytes, 100)) bytes, err := c.bufReader.Peek(MinInt(numBytes, 100))
if err == nil { if err == nil {
log.Debug("recvRoutine packet type %X, peeked: %X", pktType, bytes)
return fmt.Sprintf("recvRoutine packet type %X, peeked: %X", pktType, bytes)
} else {
return fmt.Sprintf("recvRoutine error: %v", err)
} }
}
}})
// Read more depending on packet type. // Read more depending on packet type.
switch pktType { switch pktType {
@ -397,22 +398,22 @@ FOR_LOOP:
c.recvMonitor.Update(int(*n)) c.recvMonitor.Update(int(*n))
if *err != nil { if *err != nil {
if atomic.LoadUint32(&c.stopped) != 1 { if atomic.LoadUint32(&c.stopped) != 1 {
log.Warning("%v failed @ recvRoutine", c)
log.Warn(Fmt("%v failed @ recvRoutine", c))
c.Stop() c.Stop()
} }
break FOR_LOOP break FOR_LOOP
} }
channel, ok := c.channelsIdx[pkt.ChannelId] channel, ok := c.channelsIdx[pkt.ChannelId]
if !ok || channel == nil { if !ok || channel == nil {
Panicf("Unknown channel %X", pkt.ChannelId)
panic(Fmt("Unknown channel %X", pkt.ChannelId))
} }
msgBytes := channel.recvMsgPacket(pkt) msgBytes := channel.recvMsgPacket(pkt)
log.Warning("RECEIVE_MSG_BYTES: %X", msgBytes)
log.Warn(Fmt("RECEIVE_MSG_BYTES: %X", msgBytes))
if msgBytes != nil { if msgBytes != nil {
c.onReceive(pkt.ChannelId, msgBytes) c.onReceive(pkt.ChannelId, msgBytes)
} }
default: default:
Panicf("Unknown message type %X", pktType)
panic(Fmt("Unknown message type %X", pktType))
} }
// TODO: shouldn't this go in the sendRoutine? // TODO: shouldn't this go in the sendRoutine?


+ 7
- 7
p2p/listener.go View File

@ -52,7 +52,7 @@ func NewDefaultListener(protocol string, lAddr string, requireUPNPHairpin bool)
} }
// Actual listener local IP & port // Actual listener local IP & port
listenerIP, listenerPort := splitHostPort(listener.Addr().String()) listenerIP, listenerPort := splitHostPort(listener.Addr().String())
log.Debug("Local listener: %v:%v", listenerIP, listenerPort)
log.Debug("Local listener", "ip", listenerIP, "port", listenerPort)
// Determine external address... // Determine external address...
var extAddr *NetAddress var extAddr *NetAddress
@ -62,7 +62,7 @@ func NewDefaultListener(protocol string, lAddr string, requireUPNPHairpin bool)
if requireUPNPHairpin { if requireUPNPHairpin {
upnpCapabilities, err := upnp.Probe() upnpCapabilities, err := upnp.Probe()
if err != nil { if err != nil {
log.Warning("Failed to probe UPNP: %v", err)
log.Warn("Failed to probe UPNP", "error", err)
goto SKIP_UPNP goto SKIP_UPNP
} }
if !upnpCapabilities.Hairpin { if !upnpCapabilities.Hairpin {
@ -144,13 +144,13 @@ func getUPNPExternalAddress(externalPort, internalPort int) *NetAddress {
log.Debug("Getting UPNP external address") log.Debug("Getting UPNP external address")
nat, err := upnp.Discover() nat, err := upnp.Discover()
if err != nil { if err != nil {
log.Debug("Could not get UPNP extrernal address: %v", err)
log.Debug("Could not get UPNP extrernal address", "error", err)
return nil return nil
} }
ext, err := nat.GetExternalAddress() ext, err := nat.GetExternalAddress()
if err != nil { if err != nil {
log.Debug("Could not get UPNP external address: %v", err)
log.Debug("Could not get UPNP external address", "error", err)
return nil return nil
} }
@ -161,11 +161,11 @@ func getUPNPExternalAddress(externalPort, internalPort int) *NetAddress {
externalPort, err = nat.AddPortMapping("tcp", externalPort, internalPort, "tendermint", 0) externalPort, err = nat.AddPortMapping("tcp", externalPort, internalPort, "tendermint", 0)
if err != nil { if err != nil {
log.Debug("Could not get UPNP external address: %v", err)
log.Debug("Could not get UPNP external address", "error", err)
return nil return nil
} }
log.Debug("Got UPNP external address: %v", ext)
log.Debug("Got UPNP external address", "address", ext)
return NewNetAddressIPPort(ext, uint16(externalPort)) return NewNetAddressIPPort(ext, uint16(externalPort))
} }
@ -173,7 +173,7 @@ func getUPNPExternalAddress(externalPort, internalPort int) *NetAddress {
func getNaiveExternalAddress(port int) *NetAddress { func getNaiveExternalAddress(port int) *NetAddress {
addrs, err := net.InterfaceAddrs() addrs, err := net.InterfaceAddrs()
if err != nil { if err != nil {
Panicf("Unexpected error fetching interface addresses: %v", err)
panic(Fmt("Could not fetch interface addresses: %v", err))
} }
for _, a := range addrs { for _, a := range addrs {


+ 2
- 6
p2p/log.go View File

@ -1,11 +1,7 @@
package p2p package p2p
import ( import (
"github.com/op/go-logging"
"gopkg.in/inconshreveable/log15.v2"
) )
var log = logging.MustGetLogger("p2p")
func SetP2PLogger(l *logging.Logger) {
log = l
}
var log = log15.New("module", "p2p")

+ 3
- 3
p2p/peer.go View File

@ -25,7 +25,7 @@ func newPeer(conn net.Conn, outbound bool, reactorsByCh map[byte]Reactor, chDesc
onReceive := func(chId byte, msgBytes []byte) { onReceive := func(chId byte, msgBytes []byte) {
reactor := reactorsByCh[chId] reactor := reactorsByCh[chId]
if reactor == nil { if reactor == nil {
Panicf("Unknown channel %X", chId)
panic(Fmt("Unknown channel %X", chId))
} }
reactor.Receive(chId, p, msgBytes) reactor.Receive(chId, p, msgBytes)
} }
@ -46,14 +46,14 @@ func newPeer(conn net.Conn, outbound bool, reactorsByCh map[byte]Reactor, chDesc
func (p *Peer) start() { func (p *Peer) start() {
if atomic.CompareAndSwapUint32(&p.started, 0, 1) { if atomic.CompareAndSwapUint32(&p.started, 0, 1) {
log.Debug("Starting %v", p)
log.Debug(Fmt("Starting %v", p))
p.mconn.Start() p.mconn.Start()
} }
} }
func (p *Peer) stop() { func (p *Peer) stop() {
if atomic.CompareAndSwapUint32(&p.stopped, 0, 1) { if atomic.CompareAndSwapUint32(&p.stopped, 0, 1) {
log.Debug("Stopping %v", p)
log.Debug(Fmt("Stopping %v", p))
p.mconn.Stop() p.mconn.Stop()
} }
} }


+ 3
- 3
p2p/pex_reactor.go View File

@ -90,10 +90,10 @@ func (pexR *PEXReactor) Receive(chId byte, src *Peer, msgBytes []byte) {
// decode message // decode message
msg, err := DecodeMessage(msgBytes) msg, err := DecodeMessage(msgBytes)
if err != nil { if err != nil {
log.Warning("Error decoding message: %v", err)
log.Warn(Fmt("Error decoding message: %v", err))
return return
} }
log.Info("requestRoutine received %v", msg)
log.Info(Fmt("requestRoutine received %v", msg))
switch msg.(type) { switch msg.(type) {
case *pexRequestMessage: case *pexRequestMessage:
@ -209,7 +209,7 @@ func DecodeMessage(bz []byte) (msg interface{}, err error) {
n := new(int64) n := new(int64)
msgType := bz[0] msgType := bz[0]
r := bytes.NewReader(bz) r := bytes.NewReader(bz)
// log.Debug("decoding msg bytes: %X", bz)
// log.Debug(Fmt("decoding msg bytes: %X", bz))
switch msgType { switch msgType {
case msgTypeRequest: case msgTypeRequest:
msg = &pexRequestMessage{} msg = &pexRequestMessage{}


+ 7
- 7
p2p/switch.go View File

@ -117,9 +117,9 @@ func (sw *Switch) AddPeerWithConnection(conn net.Conn, outbound bool) (*Peer, er
// Add the peer to .peers // Add the peer to .peers
if sw.peers.Add(peer) { if sw.peers.Add(peer) {
log.Info("+ %v", peer)
log.Info(Fmt("+ %v", peer))
} else { } else {
log.Info("Ignoring duplicate: %v", peer)
log.Info(Fmt("Ignoring duplicate: %v", peer))
return nil, ErrSwitchDuplicatePeer return nil, ErrSwitchDuplicatePeer
} }
@ -137,7 +137,7 @@ func (sw *Switch) DialPeerWithAddress(addr *NetAddress) (*Peer, error) {
return nil, ErrSwitchStopped return nil, ErrSwitchStopped
} }
log.Info("Dialing peer @ %v", addr)
log.Info(Fmt("Dialing peer @ %v", addr))
sw.dialing.Set(addr.String(), addr) sw.dialing.Set(addr.String(), addr)
conn, err := addr.DialTimeout(peerDialTimeoutSeconds * time.Second) conn, err := addr.DialTimeout(peerDialTimeoutSeconds * time.Second)
sw.dialing.Delete(addr.String()) sw.dialing.Delete(addr.String())
@ -161,12 +161,12 @@ func (sw *Switch) Broadcast(chId byte, msg interface{}) (numSuccess, numFailure
return return
} }
log.Debug("[%X] BROADCAST: %v", chId, msg)
log.Debug("Broadcast", "channel", chId, "msg", msg)
for _, peer := range sw.peers.List() { for _, peer := range sw.peers.List() {
// XXX XXX Change. // XXX XXX Change.
// success := peer.TrySend(chId, msg) // success := peer.TrySend(chId, msg)
success := peer.Send(chId, msg) success := peer.Send(chId, msg)
log.Debug("[%X] for peer %v success: %v", chId, peer, success)
log.Debug(Fmt("[%X] for peer %v success: %v", chId, peer, success))
if success { if success {
numSuccess += 1 numSuccess += 1
} else { } else {
@ -198,7 +198,7 @@ func (sw *Switch) Peers() IPeerSet {
// Disconnect from a peer due to external error. // Disconnect from a peer due to external error.
// TODO: make record depending on reason. // TODO: make record depending on reason.
func (sw *Switch) StopPeerForError(peer *Peer, reason interface{}) { func (sw *Switch) StopPeerForError(peer *Peer, reason interface{}) {
log.Info("- %v !! reason: %v", peer, reason)
log.Info(Fmt("- %v !! reason: %v", peer, reason))
sw.peers.Remove(peer) sw.peers.Remove(peer)
peer.stop() peer.stop()
@ -209,7 +209,7 @@ func (sw *Switch) StopPeerForError(peer *Peer, reason interface{}) {
// Disconnect from a peer gracefully. // Disconnect from a peer gracefully.
// TODO: handle graceful disconnects. // TODO: handle graceful disconnects.
func (sw *Switch) StopPeerGracefully(peer *Peer) { func (sw *Switch) StopPeerGracefully(peer *Peer) {
log.Info("- %v", peer)
log.Info(Fmt("- %v", peer))
sw.peers.Remove(peer) sw.peers.Remove(peer)
peer.stop() peer.stop()


+ 2
- 1
p2p/switch_test.go View File

@ -7,6 +7,7 @@ import (
"time" "time"
. "github.com/tendermint/tendermint/binary" . "github.com/tendermint/tendermint/binary"
. "github.com/tendermint/tendermint/common"
) )
type PeerMessage struct { type PeerMessage struct {
@ -201,7 +202,7 @@ func BenchmarkSwitches(b *testing.B) {
numFailure += nF numFailure += nF
} }
log.Warning("success: %v, failure: %v", numSuccess, numFailure)
log.Warn(Fmt("success: %v, failure: %v", numSuccess, numFailure))
// Allow everything to flush before stopping switches & closing connections. // Allow everything to flush before stopping switches & closing connections.
b.StopTimer() b.StopTimer()


+ 2
- 6
p2p/upnp/log.go View File

@ -1,11 +1,7 @@
package upnp package upnp
import ( import (
"github.com/op/go-logging"
"gopkg.in/inconshreveable/log15.v2"
) )
var log = logging.MustGetLogger("upnp")
func SetUPNPLogger(l *logging.Logger) {
log = l
}
var log = log15.New("module", "upnp")

+ 13
- 11
p2p/upnp/probe.go View File

@ -5,6 +5,8 @@ import (
"fmt" "fmt"
"net" "net"
"time" "time"
. "github.com/tendermint/tendermint/common"
) )
type UPNPCapabilities struct { type UPNPCapabilities struct {
@ -17,19 +19,19 @@ func makeUPNPListener(intPort int, extPort int) (NAT, net.Listener, net.IP, erro
if err != nil { if err != nil {
return nil, nil, nil, errors.New(fmt.Sprintf("NAT upnp could not be discovered: %v", err)) return nil, nil, nil, errors.New(fmt.Sprintf("NAT upnp could not be discovered: %v", err))
} }
log.Debug("ourIP: %v", nat.(*upnpNAT).ourIP)
log.Debug(Fmt("ourIP: %v", nat.(*upnpNAT).ourIP))
ext, err := nat.GetExternalAddress() ext, err := nat.GetExternalAddress()
if err != nil { if err != nil {
return nat, nil, nil, errors.New(fmt.Sprintf("External address error: %v", err)) return nat, nil, nil, errors.New(fmt.Sprintf("External address error: %v", err))
} }
log.Debug("External address: %v", ext)
log.Debug(Fmt("External address: %v", ext))
port, err := nat.AddPortMapping("tcp", extPort, intPort, "Tendermint UPnP Probe", 0) port, err := nat.AddPortMapping("tcp", extPort, intPort, "Tendermint UPnP Probe", 0)
if err != nil { if err != nil {
return nat, nil, ext, errors.New(fmt.Sprintf("Port mapping error: %v", err)) return nat, nil, ext, errors.New(fmt.Sprintf("Port mapping error: %v", err))
} }
log.Debug("Port mapping mapped: %v", port)
log.Debug(Fmt("Port mapping mapped: %v", port))
// also run the listener, open for all remote addresses. // also run the listener, open for all remote addresses.
listener, err := net.Listen("tcp", fmt.Sprintf(":%v", intPort)) listener, err := net.Listen("tcp", fmt.Sprintf(":%v", intPort))
@ -44,17 +46,17 @@ func testHairpin(listener net.Listener, extAddr string) (supportsHairpin bool) {
go func() { go func() {
inConn, err := listener.Accept() inConn, err := listener.Accept()
if err != nil { if err != nil {
log.Info("Listener.Accept() error: %v", err)
log.Info(Fmt("Listener.Accept() error: %v", err))
return return
} }
log.Debug("Accepted incoming connection: %v -> %v", inConn.LocalAddr(), inConn.RemoteAddr())
log.Debug(Fmt("Accepted incoming connection: %v -> %v", inConn.LocalAddr(), inConn.RemoteAddr()))
buf := make([]byte, 1024) buf := make([]byte, 1024)
n, err := inConn.Read(buf) n, err := inConn.Read(buf)
if err != nil { if err != nil {
log.Info("Incoming connection read error: %v", err)
log.Info(Fmt("Incoming connection read error: %v", err))
return return
} }
log.Debug("Incoming connection read %v bytes: %X", n, buf)
log.Debug(Fmt("Incoming connection read %v bytes: %X", n, buf))
if string(buf) == "test data" { if string(buf) == "test data" {
supportsHairpin = true supportsHairpin = true
return return
@ -64,16 +66,16 @@ func testHairpin(listener net.Listener, extAddr string) (supportsHairpin bool) {
// Establish outgoing // Establish outgoing
outConn, err := net.Dial("tcp", extAddr) outConn, err := net.Dial("tcp", extAddr)
if err != nil { if err != nil {
log.Info("Outgoing connection dial error: %v", err)
log.Info(Fmt("Outgoing connection dial error: %v", err))
return return
} }
n, err := outConn.Write([]byte("test data")) n, err := outConn.Write([]byte("test data"))
if err != nil { if err != nil {
log.Info("Outgoing connection write error: %v", err)
log.Info(Fmt("Outgoing connection write error: %v", err))
return return
} }
log.Debug("Outgoing connection wrote %v bytes", n)
log.Debug(Fmt("Outgoing connection wrote %v bytes", n))
// Wait for data receipt // Wait for data receipt
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
@ -95,7 +97,7 @@ func Probe() (caps UPNPCapabilities, err error) {
defer func() { defer func() {
err = nat.DeletePortMapping("tcp", intPort, extPort) err = nat.DeletePortMapping("tcp", intPort, extPort)
if err != nil { if err != nil {
log.Warning("Port mapping delete error: %v", err)
log.Warn(Fmt("Port mapping delete error: %v", err))
} }
listener.Close() listener.Close()
}() }()


+ 3
- 2
rpc/http_handler.go View File

@ -11,6 +11,7 @@ import (
"time" "time"
"github.com/tendermint/tendermint/alert" "github.com/tendermint/tendermint/alert"
. "github.com/tendermint/tendermint/common"
) )
type APIStatus string type APIStatus string
@ -95,7 +96,7 @@ func RecoverAndLogHandler(handler http.Handler) http.Handler {
// For the rest, // For the rest,
rww.WriteHeader(http.StatusInternalServerError) rww.WriteHeader(http.StatusInternalServerError)
rww.Write([]byte("Internal Server Error")) rww.Write([]byte("Internal Server Error"))
log.Error("%s: %s", e, debug.Stack())
log.Error("Panic in HTTP handler", "error", e, "stack", debug.Stack())
} }
} }
@ -104,7 +105,7 @@ func RecoverAndLogHandler(handler http.Handler) http.Handler {
if rww.Status == -1 { if rww.Status == -1 {
rww.Status = 200 rww.Status = 200
} }
log.Debug("%s %s %v %v %s", r.RemoteAddr, r.Method, rww.Status, durationMS, r.URL)
log.Debug(Fmt("%s %s %v %v %s", r.RemoteAddr, r.Method, rww.Status, durationMS, r.URL))
}() }()
handler.ServeHTTP(rww, r) handler.ServeHTTP(rww, r)


+ 3
- 2
rpc/http_server.go View File

@ -5,6 +5,7 @@ import (
"net/http" "net/http"
. "github.com/tendermint/tendermint/config" . "github.com/tendermint/tendermint/config"
. "github.com/tendermint/tendermint/common"
) )
func StartHTTPServer() { func StartHTTPServer() {
@ -14,9 +15,9 @@ func StartHTTPServer() {
// Serve HTTP on localhost only. // Serve HTTP on localhost only.
// Let something like Nginx handle HTTPS connections. // Let something like Nginx handle HTTPS connections.
address := fmt.Sprintf("127.0.0.1:%v", Config.RPC.HTTPPort) address := fmt.Sprintf("127.0.0.1:%v", Config.RPC.HTTPPort)
log.Info("Starting RPC HTTP server on http://%s", address)
log.Info(Fmt("Starting RPC HTTP server on http://%s", address))
go func() { go func() {
log.Fatal(http.ListenAndServe(address, RecoverAndLogHandler(http.DefaultServeMux)))
log.Crit("%v", http.ListenAndServe(address, RecoverAndLogHandler(http.DefaultServeMux)))
}() }()
} }

+ 2
- 6
rpc/log.go View File

@ -1,11 +1,7 @@
package rpc package rpc
import ( import (
"github.com/op/go-logging"
"gopkg.in/inconshreveable/log15.v2"
) )
var log = logging.MustGetLogger("rpc")
func SetRPCLogger(l *logging.Logger) {
log = l
}
var log = log15.New("module", "rpc")

+ 7
- 7
state/genesis.go View File

@ -35,7 +35,7 @@ type GenesisDoc struct {
func GenesisDocFromJSON(jsonBlob []byte) (genState *GenesisDoc) { func GenesisDocFromJSON(jsonBlob []byte) (genState *GenesisDoc) {
err := json.Unmarshal(jsonBlob, &genState) err := json.Unmarshal(jsonBlob, &genState)
if err != nil { if err != nil {
Panicf("Couldn't read GenesisDoc: %v", err)
panic(Fmt("Couldn't read GenesisDoc: %v", err))
} }
return return
} }
@ -43,7 +43,7 @@ func GenesisDocFromJSON(jsonBlob []byte) (genState *GenesisDoc) {
func MakeGenesisStateFromFile(db db_.DB, genDocFile string) *State { func MakeGenesisStateFromFile(db db_.DB, genDocFile string) *State {
jsonBlob, err := ioutil.ReadFile(genDocFile) jsonBlob, err := ioutil.ReadFile(genDocFile)
if err != nil { if err != nil {
Panicf("Couldn't read GenesisDoc file: %v", err)
panic(Fmt("Couldn't read GenesisDoc file: %v", err))
} }
genDoc := GenesisDocFromJSON(jsonBlob) genDoc := GenesisDocFromJSON(jsonBlob)
return MakeGenesisState(db, genDoc) return MakeGenesisState(db, genDoc)
@ -51,7 +51,7 @@ func MakeGenesisStateFromFile(db db_.DB, genDocFile string) *State {
func MakeGenesisState(db db_.DB, genDoc *GenesisDoc) *State { func MakeGenesisState(db db_.DB, genDoc *GenesisDoc) *State {
if len(genDoc.Validators) == 0 { if len(genDoc.Validators) == 0 {
Exitf("The genesis file has no validators")
Exit(Fmt("The genesis file has no validators"))
} }
if genDoc.GenesisTime.IsZero() { if genDoc.GenesisTime.IsZero() {
@ -63,7 +63,7 @@ func MakeGenesisState(db db_.DB, genDoc *GenesisDoc) *State {
for _, acc := range genDoc.Accounts { for _, acc := range genDoc.Accounts {
address, err := base64.StdEncoding.DecodeString(acc.Address) address, err := base64.StdEncoding.DecodeString(acc.Address)
if err != nil { if err != nil {
Exitf("Invalid account address: %v", acc.Address)
Exit(Fmt("Invalid account address: %v", acc.Address))
} }
account := &Account{ account := &Account{
Address: address, Address: address,
@ -80,12 +80,12 @@ func MakeGenesisState(db db_.DB, genDoc *GenesisDoc) *State {
for i, val := range genDoc.Validators { for i, val := range genDoc.Validators {
pubKeyBytes, err := base64.StdEncoding.DecodeString(val.PubKey) pubKeyBytes, err := base64.StdEncoding.DecodeString(val.PubKey)
if err != nil { if err != nil {
Exitf("Invalid validator pubkey: %v", val.PubKey)
Exit(Fmt("Invalid validator pubkey: %v", val.PubKey))
} }
pubKey := ReadBinary(PubKeyEd25519{}, pubKey := ReadBinary(PubKeyEd25519{},
bytes.NewBuffer(pubKeyBytes), new(int64), &err).(PubKeyEd25519) bytes.NewBuffer(pubKeyBytes), new(int64), &err).(PubKeyEd25519)
if err != nil { if err != nil {
Exitf("Invalid validator pubkey: %v", val.PubKey)
Exit(Fmt("Invalid validator pubkey: %v", val.PubKey))
} }
address := pubKey.Address() address := pubKey.Address()
@ -100,7 +100,7 @@ func MakeGenesisState(db db_.DB, genDoc *GenesisDoc) *State {
for i, unbondTo := range val.UnbondTo { for i, unbondTo := range val.UnbondTo {
address, err := base64.StdEncoding.DecodeString(unbondTo.Address) address, err := base64.StdEncoding.DecodeString(unbondTo.Address)
if err != nil { if err != nil {
Exitf("Invalid unbond-to address: %v", unbondTo.Address)
Exit(Fmt("Invalid unbond-to address: %v", unbondTo.Address))
} }
valInfo.UnbondTo[i] = &TxOutput{ valInfo.UnbondTo[i] = &TxOutput{
Address: address, Address: address,


+ 2
- 6
state/log.go View File

@ -1,11 +1,7 @@
package state package state
import ( import (
"github.com/op/go-logging"
"gopkg.in/inconshreveable/log15.v2"
) )
var log = logging.MustGetLogger("state")
func SetStateLogger(l *logging.Logger) {
log = l
}
var log = log15.New("module", "state")

+ 2
- 2
state/state.go View File

@ -513,7 +513,7 @@ func (s *State) AppendBlock(block *Block, blockPartsHeader PartSetHeader, checkS
sumVotingPower += val.VotingPower sumVotingPower += val.VotingPower
return false return false
} else { } else {
log.Warning("Invalid validation signature.\nval: %v\nvote: %v", val, vote)
log.Warn(Fmt("Invalid validation signature.\nval: %v\nvote: %v", val, vote))
err = errors.New("Invalid validation signature") err = errors.New("Invalid validation signature")
return true return true
} }
@ -542,7 +542,7 @@ func (s *State) AppendBlock(block *Block, blockPartsHeader PartSetHeader, checkS
} }
_, val := s.BondedValidators.GetByIndex(uint(i)) _, val := s.BondedValidators.GetByIndex(uint(i))
if val == nil { if val == nil {
Panicf("Failed to fetch validator at index %v", i)
panic(Fmt("Failed to fetch validator at index %v", i))
} }
val.LastCommitHeight = block.Height - 1 val.LastCommitHeight = block.Height - 1
updated := s.BondedValidators.Update(val) updated := s.BondedValidators.Update(val)


Loading…
Cancel
Save