Skip to content

Commit

Permalink
Node Auto-reconnect and connectivity enhancements (#1513)
Browse files Browse the repository at this point in the history
* Add auto-reconnect
Enhance connectivity issues

* minor enhancement [skip ci]

* minor: remove core secrets since it's empty

* pending transactions fix

* temporary fix for RBF

* remove unused hashes from cache key

* fix minimum limits check

* Add authentication to services api

* update polyseed

* override hashlib package
  • Loading branch information
OmarHatem28 authored Jul 6, 2024
1 parent 0335702 commit f902a64
Show file tree
Hide file tree
Showing 19 changed files with 128 additions and 219 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr_test_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ jobs:
/opt/android/cake_wallet/cw_monero/ios/External
/opt/android/cake_wallet/cw_shared_external/ios/External
/opt/android/cake_wallet/scripts/monero_c/release
key: ${{ hashFiles('**/prepare_moneroc.sh' ,'**/build_monero_all.sh', '**/build_haven.sh', '**/monero_api.cpp') }}
key: ${{ hashFiles('**/prepare_moneroc.sh' ,'**/build_monero_all.sh') }}

- if: ${{ steps.cache-externals.outputs.cache-hit != 'true' }}
name: Generate Externals
Expand Down
4 changes: 3 additions & 1 deletion assets/litecoin_electrum_server_list.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
-
uri: ltc-electrum.cakewallet.com:50002
uri: ltc-electrum.cakewallet.com:50002
useSSL: true
isDefault: true
55 changes: 35 additions & 20 deletions cw_bitcoin/lib/electrum_wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,26 +97,7 @@ abstract class ElectrumWalletBase
this.walletInfo = walletInfo;
transactionHistory = ElectrumTransactionHistory(walletInfo: walletInfo, password: password);

reaction((_) => syncStatus, (SyncStatus syncStatus) async {
if (syncStatus is! AttemptingSyncStatus && syncStatus is! SyncedTipSyncStatus) {
silentPaymentsScanningActive = syncStatus is SyncingSyncStatus;
}

if (syncStatus is NotConnectedSyncStatus) {
// Needs to re-subscribe to all scripthashes when reconnected
_scripthashesUpdateSubject = {};

// TODO: double check this and make sure it doesn't cause any un-necessary calls
// await this.electrumClient.connectToUri(node!.uri, useSSL: node!.useSSL);
}

// Message is shown on the UI for 3 seconds, revert to synced
if (syncStatus is SyncedTipSyncStatus) {
Timer(Duration(seconds: 3), () {
if (this.syncStatus is SyncedTipSyncStatus) this.syncStatus = SyncedSyncStatus();
});
}
});
reaction((_) => syncStatus, _syncStatusReaction);
}

static bitcoin.HDWallet getAccountHDWallet(
Expand Down Expand Up @@ -201,6 +182,8 @@ abstract class ElectrumWalletBase
@observable
bool silentPaymentsScanningActive = false;

bool _isTryingToConnect = false;

@action
Future<void> setSilentPaymentsScanning(bool active, bool usingElectrs) async {
silentPaymentsScanningActive = active;
Expand Down Expand Up @@ -1830,6 +1813,38 @@ abstract class ElectrumWalletBase
syncStatus = NotConnectedSyncStatus();
}
}

void _syncStatusReaction(SyncStatus syncStatus) async {
if (syncStatus is! AttemptingSyncStatus && syncStatus is! SyncedTipSyncStatus) {
silentPaymentsScanningActive = syncStatus is SyncingSyncStatus;
}

if (syncStatus is NotConnectedSyncStatus) {
// Needs to re-subscribe to all scripthashes when reconnected
_scripthashesUpdateSubject = {};

if (_isTryingToConnect) return;

_isTryingToConnect = true;

Future.delayed(Duration(seconds: 10), () {
if (this.syncStatus is! SyncedSyncStatus && this.syncStatus is! SyncedTipSyncStatus) {
this.electrumClient.connectToUri(
node!.uri,
useSSL: node!.useSSL ?? false,
);
}
_isTryingToConnect = false;
});
}

// Message is shown on the UI for 3 seconds, revert to synced
if (syncStatus is SyncedTipSyncStatus) {
Timer(Duration(seconds: 3), () {
if (this.syncStatus is SyncedTipSyncStatus) this.syncStatus = SyncedSyncStatus();
});
}
}
}

class ScanNode {
Expand Down
4 changes: 2 additions & 2 deletions cw_bitcoin/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -866,10 +866,10 @@ packages:
dependency: transitive
description:
name: unorm_dart
sha256: "5b35bff83fce4d76467641438f9e867dc9bcfdb8c1694854f230579d68cd8f4b"
sha256: "23d8bf65605401a6a32cff99435fed66ef3dab3ddcad3454059165df46496a3b"
url: "https://pub.dev"
source: hosted
version: "0.2.0"
version: "0.3.0"
vector_math:
dependency: transitive
description:
Expand Down
3 changes: 3 additions & 0 deletions cw_core/lib/node.dart
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ class Node extends HiveObject with Keyable {
}
}

// TODO: this will return true most of the time, even if the node has useSSL set to true while
// it doesn't support SSL or vice versa, because it will connect normally, but it will fail if
// you try to communicate with it
Future<bool> requestElectrumServer() async {
try {
if (useSSL == true) {
Expand Down
8 changes: 8 additions & 0 deletions cw_haven/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.3.1"
unorm_dart:
dependency: transitive
description:
name: unorm_dart
sha256: "23d8bf65605401a6a32cff99435fed66ef3dab3ddcad3454059165df46496a3b"
url: "https://pub.dev"
source: hosted
version: "0.3.0"
vector_math:
dependency: transitive
description:
Expand Down
12 changes: 10 additions & 2 deletions cw_monero/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -543,10 +543,10 @@ packages:
dependency: "direct main"
description:
name: polyseed
sha256: a340962242d7917b0f3e6bd02c4acc3f90eae8ff766f1244f793ae7a6414dd68
sha256: edf28042e7b0b28f97a0469aa98e6e4015937cef6b9340cd6ad2822139c95217
url: "https://pub.dev"
source: hosted
version: "0.0.4"
version: "0.0.5"
pool:
dependency: transitive
description:
Expand Down Expand Up @@ -696,6 +696,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.3.1"
unorm_dart:
dependency: transitive
description:
name: unorm_dart
sha256: "23d8bf65605401a6a32cff99435fed66ef3dab3ddcad3454059165df46496a3b"
url: "https://pub.dev"
source: hosted
version: "0.3.0"
vector_math:
dependency: transitive
description:
Expand Down
8 changes: 8 additions & 0 deletions cw_nano/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.3.2"
unorm_dart:
dependency: transitive
description:
name: unorm_dart
sha256: "23d8bf65605401a6a32cff99435fed66ef3dab3ddcad3454059165df46496a3b"
url: "https://pub.dev"
source: hosted
version: "0.3.0"
vector_math:
dependency: transitive
description:
Expand Down
12 changes: 10 additions & 2 deletions cw_wownero/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -543,10 +543,10 @@ packages:
dependency: "direct main"
description:
name: polyseed
sha256: a340962242d7917b0f3e6bd02c4acc3f90eae8ff766f1244f793ae7a6414dd68
sha256: edf28042e7b0b28f97a0469aa98e6e4015937cef6b9340cd6ad2822139c95217
url: "https://pub.dev"
source: hosted
version: "0.0.4"
version: "0.0.5"
pool:
dependency: transitive
description:
Expand Down Expand Up @@ -696,6 +696,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.3.1"
unorm_dart:
dependency: transitive
description:
name: unorm_dart
sha256: "23d8bf65605401a6a32cff99435fed66ef3dab3ddcad3454059165df46496a3b"
url: "https://pub.dev"
source: hosted
version: "0.3.0"
vector_math:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion cw_wownero/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ dependencies:
flutter_mobx: ^2.0.6+1
intl: ^0.18.0
encrypt: ^5.0.1
polyseed: ^0.0.4
polyseed: ^0.0.5
cw_core:
path: ../cw_core
monero:
Expand Down
2 changes: 1 addition & 1 deletion lib/bitcoin/cw_bitcoin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ class CWBitcoin extends Bitcoin {
@override
int getMaxCustomFeeRate(Object wallet) {
final bitcoinWallet = wallet as ElectrumWallet;
return (bitcoinWallet.feeRate(BitcoinTransactionPriority.fast) * 1.1).round();
return (bitcoinWallet.feeRate(BitcoinTransactionPriority.fast) * 10).round();
}

@override
Expand Down
12 changes: 12 additions & 0 deletions lib/entities/default_settings_migration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ Future<void> defaultSettingsMigration(
await fixBtcDerivationPaths(walletInfoSource);
break;
case 39:
_fixNodesUseSSLFlag(nodes);
await changeDefaultNanoNode(nodes, sharedPreferences);
break;
default:
Expand All @@ -258,6 +259,17 @@ Future<void> defaultSettingsMigration(
await sharedPreferences.setInt(PreferencesKey.currentDefaultSettingsMigrationVersion, version);
}

void _fixNodesUseSSLFlag(Box<Node> nodes) {
for (Node node in nodes.values) {
switch (node.uriRaw) {
case cakeWalletLitecoinElectrumUri:
case cakeWalletBitcoinElectrumUri:
node.useSSL = true;
break;
}
}
}

Future<void> updateNanoNodeList({required Box<Node> nodes}) async {
final nodeList = await loadDefaultNanoNodes();
var listOfNewEndpoints = <String>[
Expand Down
Loading

0 comments on commit f902a64

Please sign in to comment.