Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reduce peer state log, do logging in ticker #1255

Merged
merged 2 commits into from
Jul 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)
}