aboutsummaryrefslogtreecommitdiff
path: root/src/init.cpp
diff options
context:
space:
mode:
authorJonas Schnelli <dev@jonasschnelli.ch>2020-08-13 10:37:36 +0200
committerJonas Schnelli <dev@jonasschnelli.ch>2020-08-13 10:37:46 +0200
commit1052b09031c63f20390486680f3117d40bb89d88 (patch)
treecd61a8592533ec4ab07da7220fa9a3128d435200 /src/init.cpp
parent8a85377cd0b60cb00dae4f595d628d1afbd28bd5 (diff)
parent386ec192a57b76492125d691ceda1b4aa832312e (diff)
downloadbitcoin-1052b09031c63f20390486680f3117d40bb89d88.tar.xz
Merge #19011: Reduce cs_main lock accumulation during GUI startup
386ec192a57b76492125d691ceda1b4aa832312e Reduce cs_main lock accumulation during GUI startup (Jonas Schnelli) d42cb790687788c78aa2f0c1988238ab52050782 Optionally populate BlockAndHeaderTipInfo during AppInitMain (Jonas Schnelli) b354a1480abbd71fb7fb82c39c81ea0644bbfce4 Add BlockAndHeaderTipInfo to the node interface/appInit (Jonas Schnelli) 25e1d0bf417237caa5d36b4e757f29e6c8be8aad RPCConsole, take initial chaintip data as parameter (Jonas Schnelli) Pull request description: During the GUI startup, there is currently an accumulation of cs_main locks due to setting initial chain state values at multiple locations (in the GUI main thread). This PR tries to cache the initial chain state (tip height, tip time, best header, etc.) short after loading the blockindex. The cached values are then used instead of fetching them again (and thus locking `cs_main`) during setting the client model. This should fix the initial GUI blocking often experienced during or short after the splashscreen. On mac, best tested together with #19007. ACKs for top commit: promag: Code review ACK 386ec192a57b76492125d691ceda1b4aa832312e. ryanofsky: Code review ACK 386ec192a57b76492125d691ceda1b4aa832312e. Just rebased since last review due to conflicts Tree-SHA512: caccca05360e6dc0c3aade5e7ed24be513607821a8bd6612d0337259304ab772799fb2d707a0d7c7e50fbff4bd394354643fd0aeaa3bb55960ccc28562f4763d
Diffstat (limited to 'src/init.cpp')
-rw-r--r--src/init.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/init.cpp b/src/init.cpp
index 08944b79a5..966462a93f 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -24,6 +24,7 @@
#include <index/blockfilterindex.h>
#include <index/txindex.h>
#include <interfaces/chain.h>
+#include <interfaces/node.h>
#include <key.h>
#include <miner.h>
#include <net.h>
@@ -1242,7 +1243,7 @@ bool AppInitLockDataDirectory()
return true;
}
-bool AppInitMain(const util::Ref& context, NodeContext& node)
+bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
{
const CChainParams& chainparams = Params();
// ********************************************************* Step 4a: application initialization
@@ -1877,6 +1878,15 @@ bool AppInitMain(const util::Ref& context, NodeContext& node)
LOCK(cs_main);
LogPrintf("block tree size = %u\n", chainman.BlockIndex().size());
chain_active_height = chainman.ActiveChain().Height();
+ if (tip_info) {
+ tip_info->block_height = chain_active_height;
+ tip_info->block_time = chainman.ActiveChain().Tip() ? chainman.ActiveChain().Tip()->GetBlockTime() : Params().GenesisBlock().GetBlockTime();
+ tip_info->verification_progress = GuessVerificationProgress(Params().TxData(), chainman.ActiveChain().Tip());
+ }
+ if (tip_info && ::pindexBestHeader) {
+ tip_info->header_height = ::pindexBestHeader->nHeight;
+ tip_info->header_time = ::pindexBestHeader->GetBlockTime();
+ }
}
LogPrintf("nBestHeight = %d\n", chain_active_height);