Skip to content

Commit

Permalink
reduce peer state log, do logging in ticker (#1255)
Browse files Browse the repository at this point in the history
* reduce peer state log, do logging in ticker

* gofmt
  • Loading branch information
Honglei-Cong committed Jul 7, 2020
1 parent f675992 commit c4ee024
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
11 changes: 9 additions & 2 deletions consensus/vbft/state_mgmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package vbft

import (
"fmt"
"math"
"time"

Expand Down Expand Up @@ -77,6 +78,10 @@ type PeerState struct {
connected bool
}

func (peer *PeerState) String() string {
return fmt.Sprintf("{%d: (%d, %d)},", peer.peerIdx, peer.chainConfigView, peer.committedBlockNum)
}

type StateMgr struct {
server *Server
syncReadyTimeout time.Duration
Expand Down Expand Up @@ -164,6 +169,8 @@ func (self *StateMgr) run() {
}

case LiveTick:
log.Infof("server %d peer update, current blk: %d, state: %d. received peer states: %v",
self.server.Index, self.server.GetCurrentBlockNo(), self.currentState, self.peers)
self.onLiveTick(evt)
}

Expand All @@ -181,8 +188,8 @@ func (self *StateMgr) onPeerUpdate(peerState *PeerState) {
newPeer = true
}

log.Infof("server %d peer update, current blk %d, state %d, from peer %d, committed %d",
self.server.Index, self.server.GetCurrentBlockNo(), self.currentState, peerState.peerIdx, peerState.committedBlockNum)
log.Debugf("server %d peer update, current blk %d, state %d, received peer state: %v",
self.server.Index, self.server.GetCurrentBlockNo(), self.currentState, peerState)

// update peer state
self.peers[peerIdx] = peerState
Expand Down
13 changes: 13 additions & 0 deletions consensus/vbft/state_mgmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,16 @@ func TestStateMgr_getConsensusedCommittedBlockNum(t *testing.T) {
maxcomit, flag := statemgr.getConsensusedCommittedBlockNum()
t.Logf("TestgetConsensusedCommittedBlockNum maxcommitted:%v, consensused:%v", maxcomit, flag)
}

func TestPeerState_String(t *testing.T) {
peers := make(map[uint32]*PeerState)
for i := uint32(0); i < 10; i++ {
peers[i] = &PeerState{
peerIdx: i,
chainConfigView: i,
committedBlockNum: i,
}
}

t.Logf("received peer states: %v", peers)
}

0 comments on commit c4ee024

Please sign in to comment.