Skip to content
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

fix(coinjoin): prevent timeskew exceptions from stopping CoinJoin #1260

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions wallet/src/de/schildbach/wallet/service/CoinJoinService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,15 @@ class CoinJoinMixingService @Inject constructor(
}
}

suspend fun getCurrentTimeSkew(): Long {
return try {
getTimeSkew()
} catch (e: Exception) {
log.info("timeshew problem", e)
return 0L
}
}

suspend fun updateTimeSkewInternal(timeSkew: Long) {
updateState(config.getMode(), timeSkew, hasAnonymizableBalance, networkStatus, isSynced, blockChain)
}
Expand Down Expand Up @@ -270,7 +279,7 @@ class CoinJoinMixingService @Inject constructor(
)
updateState(
config.getMode(),
getTimeSkew(),
getCurrentTimeSkew(),
hasBalanceLeftToMix,
networkStatus,
isSynced,
Expand All @@ -295,7 +304,7 @@ class CoinJoinMixingService @Inject constructor(
log.info(
"coinjoin-new-state: $mode, $timeSkew ms, $hasAnonymizableBalance, $networkStatus, synced: $isSynced, ${blockChain != null}"
)
log.info("coinjoin-Current timeskew: ${getTimeSkew()}")
log.info("coinjoin-Current timeskew: ${getCurrentTimeSkew()}")
this.networkStatus = networkStatus
this.hasAnonymizableBalance = hasAnonymizableBalance
this.isSynced = isSynced
Expand Down Expand Up @@ -363,7 +372,7 @@ class CoinJoinMixingService @Inject constructor(
configureMixing()
updateBalance(walletDataProvider.wallet!!.getBalance(Wallet.BalanceType.AVAILABLE))
}
val currentTimeSkew = getTimeSkew()
val currentTimeSkew = getCurrentTimeSkew()
updateState(mode, currentTimeSkew, hasAnonymizableBalance, networkStatus, isSynced, blockChain)
}

Expand Down
17 changes: 12 additions & 5 deletions wallet/src/de/schildbach/wallet/util/TimeUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,19 @@ suspend fun getTimeSkew(): Long {
// swallow, the next block will use alternate method
}
if (networkTime == null) {
var result = Constants.HTTP_CLIENT.head("https://www.dash.org/")

networkTime = result.headers.getDate("date")?.time
if (networkTime == null) {
result = Constants.HTTP_CLIENT.head("https://insight.dash.org/insight")
try {
val result = Constants.HTTP_CLIENT.head("https://www.dash.org/")
networkTime = result.headers.getDate("date")?.time
} catch (e: Exception) {
// swallow
}
if (networkTime == null) {
try {
val result = Constants.HTTP_CLIENT.head("https://insight.dash.org/insight")
networkTime = result.headers.getDate("date")?.time
} catch (e: Exception) {
// swallow
}
}
requireNotNull(networkTime)
}
Expand Down
Loading