Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/guiinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ class CClientUIInterface
/** New block has been accepted */
boost::signals2::signal<void(bool fInitialDownload, const CBlockIndex* newTip)> NotifyBlockTip;

/** Best header has changed */
boost::signals2::signal<void (bool, const CBlockIndex *)> NotifyHeaderTip;

/** New block has been accepted and is over a certain size */
boost::signals2::signal<void(int size, const uint256& hash)> NotifyBlockSize;

Expand Down
21 changes: 12 additions & 9 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ std::string HelpMessage(HelpMessageMode mode)
#ifndef WIN32
strUsage += HelpMessageOpt("-pid=<file>", strprintf(_("Specify pid file (default: %s)"), PIVX_PID_FILENAME));
#endif
strUsage += HelpMessageOpt("-reindex-chainstate", _("Rebuild chain state from the currently indexed blocks"));
strUsage += HelpMessageOpt("-reindex", _("Rebuild block chain index from current blk000??.dat files") + " " + _("on startup"));
strUsage += HelpMessageOpt("-reindexmoneysupply", strprintf(_("Reindex the %s and z%s money supply statistics"), CURRENCY_UNIT, CURRENCY_UNIT) + " " + _("on startup"));
strUsage += HelpMessageOpt("-resync", _("Delete blockchain folders and resync from scratch") + " " + _("on startup"));
Expand Down Expand Up @@ -649,10 +650,10 @@ struct CImportingNow {
void ThreadImport(std::vector<fs::path> vImportFiles)
{
util::ThreadRename("pivx-loadblk");
CImportingNow imp;

// -reindex
if (fReindex) {
CImportingNow imp;
int nFile = 0;
while (true) {
CDiskBlockPos pos(nFile, 0);
Expand All @@ -677,7 +678,6 @@ void ThreadImport(std::vector<fs::path> vImportFiles)
if (fs::exists(pathBootstrap)) {
FILE* file = fsbridge::fopen(pathBootstrap, "rb");
if (file) {
CImportingNow imp;
fs::path pathBootstrapOld = GetDataDir() / "bootstrap.dat.old";
LogPrintf("Importing bootstrap.dat...\n");
LoadExternalBlockFile(file);
Expand All @@ -691,14 +691,20 @@ void ThreadImport(std::vector<fs::path> vImportFiles)
for (fs::path& path : vImportFiles) {
FILE* file = fsbridge::fopen(path, "rb");
if (file) {
CImportingNow imp;
LogPrintf("Importing blocks file %s...\n", path.string());
LoadExternalBlockFile(file);
} else {
LogPrintf("Warning: Could not open blocks file %s\n", path.string());
}
}

// scan for better chains in the block chain database, that are not yet connected in the active best chain
CValidationState state;
if (!ActivateBestChain(state)) {
LogPrintf("Failed to connect best block");
StartShutdown();
}

if (GetBoolArg("-stopafterblockimport", DEFAULT_STOPAFTERBLOCKIMPORT)) {
LogPrintf("Stopping after block import\n");
StartShutdown();
Expand Down Expand Up @@ -1457,6 +1463,7 @@ bool AppInit2()
// ********************************************************* Step 7: load block chain

fReindex = GetBoolArg("-reindex", false);
bool fReindexChainState = GetBoolArg("-reindex-chainstate", false);

// Create blocks directory if it doesn't already exist
fs::create_directories(GetDataDir() / "blocks");
Expand Down Expand Up @@ -1499,7 +1506,7 @@ bool AppInit2()
pSporkDB = new CSporkDB(0, false, false);

pblocktree = new CBlockTreeDB(nBlockTreeDBCache, false, fReindex);
pcoinsdbview = new CCoinsViewDB(nCoinDBCache, false, fReindex);
pcoinsdbview = new CCoinsViewDB(nCoinDBCache, false, fReindex || fReindexChainState);
pcoinscatcher = new CCoinsViewErrorCatcher(pcoinsdbview);
pcoinsTip = new CCoinsViewCache(pcoinscatcher);

Expand Down Expand Up @@ -1545,7 +1552,7 @@ bool AppInit2()

// Check for changed -txindex state
if (fTxIndex != GetBoolArg("-txindex", DEFAULT_TXINDEX)) {
strLoadError = _("You need to rebuild the database using -reindex to change -txindex");
strLoadError = _("You need to rebuild the database using -reindex-chainstate to change -txindex");
break;
}

Expand Down Expand Up @@ -1711,10 +1718,6 @@ bool AppInit2()
if (mapArgs.count("-blocksizenotify"))
uiInterface.NotifyBlockSize.connect(BlockSizeNotifyCallback);

// scan for better chains in the block chain database, that are not yet connected in the active best chain
CValidationState state;
if (!ActivateBestChain(state))
strErrors << "Failed to connect best block";
// update g_best_block if needed
{
LOCK(g_best_block_mutex);
Expand Down
17 changes: 11 additions & 6 deletions src/qt/clientmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

static const int64_t nClientStartupTime = GetTime();
// Last tip update notification
static int64_t nLastHeaderTipUpdateNotification = 0;
static int64_t nLastBlockTipUpdateNotification = 0;

ClientModel::ClientModel(OptionsModel* optionsModel, QObject* parent) : QObject(parent),
Expand Down Expand Up @@ -250,7 +251,7 @@ void ClientModel::updateBanlist()
banTableModel->refresh();
}

static void BlockTipChanged(ClientModel *clientmodel, bool initialSync, const CBlockIndex *pIndex)
static void BlockTipChanged(ClientModel *clientmodel, bool initialSync, const CBlockIndex *pIndex, bool fHeader)
{
// lock free async UI updates in case we have a new block tip
// during initial sync, only update the UI if the last update
Expand All @@ -259,15 +260,17 @@ static void BlockTipChanged(ClientModel *clientmodel, bool initialSync, const CB
if (initialSync)
now = GetTimeMillis();

int64_t& nLastUpdateNotification = fHeader ? nLastHeaderTipUpdateNotification : nLastBlockTipUpdateNotification;

// if we are in-sync, update the UI regardless of last update time
if (!initialSync || now - nLastBlockTipUpdateNotification > MODEL_UPDATE_DELAY) {
if (!initialSync || now - nLastUpdateNotification > MODEL_UPDATE_DELAY) {
//pass a async signal to the UI thread
clientmodel->setCacheTip(pIndex);
clientmodel->setCacheImporting(fImporting);
clientmodel->setCacheReindexing(fReindex);
clientmodel->setCacheInitialSync(initialSync);
Q_EMIT clientmodel->numBlocksChanged(pIndex->nHeight);
nLastBlockTipUpdateNotification = now;
Q_EMIT clientmodel->numBlocksChanged(pIndex->nHeight, fHeader);
nLastUpdateNotification = now;
}
}

Expand Down Expand Up @@ -306,7 +309,8 @@ void ClientModel::subscribeToCoreSignals()
uiInterface.NotifyNumConnectionsChanged.connect(boost::bind(NotifyNumConnectionsChanged, this, _1));
uiInterface.NotifyAlertChanged.connect(boost::bind(NotifyAlertChanged, this));
uiInterface.BannedListChanged.connect(boost::bind(BannedListChanged, this));
uiInterface.NotifyBlockTip.connect(boost::bind(BlockTipChanged, this, _1, _2));
uiInterface.NotifyBlockTip.connect(boost::bind(BlockTipChanged, this, _1, _2, false));
uiInterface.NotifyHeaderTip.connect(boost::bind(BlockTipChanged, this, _1, _2, true));
}

void ClientModel::unsubscribeFromCoreSignals()
Expand All @@ -316,7 +320,8 @@ void ClientModel::unsubscribeFromCoreSignals()
uiInterface.NotifyNumConnectionsChanged.disconnect(boost::bind(NotifyNumConnectionsChanged, this, _1));
uiInterface.NotifyAlertChanged.disconnect(boost::bind(NotifyAlertChanged, this));
uiInterface.BannedListChanged.disconnect(boost::bind(BannedListChanged, this));
uiInterface.NotifyBlockTip.disconnect(boost::bind(BlockTipChanged, this, _1, _2));
uiInterface.NotifyBlockTip.disconnect(boost::bind(BlockTipChanged, this, _1, _2, false));
uiInterface.NotifyHeaderTip.disconnect(boost::bind(BlockTipChanged, this, _1, _2, true));
}

bool ClientModel::getTorInfo(std::string& ip_port) const
Expand Down
2 changes: 1 addition & 1 deletion src/qt/clientmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class ClientModel : public QObject

Q_SIGNALS:
void numConnectionsChanged(int count);
void numBlocksChanged(int count);
void numBlocksChanged(int count, bool headers);
void strMasternodesChanged(const QString& strMasternodes);
void alertsChanged(const QString& warnings);
void bytesChanged(quint64 totalBytesIn, quint64 totalBytesOut);
Expand Down
5 changes: 3 additions & 2 deletions src/qt/pivx/settings/settingsinformationwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void SettingsInformationWidget::loadClientModel()
setNumConnections(clientModel->getNumConnections());
connect(clientModel, &ClientModel::numConnectionsChanged, this, &SettingsInformationWidget::setNumConnections);

setNumBlocks(clientModel->getNumBlocks());
setNumBlocks(clientModel->getNumBlocks(), false);
connect(clientModel, &ClientModel::numBlocksChanged, this, &SettingsInformationWidget::setNumBlocks);

connect(clientModel, &ClientModel::strMasternodesChanged, this, &SettingsInformationWidget::setMasternodeCount);
Expand All @@ -137,8 +137,9 @@ void SettingsInformationWidget::setNumConnections(int count)
ui->labelInfoConnections->setText(connections);
}

void SettingsInformationWidget::setNumBlocks(int count)
void SettingsInformationWidget::setNumBlocks(int count, bool headers)
{
if (headers) return;
ui->labelInfoBlockNumber->setText(QString::number(count));
if (clientModel) {
ui->labelInfoBlockTime->setText(clientModel->getLastBlockDate().toString());
Expand Down
2 changes: 1 addition & 1 deletion src/qt/pivx/settings/settingsinformationwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class SettingsInformationWidget : public PWidget

private Q_SLOTS:
void setNumConnections(int count);
void setNumBlocks(int count);
void setNumBlocks(int count, bool headers);
void setMasternodeCount(const QString& strMasternodes);
void showEvent(QShowEvent* event) override;
void hideEvent(QHideEvent* event) override;
Expand Down
8 changes: 5 additions & 3 deletions src/qt/pivx/topbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ void TopBar::loadClientModel()
setNumConnections(clientModel->getNumConnections());
connect(clientModel, &ClientModel::numConnectionsChanged, this, &TopBar::setNumConnections);

setNumBlocks(clientModel->getNumBlocks());
setNumBlocks(clientModel->getNumBlocks(), false);
connect(clientModel, &ClientModel::numBlocksChanged, this, &TopBar::setNumBlocks);

timerStakingIcon = new QTimer(ui->pushButtonStack);
Expand Down Expand Up @@ -420,7 +420,7 @@ void TopBar::setNumConnections(int count)
ui->pushButtonConnection->setButtonText(tr("%n active connection(s)", "", count));
}

void TopBar::setNumBlocks(int count)
void TopBar::setNumBlocks(int count, bool headers)
{
if (!clientModel)
return;
Expand All @@ -430,15 +430,17 @@ void TopBar::setNumBlocks(int count)
std::string text = "";
switch (blockSource) {
case BLOCK_SOURCE_NETWORK:
if (headers) return;
text = "Synchronizing..";
break;
case BLOCK_SOURCE_DISK:
text = "Importing blocks from disk..";
text = headers ? "Indexing blocks from disk..." : "Processing blocks on disk...";
break;
case BLOCK_SOURCE_REINDEX:
text = "Reindexing blocks on disk..";
break;
case BLOCK_SOURCE_NONE:
if (headers) return;
// Case: not Importing, not Reindexing and no network connection
text = "No block source available..";
ui->pushButtonSync->setChecked(false);
Expand Down
2 changes: 1 addition & 1 deletion src/qt/pivx/topbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public Q_SLOTS:
void updateDisplayUnit();

void setNumConnections(int count);
void setNumBlocks(int count);
void setNumBlocks(int count, bool headers);
void setStakingStatusActive(bool fActive);
void updateStakingStatus();
void updateHDState(const bool& upgraded, const QString& upgradeError);
Expand Down
5 changes: 3 additions & 2 deletions src/qt/rpcconsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ void RPCConsole::setClientModel(ClientModel* model)
setNumConnections(model->getNumConnections());
connect(model, &ClientModel::numConnectionsChanged, this, &RPCConsole::setNumConnections);

setNumBlocks(model->getNumBlocks());
setNumBlocks(model->getNumBlocks(), false);
connect(model, &ClientModel::numBlocksChanged, this, &RPCConsole::setNumBlocks);

connect(model, &ClientModel::strMasternodesChanged, this, &RPCConsole::setMasternodeCount);
Expand Down Expand Up @@ -661,8 +661,9 @@ void RPCConsole::setNumConnections(int count)
ui->numberOfConnections->setText(connections);
}

void RPCConsole::setNumBlocks(int count)
void RPCConsole::setNumBlocks(int count, bool headers)
{
if (headers) return;
ui->numberOfBlocks->setText(QString::number(count));
if (clientModel) {
ui->lastBlockTime->setText(clientModel->getLastBlockDate().toString());
Expand Down
2 changes: 1 addition & 1 deletion src/qt/rpcconsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public Q_SLOTS:
/** Set number of connections shown in the UI */
void setNumConnections(int count);
/** Set number of blocks shown in the UI */
void setNumBlocks(int count);
void setNumBlocks(int count, bool headers);
/** Set number of masternodes shown in the UI */
void setMasternodeCount(const QString& strMasternodes);
/** Go forward or back in history */
Expand Down
Loading