From 2ca882a9b6b9390c22e8296d820e9562c1d52713 Mon Sep 17 00:00:00 2001 From: Jae Kwon Date: Mon, 29 Dec 2014 19:59:06 -0800 Subject: [PATCH] Log which commits are being sent for catchup --- consensus/reactor.go | 10 +++++++--- p2p/connection.go | 21 +++++++++++---------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/consensus/reactor.go b/consensus/reactor.go index 7d1cc2bfc..a76b656c9 100644 --- a/consensus/reactor.go +++ b/consensus/reactor.go @@ -396,26 +396,30 @@ OUTER_LOOP: // which contains commit signatures for prs.Height. header, validation := conR.conS.LoadHeaderValidation(prs.Height + 1) size := uint(len(validation.Commits)) + log.Debug("Loaded HeaderValidation for catchup", "height", prs.Height+1, "header", header, "validation", validation, "size", size) // Initialize Commits if needed ps.EnsureVoteBitArrays(prs.Height, size) index, ok := validation.BitArray().Sub(prs.Commits).PickRandom() if ok { - rsig := validation.Commits[index] + commit := validation.Commits[index] + log.Debug("Picked commit to send", "index", index, "commit", commit) // Reconstruct vote. vote := &Vote{ Height: prs.Height, - Round: rsig.Round, + Round: commit.Round, Type: VoteTypeCommit, BlockHash: header.LastBlockHash, BlockParts: header.LastBlockParts, - Signature: rsig.Signature, + Signature: commit.Signature, } msg := &VoteMessage{index, vote} peer.Send(VoteCh, msg) ps.SetHasVote(vote, index) continue OUTER_LOOP + } else { + log.Debug("No commits to send", "ours", validation.BitArray(), "theirs", prs.Commits) } } diff --git a/p2p/connection.go b/p2p/connection.go index ff7345f16..9e247ba9c 100644 --- a/p2p/connection.go +++ b/p2p/connection.go @@ -362,16 +362,17 @@ FOR_LOOP: c.recvMonitor.Limit(maxMsgPacketSize, atomic.LoadInt64(&c.recvRate), true) // Peek into bufReader for debugging - log.Debug("Peek connection buffer", "bytes", log15.Lazy{func() []byte { - numBytes := c.bufReader.Buffered() - bytes, err := c.bufReader.Peek(MinInt(numBytes, 100)) - if err == nil { - return bytes - } else { - log.Warn("Error peeking connection buffer", "error", err) - return nil - } - }}) + if numBytes := c.bufReader.Buffered(); numBytes > 0 { + log.Debug("Peek connection buffer", "bytes", log15.Lazy{func() []byte { + bytes, err := c.bufReader.Peek(MinInt(numBytes, 100)) + if err == nil { + return bytes + } else { + log.Warn("Error peeking connection buffer", "error", err) + return nil + } + }}) + } // Read packet type var n int64