Skip to content

Commit 91bb7db

Browse files
authored
Merge pull request #432 from tronprotocol/sync_get_lost_block
Sync: modify get lost block logic
2 parents 0573941 + 8e5685b commit 91bb7db

File tree

3 files changed

+9
-13
lines changed

3 files changed

+9
-13
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ LinkedList<Sha256Hash> handleBlock(BlockCapsule block, boolean syncMode)
2121

2222
void handleTransaction(TransactionCapsule trx) throws BadTransactionException;
2323

24-
LinkedList<BlockId> getLostBlockIds(List<BlockId> blockChainSummary) throws UnReachBlockException;
24+
LinkedList<BlockId> getLostBlockIds(List<BlockId> blockChainSummary);
2525

2626
Deque<BlockId> getBlockChainSummary(BlockId beginBLockId, Deque<BlockId> blockIds)
2727
throws UnLinkedBlockException;

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ public void handleTransaction(TransactionCapsule trx) throws BadTransactionExcep
9292
}
9393

9494
@Override
95-
public LinkedList<BlockId> getLostBlockIds(List<BlockId> blockChainSummary)
96-
throws UnReachBlockException {
95+
public LinkedList<BlockId> getLostBlockIds(List<BlockId> blockChainSummary) {
9796
//todo: return the remain block count.
9897
//todo: return the blocks it should be have.
9998
if (dbManager.getHeadBlockNum() == 0) {
@@ -115,9 +114,11 @@ public LinkedList<BlockId> getLostBlockIds(List<BlockId> blockChainSummary)
115114
//todo: find a block we all know between the summary and my db.
116115
Collections.reverse(blockChainSummary);
117116
unForkedBlockId = blockChainSummary.stream()
118-
.filter(blockId -> containBlockInMainChain(blockId))
119-
.findFirst()
120-
.orElseThrow(UnReachBlockException::new);
117+
.filter(blockId -> containBlockInMainChain(blockId))
118+
.findFirst().orElse(null);
119+
if (unForkedBlockId == null){
120+
return new LinkedList<>();
121+
}
121122
//todo: can not find any same block form peer's summary and my db.
122123
}
123124

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -730,13 +730,8 @@ private void onHandleSyncBlockChainMessage(PeerConnection peer, SyncBlockChainMe
730730
LinkedList<BlockId> blockIds;
731731
List<BlockId> summaryChainIds = syncMsg.getBlockIds();
732732
long remainNum = 0;
733-
try {
734-
blockIds = del.getLostBlockIds(summaryChainIds);
735-
} catch (UnReachBlockException e) {
736-
//TODO: disconnect this peer casue this peer can not switch
737-
logger.debug(e.getMessage(), e);
738-
return;
739-
}
733+
734+
blockIds = del.getLostBlockIds(summaryChainIds);
740735

741736
if (blockIds.isEmpty()) {
742737
peer.setNeedSyncFromUs(false);

0 commit comments

Comments
 (0)