3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-01-30 23:02:15 +00:00

Restart chain download after download peer changes. Resolves issue 287.

The way we handle changing download peers isn't ideal and can cause some thrashing/wasted bandwidth at startup - it has lots of room for improvement.
This commit is contained in:
Mike Hearn 2013-01-29 15:25:32 +01:00
parent 20cab64943
commit 4bdb0fd5ce

View File

@ -718,15 +718,13 @@ public class PeerGroup extends AbstractIdleService {
// Link the peer to the memory pool so broadcast transactions have their confidence levels updated.
peer.setMemoryPool(memoryPool);
peer.setDownloadData(false);
// If we want to download the chain, and we aren't currently doing so, do so now.
if (downloadListener != null && downloadPeer == null && chain != null) {
log.info(" starting block chain download");
startBlockChainDownloadFromPeer(peer);
} else {
// Re-evaluate download peers.
Peer newDownloadPeer = selectDownloadPeer(peers);
if (downloadPeer != newDownloadPeer) {
setDownloadPeer(newDownloadPeer);
// Re-evaluate download peers.
Peer newDownloadPeer = selectDownloadPeer(peers);
if (downloadPeer != newDownloadPeer) {
setDownloadPeer(newDownloadPeer);
boolean shouldDownloadChain = downloadListener != null && chain != null;
if (shouldDownloadChain) {
startBlockChainDownloadFromPeer(downloadPeer);
}
}
// Make sure the peer knows how to upload transactions that are requested from us.
@ -843,6 +841,9 @@ public class PeerGroup extends AbstractIdleService {
}
private synchronized void setDownloadPeer(Peer peer) {
if (downloadPeer == peer) {
return;
}
if (chain == null) {
// PeerGroup creator did not want us to download any data. We still track the download peer for
// informational purposes.