From c4a0777003c5e59f795701f55725c38e2dbc0730 Mon Sep 17 00:00:00 2001 From: nnian Date: Wed, 7 Aug 2019 11:44:41 +0200 Subject: [PATCH] Added command line option to rewind blockchain to height In case wallet stuck syncing (e.g. on wrong chain). This will spare the need to manually delete blockchain files and sync from scratch. --- src/CommandLineParser.cpp | 6 ++++++ src/CommandLineParser.h | 3 +++ src/CryptoNoteWrapper.cpp | 5 +++++ src/Settings.cpp | 5 +++++ src/Settings.h | 2 ++ 5 files changed, 21 insertions(+) diff --git a/src/CommandLineParser.cpp b/src/CommandLineParser.cpp index 5ab5766..6b75bcc 100644 --- a/src/CommandLineParser.cpp +++ b/src/CommandLineParser.cpp @@ -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::max())), m_minimized("minimized", tr("Run application in minimized mode")) { m_parser.setApplicationDescription(tr("Qwertycoin wallet")); m_parser.addHelpOption(); @@ -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); } @@ -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(); +} + } diff --git a/src/CommandLineParser.h b/src/CommandLineParser.h index 376b06e..673aaa1 100644 --- a/src/CommandLineParser.h +++ b/src/CommandLineParser.h @@ -4,6 +4,7 @@ #pragma once +#include #include #include @@ -34,6 +35,7 @@ class CommandLineParser : public QObject { QStringList getExclusiveNodes() const; QStringList getSeedNodes() const; QString getDataDir() const; + quint32 rollBack() const; private: QCommandLineParser m_parser; @@ -50,6 +52,7 @@ class CommandLineParser : public QObject { QCommandLineOption m_seedNodeOption; QCommandLineOption m_hideMyPortOption; QCommandLineOption m_dataDirOption; + QCommandLineOption m_rollBackOption; QCommandLineOption m_minimized; }; diff --git a/src/CryptoNoteWrapper.cpp b/src/CryptoNoteWrapper.cpp index 2cf20b3..a4fb107 100644 --- a/src/CryptoNoteWrapper.cpp +++ b/src/CryptoNoteWrapper.cpp @@ -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 #include "CryptoNoteWrapper.h" #include "config/Checkpoints.h" #include "CryptoNoteCore/CryptoNoteBasicImpl.h" @@ -473,6 +474,10 @@ class InprocessNode : CryptoNote::INodeObserver, public Node { return; } + if(Settings::instance().getRollBack() != std::numeric_limits::max()) { + m_core.rollbackBlockchain(Settings::instance().getRollBack()); + } + if (!m_nodeServer.init(m_netNodeConfig)) { callback(make_error_code(CryptoNote::error::NOT_INITIALIZED)); return; diff --git a/src/Settings.cpp b/src/Settings.cpp index dbe3925..0ce8ad4 100644 --- a/src/Settings.cpp +++ b/src/Settings.cpp @@ -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"); diff --git a/src/Settings.h b/src/Settings.h index ae4c4c1..628f748 100644 --- a/src/Settings.h +++ b/src/Settings.h @@ -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;