Package org.ethereum.net

Examples of org.ethereum.net.BlockQueue


//      msgQueue.sendMessage(new DisconnectMessage(ReasonCode.INCOMPATIBLE_NETWORK));
            ctx.pipeline().remove(this); // Peer is not compatible for the 'eth' sub-protocol
        } else if (msg.getNetworkId() != EthHandler.NETWORK_ID)
            msgQueue.sendMessage(new DisconnectMessage(ReasonCode.INCOMPATIBLE_NETWORK));
        else {
            BlockQueue chainQueue = blockchain.getQueue();
            BigInteger peerTotalDifficulty = new BigInteger(1, msg.getTotalDifficulty());
            BigInteger highestKnownTotalDifficulty = blockchain.getTotalDifficulty();
            if ( highestKnownTotalDifficulty == null ||
                 peerTotalDifficulty.compareTo(highestKnownTotalDifficulty) > 0) {

                logger.info(" Their chain is better: total difficulty : {} vs {}",
                        peerTotalDifficulty.toString(),
                        highestKnownTotalDifficulty == null ? "0" : highestKnownTotalDifficulty.toString());

                hashRetrievalLock = this.peerId;
                chainQueue.setHighestTotalDifficulty(peerTotalDifficulty);
                chainQueue.setBestHash(msg.getBestHash());
                syncStatus = SyncSatus.HASH_RETRIEVING;
                sendGetBlockHashes();
            } else{
                logger.info("The peer sync process fully complete");
                syncStatus = SyncSatus.SYNC_DONE;
View Full Code Here


    }

    private void processBlockHashes(BlockHashesMessage blockHashesMessage) {

        List<byte[]> receivedHashes = blockHashesMessage.getBlockHashes();
        BlockQueue chainQueue = blockchain.getQueue();

        // result is empty, peer has no more hashes
        // or peer doesn't have the best hash anymore
        if (receivedHashes.isEmpty()
                || !this.peerId.equals(hashRetrievalLock)) {
            startGetBlockTimer(); // start getting blocks from hash queue
            return;
        }

        Iterator<byte[]> hashIterator = receivedHashes.iterator();
        byte[] foundHash, latestHash = blockchain.getBestBlockHash();
        while (hashIterator.hasNext()) {
            foundHash = hashIterator.next();
            if (FastByteComparisons.compareTo(foundHash, 0, 32, latestHash, 0, 32) != 0){
                chainQueue.addHash(foundHash);    // store unknown hashes in queue until known hash is found
            }
            else {

                logger.trace("Catch up with the hashes until: {[]}", foundHash);
                // if known hash is found, ignore the rest
                startGetBlockTimer(); // start getting blocks from hash queue
                return;
            }
        }
        // no known hash has been reached
        chainQueue.logHashQueueSize();
        sendGetBlockHashes(); // another getBlockHashes with last received hash.
    }
View Full Code Here

        msgQueue.sendMessage(msg);
    }

    // Parallel download blocks based on hashQueue
    private void sendGetBlocks() {
        BlockQueue queue = blockchain.getQueue();
        if (queue.size() > CONFIG.maxBlocksQueued()) return;

        // retrieve list of block hashes from queue
        List<byte[]> hashes = queue.getHashes();
        if (hashes.isEmpty()) {
            stopGetBlocksTimer();
            return;
        }
View Full Code Here

    public void startGetBlockTimer() {
        syncStatus = SyncSatus.BLOCK_RETRIEVING;
        getBlocksTimer = new Timer("GetBlocksTimer");
        getBlocksTimer.scheduleAtFixedRate(new TimerTask() {
            public void run() {
                BlockQueue blockQueue = blockchain.getQueue();
                if (blockQueue.size() > CONFIG.maxBlocksQueued()) {
                    logger.trace("Blocks queue too big temporary postpone blocks request");
                    return;
                }
                sendGetBlocks();
            }
View Full Code Here

TOP

Related Classes of org.ethereum.net.BlockQueue

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.