This commit is contained in:
Duke
2023-03-27 15:29:59 -07:00
parent 7364e21f99
commit 77ac1f99ae
2 changed files with 48 additions and 31 deletions

View File

@@ -71,7 +71,21 @@ void ConnectionLoader::loadConnection()
void ConnectionLoader::loadProgress() void ConnectionLoader::loadProgress()
{ {
QTimer::singleShot(1, [=]() { this->ShowProgress(); }); bool failed = false;
QTimer::singleShot(1, [=]() mutable {
// continually retry ShowProgress() until it succeeds
// by running without an exception
do {
try {
this->ShowProgress();
failed = false;
} catch (const std::exception& e) {
DEBUG("caught exception " << e.what() );
failed = true;
}
} while (failed);
});
if (!Settings::getInstance()->isHeadless()) if (!Settings::getInstance()->isHeadless())
d->exec(); d->exec();
} }
@@ -85,7 +99,7 @@ void ConnectionLoader::ShowProgress()
auto connection = makeConnection(config); auto connection = makeConnection(config);
auto me = this; auto me = this;
qDebug() << __func__ << ": server=" << config->server << " connection=" << connection << " me=" << me; DEBUG("server=" << config->server << " connection=" << connection << " me=" << me);
isSyncing = new QAtomicInteger<bool>(); isSyncing = new QAtomicInteger<bool>();
isSyncing->store(true); isSyncing->store(true);
@@ -101,39 +115,42 @@ void ConnectionLoader::ShowProgress()
// When sync is done, set the connection // When sync is done, set the connection
this->doRPCSetConnectionShield(connection); this->doRPCSetConnectionShield(connection);
}); });
// While it is syncing, we'll show the status updates while it is alive. // While it is syncing, we'll show the status updates while it is alive.
QObject::connect(syncTimer, &QTimer::timeout, [=]() { QObject::connect(syncTimer, &QTimer::timeout, [=]() {
// Check the sync status // Check the sync status
if (isSyncing != nullptr && isSyncing->load()) { if (isSyncing != nullptr && isSyncing->load()) {
// Get the sync status // Get the sync status
try { try {
connection->doRPC("syncstatus", "", [=](json reply) { connection->doRPC("syncstatus", "", [=](json reply) {
if (isSyncing != nullptr && reply.find("synced_blocks") != reply.end()) if (isSyncing != nullptr && reply.find("synced_blocks") != reply.end()) {
qint64 synced = reply["synced_blocks"].get<json::number_unsigned_t>();
{ qint64 total = reply["total_blocks"].get<json::number_unsigned_t>();
qint64 synced = reply["synced_blocks"].get<json::number_unsigned_t>(); me->showInformation(
qint64 total = reply["total_blocks"].get<json::number_unsigned_t>(); "Syncing... " + QString::number(synced) + " / " + QString::number(total)
me->showInformation( );
"Syncing... " + QString::number(synced) + " / " + QString::number(total) }
); }, [=](QString err) {
} DEBUG("Sync error " << err);
}, // We may have gotten "Unexpected compression flag: 60"
[=](QString err) { // or some other error, so let's try another server
qDebug() << "Sync error" << err; config->server = Settings::getRandomServer();
}); DEBUG("Changed server to " << config->server );
}catch (...) });
{ } catch (const std::exception& e) {
main->logger->write("catch sync progress reply"); DEBUG("syncstatus exception: " << e.what() );
} main->logger->write("catch sync progress reply");
}
});
syncTimer->setInterval(1* 1000); // rethrow exception so loadProgress can catch
syncTimer->start(); // it and retry the entire ShowProgress() function again
main->logger->write("Start sync timer"); throw new std::runtime_error(std::string("syncstatus failed"));
}
}
});
syncTimer->setInterval(1*1000);
syncTimer->start();
main->logger->write("Start sync timer");
} }

View File

@@ -1095,10 +1095,10 @@ void MainWindow::payhushURI(QString uri, QString myAddr) {
// Save the wallet // Save the wallet
this->getRPC()->saveWallet([=] (auto) { this->getRPC()->saveWallet([=] (auto) {
// Then reload the connection. The ConnectionLoader deletes itself. // Then reload the connection. The ConnectionLoader deletes itself.
auto cl = new ConnectionLoader(this, rpc); auto cl = new ConnectionLoader(this, rpc);
cl->loadProgress(); cl->loadProgress();
}); });
}); });
}else if ((pui.rescan->isChecked() == true) && (pui.privKeyTxt->toPlainText().startsWith("secret"))){ }else if ((pui.rescan->isChecked() == true) && (pui.privKeyTxt->toPlainText().startsWith("secret"))){