0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-02 09:46:52 -05:00

Reduce cs_main lock accumulation during GUI startup

This commit is contained in:
Jonas Schnelli 2020-05-19 15:15:00 +02:00
parent d42cb79068
commit 386ec192a5
5 changed files with 17 additions and 15 deletions

View file

@ -81,6 +81,7 @@ static void RegisterMetaTypes()
qRegisterMetaType<std::function<void()>>("std::function<void()>"); qRegisterMetaType<std::function<void()>>("std::function<void()>");
qRegisterMetaType<QMessageBox::Icon>("QMessageBox::Icon"); qRegisterMetaType<QMessageBox::Icon>("QMessageBox::Icon");
qRegisterMetaType<interfaces::BlockAndHeaderTipInfo>("interfaces::BlockAndHeaderTipInfo");
} }
static QString GetLangTerritory() static QString GetLangTerritory()
@ -164,8 +165,9 @@ void BitcoinCore::initialize()
{ {
qDebug() << __func__ << ": Running initialization in thread"; qDebug() << __func__ << ": Running initialization in thread";
util::ThreadRename("qt-init"); util::ThreadRename("qt-init");
bool rv = m_node.appInitMain(); interfaces::BlockAndHeaderTipInfo tip_info;
Q_EMIT initializeResult(rv); bool rv = m_node.appInitMain(&tip_info);
Q_EMIT initializeResult(rv, tip_info);
} catch (const std::exception& e) { } catch (const std::exception& e) {
handleRunawayException(&e); handleRunawayException(&e);
} catch (...) { } catch (...) {
@ -342,7 +344,7 @@ void BitcoinApplication::requestShutdown()
Q_EMIT requestedShutdown(); Q_EMIT requestedShutdown();
} }
void BitcoinApplication::initializeResult(bool success) void BitcoinApplication::initializeResult(bool success, interfaces::BlockAndHeaderTipInfo tip_info)
{ {
qDebug() << __func__ << ": Initialization result: " << success; qDebug() << __func__ << ": Initialization result: " << success;
// Set exit result. // Set exit result.
@ -352,7 +354,7 @@ void BitcoinApplication::initializeResult(bool success)
// Log this only after AppInitMain finishes, as then logging setup is guaranteed complete // Log this only after AppInitMain finishes, as then logging setup is guaranteed complete
qInfo() << "Platform customization:" << platformStyle->getName(); qInfo() << "Platform customization:" << platformStyle->getName();
clientModel = new ClientModel(m_node, optionsModel); clientModel = new ClientModel(m_node, optionsModel);
window->setClientModel(clientModel); window->setClientModel(clientModel, &tip_info);
#ifdef ENABLE_WALLET #ifdef ENABLE_WALLET
if (WalletModel::isWalletEnabled()) { if (WalletModel::isWalletEnabled()) {
m_wallet_controller = new WalletController(*clientModel, platformStyle, this); m_wallet_controller = new WalletController(*clientModel, platformStyle, this);

View file

@ -12,6 +12,8 @@
#include <QApplication> #include <QApplication>
#include <memory> #include <memory>
#include <interfaces/node.h>
class BitcoinGUI; class BitcoinGUI;
class ClientModel; class ClientModel;
class NetworkStyle; class NetworkStyle;
@ -21,10 +23,6 @@ class PlatformStyle;
class WalletController; class WalletController;
class WalletModel; class WalletModel;
namespace interfaces {
class Handler;
class Node;
} // namespace interfaces
/** Class encapsulating Bitcoin Core startup and shutdown. /** Class encapsulating Bitcoin Core startup and shutdown.
* Allows running startup and shutdown in a different thread from the UI thread. * Allows running startup and shutdown in a different thread from the UI thread.
@ -40,7 +38,7 @@ public Q_SLOTS:
void shutdown(); void shutdown();
Q_SIGNALS: Q_SIGNALS:
void initializeResult(bool success); void initializeResult(bool success, interfaces::BlockAndHeaderTipInfo tip_info);
void shutdownResult(); void shutdownResult();
void runawayException(const QString &message); void runawayException(const QString &message);
@ -91,7 +89,7 @@ public:
void setupPlatformStyle(); void setupPlatformStyle();
public Q_SLOTS: public Q_SLOTS:
void initializeResult(bool success); void initializeResult(bool success, interfaces::BlockAndHeaderTipInfo tip_info);
void shutdownResult(); void shutdownResult();
/// Handle runaway exceptions. Shows a message box with the problem and quits the program. /// Handle runaway exceptions. Shows a message box with the problem and quits the program.
void handleRunawayException(const QString &message); void handleRunawayException(const QString &message);

View file

@ -574,7 +574,7 @@ void BitcoinGUI::createToolBars()
} }
} }
void BitcoinGUI::setClientModel(ClientModel *_clientModel) void BitcoinGUI::setClientModel(ClientModel *_clientModel, interfaces::BlockAndHeaderTipInfo* tip_info)
{ {
this->clientModel = _clientModel; this->clientModel = _clientModel;
if(_clientModel) if(_clientModel)
@ -588,8 +588,8 @@ void BitcoinGUI::setClientModel(ClientModel *_clientModel)
connect(_clientModel, &ClientModel::numConnectionsChanged, this, &BitcoinGUI::setNumConnections); connect(_clientModel, &ClientModel::numConnectionsChanged, this, &BitcoinGUI::setNumConnections);
connect(_clientModel, &ClientModel::networkActiveChanged, this, &BitcoinGUI::setNetworkActive); connect(_clientModel, &ClientModel::networkActiveChanged, this, &BitcoinGUI::setNetworkActive);
modalOverlay->setKnownBestHeight(_clientModel->getHeaderTipHeight(), QDateTime::fromTime_t(_clientModel->getHeaderTipTime())); modalOverlay->setKnownBestHeight(tip_info->header_height, QDateTime::fromTime_t(tip_info->header_time));
setNumBlocks(m_node.getNumBlocks(), QDateTime::fromTime_t(m_node.getLastBlockTime()), m_node.getVerificationProgress(), false, SynchronizationState::INIT_DOWNLOAD); setNumBlocks(tip_info->block_height, QDateTime::fromTime_t(tip_info->block_time), tip_info->verification_progress, false, SynchronizationState::INIT_DOWNLOAD);
connect(_clientModel, &ClientModel::numBlocksChanged, this, &BitcoinGUI::setNumBlocks); connect(_clientModel, &ClientModel::numBlocksChanged, this, &BitcoinGUI::setNumBlocks);
// Receive and report messages from client model // Receive and report messages from client model
@ -600,7 +600,7 @@ void BitcoinGUI::setClientModel(ClientModel *_clientModel)
// Show progress dialog // Show progress dialog
connect(_clientModel, &ClientModel::showProgress, this, &BitcoinGUI::showProgress); connect(_clientModel, &ClientModel::showProgress, this, &BitcoinGUI::showProgress);
rpcConsole->setClientModel(_clientModel); rpcConsole->setClientModel(_clientModel, tip_info->block_height, tip_info->block_time, tip_info->verification_progress);
updateProxyIcon(); updateProxyIcon();

View file

@ -43,6 +43,7 @@ enum class SynchronizationState;
namespace interfaces { namespace interfaces {
class Handler; class Handler;
class Node; class Node;
struct BlockAndHeaderTipInfo;
} }
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
@ -75,7 +76,7 @@ public:
/** Set the client model. /** Set the client model.
The client model represents the part of the core that communicates with the P2P network, and is wallet-agnostic. The client model represents the part of the core that communicates with the P2P network, and is wallet-agnostic.
*/ */
void setClientModel(ClientModel *clientModel); void setClientModel(ClientModel *clientModel = nullptr, interfaces::BlockAndHeaderTipInfo* tip_info = nullptr);
#ifdef ENABLE_WALLET #ifdef ENABLE_WALLET
void setWalletController(WalletController* wallet_controller); void setWalletController(WalletController* wallet_controller);
#endif #endif

View file

@ -67,6 +67,7 @@ void AppTests::appTests()
return GetDataDir() / "blocks"; return GetDataDir() / "blocks";
}()); }());
qRegisterMetaType<interfaces::BlockAndHeaderTipInfo>("interfaces::BlockAndHeaderTipInfo");
m_app.parameterSetup(); m_app.parameterSetup();
m_app.createOptionsModel(true /* reset settings */); m_app.createOptionsModel(true /* reset settings */);
QScopedPointer<const NetworkStyle> style(NetworkStyle::instantiate(Params().NetworkIDString())); QScopedPointer<const NetworkStyle> style(NetworkStyle::instantiate(Params().NetworkIDString()));