mirror of
https://github.com/monero-project/monero-gui.git
synced 2024-11-17 00:07:51 +00:00
p2pool: Restart monerod only when needed and with proper args
This commit is contained in:
parent
b7ba9437d8
commit
757bc7d7b9
4 changed files with 127 additions and 8 deletions
6
main.qml
6
main.qml
|
@ -748,6 +748,12 @@ ApplicationWindow {
|
||||||
currentWallet.startRefresh();
|
currentWallet.startRefresh();
|
||||||
informationPopup.title = qsTr("Daemon failed to start") + translationManager.emptyString;
|
informationPopup.title = qsTr("Daemon failed to start") + translationManager.emptyString;
|
||||||
informationPopup.text = error + ".\n\n" + qsTr("Please check your wallet and daemon log for errors. You can also try to start %1 manually.").arg((isWindows)? "monerod.exe" : "monerod")
|
informationPopup.text = error + ".\n\n" + qsTr("Please check your wallet and daemon log for errors. You can also try to start %1 manually.").arg((isWindows)? "monerod.exe" : "monerod")
|
||||||
|
if (middlePanel.advancedView.miningView.stopMiningEnabled == true) {
|
||||||
|
walletManager.stopMining()
|
||||||
|
p2poolManager.exit()
|
||||||
|
middlePanel.advancedView.miningView.update()
|
||||||
|
informationPopup.text += qsTr("\n\nExiting p2pool. Please check that port 18083 is available.") + translationManager.emptyString;
|
||||||
|
}
|
||||||
informationPopup.icon = StandardIcon.Critical
|
informationPopup.icon = StandardIcon.Critical
|
||||||
informationPopup.onCloseCallback = null
|
informationPopup.onCloseCallback = null
|
||||||
informationPopup.open();
|
informationPopup.open();
|
||||||
|
|
|
@ -41,7 +41,8 @@ Rectangle {
|
||||||
property alias miningHeight: mainLayout.height
|
property alias miningHeight: mainLayout.height
|
||||||
property double currentHashRate: 0
|
property double currentHashRate: 0
|
||||||
property int threads: idealThreadCount / 2
|
property int threads: idealThreadCount / 2
|
||||||
|
property alias stopMiningEnabled: stopSoloMinerButton.enabled
|
||||||
|
property string args: ""
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
id: mainLayout
|
id: mainLayout
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
|
@ -293,13 +294,20 @@ Rectangle {
|
||||||
var success;
|
var success;
|
||||||
if (persistentSettings.allow_p2pool_mining) {
|
if (persistentSettings.allow_p2pool_mining) {
|
||||||
if (p2poolManager.isInstalled()) {
|
if (p2poolManager.isInstalled()) {
|
||||||
if (persistentSettings.allowRemoteNodeMining) {
|
args = daemonManager.getArgs(persistentSettings.blockchainDataDir) //updates arguments
|
||||||
|
if (persistentSettings.allowRemoteNodeMining || (args.includes("--zmq-pub tcp://127.0.0.1:18083") || args.includes("--zmq-pub=tcp://127.0.0.1:18083")) && !args.includes("--no-zmq")) {
|
||||||
startP2Pool()
|
startP2Pool()
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
var underSystemd = daemonManager.checkUnderSystemd();
|
||||||
|
if (underSystemd) {
|
||||||
|
miningError(qsTr("Monerod is managed by Systemd. Manually add --zmq-pub tcp://127.0.0.1:18083 to the unit file <br>") + translationManager.emptyString)
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
daemonManager.stopAsync(persistentSettings.nettype, persistentSettings.blockchainDataDir, startP2PoolLocal)
|
daemonManager.stopAsync(persistentSettings.nettype, persistentSettings.blockchainDataDir, startP2PoolLocal)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
confirmationDialog.title = qsTr("P2Pool installation") + translationManager.emptyString;
|
confirmationDialog.title = qsTr("P2Pool installation") + translationManager.emptyString;
|
||||||
confirmationDialog.text = qsTr("P2Pool will be installed at %1. Proceed?").arg(applicationDirectory) + translationManager.emptyString;
|
confirmationDialog.text = qsTr("P2Pool will be installed at %1. Proceed?").arg(applicationDirectory) + translationManager.emptyString;
|
||||||
|
@ -585,12 +593,35 @@ Rectangle {
|
||||||
|
|
||||||
function startP2PoolLocal() {
|
function startP2PoolLocal() {
|
||||||
var noSync = false;
|
var noSync = false;
|
||||||
var customDaemonArgs = persistentSettings.daemonFlags.toLowerCase();
|
//these args will be deleted because DaemonManager::start will re-add them later.
|
||||||
var daemonArgs = "--zmq-pub " + "tcp://127.0.0.1:18083 " + "--disable-dns-checkpoints "
|
//--no-zmq must be deleted. removing '--zmq-pub=tcp...' lets us blindly add '--zmq-pub tcp...' later without risking duplication.
|
||||||
if (!customDaemonArgs.includes("--zmq-pub") && !customDaemonArgs.includes("--disable-dns-checkpoints") && !customDaemonArgs.includes("--no-zmq")) {
|
var defaultArgs = ["--detach","--data-dir","--bootstrap-daemon-address","--prune-blockchain","--no-sync","--check-updates","--non-interactive","--max-concurrency","--no-zmq","--zmq-pub=tcp://127.0.0.1:18083"]
|
||||||
daemonArgs = daemonArgs + customDaemonArgs;
|
var customDaemonArgsArray = args.split(' ');
|
||||||
|
var flag = "";
|
||||||
|
var allArgs = [];
|
||||||
|
var p2poolArgs = ["--zmq-pub tcp://127.0.0.1:18083"];
|
||||||
|
//create an array (allArgs) of ['--arg value','--arg2','--arg3']
|
||||||
|
for (let i = 0; i < customDaemonArgsArray.length; i++) {
|
||||||
|
if(!customDaemonArgsArray[i].startsWith("--")) {
|
||||||
|
flag += " " + customDaemonArgsArray[i]
|
||||||
|
} else {
|
||||||
|
if(flag){
|
||||||
|
allArgs.push(flag)
|
||||||
}
|
}
|
||||||
var success = daemonManager.start(daemonArgs, persistentSettings.nettype, persistentSettings.blockchainDataDir, persistentSettings.bootstrapNodeAddress, noSync, persistentSettings.pruneBlockchain)
|
flag = customDaemonArgsArray[i]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
allArgs.push(flag)
|
||||||
|
//pop from allArgs if value is inside the deleteme array (defaultArgs)
|
||||||
|
allArgs = allArgs.filter( ( el ) => !defaultArgs.includes( el.split(" ")[0] ) )
|
||||||
|
//append required p2pool flags
|
||||||
|
for (let i = 0; i < p2poolArgs.length; i++) {
|
||||||
|
if(!allArgs.includes(p2poolArgs[i])) {
|
||||||
|
allArgs.push(p2poolArgs[i])
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var success = daemonManager.start(allArgs.join(" "), persistentSettings.nettype, persistentSettings.blockchainDataDir, persistentSettings.bootstrapNodeAddress, noSync, persistentSettings.pruneBlockchain)
|
||||||
if (success) {
|
if (success) {
|
||||||
startP2Pool()
|
startP2Pool()
|
||||||
}
|
}
|
||||||
|
|
|
@ -342,6 +342,85 @@ bool DaemonManager::checkLmdbExists(QString datadir) {
|
||||||
return validateDataDir(datadir).value("lmdbExists").value<bool>();
|
return validateDataDir(datadir).value("lmdbExists").value<bool>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool DaemonManager::checkUnderSystemd() {
|
||||||
|
#ifdef Q_OS_LINUX
|
||||||
|
QProcess p;
|
||||||
|
QStringList args;
|
||||||
|
args << "monerod";
|
||||||
|
p.setProgram("pgrep");
|
||||||
|
p.setArguments(args);
|
||||||
|
p.start();
|
||||||
|
p.waitForFinished();
|
||||||
|
QString pid = p.readAllStandardOutput().trimmed();
|
||||||
|
if (pid.isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
args.clear();
|
||||||
|
|
||||||
|
args << "-c";
|
||||||
|
args << "ps -eo pid,cgroup | grep " + pid + " | grep -q .service$";
|
||||||
|
p.setProgram("sh");
|
||||||
|
p.setArguments(args);
|
||||||
|
p.start();
|
||||||
|
p.waitForFinished();
|
||||||
|
if (p.exitCode() == 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString DaemonManager::getArgs(const QString &dataDir) {
|
||||||
|
if (!running(NetworkType::MAINNET, dataDir)) {
|
||||||
|
return args;
|
||||||
|
}
|
||||||
|
QProcess p;
|
||||||
|
QStringList tempArgs;
|
||||||
|
#ifdef Q_OS_WIN
|
||||||
|
//powershell
|
||||||
|
tempArgs << "Get-CimInstance Win32_Process -Filter \"name = 'monerod.exe'\" | select -ExpandProperty CommandLine ";
|
||||||
|
p.setProgram("powershell");
|
||||||
|
p.setArguments(tempArgs);
|
||||||
|
p.start();
|
||||||
|
p.waitForFinished();
|
||||||
|
args = p.readAllStandardOutput().simplified().trimmed();
|
||||||
|
|
||||||
|
#elif defined(Q_OS_UNIX)
|
||||||
|
//pgrep
|
||||||
|
tempArgs << "monerod";
|
||||||
|
p.setProgram("pgrep");
|
||||||
|
p.setArguments(tempArgs);
|
||||||
|
p.start();
|
||||||
|
p.waitForFinished();
|
||||||
|
QString pid = p.readAllStandardOutput().trimmed();
|
||||||
|
if (pid.isEmpty()) {
|
||||||
|
return args;
|
||||||
|
}
|
||||||
|
|
||||||
|
tempArgs.clear();
|
||||||
|
|
||||||
|
//ps
|
||||||
|
tempArgs << "-o";
|
||||||
|
tempArgs << "args=";
|
||||||
|
tempArgs << "-fp";
|
||||||
|
tempArgs << pid;
|
||||||
|
p.setProgram("ps");
|
||||||
|
p.setArguments(tempArgs);
|
||||||
|
p.start();
|
||||||
|
p.waitForFinished();
|
||||||
|
args = p.readAllStandardOutput().trimmed();
|
||||||
|
|
||||||
|
#endif
|
||||||
|
if (args.contains("--")) {
|
||||||
|
int index = args.indexOf("--");
|
||||||
|
args.remove(0, index);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
args = "";
|
||||||
|
}
|
||||||
|
return args;
|
||||||
|
}
|
||||||
|
|
||||||
DaemonManager::DaemonManager(QObject *parent)
|
DaemonManager::DaemonManager(QObject *parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
, m_scheduler(this)
|
, m_scheduler(this)
|
||||||
|
|
|
@ -58,6 +58,8 @@ public:
|
||||||
Q_INVOKABLE void exit();
|
Q_INVOKABLE void exit();
|
||||||
Q_INVOKABLE QVariantMap validateDataDir(const QString &dataDir) const;
|
Q_INVOKABLE QVariantMap validateDataDir(const QString &dataDir) const;
|
||||||
Q_INVOKABLE bool checkLmdbExists(QString datadir);
|
Q_INVOKABLE bool checkLmdbExists(QString datadir);
|
||||||
|
Q_INVOKABLE QString getArgs(const QString &dataDir);
|
||||||
|
Q_INVOKABLE bool checkUnderSystemd();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -82,6 +84,7 @@ private:
|
||||||
QString m_monerod;
|
QString m_monerod;
|
||||||
bool m_app_exit = false;
|
bool m_app_exit = false;
|
||||||
bool m_noSync = false;
|
bool m_noSync = false;
|
||||||
|
QString args = "";
|
||||||
|
|
||||||
mutable FutureScheduler m_scheduler;
|
mutable FutureScheduler m_scheduler;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue