Skip to content

Commit

Permalink
clients/bitwindow: start servers faster, less timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
octobocto committed Nov 14, 2024
1 parent 5504e07 commit 198042f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 20 deletions.
3 changes: 2 additions & 1 deletion clients/bitwindow/lib/pages/root_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ class _StatusBarState extends State<StatusBar> {
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) {
Expand Down
20 changes: 11 additions & 9 deletions clients/bitwindow/lib/providers/blockchain_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -69,7 +67,6 @@ class BlockchainProvider extends ChangeNotifier {
bool _dataHasChanged(
List<Peer> newPeers,
List<RecentTransaction> newTXs,
GetBlockchainInfoResponse newBlockchainInfo,
List<Block> newRecentBlocks,
List<OPReturn> newOPReturns,
) {
Expand All @@ -85,19 +82,24 @@ class BlockchainProvider extends ChangeNotifier {
return true;
}

if (blockchainInfo.toProto3Json() != newBlockchainInfo.toProto3Json()) {
return true;
}

if (!listEquals(opReturns, newOPReturns)) {
return true;
}

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
Expand Down
5 changes: 2 additions & 3 deletions clients/bitwindow/lib/servers/mainchain_rpc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
17 changes: 10 additions & 7 deletions clients/sail_ui/lib/classes/rpc_connection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -231,17 +234,17 @@ 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<void> _startConnectionTimer() async {
_connectionTimer = Timer.periodic(const Duration(seconds: 1), (timer) async {
Timer? connectionTimer;
Future<void> startConnectionTimer() async {
connectionTimer = Timer.periodic(const Duration(seconds: 1), (timer) async {
await testConnection();
});
}

@override
void dispose() {
super.dispose();
_connectionTimer?.cancel();
connectionTimer?.cancel();
}
}

Expand Down

0 comments on commit 198042f

Please sign in to comment.