kernel: Return btck_BlockValidationState from process_block_header API

Remove redundant int return from btck_chainstate_manager_process_block_header.
Previously returned both an int result and an output validation state parameter, creating ambiguity
where non-zero could mean either invalid header or processing failure. Since ProcessNewBlockHeaders
already provides complete validation info, the int return was redundant.

Co-authored-by: stringintech <stringintech@gmail.com>
Co-authored-by: stickies-v <stickies-v@protonmail.com>
Co-authored-by: Hodlinator <172445034+hodlinator@users.noreply.github.com>
This commit is contained in:
yuvicc
2026-05-18 19:28:09 +05:30
parent d4bc620ad8
commit 88d9bc5aa4
4 changed files with 18 additions and 17 deletions

View File

@@ -1298,19 +1298,20 @@ int btck_chainstate_manager_process_block(
return result ? 0 : -1;
}
int btck_chainstate_manager_process_block_header(
btck_BlockValidationState* btck_chainstate_manager_process_block_header(
btck_ChainstateManager* chainstate_manager,
const btck_BlockHeader* header,
btck_BlockValidationState* state)
const btck_BlockHeader* header)
{
try {
auto& chainman = btck_ChainstateManager::get(chainstate_manager).m_chainman;
auto result = chainman->ProcessNewBlockHeaders({&btck_BlockHeader::get(header), 1}, /*min_pow_checked=*/true, btck_BlockValidationState::get(state), /*ppindex=*/nullptr);
return result ? 0 : -1;
auto state = btck_BlockValidationState::create();
bool result{chainman->ProcessNewBlockHeaders({&btck_BlockHeader::get(header), 1}, /*min_pow_checked=*/true, btck_BlockValidationState::get(state))};
assert(result == btck_BlockValidationState::get(state).IsValid());
return state;
} catch (const std::exception& e) {
LogError("Failed to process block header: %s", e.what());
return -1;
return nullptr;
}
}

View File

@@ -1117,13 +1117,11 @@ BITCOINKERNEL_API const btck_BlockTreeEntry* BITCOINKERNEL_WARN_UNUSED_RESULT bt
*
* @param[in] chainstate_manager Non-null.
* @param[in] header Non-null btck_BlockHeader to be validated.
* @param[out] block_validation_state The result of the btck_BlockHeader validation.
* @return 0 if btck_BlockHeader processing completed successfully, non-zero on error.
* @return The btck_BlockValidationState containing validation result, or null on error.
*/
BITCOINKERNEL_API int BITCOINKERNEL_WARN_UNUSED_RESULT btck_chainstate_manager_process_block_header(
BITCOINKERNEL_API btck_BlockValidationState* BITCOINKERNEL_WARN_UNUSED_RESULT btck_chainstate_manager_process_block_header(
btck_ChainstateManager* chainstate_manager,
const btck_BlockHeader* header,
btck_BlockValidationState* block_validation_state) BITCOINKERNEL_ARG_NONNULL(1, 2, 3);
const btck_BlockHeader* header) BITCOINKERNEL_ARG_NONNULL(1, 2);
/**
* @brief Triggers the start of a reindex if the wipe options were previously

View File

@@ -939,7 +939,9 @@ class BlockValidationState : public Handle<btck_BlockValidationState, btck_block
public:
explicit BlockValidationState() : Handle{btck_block_validation_state_create()} {}
BlockValidationState(const BlockValidationStateView& view) : Handle{view} {}
explicit BlockValidationState(const BlockValidationStateView& view) : Handle{view} {}
explicit BlockValidationState(btck_BlockValidationState* state) : Handle{state} {}
};
class ValidationInterface
@@ -1217,9 +1219,10 @@ public:
return res == 0;
}
bool ProcessBlockHeader(const BlockHeader& header, BlockValidationState& state)
BlockValidationState ProcessBlockHeader(const BlockHeader& header)
{
return btck_chainstate_manager_process_block_header(get(), header.get(), state.get()) == 0;
auto state = btck_chainstate_manager_process_block_header(get(), header.get());
return BlockValidationState{state};
}
ChainView GetChain() const

View File

@@ -1013,10 +1013,9 @@ BOOST_AUTO_TEST_CASE(btck_chainman_regtest_tests)
for (const auto& data : REGTEST_BLOCK_DATA) {
Block block{hex_string_to_byte_vec(data)};
BlockHeader header = block.GetHeader();
BlockValidationState state{};
BOOST_CHECK(state.GetBlockValidationResult() == BlockValidationResult::UNSET);
BOOST_CHECK(chainman->ProcessBlockHeader(header, state));
BlockValidationState state = chainman->ProcessBlockHeader(header);
BOOST_CHECK(state.GetValidationMode() == ValidationMode::VALID);
BOOST_CHECK(state.GetBlockValidationResult() == BlockValidationResult::UNSET);
BlockTreeEntry entry{*chainman->GetBlockTreeEntry(header.Hash())};
BOOST_CHECK(!chainman->GetChain().Contains(entry));
BlockTreeEntry best_entry{chainman->GetBestEntry()};