WIP: fix electrumx failovers, add some "default" firo nodes, and tweak firo pings

This commit is contained in:
julian 2024-12-13 23:10:41 -06:00 committed by julian-CStack
parent 34ad1d9022
commit 744f273862
9 changed files with 68 additions and 71 deletions

View file

@ -108,7 +108,7 @@ class ElectrumXClient {
late Prefs _prefs;
late TorService _torService;
List<ElectrumXNode>? failovers;
late final List<ElectrumXNode> _failovers;
int currentFailoverIndex = -1;
final Duration connectionTimeoutForSpecialCaseJsonRPCClients;
@ -145,6 +145,7 @@ class ElectrumXClient {
_host = host;
_port = port;
_useSSL = useSSL;
_failovers = failovers;
final bus = globalEventBusForTesting ?? GlobalEventBus.instance;
@ -284,9 +285,11 @@ class ElectrumXClient {
usePort = port;
useUseSSL = useSSL;
} else {
useHost = failovers![currentFailoverIndex].address;
usePort = failovers![currentFailoverIndex].port;
useUseSSL = failovers![currentFailoverIndex].useSSL;
_electrumAdapterChannel = null;
await ClientManager.sharedInstance.remove(cryptoCurrency: cryptoCurrency);
useHost = _failovers[currentFailoverIndex].address;
usePort = _failovers[currentFailoverIndex].port;
useUseSSL = _failovers[currentFailoverIndex].useSSL;
}
_electrumAdapterChannel ??= await electrum_adapter.connect(
@ -402,7 +405,7 @@ class ElectrumXClient {
rethrow;
}
} catch (e) {
if (failovers != null && currentFailoverIndex < failovers!.length - 1) {
if (currentFailoverIndex < _failovers.length - 1) {
currentFailoverIndex++;
return request(
command: command,
@ -495,7 +498,7 @@ class ElectrumXClient {
rethrow;
}
} catch (e) {
if (failovers != null && currentFailoverIndex < failovers!.length - 1) {
if (currentFailoverIndex < _failovers.length - 1) {
currentFailoverIndex++;
return batchRequest(
command: command,

View file

@ -32,6 +32,49 @@ class NodeService extends ChangeNotifier {
});
Future<void> updateDefaults() async {
// hack
if (AppConfig.coins.where((e) => e.identifier == "firo").isNotEmpty) {
final others = [
"electrumx01.firo.org",
"electrumx02.firo.org",
"electrumx03.firo.org",
"electrumx.firo.org",
];
const port = 50002;
const idPrefix = "not_a_real_default_but_temp";
for (final host in others) {
final _id = "${idPrefix}_$host";
NodeModel? node = DB.instance.get<NodeModel>(
boxName: DB.boxNameNodeModels,
key: _id,
);
if (node == null) {
node = NodeModel(
host: host,
port: port,
name: host,
id: _id,
useSSL: true,
enabled: true,
coinName: "firo",
isFailover: true,
isDown: false,
torEnabled: true,
clearnetEnabled: true,
);
await DB.instance.put<NodeModel>(
boxName: DB.boxNameNodeModels,
key: _id,
value: node,
);
}
}
}
for (final defaultNode in AppConfig.coins.map(
(e) => e.defaultNode,
)) {

View file

@ -569,16 +569,19 @@ abstract class Wallet<T extends CryptoCurrency> {
final start = DateTime.now();
bool tAlive = true;
final t = Timer.periodic(const Duration(seconds: 1), (timer) async {
if (tAlive) {
final pingSuccess = await pingCheck();
if (!pingSuccess) {
tAlive = false;
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();
}
} else {
timer.cancel();
}
});
});
}
void _checkAlive() {
if (!tAlive) throw Exception("refresh alive ping failure");
@ -717,13 +720,15 @@ abstract class Wallet<T extends CryptoCurrency> {
_checkAlive();
GlobalEventBus.instance.fire(RefreshPercentChangedEvent(1.0, walletId));
tAlive = false; // interrupt timer as its not needed anymore
if (this is! SparkInterface) {
tAlive = false; // interrupt timer as its not needed anymore
}
completer.complete();
} catch (error, strace) {
completer.completeError(error, strace);
} finally {
t.cancel();
t?.cancel();
refreshMutex.release();
if (!completer.isCompleted) {
completer.completeError(

View file

@ -90,15 +90,6 @@ class MockElectrumXClient extends _i1.Mock implements _i5.ElectrumXClient {
),
) as _i2.CryptoCurrency);
@override
set failovers(List<_i5.ElectrumXNode>? _failovers) => super.noSuchMethod(
Invocation.setter(
#failovers,
_failovers,
),
returnValueForMissingStub: null,
);
@override
int get currentFailoverIndex => (super.noSuchMethod(
Invocation.getter(#currentFailoverIndex),

View file

@ -87,15 +87,6 @@ class MockElectrumXClient extends _i1.Mock implements _i4.ElectrumXClient {
),
) as _i2.CryptoCurrency);
@override
set failovers(List<_i4.ElectrumXNode>? _failovers) => super.noSuchMethod(
Invocation.setter(
#failovers,
_failovers,
),
returnValueForMissingStub: null,
);
@override
int get currentFailoverIndex => (super.noSuchMethod(
Invocation.getter(#currentFailoverIndex),

View file

@ -87,15 +87,6 @@ class MockElectrumXClient extends _i1.Mock implements _i4.ElectrumXClient {
),
) as _i2.CryptoCurrency);
@override
set failovers(List<_i4.ElectrumXNode>? _failovers) => super.noSuchMethod(
Invocation.setter(
#failovers,
_failovers,
),
returnValueForMissingStub: null,
);
@override
int get currentFailoverIndex => (super.noSuchMethod(
Invocation.getter(#currentFailoverIndex),

View file

@ -87,15 +87,6 @@ class MockElectrumXClient extends _i1.Mock implements _i4.ElectrumXClient {
),
) as _i2.CryptoCurrency);
@override
set failovers(List<_i4.ElectrumXNode>? _failovers) => super.noSuchMethod(
Invocation.setter(
#failovers,
_failovers,
),
returnValueForMissingStub: null,
);
@override
int get currentFailoverIndex => (super.noSuchMethod(
Invocation.getter(#currentFailoverIndex),

View file

@ -87,15 +87,6 @@ class MockElectrumXClient extends _i1.Mock implements _i4.ElectrumXClient {
),
) as _i2.CryptoCurrency);
@override
set failovers(List<_i4.ElectrumXNode>? _failovers) => super.noSuchMethod(
Invocation.setter(
#failovers,
_failovers,
),
returnValueForMissingStub: null,
);
@override
int get currentFailoverIndex => (super.noSuchMethod(
Invocation.getter(#currentFailoverIndex),

View file

@ -87,15 +87,6 @@ class MockElectrumXClient extends _i1.Mock implements _i4.ElectrumXClient {
),
) as _i2.CryptoCurrency);
@override
set failovers(List<_i4.ElectrumXNode>? _failovers) => super.noSuchMethod(
Invocation.setter(
#failovers,
_failovers,
),
returnValueForMissingStub: null,
);
@override
int get currentFailoverIndex => (super.noSuchMethod(
Invocation.getter(#currentFailoverIndex),