Skip to content

Commit 1e49016

Browse files
committed
modify the problem of the bad block & bad peer reason
1 parent 8441225 commit 1e49016

File tree

4 files changed

+14
-27
lines changed

4 files changed

+14
-27
lines changed

src/main/java/org/tron/common/net/udp/handler/MessageHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void channelActive(ChannelHandlerContext ctx) throws Exception {
5050

5151
@Override
5252
public void channelRead0(ChannelHandlerContext ctx, UdpEvent udpEvent) {
53-
logger.info("rcv udp msg type {}, len {} from {} ",
53+
logger.debug("rcv udp msg type {}, len {} from {} ",
5454
udpEvent.getMessage().getType(),
5555
udpEvent.getMessage().getSendData().length,
5656
udpEvent.getAddress());
@@ -59,7 +59,7 @@ public void channelRead0(ChannelHandlerContext ctx, UdpEvent udpEvent) {
5959

6060
@Override
6161
public void accept(UdpEvent udpEvent) {
62-
logger.info("send udp msg type {}, len {} to {} ",
62+
logger.debug("send udp msg type {}, len {} to {} ",
6363
udpEvent.getMessage().getType(),
6464
udpEvent.getMessage().getSendData().length,
6565
udpEvent.getAddress());

src/main/java/org/tron/common/overlay/discover/node/NodeHandler.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ private void challengeWith(NodeHandler replaceCandidate) {
127127

128128
// Manages state transfers
129129
public void changeState(State newState) {
130-
logger.info("Node {} change status {} to {}", node.getHost(), state, newState);
131130
State oldState = state;
132131
if (newState == State.Discovered) {
133132
sendPing();
@@ -226,7 +225,7 @@ public void handleFindNode(FindNodeMessage msg) {
226225
}
227226

228227
public void handleTimedOut() {
229-
logger.info("ping timeout {}", node);
228+
logger.debug("ping timeout {}", node);
230229
waitForPong = false;
231230
if (--pingTrials > 0) {
232231
sendPing();

src/main/java/org/tron/common/overlay/server/ChannelManager.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,9 @@ public void processDisconnect(Channel channel, ReasonCode reason){
7878
return;
7979
}
8080
switch (reason){
81-
case FORKED:
8281
case BAD_PROTOCOL:
8382
case BAD_BLOCK:
84-
case INCOMPATIBLE_CHAIN:
85-
case INCOMPATIBLE_PROTOCOL:
83+
case BAD_TX:
8684
badPeers.put(channel.getInetAddress(), reason);
8785
break;
8886
default:

src/main/java/org/tron/core/net/node/NodeImpl.java

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,6 @@ public Thread newThread(Runnable r) {
249249
}
250250
});
251251

252-
private HashMap<Sha256Hash, Long> badAdvObj = new HashMap<>(); //TODO:need auto erase oldest obj
253-
254252
//blocks we requested but not received
255253

256254
private Cache<BlockId, Long> syncBlockIdWeRequested = CacheBuilder.newBuilder()
@@ -619,17 +617,15 @@ private synchronized void logNodeStatus() {
619617
+ "unSyncNum: %d\n"
620618
+ "blockWaitToProc: %d\n"
621619
+ "blockJustReceived: %d\n"
622-
+ "syncBlockIdWeRequested: %d\n"
623-
+ "badAdvObj: %d\n",
620+
+ "syncBlockIdWeRequested: %d\n",
624621
del.getHeadBlockId().getNum(),
625622
advObjToSpread.size(),
626623
advObjToFetch.size(),
627624
advObjWeRequested.size(),
628625
getUnSyncNum(),
629626
blockWaitToProc.size(),
630627
blockJustReceived.size(),
631-
syncBlockIdWeRequested.size(),
632-
badAdvObj.size()
628+
syncBlockIdWeRequested.size()
633629
));
634630

635631
logger.info(sb.toString());
@@ -706,17 +702,15 @@ private void onHandleInventoryMessage(PeerConnection peer, InventoryMessage msg)
706702

707703
peer.getAdvObjSpreadToUs().put(id, System.currentTimeMillis());
708704
if (!requested[0]) {
709-
if (!badAdvObj.containsKey(id)) {
710-
PriorItem targetPriorItem = this.advObjToFetch.get(id);
705+
PriorItem targetPriorItem = this.advObjToFetch.get(id);
711706

712-
if (targetPriorItem != null) {
713-
//another peer tell this trx to us, refresh its time.
714-
targetPriorItem.refreshTime();
715-
} else {
716-
fetchWaterLine.increase();
717-
this.advObjToFetch.put(id, new PriorItem(new Item(id, msg.getInventoryType()),
718-
fetchSequenceCounter.incrementAndGet()));
719-
}
707+
if (targetPriorItem != null) {
708+
//another peer tell this trx to us, refresh its time.
709+
targetPriorItem.refreshTime();
710+
} else {
711+
fetchWaterLine.increase();
712+
this.advObjToFetch.put(id, new PriorItem(new Item(id, msg.getInventoryType()),
713+
fetchSequenceCounter.incrementAndGet()));
720714
}
721715
}
722716
}
@@ -798,7 +792,6 @@ private void processAdvBlock(PeerConnection peer, BlockCapsule block) {
798792
} catch (BadBlockException e) {
799793
logger.error("We get a bad block {}, from {}, reason is {} ",
800794
block.getBlockId().getString(), peer.getNode().getHost(), e.getMessage());
801-
badAdvObj.put(block.getBlockId(), System.currentTimeMillis());
802795
disconnectPeer(peer, ReasonCode.BAD_BLOCK);
803796
} catch (UnLinkedBlockException e) {
804797
logger.error("We get a unlinked block {}, from {}, head is {}",
@@ -808,7 +801,6 @@ private void processAdvBlock(PeerConnection peer, BlockCapsule block) {
808801
} catch (NonCommonBlockException e) {
809802
logger.error("We get a block {} that do not have the most recent common ancestor with the main chain, from {}, reason is {} ",
810803
block.getBlockId().getString(), peer.getNode().getHost(), e.getMessage());
811-
badAdvObj.put(block.getBlockId(), System.currentTimeMillis());
812804
disconnectPeer(peer, ReasonCode.FORKED);
813805
} catch (InterruptedException e) {
814806
Thread.currentThread().interrupt();
@@ -835,7 +827,6 @@ private boolean processSyncBlock(BlockCapsule block) {
835827
} catch (BadBlockException e) {
836828
logger.error("We get a bad block {}, reason is {} ", block.getBlockId().getString(),
837829
e.getMessage());
838-
badAdvObj.put(block.getBlockId(), System.currentTimeMillis());
839830
reason = ReasonCode.BAD_BLOCK;
840831
} catch (UnLinkedBlockException e) {
841832
logger.error("We get a unlinked block {}, head is {}", block.getBlockId().getString(),
@@ -901,7 +892,6 @@ private void onHandleTransactionMessage(PeerConnection peer, TransactionMessage
901892
logger.error(e.getMessage());
902893
banTraitorPeer(peer, ReasonCode.BAD_PROTOCOL);
903894
} catch (BadTransactionException e) {
904-
badAdvObj.put(trxMsg.getMessageId(), System.currentTimeMillis());
905895
banTraitorPeer(peer, ReasonCode.BAD_TX);
906896
}
907897
}

0 commit comments

Comments
 (0)