Skip to content

Commit

Permalink
add debug log
Browse files Browse the repository at this point in the history
  • Loading branch information
Liuhaai committed Jun 1, 2022
1 parent e82a697 commit b7f1a91
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
7 changes: 7 additions & 0 deletions blocksync/blocksync.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,13 @@ func (bs *blockSyncer) ProcessSyncRequest(ctx context.Context, peer peer.AddrInf
)
end = tip
}
log.L().Info(
"SyncRequest",
zap.Uint64("start", start),
zap.Uint64("end", end),
zap.Uint64("tipHeight", tip),
zap.Uint64("targetHeight", bs.targetHeight),
)
for i := start; i <= end; i++ {
// TODO: fetch block from buffer
blk, err := bs.blockByHeightHandler(i)
Expand Down
2 changes: 2 additions & 0 deletions dispatcher/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,12 +423,14 @@ func (d *IotxDispatcher) HandleBroadcast(ctx context.Context, chainID uint32, pe

switch msgType {
case iotexrpc.MessageType_CONSENSUS:
log.L().Info("broadcast censensus msg")
if err := subscriber.HandleConsensusMsg(message.(*iotextypes.ConsensusMessage)); err != nil {
log.L().Debug("Failed to handle consensus message.", zap.Error(err))
}
case iotexrpc.MessageType_ACTION:
d.dispatchAction(ctx, chainID, message)
case iotexrpc.MessageType_BLOCK:
log.L().Info("broadcast block msg")
d.dispatchBlock(ctx, chainID, peer, message)
default:
log.L().Warn("Unexpected msgType handled by HandleBroadcast.", zap.Any("msgType", msgType))
Expand Down
14 changes: 10 additions & 4 deletions p2p/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ type (
Neighbors(ctx context.Context) ([]peer.AddrInfo, error)
// ConnectedPeers returns the connected peers' info
ConnectedPeers(ctx context.Context) ([]peer.AddrInfo, error)
// BlockPeer blocks in the peer in p2p layer
// BlockPeer blocks the peer in p2p layer
BlockPeer(string)
}

Expand Down Expand Up @@ -291,7 +291,7 @@ func (p *agent) Start(ctx context.Context) error {
<-ready
var (
unicast iotexrpc.UnicastMsg
peerID string
peerID = peerInfo.ID.Pretty()
latency int64
)
defer func() {
Expand Down Expand Up @@ -341,6 +341,7 @@ func (p *agent) Start(ctx context.Context) error {
// connect to bootstrap nodes
p.host = host
if err := p.joinP2P(ctx); err != nil {
log.L().Error("fail to join p2p network", zap.Error(err))
return err
}
close(ready)
Expand Down Expand Up @@ -502,6 +503,7 @@ func (p *agent) ConnectedPeers(ctx context.Context) ([]peer.AddrInfo, error) {
}

func (p *agent) BlockPeer(pidStr string) {
log.L().Info("blockPeer", zap.String("pid", pidStr))
pid, err := peer.Decode(pidStr)
if err != nil {
log.L().Error("fail to block peer", zap.Error(err))
Expand Down Expand Up @@ -586,10 +588,14 @@ func (p *agent) reconnect() {
if len(p.host.ConnectedPeers()) == 0 || p.qosMetrics.lostConnection() {
log.L().Info("network lost, try re-connecting.")
p.host.ClearBlocklist()
p.joinP2P(context.Background())
if err := p.joinP2P(context.Background()); err != nil {
log.L().Error("fail to join p2p network", zap.Error(err))
}
return
}
p.host.FindPeers(context.Background())
if err := p.host.FindPeers(context.Background()); err != nil {
log.L().Error("fail to find peers", zap.Error(err))
}
}

func convertAppMsg(msg proto.Message) (iotexrpc.MessageType, []byte, error) {
Expand Down

0 comments on commit b7f1a91

Please sign in to comment.