From 4957b22bd2a04f48f4cf15ea8ed358f56f9b285f Mon Sep 17 00:00:00 2001 From: wubin01 Date: Fri, 13 Apr 2018 20:20:18 +0800 Subject: [PATCH] modify get lost block --- .../java/org/tron/core/net/node/NodeDelegate.java | 2 +- .../java/org/tron/core/net/node/NodeDelegateImpl.java | 11 ++++++----- src/main/java/org/tron/core/net/node/NodeImpl.java | 9 ++------- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/tron/core/net/node/NodeDelegate.java b/src/main/java/org/tron/core/net/node/NodeDelegate.java index 115ed29bf1e..f9856bebeda 100644 --- a/src/main/java/org/tron/core/net/node/NodeDelegate.java +++ b/src/main/java/org/tron/core/net/node/NodeDelegate.java @@ -21,7 +21,7 @@ LinkedList handleBlock(BlockCapsule block, boolean syncMode) void handleTransaction(TransactionCapsule trx) throws BadTransactionException; - LinkedList getLostBlockIds(List blockChainSummary) throws UnReachBlockException; + LinkedList getLostBlockIds(List blockChainSummary); Deque getBlockChainSummary(BlockId beginBLockId, Deque blockIds) throws UnLinkedBlockException; diff --git a/src/main/java/org/tron/core/net/node/NodeDelegateImpl.java b/src/main/java/org/tron/core/net/node/NodeDelegateImpl.java index 5c402a797fe..29f941cca81 100755 --- a/src/main/java/org/tron/core/net/node/NodeDelegateImpl.java +++ b/src/main/java/org/tron/core/net/node/NodeDelegateImpl.java @@ -92,8 +92,7 @@ public void handleTransaction(TransactionCapsule trx) throws BadTransactionExcep } @Override - public LinkedList getLostBlockIds(List blockChainSummary) - throws UnReachBlockException { + public LinkedList getLostBlockIds(List blockChainSummary) { //todo: return the remain block count. //todo: return the blocks it should be have. if (dbManager.getHeadBlockNum() == 0) { @@ -115,9 +114,11 @@ public LinkedList getLostBlockIds(List blockChainSummary) //todo: find a block we all know between the summary and my db. Collections.reverse(blockChainSummary); unForkedBlockId = blockChainSummary.stream() - .filter(blockId -> containBlockInMainChain(blockId)) - .findFirst() - .orElseThrow(UnReachBlockException::new); + .filter(blockId -> containBlockInMainChain(blockId)) + .findFirst().orElse(null); + if (unForkedBlockId == null){ + return new LinkedList<>(); + } //todo: can not find any same block form peer's summary and my db. } 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 cfae771d935..53f5dd73891 100755 --- a/src/main/java/org/tron/core/net/node/NodeImpl.java +++ b/src/main/java/org/tron/core/net/node/NodeImpl.java @@ -730,13 +730,8 @@ private void onHandleSyncBlockChainMessage(PeerConnection peer, SyncBlockChainMe LinkedList blockIds; List summaryChainIds = syncMsg.getBlockIds(); long remainNum = 0; - try { - blockIds = del.getLostBlockIds(summaryChainIds); - } catch (UnReachBlockException e) { - //TODO: disconnect this peer casue this peer can not switch - logger.debug(e.getMessage(), e); - return; - } + + blockIds = del.getLostBlockIds(summaryChainIds); if (blockIds.isEmpty()) { peer.setNeedSyncFromUs(false);