Skip to content

Commit

Permalink
Merge pull request #432 from tronprotocol/sync_get_lost_block
Browse files Browse the repository at this point in the history
Sync: modify get lost block logic
  • Loading branch information
zhaohong authored Apr 13, 2018
2 parents 0573941 + 8e5685b commit 91bb7db
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/tron/core/net/node/NodeDelegate.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ LinkedList<Sha256Hash> handleBlock(BlockCapsule block, boolean syncMode)

void handleTransaction(TransactionCapsule trx) throws BadTransactionException;

LinkedList<BlockId> getLostBlockIds(List<BlockId> blockChainSummary) throws UnReachBlockException;
LinkedList<BlockId> getLostBlockIds(List<BlockId> blockChainSummary);

Deque<BlockId> getBlockChainSummary(BlockId beginBLockId, Deque<BlockId> blockIds)
throws UnLinkedBlockException;
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/org/tron/core/net/node/NodeDelegateImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ public void handleTransaction(TransactionCapsule trx) throws BadTransactionExcep
}

@Override
public LinkedList<BlockId> getLostBlockIds(List<BlockId> blockChainSummary)
throws UnReachBlockException {
public LinkedList<BlockId> getLostBlockIds(List<BlockId> blockChainSummary) {
//todo: return the remain block count.
//todo: return the blocks it should be have.
if (dbManager.getHeadBlockNum() == 0) {
Expand All @@ -115,9 +114,11 @@ public LinkedList<BlockId> getLostBlockIds(List<BlockId> 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.
}

Expand Down
9 changes: 2 additions & 7 deletions src/main/java/org/tron/core/net/node/NodeImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -730,13 +730,8 @@ private void onHandleSyncBlockChainMessage(PeerConnection peer, SyncBlockChainMe
LinkedList<BlockId> blockIds;
List<BlockId> 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);
Expand Down

0 comments on commit 91bb7db

Please sign in to comment.