From 198042fbee87a4fa221e2a044d88b0dc0990db9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Olav?= Date: Thu, 14 Nov 2024 07:34:54 +0100 Subject: [PATCH] clients/bitwindow: start servers faster, less timeout --- clients/bitwindow/lib/pages/root_page.dart | 3 ++- .../lib/providers/blockchain_provider.dart | 20 ++++++++++--------- .../bitwindow/lib/servers/mainchain_rpc.dart | 5 ++--- .../sail_ui/lib/classes/rpc_connection.dart | 17 +++++++++------- 4 files changed, 25 insertions(+), 20 deletions(-) diff --git a/clients/bitwindow/lib/pages/root_page.dart b/clients/bitwindow/lib/pages/root_page.dart index b2c2f29c..1d753996 100644 --- a/clients/bitwindow/lib/pages/root_page.dart +++ b/clients/bitwindow/lib/pages/root_page.dart @@ -234,7 +234,8 @@ class _StatusBarState extends State { await widgetDialog( context: context, title: 'Daemon Status', - subtitle: "You can use BitWindow without the enforcer, but it's not that interesting.", + subtitle: + "You can use BitWindow without the enforcer, but it's not that interesting because the wallet does not work.", child: ViewModelBuilder.reactive( viewModelBuilder: () => BottomNavViewModel(), builder: ((context, model, child) { diff --git a/clients/bitwindow/lib/providers/blockchain_provider.dart b/clients/bitwindow/lib/providers/blockchain_provider.dart index 23d91804..6e67670f 100644 --- a/clients/bitwindow/lib/providers/blockchain_provider.dart +++ b/clients/bitwindow/lib/providers/blockchain_provider.dart @@ -45,14 +45,12 @@ class BlockchainProvider extends ChangeNotifier { try { final newPeers = await api.bitcoind.listPeers(); final newTXs = await api.bitcoind.listRecentTransactions(); - final newBlockchainInfo = await api.bitcoind.getBlockchainInfo(); final newRecentBlocks = await api.bitcoind.listRecentBlocks(); final newOPReturns = await api.misc.listOPReturns(); - if (_dataHasChanged(newPeers, newTXs, newBlockchainInfo, newRecentBlocks, newOPReturns)) { + if (_dataHasChanged(newPeers, newTXs, newRecentBlocks, newOPReturns)) { peers = newPeers; recentTransactions = newTXs; - blockchainInfo = newBlockchainInfo; recentBlocks = newRecentBlocks; opReturns = newOPReturns; error = null; @@ -69,7 +67,6 @@ class BlockchainProvider extends ChangeNotifier { bool _dataHasChanged( List newPeers, List newTXs, - GetBlockchainInfoResponse newBlockchainInfo, List newRecentBlocks, List newOPReturns, ) { @@ -85,10 +82,6 @@ class BlockchainProvider extends ChangeNotifier { return true; } - if (blockchainInfo.toProto3Json() != newBlockchainInfo.toProto3Json()) { - return true; - } - if (!listEquals(opReturns, newOPReturns)) { return true; } @@ -96,8 +89,17 @@ class BlockchainProvider extends ChangeNotifier { return false; } + void _fetchBlockchainInfo() async { + final newBlockchainInfo = await api.bitcoind.getBlockchainInfo(); + blockchainInfo = newBlockchainInfo; + notifyListeners(); + } + void _startFetchTimer() { - _fetchTimer = Timer.periodic(const Duration(seconds: 5), (_) => fetch()); + _fetchTimer = Timer.periodic(const Duration(seconds: 5), (_) { + fetch(); + _fetchBlockchainInfo(); + }); } @override diff --git a/clients/bitwindow/lib/servers/mainchain_rpc.dart b/clients/bitwindow/lib/servers/mainchain_rpc.dart index 7dd37439..b830960e 100644 --- a/clients/bitwindow/lib/servers/mainchain_rpc.dart +++ b/clients/bitwindow/lib/servers/mainchain_rpc.dart @@ -70,9 +70,8 @@ class MainchainRPCLive extends MainchainRPC { while (inIBD) { try { final info = await getBlockchainInfo(); - // if block height is 0, the node might have not synced headers yet, and believe - // height 1 is the current best height - inIBD = (info.initialBlockDownload || info.headers <= 1) && (info.headers > 0 && info.blocks != info.headers); + // if block height is small, the node have probably not synced headers yet + inIBD = info.blocks <= 10; // Log height every 10 seconds if (DateTime.now().difference(lastLogTime).inSeconds >= 10) { diff --git a/clients/sail_ui/lib/classes/rpc_connection.dart b/clients/sail_ui/lib/classes/rpc_connection.dart index 2c182059..613814d9 100644 --- a/clients/sail_ui/lib/classes/rpc_connection.dart +++ b/clients/sail_ui/lib/classes/rpc_connection.dart @@ -170,9 +170,12 @@ abstract class RPCConnection extends ChangeNotifier { log.i('init binaries: waiting for $binary connection'); - await _startConnectionTimer(); - // zcash can take a long time. initial sync as well - const timeout = Duration(seconds: 5 * 60); + await startConnectionTimer(); + var timeout = Duration(seconds: 3); + if (binary == 'zsided') { + // zcash can take a long time. initial sync as well + timeout = Duration(seconds: 5 * 60); + } try { await Future.any([ // Happy case: able to connect. we start a poller at the @@ -231,9 +234,9 @@ abstract class RPCConnection extends ChangeNotifier { // responsible for pinging the node every x seconds, // so we can update the UI immediately when the connection drops/begins - Timer? _connectionTimer; - Future _startConnectionTimer() async { - _connectionTimer = Timer.periodic(const Duration(seconds: 1), (timer) async { + Timer? connectionTimer; + Future startConnectionTimer() async { + connectionTimer = Timer.periodic(const Duration(seconds: 1), (timer) async { await testConnection(); }); } @@ -241,7 +244,7 @@ abstract class RPCConnection extends ChangeNotifier { @override void dispose() { super.dispose(); - _connectionTimer?.cancel(); + connectionTimer?.cancel(); } }