@Test public void chainDownloadEnd2End() throws Exception { Block b1 = createFakeBlock(blockStore, Block.BLOCK_HEIGHT_GENESIS).block; blockChain.add(b1); Block b2 = makeSolvedTestBlock(b1); Block b3 = makeSolvedTestBlock(b2); Block b4 = makeSolvedTestBlock(b3); Block b5 = makeSolvedTestBlock(b4); connect(); peer.startBlockChainDownload(); GetBlocksMessage getblocks = (GetBlocksMessage)outbound(writeTarget); assertEquals(blockStore.getChainHead().getHeader().getHash(), getblocks.getLocator().get(0)); assertEquals(Sha256Hash.ZERO_HASH, getblocks.getStopHash()); InventoryMessage inv = new InventoryMessage(UNITTEST); inv.addBlock(b2); inv.addBlock(b3); inbound(writeTarget, inv); GetDataMessage getdata = (GetDataMessage)outbound(writeTarget); assertEquals(b2.getHash(), getdata.getItems().get(0).hash); assertEquals(b3.getHash(), getdata.getItems().get(1).hash); assertEquals(2, getdata.getItems().size()); inbound(writeTarget, b2); inbound(writeTarget, b3); inv = new InventoryMessage(UNITTEST); inv.addBlock(b5); inbound(writeTarget, inv); getdata = (GetDataMessage)outbound(writeTarget); assertEquals(b5.getHash(), getdata.getItems().get(0).hash); assertEquals(1, getdata.getItems().size()); inbound(writeTarget, b5); getblocks = (GetBlocksMessage)outbound(writeTarget); assertEquals(b5.getHash(), getblocks.getStopHash()); assertEquals(b3.getHash(), getblocks.getLocator().getHashes().get(0)); Block b6 = makeSolvedTestBlock(b5); inv = new InventoryMessage(UNITTEST); inv.addBlock(b6); inbound(writeTarget, inv); getdata = (GetDataMessage)outbound(writeTarget); assertEquals(1, getdata.getItems().size()); assertEquals(b6.getHash(), getdata.getItems().get(0).hash); inbound(writeTarget, b6); assertNull(outbound(writeTarget)); inv = new InventoryMessage(UNITTEST); inv.addBlock(b4); inv.addBlock(b5); inbound(writeTarget, inv); getdata = (GetDataMessage)outbound(writeTarget); assertEquals(1, getdata.getItems().size()); assertEquals(b4.getHash(), getdata.getItems().get(0).hash); inbound(writeTarget, b4); assertNull(outbound(writeTarget)); assertNull(outbound(writeTarget)); closePeer(peer); }
public void startBlockChainDownload() { setDownloadData(true); final int blocksLeft = getPeerBlockHeightDifference(); if (blocksLeft >= 0) { for (final ListenerRegistration<ChainDownloadStartedEventListener> registration : chainDownloadStartedEventListeners) { registration.executor.execute(new Runnable() { @Override public void run() { registration.listener.onChainDownloadStarted(Peer.this, blocksLeft); } }); } lock.lock(); try { blockChainDownloadLocked(Sha256Hash.ZERO_HASH); } finally { lock.unlock(); } } }
Peer extends PeerSocketHandler { public void startBlockChainDownload() { setDownloadData(true); final int blocksLeft = getPeerBlockHeightDifference(); if (blocksLeft >= 0) { for (final ListenerRegistration<ChainDownloadStartedEventListener> registration : chainDownloadStartedEventListeners) { registration.executor.execute(new Runnable() { @Override public void run() { registration.listener.onChainDownloadStarted(Peer.this, blocksLeft); } }); } lock.lock(); try { blockChainDownloadLocked(Sha256Hash.ZERO_HASH); } finally { lock.unlock(); } } } }
Peer extends PeerSocketHandler { public void startBlockChainDownload() { setDownloadData(true); final int blocksLeft = getPeerBlockHeightDifference(); if (blocksLeft >= 0) { for (final ListenerRegistration<ChainDownloadStartedEventListener> registration : chainDownloadStartedEventListeners) { registration.executor.execute(new Runnable() { @Override public void run() { registration.listener.onChainDownloadStarted(Peer.this, blocksLeft); } }); } lock.lock(); try { blockChainDownloadLocked(Sha256Hash.ZERO_HASH); } finally { lock.unlock(); } } } @Deprecated  Peer(NetworkParameters params, VersionMessage ver, @Nullable AbstractBlockChain chain, PeerAddress remoteAddress);  Peer(NetworkParameters params, VersionMessage ver, PeerAddress remoteAddress,
                @Nullable AbstractBlockChain chain);  Peer(NetworkParameters params, VersionMessage ver, PeerAddress remoteAddress,
                @Nullable AbstractBlockChain chain, long requiredServices, int downloadTxDependencyDepth);  Peer(NetworkParameters params, AbstractBlockChain blockChain, PeerAddress peerAddress, String thisSoftwareName, String thisSoftwareVersion); }
Peer extends PeerSocketHandler { public void startBlockChainDownload() { setDownloadData(true); final int blocksLeft = getPeerBlockHeightDifference(); if (blocksLeft >= 0) { for (final ListenerRegistration<ChainDownloadStartedEventListener> registration : chainDownloadStartedEventListeners) { registration.executor.execute(new Runnable() { @Override public void run() { registration.listener.onChainDownloadStarted(Peer.this, blocksLeft); } }); } lock.lock(); try { blockChainDownloadLocked(Sha256Hash.ZERO_HASH); } finally { lock.unlock(); } } } @Deprecated  Peer(NetworkParameters params, VersionMessage ver, @Nullable AbstractBlockChain chain, PeerAddress remoteAddress);  Peer(NetworkParameters params, VersionMessage ver, PeerAddress remoteAddress,
                @Nullable AbstractBlockChain chain);  Peer(NetworkParameters params, VersionMessage ver, PeerAddress remoteAddress,
                @Nullable AbstractBlockChain chain, long requiredServices, int downloadTxDependencyDepth);  Peer(NetworkParameters params, AbstractBlockChain blockChain, PeerAddress peerAddress, String thisSoftwareName, String thisSoftwareVersion); void addBlocksDownloadedEventListener(BlocksDownloadedEventListener listener); void addBlocksDownloadedEventListener(Executor executor, BlocksDownloadedEventListener listener); void addChainDownloadStartedEventListener(ChainDownloadStartedEventListener listener); void addChainDownloadStartedEventListener(Executor executor, ChainDownloadStartedEventListener listener); void addConnectedEventListener(PeerConnectedEventListener listener); void addConnectedEventListener(Executor executor, PeerConnectedEventListener listener); void addDisconnectedEventListener(PeerDisconnectedEventListener listener); void addDisconnectedEventListener(Executor executor, PeerDisconnectedEventListener listener); void addGetDataEventListener(GetDataEventListener listener); void addGetDataEventListener(Executor executor, GetDataEventListener listener); void addOnTransactionBroadcastListener(OnTransactionBroadcastListener listener); void addOnTransactionBroadcastListener(Executor executor, OnTransactionBroadcastListener listener); void addPreMessageReceivedEventListener(PreMessageReceivedEventListener listener); void addPreMessageReceivedEventListener(Executor executor, PreMessageReceivedEventListener listener); boolean removeBlocksDownloadedEventListener(BlocksDownloadedEventListener listener); boolean removeChainDownloadStartedEventListener(ChainDownloadStartedEventListener listener); boolean removeConnectedEventListener(PeerConnectedEventListener listener); boolean removeDisconnectedEventListener(PeerDisconnectedEventListener listener); boolean removeGetDataEventListener(GetDataEventListener listener); boolean removeOnTransactionBroadcastListener(OnTransactionBroadcastListener listener); boolean removePreMessageReceivedEventListener(PreMessageReceivedEventListener listener); @Override String toString(); @Deprecated String toStringServices(long services); @Override void connectionClosed(); @Override void connectionOpened(); ListenableFuture<Peer> getConnectionOpenFuture(); ListenableFuture<Peer> getVersionHandshakeFuture(); ListenableFuture<List<Transaction>> downloadDependencies(Transaction tx); @SuppressWarnings("unchecked") // The 'unchecked conversion' warning being suppressed here comes from the sendSingleGetData() formally returning // ListenableFuture instead of ListenableFuture<Block>. This is okay as sendSingleGetData() actually returns // ListenableFuture<Block> in this context. Note that sendSingleGetData() is also used for Transactions. ListenableFuture<Block> getBlock(Sha256Hash blockHash); @SuppressWarnings("unchecked") // The 'unchecked conversion' warning being suppressed here comes from the sendSingleGetData() formally returning // ListenableFuture instead of ListenableFuture<Transaction>. This is okay as sendSingleGetData() actually returns // ListenableFuture<Transaction> in this context. Note that sendSingleGetData() is also used for Blocks. ListenableFuture<Transaction> getPeerMempoolTransaction(Sha256Hash hash); ListenableFuture<AddressMessage> getAddr(); void setDownloadParameters(long secondsSinceEpoch, boolean useFilteredBlocks); void addWallet(Wallet wallet); void removeWallet(Wallet wallet); void startBlockChainDownload(); ListenableFuture<Long> ping(); long getLastPingTime(); long getPingTime(); int getPeerBlockHeightDifference(); boolean isDownloadData(); void setDownloadData(boolean downloadData); VersionMessage getPeerVersionMessage(); VersionMessage getVersionMessage(); long getBestHeight(); boolean setMinProtocolVersion(int minProtocolVersion); void setBloomFilter(BloomFilter filter); void setBloomFilter(BloomFilter filter, boolean andQueryMemPool); BloomFilter getBloomFilter(); ListenableFuture<UTXOsMessage> getUTXOs(List<TransactionOutPoint> outPoints); ListenableFuture<UTXOsMessage> getUTXOs(List<TransactionOutPoint> outPoints, boolean includeMempool); boolean isDownloadTxDependencies(); void setDownloadTxDependencies(boolean enable); void setDownloadTxDependencies(int depth); }
Peer extends PeerSocketHandler { public void startBlockChainDownload() { setDownloadData(true); final int blocksLeft = getPeerBlockHeightDifference(); if (blocksLeft >= 0) { for (final ListenerRegistration<ChainDownloadStartedEventListener> registration : chainDownloadStartedEventListeners) { registration.executor.execute(new Runnable() { @Override public void run() { registration.listener.onChainDownloadStarted(Peer.this, blocksLeft); } }); } lock.lock(); try { blockChainDownloadLocked(Sha256Hash.ZERO_HASH); } finally { lock.unlock(); } } } @Deprecated  Peer(NetworkParameters params, VersionMessage ver, @Nullable AbstractBlockChain chain, PeerAddress remoteAddress);  Peer(NetworkParameters params, VersionMessage ver, PeerAddress remoteAddress,
                @Nullable AbstractBlockChain chain);  Peer(NetworkParameters params, VersionMessage ver, PeerAddress remoteAddress,
                @Nullable AbstractBlockChain chain, long requiredServices, int downloadTxDependencyDepth);  Peer(NetworkParameters params, AbstractBlockChain blockChain, PeerAddress peerAddress, String thisSoftwareName, String thisSoftwareVersion); void addBlocksDownloadedEventListener(BlocksDownloadedEventListener listener); void addBlocksDownloadedEventListener(Executor executor, BlocksDownloadedEventListener listener); void addChainDownloadStartedEventListener(ChainDownloadStartedEventListener listener); void addChainDownloadStartedEventListener(Executor executor, ChainDownloadStartedEventListener listener); void addConnectedEventListener(PeerConnectedEventListener listener); void addConnectedEventListener(Executor executor, PeerConnectedEventListener listener); void addDisconnectedEventListener(PeerDisconnectedEventListener listener); void addDisconnectedEventListener(Executor executor, PeerDisconnectedEventListener listener); void addGetDataEventListener(GetDataEventListener listener); void addGetDataEventListener(Executor executor, GetDataEventListener listener); void addOnTransactionBroadcastListener(OnTransactionBroadcastListener listener); void addOnTransactionBroadcastListener(Executor executor, OnTransactionBroadcastListener listener); void addPreMessageReceivedEventListener(PreMessageReceivedEventListener listener); void addPreMessageReceivedEventListener(Executor executor, PreMessageReceivedEventListener listener); boolean removeBlocksDownloadedEventListener(BlocksDownloadedEventListener listener); boolean removeChainDownloadStartedEventListener(ChainDownloadStartedEventListener listener); boolean removeConnectedEventListener(PeerConnectedEventListener listener); boolean removeDisconnectedEventListener(PeerDisconnectedEventListener listener); boolean removeGetDataEventListener(GetDataEventListener listener); boolean removeOnTransactionBroadcastListener(OnTransactionBroadcastListener listener); boolean removePreMessageReceivedEventListener(PreMessageReceivedEventListener listener); @Override String toString(); @Deprecated String toStringServices(long services); @Override void connectionClosed(); @Override void connectionOpened(); ListenableFuture<Peer> getConnectionOpenFuture(); ListenableFuture<Peer> getVersionHandshakeFuture(); ListenableFuture<List<Transaction>> downloadDependencies(Transaction tx); @SuppressWarnings("unchecked") // The 'unchecked conversion' warning being suppressed here comes from the sendSingleGetData() formally returning // ListenableFuture instead of ListenableFuture<Block>. This is okay as sendSingleGetData() actually returns // ListenableFuture<Block> in this context. Note that sendSingleGetData() is also used for Transactions. ListenableFuture<Block> getBlock(Sha256Hash blockHash); @SuppressWarnings("unchecked") // The 'unchecked conversion' warning being suppressed here comes from the sendSingleGetData() formally returning // ListenableFuture instead of ListenableFuture<Transaction>. This is okay as sendSingleGetData() actually returns // ListenableFuture<Transaction> in this context. Note that sendSingleGetData() is also used for Blocks. ListenableFuture<Transaction> getPeerMempoolTransaction(Sha256Hash hash); ListenableFuture<AddressMessage> getAddr(); void setDownloadParameters(long secondsSinceEpoch, boolean useFilteredBlocks); void addWallet(Wallet wallet); void removeWallet(Wallet wallet); void startBlockChainDownload(); ListenableFuture<Long> ping(); long getLastPingTime(); long getPingTime(); int getPeerBlockHeightDifference(); boolean isDownloadData(); void setDownloadData(boolean downloadData); VersionMessage getPeerVersionMessage(); VersionMessage getVersionMessage(); long getBestHeight(); boolean setMinProtocolVersion(int minProtocolVersion); void setBloomFilter(BloomFilter filter); void setBloomFilter(BloomFilter filter, boolean andQueryMemPool); BloomFilter getBloomFilter(); ListenableFuture<UTXOsMessage> getUTXOs(List<TransactionOutPoint> outPoints); ListenableFuture<UTXOsMessage> getUTXOs(List<TransactionOutPoint> outPoints, boolean includeMempool); boolean isDownloadTxDependencies(); void setDownloadTxDependencies(boolean enable); void setDownloadTxDependencies(int depth);  }