mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-16 02:27:43 +02:00
init refactor: Only initialize node.notifications one time
Instead of having the InitAndLoadChainstate function delete and create the KernelNotifications object each time it is called (it can be called twice when reindexing) to clear cached state, create it just one time and add a setChainstateLoaded() method to manage state as it is loaded and unloaded. This refactoring should make sense by itself to be more explicit about how KernelNotifications state is cleared, but it's also needed to make outside code accessing KernelNotifications state (currently just mining code) safe during node startup and shutdown so the KernelNofications mutex can be used for synchronization and does not get recreated itself.
This commit is contained in:
@@ -53,7 +53,7 @@ kernel::InterruptResult KernelNotifications::blockTip(SynchronizationState state
|
||||
{
|
||||
LOCK(m_tip_block_mutex);
|
||||
Assume(index.GetBlockHash() != uint256::ZERO);
|
||||
m_tip_block = index.GetBlockHash();
|
||||
m_state.tip_block = index.GetBlockHash();
|
||||
m_tip_block_cv.notify_all();
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ void KernelNotifications::fatalError(const bilingual_str& message)
|
||||
std::optional<uint256> KernelNotifications::TipBlock()
|
||||
{
|
||||
AssertLockHeld(m_tip_block_mutex);
|
||||
return m_tip_block;
|
||||
return m_state.tip_block;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user