Improve synchronization

This commit is contained in:
catbref 2019-05-10 20:11:01 +01:00
parent 4744232a1c
commit e5b3166df4
2 changed files with 5 additions and 5 deletions

View File

@ -212,7 +212,7 @@ public class Controller extends Thread {
try {
while (!isStopping) {
Thread.sleep(1000);
Thread.sleep(10000);
potentiallySynchronize();

View File

@ -69,6 +69,10 @@ public class Synchronizer {
this.ourHeight = this.repository.getBlockRepository().getBlockchainHeight();
final int peerHeight = peer.getPeerData().getLastHeight();
// If peer is at genesis block then peer has no blocks so ignore them for a while
if (peerHeight == 1)
return false;
LOGGER.info(String.format("Synchronizing with peer %s at height %d, our height %d", peer, peerHeight, this.ourHeight));
List<byte[]> signatures = findSignaturesFromCommonBlock(peer);
@ -83,10 +87,6 @@ public class Synchronizer {
LOGGER.info(String.format("Common block with peer %s is at height %d", peer, commonBlockHeight));
signatures.remove(0);
// If common block is genesis block then peer has no blocks so ignore them for a while
if (commonBlockHeight == 1)
return false;
// If common block is peer's latest block then we simply have a longer chain to peer, so exit now
if (commonBlockHeight == peerHeight)
return true;