From 844122528731bcf53230bfc84d9b4ff1f5cde915 Mon Sep 17 00:00:00 2001 From: wubin01 Date: Mon, 9 Jul 2018 19:55:07 +0800 Subject: [PATCH 1/2] add udp log --- .../java/org/tron/common/net/udp/handler/MessageHandler.java | 4 ++-- .../org/tron/common/overlay/discover/node/NodeHandler.java | 3 ++- src/main/java/org/tron/core/config/args/Args.java | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/tron/common/net/udp/handler/MessageHandler.java b/src/main/java/org/tron/common/net/udp/handler/MessageHandler.java index 23660f12939..e10cf49cf31 100644 --- a/src/main/java/org/tron/common/net/udp/handler/MessageHandler.java +++ b/src/main/java/org/tron/common/net/udp/handler/MessageHandler.java @@ -50,7 +50,7 @@ public void channelActive(ChannelHandlerContext ctx) throws Exception { @Override public void channelRead0(ChannelHandlerContext ctx, UdpEvent udpEvent) { - logger.debug("rcv udp msg type {}, len {} from {} ", + logger.info("rcv udp msg type {}, len {} from {} ", udpEvent.getMessage().getType(), udpEvent.getMessage().getSendData().length, udpEvent.getAddress()); @@ -59,7 +59,7 @@ public void channelRead0(ChannelHandlerContext ctx, UdpEvent udpEvent) { @Override public void accept(UdpEvent udpEvent) { - logger.debug("send udp msg type {}, len {} to {} ", + logger.info("send udp msg type {}, len {} to {} ", udpEvent.getMessage().getType(), udpEvent.getMessage().getSendData().length, udpEvent.getAddress()); diff --git a/src/main/java/org/tron/common/overlay/discover/node/NodeHandler.java b/src/main/java/org/tron/common/overlay/discover/node/NodeHandler.java index 9a85251fe88..5d113aa0484 100644 --- a/src/main/java/org/tron/common/overlay/discover/node/NodeHandler.java +++ b/src/main/java/org/tron/common/overlay/discover/node/NodeHandler.java @@ -127,6 +127,7 @@ private void challengeWith(NodeHandler replaceCandidate) { // Manages state transfers public void changeState(State newState) { + logger.info("Node {} change status {} to {}", node.getHost(), state, newState); State oldState = state; if (newState == State.Discovered) { sendPing(); @@ -225,7 +226,7 @@ public void handleFindNode(FindNodeMessage msg) { } public void handleTimedOut() { - logger.debug("ping timeout {}", node); + logger.info("ping timeout {}", node); waitForPong = false; if (--pingTrials > 0) { sendPing(); diff --git a/src/main/java/org/tron/core/config/args/Args.java b/src/main/java/org/tron/core/config/args/Args.java index baebcfd816f..e3f927548fd 100644 --- a/src/main/java/org/tron/core/config/args/Args.java +++ b/src/main/java/org/tron/core/config/args/Args.java @@ -716,7 +716,7 @@ private static void logConfig(){ logger.info("Discover enable: {}", args.isNodeDiscoveryEnable()); logger.info("Active node size: {}", args.getActiveNodes().size()); logger.info("Passive node size: {}", args.getPassiveNodes().size()); - logger.info("Seed node size: {}", args.getSeedNodes().size()); + logger.info("Seed node size: {}", args.getSeedNode().getIpList().size()); logger.info("Max connection: {}", args.getNodeMaxActiveNodes()); logger.info("Max connection with same IP: {}", args.getNodeMaxActiveNodesWithSameIp()); logger.info("************************ Backup config ************************"); From 1e490169d5d37587354c915815393b9ea188cecd Mon Sep 17 00:00:00 2001 From: wubin01 Date: Tue, 10 Jul 2018 19:06:03 +0800 Subject: [PATCH 2/2] modify the problem of the bad block & bad peer reason --- .../net/udp/handler/MessageHandler.java | 4 +-- .../overlay/discover/node/NodeHandler.java | 3 +- .../common/overlay/server/ChannelManager.java | 4 +-- .../java/org/tron/core/net/node/NodeImpl.java | 30 +++++++------------ 4 files changed, 14 insertions(+), 27 deletions(-) diff --git a/src/main/java/org/tron/common/net/udp/handler/MessageHandler.java b/src/main/java/org/tron/common/net/udp/handler/MessageHandler.java index e10cf49cf31..23660f12939 100644 --- a/src/main/java/org/tron/common/net/udp/handler/MessageHandler.java +++ b/src/main/java/org/tron/common/net/udp/handler/MessageHandler.java @@ -50,7 +50,7 @@ public void channelActive(ChannelHandlerContext ctx) throws Exception { @Override public void channelRead0(ChannelHandlerContext ctx, UdpEvent udpEvent) { - logger.info("rcv udp msg type {}, len {} from {} ", + logger.debug("rcv udp msg type {}, len {} from {} ", udpEvent.getMessage().getType(), udpEvent.getMessage().getSendData().length, udpEvent.getAddress()); @@ -59,7 +59,7 @@ public void channelRead0(ChannelHandlerContext ctx, UdpEvent udpEvent) { @Override public void accept(UdpEvent udpEvent) { - logger.info("send udp msg type {}, len {} to {} ", + logger.debug("send udp msg type {}, len {} to {} ", udpEvent.getMessage().getType(), udpEvent.getMessage().getSendData().length, udpEvent.getAddress()); diff --git a/src/main/java/org/tron/common/overlay/discover/node/NodeHandler.java b/src/main/java/org/tron/common/overlay/discover/node/NodeHandler.java index 5d113aa0484..9a85251fe88 100644 --- a/src/main/java/org/tron/common/overlay/discover/node/NodeHandler.java +++ b/src/main/java/org/tron/common/overlay/discover/node/NodeHandler.java @@ -127,7 +127,6 @@ private void challengeWith(NodeHandler replaceCandidate) { // Manages state transfers public void changeState(State newState) { - logger.info("Node {} change status {} to {}", node.getHost(), state, newState); State oldState = state; if (newState == State.Discovered) { sendPing(); @@ -226,7 +225,7 @@ public void handleFindNode(FindNodeMessage msg) { } public void handleTimedOut() { - logger.info("ping timeout {}", node); + logger.debug("ping timeout {}", node); waitForPong = false; if (--pingTrials > 0) { sendPing(); diff --git a/src/main/java/org/tron/common/overlay/server/ChannelManager.java b/src/main/java/org/tron/common/overlay/server/ChannelManager.java index 6fcda584930..3123e536a78 100644 --- a/src/main/java/org/tron/common/overlay/server/ChannelManager.java +++ b/src/main/java/org/tron/common/overlay/server/ChannelManager.java @@ -78,11 +78,9 @@ public void processDisconnect(Channel channel, ReasonCode reason){ return; } switch (reason){ - case FORKED: case BAD_PROTOCOL: case BAD_BLOCK: - case INCOMPATIBLE_CHAIN: - case INCOMPATIBLE_PROTOCOL: + case BAD_TX: badPeers.put(channel.getInetAddress(), reason); break; default: diff --git a/src/main/java/org/tron/core/net/node/NodeImpl.java b/src/main/java/org/tron/core/net/node/NodeImpl.java index 7495bb6681b..b0da82eeb2f 100644 --- a/src/main/java/org/tron/core/net/node/NodeImpl.java +++ b/src/main/java/org/tron/core/net/node/NodeImpl.java @@ -249,8 +249,6 @@ public Thread newThread(Runnable r) { } }); - private HashMap badAdvObj = new HashMap<>(); //TODO:need auto erase oldest obj - //blocks we requested but not received private Cache syncBlockIdWeRequested = CacheBuilder.newBuilder() @@ -619,8 +617,7 @@ private synchronized void logNodeStatus() { + "unSyncNum: %d\n" + "blockWaitToProc: %d\n" + "blockJustReceived: %d\n" - + "syncBlockIdWeRequested: %d\n" - + "badAdvObj: %d\n", + + "syncBlockIdWeRequested: %d\n", del.getHeadBlockId().getNum(), advObjToSpread.size(), advObjToFetch.size(), @@ -628,8 +625,7 @@ private synchronized void logNodeStatus() { getUnSyncNum(), blockWaitToProc.size(), blockJustReceived.size(), - syncBlockIdWeRequested.size(), - badAdvObj.size() + syncBlockIdWeRequested.size() )); logger.info(sb.toString()); @@ -706,17 +702,15 @@ private void onHandleInventoryMessage(PeerConnection peer, InventoryMessage msg) peer.getAdvObjSpreadToUs().put(id, System.currentTimeMillis()); if (!requested[0]) { - if (!badAdvObj.containsKey(id)) { - PriorItem targetPriorItem = this.advObjToFetch.get(id); + PriorItem targetPriorItem = this.advObjToFetch.get(id); - if (targetPriorItem != null) { - //another peer tell this trx to us, refresh its time. - targetPriorItem.refreshTime(); - } else { - fetchWaterLine.increase(); - this.advObjToFetch.put(id, new PriorItem(new Item(id, msg.getInventoryType()), - fetchSequenceCounter.incrementAndGet())); - } + if (targetPriorItem != null) { + //another peer tell this trx to us, refresh its time. + targetPriorItem.refreshTime(); + } else { + fetchWaterLine.increase(); + this.advObjToFetch.put(id, new PriorItem(new Item(id, msg.getInventoryType()), + fetchSequenceCounter.incrementAndGet())); } } } @@ -798,7 +792,6 @@ private void processAdvBlock(PeerConnection peer, BlockCapsule block) { } catch (BadBlockException e) { logger.error("We get a bad block {}, from {}, reason is {} ", block.getBlockId().getString(), peer.getNode().getHost(), e.getMessage()); - badAdvObj.put(block.getBlockId(), System.currentTimeMillis()); disconnectPeer(peer, ReasonCode.BAD_BLOCK); } catch (UnLinkedBlockException e) { logger.error("We get a unlinked block {}, from {}, head is {}", @@ -808,7 +801,6 @@ private void processAdvBlock(PeerConnection peer, BlockCapsule block) { } catch (NonCommonBlockException e) { logger.error("We get a block {} that do not have the most recent common ancestor with the main chain, from {}, reason is {} ", block.getBlockId().getString(), peer.getNode().getHost(), e.getMessage()); - badAdvObj.put(block.getBlockId(), System.currentTimeMillis()); disconnectPeer(peer, ReasonCode.FORKED); } catch (InterruptedException e) { Thread.currentThread().interrupt(); @@ -835,7 +827,6 @@ private boolean processSyncBlock(BlockCapsule block) { } catch (BadBlockException e) { logger.error("We get a bad block {}, reason is {} ", block.getBlockId().getString(), e.getMessage()); - badAdvObj.put(block.getBlockId(), System.currentTimeMillis()); reason = ReasonCode.BAD_BLOCK; } catch (UnLinkedBlockException e) { logger.error("We get a unlinked block {}, head is {}", block.getBlockId().getString(), @@ -901,7 +892,6 @@ private void onHandleTransactionMessage(PeerConnection peer, TransactionMessage logger.error(e.getMessage()); banTraitorPeer(peer, ReasonCode.BAD_PROTOCOL); } catch (BadTransactionException e) { - badAdvObj.put(trxMsg.getMessageId(), System.currentTimeMillis()); banTraitorPeer(peer, ReasonCode.BAD_TX); } }