Update SysTray for all synchronizing scenarios.

When synchronizing is forced via API call, the SysTray doesn't update
to reflect this.

We fix this by moving the SysTray updating code from
Controller.potentiallySynchronize() to the inner method
Controller.actuallySynchronize(), which is also the method called
directly by the API.
This commit is contained in:
catbref 2020-04-15 17:36:12 +01:00
parent e25d24964c
commit 1e9a7ac87d

View File

@ -528,19 +528,17 @@ public class Controller extends Thread {
int index = new SecureRandom().nextInt(peers.size());
Peer peer = peers.get(index);
actuallySynchronize(peer, false);
}
public SynchronizationResult actuallySynchronize(Peer peer, boolean force) throws InterruptedException {
syncPercent = (this.chainTip.getHeight() * 100) / peer.getChainTipData().getLastHeight();
isSynchronizing = true;
updateSysTray();
actuallySynchronize(peer, false);
isSynchronizing = false;
requestSysTrayUpdate = true;
}
public SynchronizationResult actuallySynchronize(Peer peer, boolean force) throws InterruptedException {
BlockData latestBlockData = getChainTip();
BlockData priorChainTip = this.chainTip;
try {
SynchronizationResult syncResult = Synchronizer.getInstance().synchronize(peer, force);
switch (syncResult) {
case GENESIS_ONLY:
@ -575,7 +573,7 @@ public class Controller extends Thread {
LOGGER.debug(() -> String.format("Refused to synchronize with peer %s (%s)", peer, syncResult.name()));
// Notify peer of our superior chain
if (!peer.sendMessage(Network.getInstance().buildHeightMessage(peer, latestBlockData)))
if (!peer.sendMessage(Network.getInstance().buildHeightMessage(peer, priorChainTip)))
peer.disconnect("failed to notify peer of our superior chain");
break;
}
@ -606,25 +604,29 @@ public class Controller extends Thread {
}
// Has our chain tip changed?
BlockData newLatestBlockData;
BlockData newChainTip;
try (final Repository repository = RepositoryManager.getRepository()) {
newLatestBlockData = repository.getBlockRepository().getLastBlock();
this.setChainTip(newLatestBlockData);
newChainTip = repository.getBlockRepository().getLastBlock();
this.setChainTip(newChainTip);
} catch (DataException e) {
LOGGER.warn(String.format("Repository issue when trying to fetch post-synchronization chain tip: %s", e.getMessage()));
return syncResult;
}
if (!Arrays.equals(newLatestBlockData.getSignature(), latestBlockData.getSignature())) {
if (!Arrays.equals(newChainTip.getSignature(), priorChainTip.getSignature())) {
// Broadcast our new chain tip
Network.getInstance().broadcast(recipientPeer -> Network.getInstance().buildHeightMessage(recipientPeer, newLatestBlockData));
Network.getInstance().broadcast(recipientPeer -> Network.getInstance().buildHeightMessage(recipientPeer, newChainTip));
// Reset our cache of inferior chains
inferiorChainSignatures.clear();
}
return syncResult;
} finally {
isSynchronizing = false;
requestSysTrayUpdate = true;
}
}
private void updateSysTray() {