Skip to content

Commit cc4848b

Browse files
authored
Merge pull request #1139 from tronprotocol/p2p_t4
P2p:modify bad block problem & bad peer reason
2 parents 58a7b59 + 1e49016 commit cc4848b

File tree

3 files changed

+12
-24
lines changed

3 files changed

+12
-24
lines changed

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/config/args/Args.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ private static void logConfig(){
716716
logger.info("Discover enable: {}", args.isNodeDiscoveryEnable());
717717
logger.info("Active node size: {}", args.getActiveNodes().size());
718718
logger.info("Passive node size: {}", args.getPassiveNodes().size());
719-
logger.info("Seed node size: {}", args.getSeedNodes().size());
719+
logger.info("Seed node size: {}", args.getSeedNode().getIpList().size());
720720
logger.info("Max connection: {}", args.getNodeMaxActiveNodes());
721721
logger.info("Max connection with same IP: {}", args.getNodeMaxActiveNodesWithSameIp());
722722
logger.info("************************ Backup config ************************");

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)