mirror of
https://github.com/Qortal/qortal.git
synced 2025-05-05 09:17:51 +00:00
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:
parent
e25d24964c
commit
1e9a7ac87d
@ -528,19 +528,17 @@ public class Controller extends Thread {
|
|||||||
int index = new SecureRandom().nextInt(peers.size());
|
int index = new SecureRandom().nextInt(peers.size());
|
||||||
Peer peer = peers.get(index);
|
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();
|
syncPercent = (this.chainTip.getHeight() * 100) / peer.getChainTipData().getLastHeight();
|
||||||
isSynchronizing = true;
|
isSynchronizing = true;
|
||||||
updateSysTray();
|
updateSysTray();
|
||||||
|
|
||||||
actuallySynchronize(peer, false);
|
BlockData priorChainTip = this.chainTip;
|
||||||
|
|
||||||
isSynchronizing = false;
|
|
||||||
requestSysTrayUpdate = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SynchronizationResult actuallySynchronize(Peer peer, boolean force) throws InterruptedException {
|
|
||||||
BlockData latestBlockData = getChainTip();
|
|
||||||
|
|
||||||
|
try {
|
||||||
SynchronizationResult syncResult = Synchronizer.getInstance().synchronize(peer, force);
|
SynchronizationResult syncResult = Synchronizer.getInstance().synchronize(peer, force);
|
||||||
switch (syncResult) {
|
switch (syncResult) {
|
||||||
case GENESIS_ONLY:
|
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()));
|
LOGGER.debug(() -> String.format("Refused to synchronize with peer %s (%s)", peer, syncResult.name()));
|
||||||
|
|
||||||
// Notify peer of our superior chain
|
// 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");
|
peer.disconnect("failed to notify peer of our superior chain");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -606,25 +604,29 @@ public class Controller extends Thread {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Has our chain tip changed?
|
// Has our chain tip changed?
|
||||||
BlockData newLatestBlockData;
|
BlockData newChainTip;
|
||||||
|
|
||||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||||
newLatestBlockData = repository.getBlockRepository().getLastBlock();
|
newChainTip = repository.getBlockRepository().getLastBlock();
|
||||||
this.setChainTip(newLatestBlockData);
|
this.setChainTip(newChainTip);
|
||||||
} catch (DataException e) {
|
} catch (DataException e) {
|
||||||
LOGGER.warn(String.format("Repository issue when trying to fetch post-synchronization chain tip: %s", e.getMessage()));
|
LOGGER.warn(String.format("Repository issue when trying to fetch post-synchronization chain tip: %s", e.getMessage()));
|
||||||
return syncResult;
|
return syncResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Arrays.equals(newLatestBlockData.getSignature(), latestBlockData.getSignature())) {
|
if (!Arrays.equals(newChainTip.getSignature(), priorChainTip.getSignature())) {
|
||||||
// Broadcast our new chain tip
|
// 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
|
// Reset our cache of inferior chains
|
||||||
inferiorChainSignatures.clear();
|
inferiorChainSignatures.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
return syncResult;
|
return syncResult;
|
||||||
|
} finally {
|
||||||
|
isSynchronizing = false;
|
||||||
|
requestSysTrayUpdate = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateSysTray() {
|
private void updateSysTray() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user