-
Notifications
You must be signed in to change notification settings - Fork 277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Display 'Connecting...' when connection to daemon is lost #829
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,8 +121,9 @@ public void newBlock(long height) { | |
Timber.d("newBlock() @ %d with observer %s", height, observer); | ||
if (observer != null) { | ||
boolean fullRefresh = false; | ||
updateDaemonState(wallet, wallet.isSynchronized() ? height : 0); | ||
if (!wallet.isSynchronized()) { | ||
boolean receivedNewBlock = true; | ||
boolean updatedWalletConnectionStatus = updateDaemonState(wallet, height, receivedNewBlock); | ||
if (updatedWalletConnectionStatus || !wallet.isSynchronized()) { | ||
updated = true; | ||
// we want to see our transactions as they come in | ||
wallet.refreshHistory(); | ||
|
@@ -146,13 +147,13 @@ public void updated() { | |
updated = true; | ||
} | ||
|
||
public void refreshed() { // this means it's synced | ||
public void refreshed() { | ||
Timber.d("refreshed()"); | ||
final Wallet wallet = getWallet(); | ||
if (wallet == null) throw new IllegalStateException("No wallet!"); | ||
wallet.setSynchronized(); | ||
if (updated) { | ||
updateDaemonState(wallet, wallet.getBlockChainHeight()); | ||
boolean receivedNewBlock = false; | ||
boolean updatedWalletConnectionStatus = updateDaemonState(wallet, wallet.getBlockChainHeight(), receivedNewBlock); | ||
if (updated || updatedWalletConnectionStatus) { | ||
wallet.refreshHistory(); | ||
if (observer != null) { | ||
updated = !observer.onRefreshed(wallet, true); | ||
|
@@ -164,16 +165,20 @@ public void refreshed() { // this means it's synced | |
private long lastDaemonStatusUpdate = 0; | ||
private long daemonHeight = 0; | ||
private Wallet.ConnectionStatus connectionStatus = Wallet.ConnectionStatus.ConnectionStatus_Disconnected; | ||
private static final long STATUS_UPDATE_INTERVAL = 120000; // 120s (blocktime) | ||
private static final long STATUS_UPDATE_INTERVAL_SYNCED = 120000; // 120s (blocktime) | ||
private static final long STATUS_UPDATE_INTERVAL_SYNCING = 10000; // 10s | ||
|
||
private void updateDaemonState(Wallet wallet, long height) { | ||
private boolean updateDaemonState(Wallet wallet, long height, boolean receivedNewBlock) { | ||
Wallet.ConnectionStatus startConnectionStatus = connectionStatus; | ||
long t = System.currentTimeMillis(); | ||
if (height > 0) { // if we get a height, we are connected | ||
daemonHeight = height; | ||
if (daemonHeight > 0 && height > 0 && (height > daemonHeight || receivedNewBlock)) { | ||
if (height > daemonHeight) | ||
daemonHeight = height; | ||
connectionStatus = Wallet.ConnectionStatus.ConnectionStatus_Connected; | ||
lastDaemonStatusUpdate = t; | ||
} else { | ||
if (t - lastDaemonStatusUpdate > STATUS_UPDATE_INTERVAL) { | ||
long statusUpdateInterval = wallet.isSynchronized() ? STATUS_UPDATE_INTERVAL_SYNCED : STATUS_UPDATE_INTERVAL_SYNCING; | ||
if (daemonHeight == 0 || t - lastDaemonStatusUpdate > statusUpdateInterval) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also calling out this part. Notice how I added The work over in monero-project/monero#8076 should minimize trips to the daemon and ideally get the height cached so the client shouldn't need to make a trip to the daemon here the first time this is called. Looking into this as well. |
||
lastDaemonStatusUpdate = t; | ||
// these calls really connect to the daemon - wasting time | ||
daemonHeight = wallet.getDaemonBlockChainHeight(); | ||
|
@@ -185,6 +190,16 @@ private void updateDaemonState(Wallet wallet, long height) { | |
} | ||
} | ||
} | ||
setWalletSyncState(wallet); | ||
return startConnectionStatus != connectionStatus; | ||
} | ||
|
||
public void setWalletSyncState(Wallet wallet) { | ||
if (daemonHeight > 0 && daemonHeight <= wallet.getBlockChainHeight()) { | ||
wallet.setSynchronized(); | ||
} else { | ||
wallet.setUnsynchronized(); | ||
} | ||
} | ||
|
||
public long getDaemonHeight() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i am not sure not unsetting
firstBlock
inunsync()
has no adverse effectsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there another place
unsync()
is called I'm not seeing except in the place I added? Or do you mean that it should also unset thefirstBlock
even in that place I added the call tounsync()
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will dig into it/test it some more. The issue I was thinking with resetting it in that new call to
unsync
I added is if it might cause continual resets of the progress bar before it's synchronized IIRCThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don*t see another place either. yes, i mean also unsetting
firstBlock
- maybe even scrapping this method as its only used once and has no obvious reuse scenario (or?).