Browse Source

#49 - Handle zcashd set to daemon=1

recurring
Aditya Kulkarni 6 years ago
parent
commit
3167fb97d4
  1. 48
      src/connection.cpp
  2. 1
      src/connection.h
  3. 4
      src/rpc.cpp

48
src/connection.cpp

@ -53,25 +53,38 @@ void ConnectionLoader::doAutoConnect(bool tryEzcashdStart) {
main->logger->write("Embedded zcashd started up, trying autoconnect in 1 sec");
QTimer::singleShot(1000, [=]() { doAutoConnect(); } );
} else {
// Something is wrong. This is happenening intermittently on Mac platforms.
// - We tried to start zcashd
// - QProcess started
// - QProcess ended, but the embedded zcashd is still in the background.
// We're going to attempt to connect to the one in the background one last time
// and see if that works, else throw an error
main->logger->write("Something is wrong, trying no-retry autoconnect in 2 sec");
QTimer::singleShot(2000, [=]() { doAutoConnect(/* don't attempt to start ezcashd */ false); });
if (config->zcashDaemon) {
// zcashd is configured to run as a daemon, so we must wait for a few seconds
// to let it start up.
main->logger->write("zcashd is daemon=1. Waiting for it to start up");
this->showInformation("zcashd is set to run as daemon", "Waiting for zcashd");
QTimer::singleShot(5000, [=]() { doAutoConnect(/* don't attempt to start ezcashd */ false); });
} else {
// Something is wrong.
// We're going to attempt to connect to the one in the background one last time
// and see if that works, else throw an error
main->logger->write("Unknown problem while trying to start zcashd");
QTimer::singleShot(2000, [=]() { doAutoConnect(/* don't attempt to start ezcashd */ false); });
}
}
} else {
// We tried to start ezcashd previously, and it didn't work. So, show the error.
main->logger->write("Couldn't start embedded zcashd for unknown reason");
QString explanation = QString() % "Couldn't start the embedded zcashd.\n\n" %
"Please try restarting.\n\nIf you previously started zcashd with custom arguments, you might need to reset zcash.conf.\n\n" %
"If all else fails, please run zcashd manually." %
(ezcashd ? "The process returned:\n\n" % ezcashd->errorString() : QString(""));
QString explanation;
if (config->zcashDaemon) {
explanation = QString() % "You have zcashd set to start as a daemon, which can cause problems "
"with zec-qt-wallet\n\n."
"Please remove the following line from your zcash.conf and restart zec-qt-wallet\n"
"daemon=1";
} else {
explanation = QString() % "Couldn't start the embedded zcashd.\n\n" %
"Please try restarting.\n\nIf you previously started zcashd with custom arguments, you might need to reset zcash.conf.\n\n" %
"If all else fails, please run zcashd manually." %
(ezcashd ? "The process returned:\n\n" % ezcashd->errorString() : QString(""));
}
this->showError(explanation);
}
}
} else {
// zcash.conf exists, there's no connection, and the user asked us not to start zcashd. Error!
main->logger->write("Not using embedded and couldn't connect to zcashd");
@ -255,7 +268,6 @@ bool ConnectionLoader::startEmbeddedZcashd() {
if (ezcashd != nullptr) {
if (ezcashd->state() == QProcess::NotRunning) {
qDebug() << "Process started and then crashed";
if (!processStdErrOutput.isEmpty()) {
QMessageBox::critical(main, "zcashd error", "zcashd said: " + processStdErrOutput,
QMessageBox::Ok);
@ -516,6 +528,7 @@ std::shared_ptr<ConnectionConfig> ConnectionLoader::autoDetectZcashConf() {
zcashconf->connType = ConnectionType::DetectedConfExternalZcashD;
zcashconf->usingZcashConf = true;
zcashconf->zcashDir = QFileInfo(confLocation).absoluteDir().absolutePath();
zcashconf->zcashDaemon = false;
Settings::getInstance()->setUsingZcashConf(confLocation);
@ -534,6 +547,9 @@ std::shared_ptr<ConnectionConfig> ConnectionLoader::autoDetectZcashConf() {
if (name == "rpcport") {
zcashconf->port = value;
}
if (name == "daemon" && value == "1") {
zcashconf->zcashDaemon = true;
}
if (name == "testnet" &&
value == "1" &&
zcashconf->port.isEmpty()) {
@ -565,7 +581,7 @@ std::shared_ptr<ConnectionConfig> ConnectionLoader::loadFromSettings() {
if (username.isEmpty() || password.isEmpty())
return nullptr;
auto uiConfig = new ConnectionConfig{ host, port, username, password, false, "", ConnectionType::UISettingsZCashD};
auto uiConfig = new ConnectionConfig{ host, port, username, password, false, false, "", ConnectionType::UISettingsZCashD};
return std::shared_ptr<ConnectionConfig>(uiConfig);
}

1
src/connection.h

@ -21,6 +21,7 @@ struct ConnectionConfig {
QString rpcuser;
QString rpcpassword;
bool usingZcashConf;
bool zcashDaemon;
QString zcashDir;
ConnectionType connType;

4
src/rpc.cpp

@ -940,8 +940,10 @@ void RPC::shutdownZcashd() {
int waitCount = 0;
QObject::connect(&waiter, &QTimer::timeout, [&] () {
waitCount++;
if ((ezcashd->atEnd() && ezcashd->processId() == 0) ||
waitCount > 30) {
waitCount > 30 ||
conn->config->zcashDaemon) { // If zcashd is daemon, then we don't have to do anything else
qDebug() << "Ended";
waiter.stop();
QTimer::singleShot(1000, [&]() { d.accept(); });

Loading…
Cancel
Save