Merge bitcoin/bitcoin#33867: kernel: handle null or empty directories in implementation

6657bcbdb4 kernel: allow null data_directory (stickies-v)

Pull request description:

  An empty path may be represented with a `nullptr`. For example, `std::string_view{}.data()` may return nullptr.

  Removes the `BITCOINKERNEL_ARG_NONNULL` attribute for `btck_chainstate_manager_options_create` 's `data_directory` parameter, and instead handles such null arguments in the implementation. [Because an empty path is meaningless](https://github.com/bitcoin/bitcoin/pull/33867#discussion_r2523930442), `btck_chainstate_manager_options_create` now treats both null and empty directories as invalid, tightening the interface.

  Also documents how `BITCOINKERNEL_ARG_NONNULL` should be used.

  Follow-up to https://github.com/bitcoin/bitcoin/pull/33853#pullrequestreview-3454620265

ACKs for top commit:
  stringintech:
    ACK 6657bcb
  maflcko:
    review ACK 6657bcbdb4 🐪
  achow101:
    ACK 6657bcbdb4
  TheCharlatan:
    ACK 6657bcbdb4
  janb84:
    ACK 6657bcbdb4

Tree-SHA512: 11c02b221ff19a5357e94355808e3b503b3a336c16fc5186c9c9137931709e880383ed1f4990fc4cc6b0e23961e2e1e03fc90154a3b546b9490ef66bd63688b7
This commit is contained in:
Ava Chow
2025-11-19 16:22:01 -08:00
4 changed files with 39 additions and 8 deletions

View File

@@ -625,6 +625,20 @@ BOOST_AUTO_TEST_CASE(btck_chainman_tests)
ChainstateManagerOptions chainman_opts{context, test_directory.m_directory.string(), (test_directory.m_directory / "blocks").string()};
ChainMan chainman{context, chainman_opts};
}
{ // null or empty data_directory or blocks_directory are not allowed
Context context{};
auto valid_dir{test_directory.m_directory.string()};
std::vector<std::pair<std::string_view, std::string_view>> illegal_cases{
{"", valid_dir},
{valid_dir, {nullptr, 0}},
{"", ""},
{{nullptr, 0}, {nullptr, 0}},
};
for (auto& [data_dir, blocks_dir] : illegal_cases) {
BOOST_CHECK_THROW(ChainstateManagerOptions(context, data_dir, blocks_dir),
std::runtime_error);
};
}
auto notifications{std::make_shared<TestKernelNotifications>()};
auto context{create_context(notifications, ChainType::MAINNET)};