@@ -685,21 +685,6 @@ void SetupServerArgs(ArgsManager& argsman, bool can_listen_ipc)
685
685
argsman.AddHiddenArgs (hidden_args);
686
686
}
687
687
688
- static bool fHaveGenesis = false ;
689
- static GlobalMutex g_genesis_wait_mutex;
690
- static std::condition_variable g_genesis_wait_cv;
691
-
692
- static void BlockNotifyGenesisWait (const CBlockIndex* pBlockIndex)
693
- {
694
- if (pBlockIndex != nullptr ) {
695
- {
696
- LOCK (g_genesis_wait_mutex);
697
- fHaveGenesis = true ;
698
- }
699
- g_genesis_wait_cv.notify_all ();
700
- }
701
- }
702
-
703
688
#if HAVE_SYSTEM
704
689
static void StartupNotify (const ArgsManager& args)
705
690
{
@@ -1616,7 +1601,8 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
1616
1601
// ********************************************************* Step 7: load block chain
1617
1602
1618
1603
node.notifications = std::make_unique<KernelNotifications>(Assert (node.shutdown_request ), node.exit_status , *Assert (node.warnings ));
1619
- ReadNotificationArgs (args, *node.notifications );
1604
+ auto & kernel_notifications{*node.notifications };
1605
+ ReadNotificationArgs (args, kernel_notifications);
1620
1606
1621
1607
// cache size calculations
1622
1608
CacheSizes cache_sizes = CalculateCacheSizes (args, g_enabled_filter_types.size ());
@@ -1768,15 +1754,6 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
1768
1754
}
1769
1755
}
1770
1756
1771
- // Either install a handler to notify us when genesis activates, or set fHaveGenesis directly.
1772
- // No locking, as this happens before any background thread is started.
1773
- boost::signals2::connection block_notify_genesis_wait_connection;
1774
- if (WITH_LOCK (chainman.GetMutex (), return chainman.ActiveChain ().Tip () == nullptr )) {
1775
- block_notify_genesis_wait_connection = uiInterface.NotifyBlockTip_connect (std::bind (BlockNotifyGenesisWait, std::placeholders::_2));
1776
- } else {
1777
- fHaveGenesis = true ;
1778
- }
1779
-
1780
1757
#if HAVE_SYSTEM
1781
1758
const std::string block_notify = args.GetArg (" -blocknotify" , " " );
1782
1759
if (!block_notify.empty ()) {
@@ -1821,15 +1798,11 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
1821
1798
});
1822
1799
1823
1800
// Wait for genesis block to be processed
1824
- {
1825
- WAIT_LOCK (g_genesis_wait_mutex, lock);
1826
- // We previously could hang here if shutdown was requested prior to
1827
- // ImportBlocks getting started, so instead we just wait on a timer to
1828
- // check ShutdownRequested() regularly.
1829
- while (!fHaveGenesis && !ShutdownRequested (node)) {
1830
- g_genesis_wait_cv.wait_for (lock, std::chrono::milliseconds (500 ));
1831
- }
1832
- block_notify_genesis_wait_connection.disconnect ();
1801
+ if (WITH_LOCK (chainman.GetMutex (), return chainman.ActiveTip () == nullptr )) {
1802
+ WAIT_LOCK (kernel_notifications.m_tip_block_mutex , lock);
1803
+ kernel_notifications.m_tip_block_cv .wait (lock, [&]() EXCLUSIVE_LOCKS_REQUIRED (kernel_notifications.m_tip_block_mutex ) {
1804
+ return !kernel_notifications.m_tip_block .IsNull () || ShutdownRequested (node);
1805
+ });
1833
1806
}
1834
1807
1835
1808
if (ShutdownRequested (node)) {
0 commit comments