mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-09 12:19:24 +00:00
reduced pings
This commit is contained in:
parent
ae10bef0ee
commit
c1ef98833a
3 changed files with 9 additions and 45 deletions
|
@ -399,6 +399,7 @@ class ElectrumXClient {
|
||||||
rethrow;
|
rethrow;
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
Logging.instance.log("$host $e", level: LogLevel.Debug);
|
||||||
if (currentFailoverIndex < _failovers.length - 1) {
|
if (currentFailoverIndex < _failovers.length - 1) {
|
||||||
currentFailoverIndex++;
|
currentFailoverIndex++;
|
||||||
return request(
|
return request(
|
||||||
|
@ -525,10 +526,10 @@ class ElectrumXClient {
|
||||||
return await request(
|
return await request(
|
||||||
requestID: requestID,
|
requestID: requestID,
|
||||||
command: 'server.ping',
|
command: 'server.ping',
|
||||||
requestTimeout: const Duration(seconds: 3),
|
requestTimeout: const Duration(seconds: 30),
|
||||||
retries: retryCount,
|
retries: retryCount,
|
||||||
).timeout(
|
).timeout(
|
||||||
const Duration(seconds: 3),
|
const Duration(seconds: 30),
|
||||||
onTimeout: () {
|
onTimeout: () {
|
||||||
Logging.instance.log(
|
Logging.instance.log(
|
||||||
"ElectrumxClient.ping timed out with retryCount=$retryCount, host=$_host",
|
"ElectrumxClient.ping timed out with retryCount=$retryCount, host=$_host",
|
||||||
|
|
|
@ -35,7 +35,7 @@ abstract class Constants {
|
||||||
// // true; // true for development,
|
// // true; // true for development,
|
||||||
|
|
||||||
static const int notificationsMax = 0xFFFFFFFF;
|
static const int notificationsMax = 0xFFFFFFFF;
|
||||||
static const Duration networkAliveTimerDuration = Duration(seconds: 10);
|
static const Duration networkAliveTimerDuration = Duration(seconds: 30);
|
||||||
|
|
||||||
// Enable Logger.print statements
|
// Enable Logger.print statements
|
||||||
static const bool disableLogger = false;
|
static const bool disableLogger = false;
|
||||||
|
|
|
@ -415,6 +415,11 @@ abstract class Wallet<T extends CryptoCurrency> {
|
||||||
}
|
}
|
||||||
|
|
||||||
void _periodicPingCheck() async {
|
void _periodicPingCheck() async {
|
||||||
|
if (refreshMutex.isLocked) {
|
||||||
|
// should be active calls happening so no need to make extra work
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
final bool hasNetwork = await pingCheck();
|
final bool hasNetwork = await pingCheck();
|
||||||
|
|
||||||
if (_isConnected != hasNetwork) {
|
if (_isConnected != hasNetwork) {
|
||||||
|
@ -568,25 +573,6 @@ abstract class Wallet<T extends CryptoCurrency> {
|
||||||
}
|
}
|
||||||
final start = DateTime.now();
|
final start = DateTime.now();
|
||||||
|
|
||||||
bool tAlive = true;
|
|
||||||
Timer? t;
|
|
||||||
if (this is! SparkInterface) {
|
|
||||||
t = Timer.periodic(const Duration(seconds: 1), (timer) async {
|
|
||||||
if (tAlive) {
|
|
||||||
final pingSuccess = await pingCheck();
|
|
||||||
if (!pingSuccess) {
|
|
||||||
tAlive = false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
timer.cancel();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void _checkAlive() {
|
|
||||||
if (!tAlive) throw Exception("refresh alive ping failure");
|
|
||||||
}
|
|
||||||
|
|
||||||
final viewOnly = this is ViewOnlyOptionInterface &&
|
final viewOnly = this is ViewOnlyOptionInterface &&
|
||||||
(this as ViewOnlyOptionInterface).isViewOnly;
|
(this as ViewOnlyOptionInterface).isViewOnly;
|
||||||
|
|
||||||
|
@ -603,57 +589,45 @@ abstract class Wallet<T extends CryptoCurrency> {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
_checkAlive();
|
|
||||||
|
|
||||||
// add some small buffer before making calls.
|
// add some small buffer before making calls.
|
||||||
// this can probably be removed in the future but was added as a
|
// this can probably be removed in the future but was added as a
|
||||||
// debugging feature
|
// debugging feature
|
||||||
await Future<void>.delayed(const Duration(milliseconds: 300));
|
await Future<void>.delayed(const Duration(milliseconds: 300));
|
||||||
_checkAlive();
|
|
||||||
|
|
||||||
// TODO: [prio=low] handle this differently. Extra modification of this file for coin specific functionality should be avoided.
|
// TODO: [prio=low] handle this differently. Extra modification of this file for coin specific functionality should be avoided.
|
||||||
final Set<String> codesToCheck = {};
|
final Set<String> codesToCheck = {};
|
||||||
_checkAlive();
|
|
||||||
if (this is PaynymInterface && !viewOnly) {
|
if (this is PaynymInterface && !viewOnly) {
|
||||||
// isSegwit does not matter here at all
|
// isSegwit does not matter here at all
|
||||||
final myCode =
|
final myCode =
|
||||||
await (this as PaynymInterface).getPaymentCode(isSegwit: false);
|
await (this as PaynymInterface).getPaymentCode(isSegwit: false);
|
||||||
_checkAlive();
|
|
||||||
|
|
||||||
final nym = await PaynymIsApi().nym(myCode.toString());
|
final nym = await PaynymIsApi().nym(myCode.toString());
|
||||||
_checkAlive();
|
|
||||||
if (nym.value != null) {
|
if (nym.value != null) {
|
||||||
for (final follower in nym.value!.followers) {
|
for (final follower in nym.value!.followers) {
|
||||||
codesToCheck.add(follower.code);
|
codesToCheck.add(follower.code);
|
||||||
}
|
}
|
||||||
_checkAlive();
|
|
||||||
for (final following in nym.value!.following) {
|
for (final following in nym.value!.following) {
|
||||||
codesToCheck.add(following.code);
|
codesToCheck.add(following.code);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_checkAlive();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GlobalEventBus.instance.fire(RefreshPercentChangedEvent(0.0, walletId));
|
GlobalEventBus.instance.fire(RefreshPercentChangedEvent(0.0, walletId));
|
||||||
_checkAlive();
|
_checkAlive();
|
||||||
await updateChainHeight();
|
await updateChainHeight();
|
||||||
|
|
||||||
_checkAlive();
|
|
||||||
if (this is BitcoinFrostWallet) {
|
if (this is BitcoinFrostWallet) {
|
||||||
await (this as BitcoinFrostWallet).lookAhead();
|
await (this as BitcoinFrostWallet).lookAhead();
|
||||||
}
|
}
|
||||||
_checkAlive();
|
|
||||||
|
|
||||||
GlobalEventBus.instance.fire(RefreshPercentChangedEvent(0.1, walletId));
|
GlobalEventBus.instance.fire(RefreshPercentChangedEvent(0.1, walletId));
|
||||||
|
|
||||||
_checkAlive();
|
|
||||||
// TODO: [prio=low] handle this differently. Extra modification of this file for coin specific functionality should be avoided.
|
// TODO: [prio=low] handle this differently. Extra modification of this file for coin specific functionality should be avoided.
|
||||||
if (this is MultiAddressInterface) {
|
if (this is MultiAddressInterface) {
|
||||||
if (info.otherData[WalletInfoKeys.reuseAddress] != true) {
|
if (info.otherData[WalletInfoKeys.reuseAddress] != true) {
|
||||||
await (this as MultiAddressInterface)
|
await (this as MultiAddressInterface)
|
||||||
.checkReceivingAddressForTransactions();
|
.checkReceivingAddressForTransactions();
|
||||||
}
|
}
|
||||||
_checkAlive();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GlobalEventBus.instance.fire(RefreshPercentChangedEvent(0.2, walletId));
|
GlobalEventBus.instance.fire(RefreshPercentChangedEvent(0.2, walletId));
|
||||||
|
@ -672,49 +646,39 @@ abstract class Wallet<T extends CryptoCurrency> {
|
||||||
// this should be called before updateTransactions()
|
// this should be called before updateTransactions()
|
||||||
await (this as SparkInterface).refreshSparkData(null);
|
await (this as SparkInterface).refreshSparkData(null);
|
||||||
}
|
}
|
||||||
_checkAlive();
|
|
||||||
|
|
||||||
GlobalEventBus.instance.fire(RefreshPercentChangedEvent(0.50, walletId));
|
|
||||||
_checkAlive();
|
|
||||||
final fetchFuture = updateTransactions();
|
final fetchFuture = updateTransactions();
|
||||||
_checkAlive();
|
_checkAlive();
|
||||||
final utxosRefreshFuture = updateUTXOs();
|
final utxosRefreshFuture = updateUTXOs();
|
||||||
// if (currentHeight != storedHeight) {
|
// if (currentHeight != storedHeight) {
|
||||||
GlobalEventBus.instance.fire(RefreshPercentChangedEvent(0.60, walletId));
|
GlobalEventBus.instance.fire(RefreshPercentChangedEvent(0.60, walletId));
|
||||||
|
|
||||||
_checkAlive();
|
|
||||||
await utxosRefreshFuture;
|
await utxosRefreshFuture;
|
||||||
GlobalEventBus.instance.fire(RefreshPercentChangedEvent(0.70, walletId));
|
GlobalEventBus.instance.fire(RefreshPercentChangedEvent(0.70, walletId));
|
||||||
|
|
||||||
_checkAlive();
|
|
||||||
await fetchFuture;
|
await fetchFuture;
|
||||||
|
|
||||||
// TODO: [prio=low] handle this differently. Extra modification of this file for coin specific functionality should be avoided.
|
// TODO: [prio=low] handle this differently. Extra modification of this file for coin specific functionality should be avoided.
|
||||||
if (!viewOnly && this is PaynymInterface && codesToCheck.isNotEmpty) {
|
if (!viewOnly && this is PaynymInterface && codesToCheck.isNotEmpty) {
|
||||||
_checkAlive();
|
|
||||||
await (this as PaynymInterface)
|
await (this as PaynymInterface)
|
||||||
.checkForNotificationTransactionsTo(codesToCheck);
|
.checkForNotificationTransactionsTo(codesToCheck);
|
||||||
// check utxos again for notification outputs
|
// check utxos again for notification outputs
|
||||||
_checkAlive();
|
|
||||||
await updateUTXOs();
|
await updateUTXOs();
|
||||||
}
|
}
|
||||||
_checkAlive();
|
_checkAlive();
|
||||||
GlobalEventBus.instance.fire(RefreshPercentChangedEvent(0.80, walletId));
|
GlobalEventBus.instance.fire(RefreshPercentChangedEvent(0.80, walletId));
|
||||||
|
|
||||||
// await getAllTxsToWatch();
|
// await getAllTxsToWatch();
|
||||||
_checkAlive();
|
|
||||||
|
|
||||||
// TODO: [prio=low] handle this differently. Extra modification of this file for coin specific functionality should be avoided.
|
// TODO: [prio=low] handle this differently. Extra modification of this file for coin specific functionality should be avoided.
|
||||||
if (this is LelantusInterface && !viewOnly) {
|
if (this is LelantusInterface && !viewOnly) {
|
||||||
if (info.otherData[WalletInfoKeys.enableLelantusScanning] as bool? ??
|
if (info.otherData[WalletInfoKeys.enableLelantusScanning] as bool? ??
|
||||||
false) {
|
false) {
|
||||||
await (this as LelantusInterface).refreshLelantusData();
|
await (this as LelantusInterface).refreshLelantusData();
|
||||||
_checkAlive();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GlobalEventBus.instance.fire(RefreshPercentChangedEvent(0.90, walletId));
|
GlobalEventBus.instance.fire(RefreshPercentChangedEvent(0.90, walletId));
|
||||||
|
|
||||||
_checkAlive();
|
|
||||||
await updateBalance();
|
await updateBalance();
|
||||||
|
|
||||||
_checkAlive();
|
_checkAlive();
|
||||||
|
@ -728,7 +692,6 @@ abstract class Wallet<T extends CryptoCurrency> {
|
||||||
} catch (error, strace) {
|
} catch (error, strace) {
|
||||||
completer.completeError(error, strace);
|
completer.completeError(error, strace);
|
||||||
} finally {
|
} finally {
|
||||||
t?.cancel();
|
|
||||||
refreshMutex.release();
|
refreshMutex.release();
|
||||||
if (!completer.isCompleted) {
|
if (!completer.isCompleted) {
|
||||||
completer.completeError(
|
completer.completeError(
|
||||||
|
|
Loading…
Reference in a new issue