Skip to content

Commit

Permalink
Added command line option to rewind blockchain to height
Browse files Browse the repository at this point in the history
In case wallet stuck syncing (e.g. on wrong chain). This will spare the need to manually delete blockchain files and sync from scratch.
  • Loading branch information
nnian committed Aug 7, 2019
1 parent cb31619 commit c4a0777
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/CommandLineParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ CommandLineParser::CommandLineParser(QObject* _parent) : QObject(_parent), m_par
m_seedNodeOption("seed-node", tr("Connect to a node to retrieve peer addresses, and disconnect"), tr("node")),
m_hideMyPortOption("hide-my-port", tr("Do not announce yourself as peerlist candidate")),
m_dataDirOption("data-dir", tr("Specify data directory"), tr("directory"), QString::fromLocal8Bit(Tools::getDefaultDataDirectory().c_str())),
m_rollBackOption("rollback", tr("Rollback to height"), tr("height"), QString::number(std::numeric_limits<uint32_t>::max())),
m_minimized("minimized", tr("Run application in minimized mode")) {
m_parser.setApplicationDescription(tr("Qwertycoin wallet"));
m_parser.addHelpOption();
Expand All @@ -42,6 +43,7 @@ CommandLineParser::CommandLineParser(QObject* _parent) : QObject(_parent), m_par
m_parser.addOption(m_seedNodeOption);
m_parser.addOption(m_hideMyPortOption);
m_parser.addOption(m_dataDirOption);
m_parser.addOption(m_rollBackOption);
m_parser.addOption(m_minimized);
}

Expand Down Expand Up @@ -121,4 +123,8 @@ QString CommandLineParser::getDataDir() const {
return m_parser.value(m_dataDirOption);
}

quint32 CommandLineParser::rollBack() const {
return m_parser.value(m_rollBackOption).toULong();
}

}
3 changes: 3 additions & 0 deletions src/CommandLineParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#pragma once

#include <limits>
#include <QCommandLineParser>
#include <QObject>

Expand Down Expand Up @@ -34,6 +35,7 @@ class CommandLineParser : public QObject {
QStringList getExclusiveNodes() const;
QStringList getSeedNodes() const;
QString getDataDir() const;
quint32 rollBack() const;

private:
QCommandLineParser m_parser;
Expand All @@ -50,6 +52,7 @@ class CommandLineParser : public QObject {
QCommandLineOption m_seedNodeOption;
QCommandLineOption m_hideMyPortOption;
QCommandLineOption m_dataDirOption;
QCommandLineOption m_rollBackOption;
QCommandLineOption m_minimized;
};

Expand Down
5 changes: 5 additions & 0 deletions src/CryptoNoteWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <limits>
#include "CryptoNoteWrapper.h"
#include "config/Checkpoints.h"
#include "CryptoNoteCore/CryptoNoteBasicImpl.h"
Expand Down Expand Up @@ -473,6 +474,10 @@ class InprocessNode : CryptoNote::INodeObserver, public Node {
return;
}

if(Settings::instance().getRollBack() != std::numeric_limits<uint32_t>::max()) {
m_core.rollbackBlockchain(Settings::instance().getRollBack());
}

if (!m_nodeServer.init(m_netNodeConfig)) {
callback(make_error_code(CryptoNote::error::NOT_INITIALIZED));
return;
Expand Down
5 changes: 5 additions & 0 deletions src/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ QDir Settings::getDataDir() const {
return QDir(m_cmdLineParser->getDataDir());
}

quint32 Settings::getRollBack() const {
Q_CHECK_PTR(m_cmdLineParser);
return m_cmdLineParser->rollBack();
}

QString Settings::getWalletFile() const {
return m_settings.contains("walletFile") ? m_settings.value("walletFile").toString() :
getDataDir().absoluteFilePath(QCoreApplication::applicationName() + ".wallet");
Expand Down
2 changes: 2 additions & 0 deletions src/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class Settings : public QObject {
quint64 getOptimizationThreshold() const;
quint64 getOptimizationMixin() const;

quint32 getRollBack() const;

bool isEncrypted() const;
bool isStartOnLoginEnabled() const;
bool isTrackingMode() const;
Expand Down

0 comments on commit c4a0777

Please sign in to comment.