Skip to content

Commit fe6eeb8

Browse files
committed
kernel: Add check if the chainstate maanger is busy loading blocks
1 parent 269e070 commit fe6eeb8

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

src/kernel/bitcoinkernel.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,3 +1448,8 @@ kernel_Transaction* kernel_get_transaction_by_index(kernel_Block* block_, uint64
14481448
return reinterpret_cast<kernel_Transaction*>(new CTransaction{*(**block).vtx[index]});
14491449
}
14501450

1451+
bool kernel_loading_blocks(kernel_ChainstateManager* chainman)
1452+
{
1453+
return cast_chainstate_manager(chainman)->m_blockman.LoadingBlocks();
1454+
}
1455+

src/kernel/bitcoinkernel.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,6 +1389,17 @@ kernel_ByteArray* BITCOINKERNEL_WARN_UNUSED_RESULT kernel_copy_transaction_data(
13891389
kernel_Transaction* transaction
13901390
) BITCOINKERNEL_ARG_NONNULL(1);
13911391

1392+
/**
1393+
* @brief Check if the chainstate manager is busy loading blocks from disk. This
1394+
* may be the case when reindexing, or importing block files from disk.
1395+
*
1396+
* @param[in] chainman Non-null.
1397+
* @return True if the chainstate manager is busy loading blocks.
1398+
*/
1399+
bool BITCOINKERNEL_WARN_UNUSED_RESULT kernel_loading_blocks(
1400+
kernel_ChainstateManager* chainman
1401+
) BITCOINKERNEL_ARG_NONNULL(1);
1402+
13921403
#ifdef __cplusplus
13931404
} // extern "C"
13941405
#endif // __cplusplus

src/kernel/bitcoinkernel_wrapper.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,11 @@ class ChainMan
756756
return kernel_import_blocks(m_context.m_context.get(), m_chainman, c_paths.data(), c_paths.size());
757757
}
758758

759+
bool LoadingBlocks() const noexcept
760+
{
761+
return kernel_loading_blocks(m_chainman);
762+
}
763+
759764
bool ProcessBlockHeader(BlockHeader& header) const noexcept
760765
{
761766
return kernel_chainstate_manager_process_block_header(m_context.m_context.get(), m_chainman, header.m_block_header.get());

src/test/kernel/test_kernel.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,7 @@ void chainman_reindex_chainstate_test(TestDirectory& test_directory)
689689
std::vector<std::string> import_files;
690690
import_files.push_back(test_directory.m_directory / "blocks" / "blk00000.dat");
691691
chainman->ImportBlocks(import_files);
692+
assert(!chainman->LoadingBlocks());
692693
}
693694

694695
int main()

0 commit comments

Comments
 (0)