Search in sources :

Example 6 with BlockId

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));
}
Also used : BadTransactionException(org.tron.core.exception.BadTransactionException) ContractValidateException(org.tron.core.exception.ContractValidateException) BlockStore(org.tron.core.db.BlockStore) HighFreqException(org.tron.core.exception.HighFreqException) Deque(java.util.Deque) BlockCapsule(org.tron.core.capsule.BlockCapsule) ContractExeException(org.tron.core.exception.ContractExeException) BlockId(org.tron.core.capsule.BlockCapsule.BlockId) Manager(org.tron.core.db.Manager) BadBlockException(org.tron.core.exception.BadBlockException) TransactionMessage(org.tron.core.net.message.TransactionMessage) LinkedList(java.util.LinkedList) Sha256Hash(org.tron.common.utils.Sha256Hash) BlockMessage(org.tron.core.net.message.BlockMessage) Message(org.tron.common.overlay.message.Message) NodeConstant(org.tron.core.config.Parameter.NodeConstant) Longs(com.google.common.primitives.Longs) LongStream(java.util.stream.LongStream) MessageTypes(org.tron.core.net.message.MessageTypes) UnReachBlockException(org.tron.core.exception.UnReachBlockException) Collectors(java.util.stream.Collectors) TransactionCapsule(org.tron.core.capsule.TransactionCapsule) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) ValidateSignatureException(org.tron.core.exception.ValidateSignatureException) Collections(java.util.Collections) UnLinkedBlockException(org.tron.core.exception.UnLinkedBlockException) BlockId(org.tron.core.capsule.BlockCapsule.BlockId) LinkedList(java.util.LinkedList)

Aggregations

BlockId (org.tron.core.capsule.BlockCapsule.BlockId)6 LinkedList (java.util.LinkedList)4 UnReachBlockException (org.tron.core.exception.UnReachBlockException)4 Sha256Hash (org.tron.common.utils.Sha256Hash)3 BadBlockException (org.tron.core.exception.BadBlockException)3 BadTransactionException (org.tron.core.exception.BadTransactionException)3 TraitorPeerException (org.tron.core.exception.TraitorPeerException)3 UnLinkedBlockException (org.tron.core.exception.UnLinkedBlockException)3 BlockMessage (org.tron.core.net.message.BlockMessage)3 Deque (java.util.Deque)2 List (java.util.List)2 Slf4j (lombok.extern.slf4j.Slf4j)2 Message (org.tron.common.overlay.message.Message)2 BlockCapsule (org.tron.core.capsule.BlockCapsule)2 NodeConstant (org.tron.core.config.Parameter.NodeConstant)2 TronException (org.tron.core.exception.TronException)2 MessageTypes (org.tron.core.net.message.MessageTypes)2 SyncBlockChainMessage (org.tron.core.net.message.SyncBlockChainMessage)2 TransactionMessage (org.tron.core.net.message.TransactionMessage)2 PeerConnection (org.tron.core.net.peer.PeerConnection)2