Skip to content
Merged
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
6 changes: 3 additions & 3 deletions src/qt/clientmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ ClientModel::ClientModel(OptionsModel *_optionsModel, QObject *parent) :
{
cachedBestHeaderHeight = -1;
cachedBestHeaderTime = -1;
cachedNumBlocks = 0;
cachedNumBlocks = g_connman ? g_connman->GetBestHeight() : 0;
cachedLastBlockDate = QDateTime();
peerTableModel = new PeerTableModel(this);
banTableModel = new BanTableModel(this);
Expand Down Expand Up @@ -360,12 +360,12 @@ static void BlockTipChanged(ClientModel *clientmodel, bool initialSync, const CB
now = GetTimeMillis();

int64_t& nLastUpdateNotification = fHeader ? nLastHeaderTipUpdateNotification : nLastBlockTipUpdateNotification;
clientmodel->cachedNumBlocks = pIndex->nHeight;

if (fHeader) {
// cache best headers time and height to reduce future cs_main locks
clientmodel->cachedBestHeaderHeight = pIndex->nHeight;
clientmodel->cachedBestHeaderTime = pIndex->GetBlockTime();
} else {
clientmodel->cachedNumBlocks = pIndex->nHeight;
}
// if we are in-sync, update the UI regardless of last update time
if (!initialSync || now - nLastUpdateNotification > MODEL_UPDATE_DELAY) {
Expand Down
1 change: 1 addition & 0 deletions src/qt/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ add_executable(test_firo-qt
# Add this to skip specific files from UIC processing
set_source_files_properties(
${CMAKE_CURRENT_SOURCE_DIR}/../../test/test_bitcoin.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_sendcoinsentry.cpp
PROPERTIES SKIP_AUTOUIC ON
)

Expand Down
23 changes: 23 additions & 0 deletions src/qt/test/test_sendcoinsentry.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#include "test_sendcoinsentry.h"

#include "chain.h"
#include "clientmodel.h"
#include "coincontroldialog.h"
#include "platformstyle.h"
#include "sendcoinsdialog.h"
#include "ui_interface.h"

#include <QCheckBox>

Expand Down Expand Up @@ -75,3 +78,23 @@ void TestSendCoinsEntry::testSparkCoinControlSizeEstimate()
true),
std::numeric_limits<unsigned int>::max());
}

void TestSendCoinsEntry::testBlockHeightCacheIgnoresHeaders()
{
ClientModel client(nullptr);
CBlockIndex block;
block.nHeight = 100;
uiInterface.NotifyBlockTip(false, &block);
QCOMPARE(client.cachedNumBlocks.load(), 100);

// Spark send controls must not use a header-only activation height.
CBlockIndex header;
header.nHeight = 200;
uiInterface.NotifyHeaderTip(false, &header);
QCOMPARE(client.cachedBestHeaderHeight.load(), 200);
QCOMPARE(client.cachedNumBlocks.load(), 100);

block.nHeight = 99;
uiInterface.NotifyBlockTip(false, &block);
QCOMPARE(client.cachedNumBlocks.load(), 99);
}
1 change: 1 addition & 0 deletions src/qt/test/test_sendcoinsentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ private Q_SLOTS:
void testTransactionCreationErrorDetails();
void testPrivateModeUpdatesExistingEntries();
void testSparkCoinControlSizeEstimate();
void testBlockHeightCacheIgnoresHeaders();
};

#endif // BITCOIN_QT_TEST_SENDCOINSENTRY_H
3 changes: 1 addition & 2 deletions src/qt/walletmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1715,8 +1715,7 @@ bool WalletModel::sparkNamesAllowed() const

bool WalletModel::versionedSparkSpendsAllowed() const
{
LOCK(cs_main);
return chainActive.Height() + 1 >=
return _client_model && _client_model->getNumBlocks() + 1 >=
Params().GetConsensus().nSparkChaumV2StartBlock;
}

Expand Down
2 changes: 1 addition & 1 deletion src/qt/walletview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ void WalletView::setClientModel(ClientModel *_clientModel)
void WalletView::setWalletModel(WalletModel *_walletModel)
{
this->walletModel = _walletModel;
walletModel->setClientModel(clientModel);

// Put transaction list in tabs
firoTransactionList->setModel(_walletModel);
Expand Down Expand Up @@ -206,7 +207,6 @@ void WalletView::setWalletModel(WalletModel *_walletModel)
connect(autoMintSparkModel, &AutoMintSparkModel::requireShowAutomintSparkNotification, this, &WalletView::showAutomintSparkNotification);
connect(autoMintSparkModel, &AutoMintSparkModel::closeAutomintSparkNotification, this, &WalletView::closeAutomintSparkNotification);
}
walletModel->setClientModel(clientModel);
}
}

Expand Down