Skip to content

Commit

Permalink
kernel: Add check if the chainstate maanger is busy loading blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCharlatan committed Nov 8, 2024
1 parent 269e070 commit fe6eeb8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/kernel/bitcoinkernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1448,3 +1448,8 @@ kernel_Transaction* kernel_get_transaction_by_index(kernel_Block* block_, uint64
return reinterpret_cast<kernel_Transaction*>(new CTransaction{*(**block).vtx[index]});
}

bool kernel_loading_blocks(kernel_ChainstateManager* chainman)
{
return cast_chainstate_manager(chainman)->m_blockman.LoadingBlocks();
}

11 changes: 11 additions & 0 deletions src/kernel/bitcoinkernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -1389,6 +1389,17 @@ kernel_ByteArray* BITCOINKERNEL_WARN_UNUSED_RESULT kernel_copy_transaction_data(
kernel_Transaction* transaction
) BITCOINKERNEL_ARG_NONNULL(1);

/**
* @brief Check if the chainstate manager is busy loading blocks from disk. This
* may be the case when reindexing, or importing block files from disk.
*
* @param[in] chainman Non-null.
* @return True if the chainstate manager is busy loading blocks.
*/
bool BITCOINKERNEL_WARN_UNUSED_RESULT kernel_loading_blocks(
kernel_ChainstateManager* chainman
) BITCOINKERNEL_ARG_NONNULL(1);

#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
Expand Down
5 changes: 5 additions & 0 deletions src/kernel/bitcoinkernel_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,11 @@ class ChainMan
return kernel_import_blocks(m_context.m_context.get(), m_chainman, c_paths.data(), c_paths.size());
}

bool LoadingBlocks() const noexcept
{
return kernel_loading_blocks(m_chainman);
}

bool ProcessBlockHeader(BlockHeader& header) const noexcept
{
return kernel_chainstate_manager_process_block_header(m_context.m_context.get(), m_chainman, header.m_block_header.get());
Expand Down
1 change: 1 addition & 0 deletions src/test/kernel/test_kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,7 @@ void chainman_reindex_chainstate_test(TestDirectory& test_directory)
std::vector<std::string> import_files;
import_files.push_back(test_directory.m_directory / "blocks" / "blk00000.dat");
chainman->ImportBlocks(import_files);
assert(!chainman->LoadingBlocks());
}

int main()
Expand Down

0 comments on commit fe6eeb8

Please sign in to comment.