use of org.tron.core.capsule.BlockCapsule.BlockId in project java-tron by tronprotocol.
the class NodeDelegateImpl method getLostBlockIds.
@Override
public LinkedList<BlockId> getLostBlockIds(List<BlockId> blockChainSummary) throws UnReachBlockException {
// todo: return the blocks it should be have.
if (dbManager.getHeadBlockNum() == 0) {
return new LinkedList<>();
}
BlockId unForkedBlockId = null;
if (blockChainSummary.isEmpty() || blockChainSummary.size() == 1) {
unForkedBlockId = dbManager.getGenesisBlockId();
} else {
// todo: find a block we all know between the summary and my db.
Collections.reverse(blockChainSummary);
unForkedBlockId = blockChainSummary.stream().filter(blockId -> dbManager.containBlock(blockId)).findFirst().orElseThrow(UnReachBlockException::new);
// todo: can not find any same block form peer's summary and my db.
}
// todo: limit the count of block to send peer by one time.
long unForkedBlockIdNum = unForkedBlockId.getNum();
long len = Longs.min(dbManager.getHeadBlockNum(), unForkedBlockIdNum + NodeConstant.SYNC_FETCH_BATCH_NUM);
return LongStream.rangeClosed(unForkedBlockIdNum, len).filter(num -> num > 0).mapToObj(num -> dbManager.getBlockIdByNum(num)).collect(Collectors.toCollection(LinkedList::new));
}
Aggregations