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 (
"fmt"
"github.com/sfreiberg/gotwilio"
"time"
"github.com/sfreiberg/gotwilio"
. "github.com/tendermint/tendermint/common"
. "github.com/tendermint/tendermint/config"
)
@ -35,7 +37,7 @@ func Alert(message string) {
func sendTwilio(message string) {
defer func() {
if err := recover(); err != nil {
log.Error("sendTwilio error: %v", err)
log.Error(Fmt("sendTwilio error: %v", err))
}
}()
if len(message) > 50 {
@ -44,14 +46,14 @@ func sendTwilio(message string) {
twilio := gotwilio.NewTwilioClient(Config.Alert.TwilioSid, Config.Alert.TwilioToken)
res, exp, err := twilio.SendSMS(Config.Alert.TwilioFrom, Config.Alert.TwilioTo, message, "", "")
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) {
defer func() {
if err := recover(); err != nil {
log.Error("sendEmail error: %v", err)
log.Error(Fmt("sendEmail error: %v", err))
}
}()
subject := message
@ -60,6 +62,6 @@ func sendEmail(message string) {
}
err := SendEmail(subject, message, Config.Alert.EmailRecipients)
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
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
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"
"reflect"
"sync"
. "github.com/tendermint/tendermint/common"
)
type TypeInfo struct {
@ -113,7 +115,7 @@ func readReflect(rv reflect.Value, rt reflect.Type, r Unreader, n *int64, err *e
// Read TypeByte prefix
if typeInfo.HasTypeByte {
typeByte := ReadByte(r, n, err)
log.Debug("Read TypeByte: %X", typeByte)
log.Debug("Read typebyte", "typeByte", typeByte)
if typeByte != typeInfo.TypeByte {
*err = errors.New(fmt.Sprintf("Expected TypeByte of %X but got %X", typeInfo.TypeByte, typeByte))
return
@ -126,12 +128,12 @@ func readReflect(rv reflect.Value, rt reflect.Type, r Unreader, n *int64, err *e
if elemRt.Kind() == reflect.Uint8 {
// Special case: Byteslices
byteslice := ReadByteSlice(r, n, err)
log.Debug("Read byteslice: %X", byteslice)
log.Debug("Read byteslice", "bytes", byteslice)
rv.Set(reflect.ValueOf(byteslice))
} else {
// Read length
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)
// Read elems
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:
str := ReadString(r, n, err)
log.Debug("Read string: %v", str)
log.Debug(Fmt("Read string: %v", str))
rv.SetString(str)
case reflect.Int64:
num := ReadUint64(r, n, err)
log.Debug("Read num: %v", num)
log.Debug(Fmt("Read num: %v", num))
rv.SetInt(int64(num))
case reflect.Int32:
num := ReadUint32(r, n, err)
log.Debug("Read num: %v", num)
log.Debug(Fmt("Read num: %v", num))
rv.SetInt(int64(num))
case reflect.Int16:
num := ReadUint16(r, n, err)
log.Debug("Read num: %v", num)
log.Debug(Fmt("Read num: %v", num))
rv.SetInt(int64(num))
case reflect.Int8:
num := ReadUint8(r, n, err)
log.Debug("Read num: %v", num)
log.Debug(Fmt("Read num: %v", num))
rv.SetInt(int64(num))
case reflect.Int:
num := ReadUvarint(r, n, err)
log.Debug("Read num: %v", num)
log.Debug(Fmt("Read num: %v", num))
rv.SetInt(int64(num))
case reflect.Uint64:
num := ReadUint64(r, n, err)
log.Debug("Read num: %v", num)
log.Debug(Fmt("Read num: %v", num))
rv.SetUint(uint64(num))
case reflect.Uint32:
num := ReadUint32(r, n, err)
log.Debug("Read num: %v", num)
log.Debug(Fmt("Read num: %v", num))
rv.SetUint(uint64(num))
case reflect.Uint16:
num := ReadUint16(r, n, err)
log.Debug("Read num: %v", num)
log.Debug(Fmt("Read num: %v", num))
rv.SetUint(uint64(num))
case reflect.Uint8:
num := ReadUint8(r, n, err)
log.Debug("Read num: %v", num)
log.Debug(Fmt("Read num: %v", num))
rv.SetUint(uint64(num))
case reflect.Uint:
num := ReadUvarint(r, n, err)
log.Debug("Read num: %v", num)
log.Debug(Fmt("Read num: %v", num))
rv.SetUint(uint64(num))
default:


+ 10
- 10
block/store.go View File

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

+ 5
- 4
cmd/daemon.go View File

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


+ 2
- 2
cmd/log.go View File

@ -1,7 +1,7 @@
package main
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"
)
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)
}

+ 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{}
err = json.Unmarshal(configBytes, &Config)
if err != nil {
Exitf("Invalid configuration file %s: %v", configFile, err)
Exit(Fmt("Invalid configuration file %s: %v", configFile, err))
}
err = Config.validate()
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.


+ 2
- 6
consensus/log.go View File

@ -1,11 +1,7 @@
package consensus
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)
_, msg_, err := DecodeMessage(msgBytes)
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
}
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 {
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)
if err != nil {
// 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
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 {
log.Warning("Error in Receive(): %v", err)
log.Warn(Fmt("Error in Receive(): %v", err))
}
}
@ -254,7 +252,7 @@ OUTER_LOOP:
for {
// Manage disconnects from self or peer.
if peer.IsStopped() || conR.IsStopped() {
log.Info("Stopping gossipDataRoutine for %v.", peer)
log.Info(Fmt("Stopping gossipDataRoutine for %v.", peer))
return
}
rs := conR.conS.GetRoundState()
@ -319,7 +317,7 @@ OUTER_LOOP:
for {
// Manage disconnects from self or peer.
if peer.IsStopped() || conR.IsStopped() {
log.Info("Stopping gossipVotesRoutine for %v.", peer)
log.Info(Fmt("Stopping gossipVotesRoutine for %v.", peer))
return
}
rs := conR.conS.GetRoundState()
@ -641,7 +639,7 @@ const (
// TODO: check for unnecessary extra bytes at the end.
func DecodeMessage(bz []byte) (msgType byte, msg interface{}, err error) {
n := new(int64)
// log.Debug("decoding msg bytes: %X", bz)
// log.Debug(Fmt("decoding msg bytes: %X", bz))
msgType = bz[0]
r := bytes.NewReader(bz)
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.
rs := cs.getRoundState()
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 {
case RoundStepNewHeight:
// We should run RoundActionPropose when rs.StartTime passes.
@ -306,7 +306,7 @@ ACTION_LOOP:
height, round, action := roundAction.Height, roundAction.Round, roundAction.Action
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
if height != rs.Height {
@ -394,8 +394,8 @@ ACTION_LOOP:
func (cs *ConsensusState) updateToState(state *state.State) {
// Sanity check state.
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.
@ -586,7 +586,7 @@ func (cs *ConsensusState) RunActionPrevote(height uint, round uint) {
cs.mtx.Lock()
defer cs.mtx.Unlock()
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() {
cs.Step = RoundStepPrevote
@ -601,7 +601,7 @@ func (cs *ConsensusState) RunActionPrevote(height uint, round uint) {
// If ProposalBlock is nil, prevote nil.
if cs.ProposalBlock == nil {
log.Warning("ProposalBlock is nil")
log.Warn("ProposalBlock is nil")
cs.signAddVote(VoteTypePrevote, nil, PartSetHeader{})
return
}
@ -610,7 +610,7 @@ func (cs *ConsensusState) RunActionPrevote(height uint, round uint) {
err := cs.stageBlock(cs.ProposalBlock, cs.ProposalBlockParts)
if err != 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{})
return
}
@ -626,7 +626,7 @@ func (cs *ConsensusState) RunActionPrecommit(height uint, round uint) {
cs.mtx.Lock()
defer cs.mtx.Unlock()
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() {
cs.Step = RoundStepPrecommit
@ -661,7 +661,7 @@ func (cs *ConsensusState) RunActionPrecommit(height uint, round uint) {
// Validate the block.
if err := cs.stageBlock(cs.ProposalBlock, cs.ProposalBlockParts); err != nil {
// 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
}
cs.LockedBlock = cs.ProposalBlock
@ -686,7 +686,7 @@ func (cs *ConsensusState) RunActionCommit(height uint) {
cs.mtx.Lock()
defer cs.mtx.Unlock()
if cs.Height != height {
Panicf("RunActionCommit(%v), expected %v", height, cs.Height)
panic(Fmt("RunActionCommit(%v), expected %v", height, cs.Height))
}
defer func() {
cs.Step = RoundStepCommit
@ -745,7 +745,7 @@ func (cs *ConsensusState) TryFinalizeCommit(height uint) bool {
defer cs.mtx.Unlock()
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 &&
@ -754,19 +754,19 @@ func (cs *ConsensusState) TryFinalizeCommit(height uint) bool {
// Sanity check
if cs.ProposalBlock == nil {
Panicf("Expected ProposalBlock to exist")
panic(Fmt("Expected ProposalBlock to exist"))
}
hash, header, _ := cs.Commits.TwoThirdsMajority()
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) {
Panicf("Expected ProposalBlockParts header to be commit header")
panic(Fmt("Expected ProposalBlockParts header to be commit header"))
}
err := cs.stageBlock(cs.ProposalBlock, cs.ProposalBlockParts)
if err == nil {
log.Debug("Finalizing commit of block: %v", cs.ProposalBlock)
log.Debug(Fmt("Finalizing commit of block: %v", cs.ProposalBlock))
// Increment height.
cs.updateToState(cs.stagedState)
// cs.Step is now RoundStepNewHeight or RoundStepNewRound
@ -775,7 +775,7 @@ func (cs *ConsensusState) TryFinalizeCommit(height uint) bool {
} else {
// Prevent zombies.
// 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
@ -910,7 +910,7 @@ func (cs *ConsensusState) addVote(address []byte, vote *Vote) (added bool, index
added, index, err = cs.Commits.Add(address, vote)
if added && cs.Commits.HasTwoThirdsMajority() && cs.CommitTime.IsZero() {
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 {
cs.queueAction(RoundAction{cs.Height, cs.Round, RoundActionCommit})
} else {
@ -974,7 +974,7 @@ func (cs *ConsensusState) saveCommitVoteBlock(block *Block, blockParts *PartSet)
// The proposal must be valid.
if err := cs.stageBlock(block, blockParts); err != nil {
// Prevent zombies.
log.Warning("+2/3 precommitted an invalid block: %v", err)
log.Warn(Fmt("+2/3 precommitted an invalid block: %v", err))
return
}
@ -1022,7 +1022,7 @@ func calcRound(startTime time.Time) uint {
panic("Could not calc round, should not happen")
}
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 {
return 0


+ 0
- 1
consensus/vote_set.go View File

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


+ 2
- 6
mempool/log.go View File

@ -1,11 +1,7 @@
package mempool
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/block"
. "github.com/tendermint/tendermint/common"
"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) {
_, msg_, err := DecodeMessage(msgBytes)
if err != nil {
log.Warning("Error decoding message: %v", err)
log.Warn(Fmt("Error decoding message: %v", err))
return
}
log.Info("MempoolReactor received %v", msg_)
log.Info(Fmt("MempoolReactor received %v", msg_))
switch msg_.(type) {
case *TxMessage:
@ -81,10 +82,10 @@ func (memR *MempoolReactor) Receive(chId byte, src *p2p.Peer, msgBytes []byte) {
err := memR.Mempool.AddTx(msg.Tx)
if err != nil {
// 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
} else {
log.Debug("Added valid tx %V", msg.Tx)
log.Debug(Fmt("Added valid tx %V", msg.Tx))
}
// Share tx.
// 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")
_, err = w.Write(jsonBytes)
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 {
select {
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)
case <-a.quit:
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 {
// Sanity check
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
}
@ -439,11 +439,11 @@ func (a *AddrBook) addToNewBucket(ka *knownAddress, bucketIdx int) bool {
func (a *AddrBook) addToOldBucket(ka *knownAddress, bucketIdx int) bool {
// Sanity check
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
}
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
}
@ -474,7 +474,7 @@ func (a *AddrBook) addToOldBucket(ka *knownAddress, bucketIdx int) bool {
func (a *AddrBook) removeFromBucket(ka *knownAddress, bucketType byte, bucketIdx int) {
if ka.BucketType != bucketType {
log.Warning("Bucket type mismatch: %v", ka)
log.Warn(Fmt("Bucket type mismatch: %v", ka))
return
}
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) {
if !addr.Routable() {
log.Warning("Cannot add non-routable address %v", addr)
log.Warn(Fmt("Cannot add non-routable address %v", addr))
return
}
if _, ok := a.ourAddrs[addr.String()]; ok {
@ -547,7 +547,7 @@ func (a *AddrBook) addAddress(addr, src *NetAddress) {
bucket := a.calcNewBucket(addr, src)
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.
@ -556,7 +556,7 @@ func (a *AddrBook) expireNew(bucketIdx int) {
for addrStr, ka := range a.addrNew[bucketIdx] {
// If an entry is bad, throw it away
if ka.isBad() {
log.Info("expiring bad address %v", addrStr)
log.Info(Fmt("expiring bad address %v", addrStr))
a.removeFromBucket(ka, bucketTypeNew, bucketIdx)
return
}
@ -573,11 +573,11 @@ func (a *AddrBook) expireNew(bucketIdx int) {
func (a *AddrBook) moveToOld(ka *knownAddress) {
// Sanity check
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
}
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
}
@ -602,13 +602,13 @@ func (a *AddrBook) moveToOld(ka *knownAddress) {
if !added {
added := a.addToNewBucket(oldest, freedBucket)
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.
added = a.addToOldBucket(ka, oldBucketIdx)
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 {
for _, bucket := range ka.Buckets {
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
}
}
@ -771,7 +771,7 @@ func (ka *knownAddress) removeBucketRef(bucketIdx int) int {
}
}
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
}
ka.Buckets = buckets


+ 21
- 20
p2p/connection.go View File

@ -11,9 +11,9 @@ import (
"time"
flow "code.google.com/p/mxk/go1/flowcontrol"
"github.com/op/go-logging"
. "github.com/tendermint/tendermint/binary"
. "github.com/tendermint/tendermint/common"
"gopkg.in/inconshreveable/log15.v2"
)
const (
@ -123,7 +123,7 @@ func NewMConnection(conn net.Conn, chDescs []*ChannelDescriptor, onReceive recei
// .Start() begins multiplexing packets to and from "channels".
func (c *MConnection) Start() {
if atomic.CompareAndSwapUint32(&c.started, 0, 1) {
log.Debug("Starting %v", c)
log.Debug(Fmt("Starting %v", c))
go c.sendRoutine()
go c.recvRoutine()
}
@ -131,7 +131,7 @@ func (c *MConnection) Start() {
func (c *MConnection) Stop() {
if atomic.CompareAndSwapUint32(&c.stopped, 0, 1) {
log.Debug("Stopping %v", c)
log.Debug(Fmt("Stopping %v", c))
close(c.quit)
c.conn.Close()
c.flushTimer.Stop()
@ -153,7 +153,7 @@ func (c *MConnection) flush() {
err := c.bufWriter.Flush()
if err != nil {
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
}
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.
channel, ok := c.channelsIdx[chId]
if !ok {
log.Error("Cannot send bytes, unknown channel %X", chId)
log.Error(Fmt("Cannot send bytes, unknown channel %X", chId))
return false
}
@ -210,12 +209,12 @@ func (c *MConnection) TrySend(chId byte, msg interface{}) bool {
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.
channel, ok := c.channelsIdx[chId]
if !ok {
log.Error("Cannot send bytes, unknown channel %X", chId)
log.Error(Fmt("Cannot send bytes, unknown channel %X", chId))
return false
}
@ -238,7 +237,7 @@ func (c *MConnection) CanSend(chId byte) bool {
channel, ok := c.channelsIdx[chId]
if !ok {
log.Error("Unknown channel %X", chId)
log.Error(Fmt("Unknown channel %X", chId))
return false
}
return channel.canSend()
@ -287,7 +286,7 @@ FOR_LOOP:
break FOR_LOOP
}
if err != nil {
log.Warning("%v failed @ sendRoutine:\n%v", c, err)
log.Warn(Fmt("%v failed @ sendRoutine:\n%v", c, err))
c.Stop()
break FOR_LOOP
}
@ -342,7 +341,7 @@ func (c *MConnection) sendMsgPacket() bool {
// Make & send a msgPacket from this channel
n, err := leastChannel.writeMsgPacketTo(c.bufWriter)
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)
return true
}
@ -369,20 +368,22 @@ FOR_LOOP:
c.recvMonitor.Update(int(n))
if err != nil {
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()
}
break FOR_LOOP
}
// Peek into bufReader for debugging
if log.IsEnabledFor(logging.DEBUG) {
log.Debug("%v", log15.Lazy{func() string {
numBytes := c.bufReader.Buffered()
bytes, err := c.bufReader.Peek(MinInt(numBytes, 100))
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.
switch pktType {
@ -397,22 +398,22 @@ FOR_LOOP:
c.recvMonitor.Update(int(*n))
if *err != nil {
if atomic.LoadUint32(&c.stopped) != 1 {
log.Warning("%v failed @ recvRoutine", c)
log.Warn(Fmt("%v failed @ recvRoutine", c))
c.Stop()
}
break FOR_LOOP
}
channel, ok := c.channelsIdx[pkt.ChannelId]
if !ok || channel == nil {
Panicf("Unknown channel %X", pkt.ChannelId)
panic(Fmt("Unknown channel %X", pkt.ChannelId))
}
msgBytes := channel.recvMsgPacket(pkt)
log.Warning("RECEIVE_MSG_BYTES: %X", msgBytes)
log.Warn(Fmt("RECEIVE_MSG_BYTES: %X", msgBytes))
if msgBytes != nil {
c.onReceive(pkt.ChannelId, msgBytes)
}
default:
Panicf("Unknown message type %X", pktType)
panic(Fmt("Unknown message type %X", pktType))
}
// 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
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...
var extAddr *NetAddress
@ -62,7 +62,7 @@ func NewDefaultListener(protocol string, lAddr string, requireUPNPHairpin bool)
if requireUPNPHairpin {
upnpCapabilities, err := upnp.Probe()
if err != nil {
log.Warning("Failed to probe UPNP: %v", err)
log.Warn("Failed to probe UPNP", "error", err)
goto SKIP_UPNP
}
if !upnpCapabilities.Hairpin {
@ -144,13 +144,13 @@ func getUPNPExternalAddress(externalPort, internalPort int) *NetAddress {
log.Debug("Getting UPNP external address")
nat, err := upnp.Discover()
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
}
ext, err := nat.GetExternalAddress()
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
}
@ -161,11 +161,11 @@ func getUPNPExternalAddress(externalPort, internalPort int) *NetAddress {
externalPort, err = nat.AddPortMapping("tcp", externalPort, internalPort, "tendermint", 0)
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
}
log.Debug("Got UPNP external address: %v", ext)
log.Debug("Got UPNP external address", "address", ext)
return NewNetAddressIPPort(ext, uint16(externalPort))
}
@ -173,7 +173,7 @@ func getUPNPExternalAddress(externalPort, internalPort int) *NetAddress {
func getNaiveExternalAddress(port int) *NetAddress {
addrs, err := net.InterfaceAddrs()
if err != nil {
Panicf("Unexpected error fetching interface addresses: %v", err)
panic(Fmt("Could not fetch interface addresses: %v", err))
}
for _, a := range addrs {


+ 2
- 6
p2p/log.go View File

@ -1,11 +1,7 @@
package p2p
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) {
reactor := reactorsByCh[chId]
if reactor == nil {
Panicf("Unknown channel %X", chId)
panic(Fmt("Unknown channel %X", chId))
}
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() {
if atomic.CompareAndSwapUint32(&p.started, 0, 1) {
log.Debug("Starting %v", p)
log.Debug(Fmt("Starting %v", p))
p.mconn.Start()
}
}
func (p *Peer) stop() {
if atomic.CompareAndSwapUint32(&p.stopped, 0, 1) {
log.Debug("Stopping %v", p)
log.Debug(Fmt("Stopping %v", p))
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
msg, err := DecodeMessage(msgBytes)
if err != nil {
log.Warning("Error decoding message: %v", err)
log.Warn(Fmt("Error decoding message: %v", err))
return
}
log.Info("requestRoutine received %v", msg)
log.Info(Fmt("requestRoutine received %v", msg))
switch msg.(type) {
case *pexRequestMessage:
@ -209,7 +209,7 @@ func DecodeMessage(bz []byte) (msg interface{}, err error) {
n := new(int64)
msgType := bz[0]
r := bytes.NewReader(bz)
// log.Debug("decoding msg bytes: %X", bz)
// log.Debug(Fmt("decoding msg bytes: %X", bz))
switch msgType {
case msgTypeRequest:
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
if sw.peers.Add(peer) {
log.Info("+ %v", peer)
log.Info(Fmt("+ %v", peer))
} else {
log.Info("Ignoring duplicate: %v", peer)
log.Info(Fmt("Ignoring duplicate: %v", peer))
return nil, ErrSwitchDuplicatePeer
}
@ -137,7 +137,7 @@ func (sw *Switch) DialPeerWithAddress(addr *NetAddress) (*Peer, error) {
return nil, ErrSwitchStopped
}
log.Info("Dialing peer @ %v", addr)
log.Info(Fmt("Dialing peer @ %v", addr))
sw.dialing.Set(addr.String(), addr)
conn, err := addr.DialTimeout(peerDialTimeoutSeconds * time.Second)
sw.dialing.Delete(addr.String())
@ -161,12 +161,12 @@ func (sw *Switch) Broadcast(chId byte, msg interface{}) (numSuccess, numFailure
return
}
log.Debug("[%X] BROADCAST: %v", chId, msg)
log.Debug("Broadcast", "channel", chId, "msg", msg)
for _, peer := range sw.peers.List() {
// XXX XXX Change.
// success := peer.TrySend(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 {
numSuccess += 1
} else {
@ -198,7 +198,7 @@ func (sw *Switch) Peers() IPeerSet {
// Disconnect from a peer due to external error.
// TODO: make record depending on reason.
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)
peer.stop()
@ -209,7 +209,7 @@ func (sw *Switch) StopPeerForError(peer *Peer, reason interface{}) {
// Disconnect from a peer gracefully.
// TODO: handle graceful disconnects.
func (sw *Switch) StopPeerGracefully(peer *Peer) {
log.Info("- %v", peer)
log.Info(Fmt("- %v", peer))
sw.peers.Remove(peer)
peer.stop()


+ 2
- 1
p2p/switch_test.go View File

@ -7,6 +7,7 @@ import (
"time"
. "github.com/tendermint/tendermint/binary"
. "github.com/tendermint/tendermint/common"
)
type PeerMessage struct {
@ -201,7 +202,7 @@ func BenchmarkSwitches(b *testing.B) {
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.
b.StopTimer()


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

@ -1,11 +1,7 @@
package upnp
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"
"net"
"time"
. "github.com/tendermint/tendermint/common"
)
type UPNPCapabilities struct {
@ -17,19 +19,19 @@ func makeUPNPListener(intPort int, extPort int) (NAT, net.Listener, net.IP, erro
if err != nil {
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()
if err != nil {
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)
if err != nil {
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.
listener, err := net.Listen("tcp", fmt.Sprintf(":%v", intPort))
@ -44,17 +46,17 @@ func testHairpin(listener net.Listener, extAddr string) (supportsHairpin bool) {
go func() {
inConn, err := listener.Accept()
if err != nil {
log.Info("Listener.Accept() error: %v", err)
log.Info(Fmt("Listener.Accept() error: %v", err))
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)
n, err := inConn.Read(buf)
if err != nil {
log.Info("Incoming connection read error: %v", err)
log.Info(Fmt("Incoming connection read error: %v", err))
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" {
supportsHairpin = true
return
@ -64,16 +66,16 @@ func testHairpin(listener net.Listener, extAddr string) (supportsHairpin bool) {
// Establish outgoing
outConn, err := net.Dial("tcp", extAddr)
if err != nil {
log.Info("Outgoing connection dial error: %v", err)
log.Info(Fmt("Outgoing connection dial error: %v", err))
return
}
n, err := outConn.Write([]byte("test data"))
if err != nil {
log.Info("Outgoing connection write error: %v", err)
log.Info(Fmt("Outgoing connection write error: %v", err))
return
}
log.Debug("Outgoing connection wrote %v bytes", n)
log.Debug(Fmt("Outgoing connection wrote %v bytes", n))
// Wait for data receipt
time.Sleep(1 * time.Second)
@ -95,7 +97,7 @@ func Probe() (caps UPNPCapabilities, err error) {
defer func() {
err = nat.DeletePortMapping("tcp", intPort, extPort)
if err != nil {
log.Warning("Port mapping delete error: %v", err)
log.Warn(Fmt("Port mapping delete error: %v", err))
}
listener.Close()
}()


+ 3
- 2
rpc/http_handler.go View File

@ -11,6 +11,7 @@ import (
"time"
"github.com/tendermint/tendermint/alert"
. "github.com/tendermint/tendermint/common"
)
type APIStatus string
@ -95,7 +96,7 @@ func RecoverAndLogHandler(handler http.Handler) http.Handler {
// For the rest,
rww.WriteHeader(http.StatusInternalServerError)
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 {
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)


+ 3
- 2
rpc/http_server.go View File

@ -5,6 +5,7 @@ import (
"net/http"
. "github.com/tendermint/tendermint/config"
. "github.com/tendermint/tendermint/common"
)
func StartHTTPServer() {
@ -14,9 +15,9 @@ func StartHTTPServer() {
// Serve HTTP on localhost only.
// Let something like Nginx handle HTTPS connections.
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() {
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
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) {
err := json.Unmarshal(jsonBlob, &genState)
if err != nil {
Panicf("Couldn't read GenesisDoc: %v", err)
panic(Fmt("Couldn't read GenesisDoc: %v", err))
}
return
}
@ -43,7 +43,7 @@ func GenesisDocFromJSON(jsonBlob []byte) (genState *GenesisDoc) {
func MakeGenesisStateFromFile(db db_.DB, genDocFile string) *State {
jsonBlob, err := ioutil.ReadFile(genDocFile)
if err != nil {
Panicf("Couldn't read GenesisDoc file: %v", err)
panic(Fmt("Couldn't read GenesisDoc file: %v", err))
}
genDoc := GenesisDocFromJSON(jsonBlob)
return MakeGenesisState(db, genDoc)
@ -51,7 +51,7 @@ func MakeGenesisStateFromFile(db db_.DB, genDocFile string) *State {
func MakeGenesisState(db db_.DB, genDoc *GenesisDoc) *State {
if len(genDoc.Validators) == 0 {
Exitf("The genesis file has no validators")
Exit(Fmt("The genesis file has no validators"))
}
if genDoc.GenesisTime.IsZero() {
@ -63,7 +63,7 @@ func MakeGenesisState(db db_.DB, genDoc *GenesisDoc) *State {
for _, acc := range genDoc.Accounts {
address, err := base64.StdEncoding.DecodeString(acc.Address)
if err != nil {
Exitf("Invalid account address: %v", acc.Address)
Exit(Fmt("Invalid account address: %v", acc.Address))
}
account := &Account{
Address: address,
@ -80,12 +80,12 @@ func MakeGenesisState(db db_.DB, genDoc *GenesisDoc) *State {
for i, val := range genDoc.Validators {
pubKeyBytes, err := base64.StdEncoding.DecodeString(val.PubKey)
if err != nil {
Exitf("Invalid validator pubkey: %v", val.PubKey)
Exit(Fmt("Invalid validator pubkey: %v", val.PubKey))
}
pubKey := ReadBinary(PubKeyEd25519{},
bytes.NewBuffer(pubKeyBytes), new(int64), &err).(PubKeyEd25519)
if err != nil {
Exitf("Invalid validator pubkey: %v", val.PubKey)
Exit(Fmt("Invalid validator pubkey: %v", val.PubKey))
}
address := pubKey.Address()
@ -100,7 +100,7 @@ func MakeGenesisState(db db_.DB, genDoc *GenesisDoc) *State {
for i, unbondTo := range val.UnbondTo {
address, err := base64.StdEncoding.DecodeString(unbondTo.Address)
if err != nil {
Exitf("Invalid unbond-to address: %v", unbondTo.Address)
Exit(Fmt("Invalid unbond-to address: %v", unbondTo.Address))
}
valInfo.UnbondTo[i] = &TxOutput{
Address: address,


+ 2
- 6
state/log.go View File

@ -1,11 +1,7 @@
package state
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
return false
} 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")
return true
}
@ -542,7 +542,7 @@ func (s *State) AppendBlock(block *Block, blockPartsHeader PartSetHeader, checkS
}
_, val := s.BondedValidators.GetByIndex(uint(i))
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
updated := s.BondedValidators.Update(val)


Loading…
Cancel
Save