Skip to content

[[nodiscard]]#169

Draft
l0rinc wants to merge 5 commits into
masterfrom
detached528
Draft

[[nodiscard]]#169
l0rinc wants to merge 5 commits into
masterfrom
detached528

Conversation

@l0rinc
Copy link
Copy Markdown
Owner

@l0rinc l0rinc commented May 12, 2026

Temporarily Annotated

  • Validation/mempool/block helpers: AcceptToMemoryPool, ProcessNewPackage, CheckFinalTxAtTip, CalculateLockPointsAtTip, CheckSequenceLocksAtTip, CScriptCheck::operator(), CheckBlock, TestBlockValidity, HasValidProofOfWork, IsBlockMutated,
    CalculateClaimedHeadersWork, CheckInputScripts, CalculatePrevHeights, CheckInputsFromMempoolAndCache, MemPoolAccept::*, ApplyTxInUndo, CheckBlockHeader, CheckMerkleRoot, CheckWitnessMalleation, ContextualCheckBlockHeader, ContextualCheckBlock,
    GetSynchronizationState.
  • Chainstate/manager APIs: ResizeCoinsCaches, FlushStateToDisk, ActivateBestChain, DisconnectBlock, ConnectBlock, DisconnectTip, PreciousBlock, InvalidateBlock, ReplayBlocks, LoadGenesisBlock, LoadChainTip, GetCoinsCacheSizeState,
    ActivateBestChainStep, ConnectTip, FindMostWorkChain, RollforwardBlock, NotifyHeaderTip, AcceptBlockHeader, MaybeValidateSnapshot, ProcessNewBlock, ProcessNewBlockHeaders, AcceptBlock, LoadBlockIndex, LoadAssumeutxoChainstate,
    ValidatedSnapshotCleanup, GetHistoricalBlockRange, ActivateBestChains, BlocksAheadOfTip.
  • Direct validation callees: BlockManager::{LoadBlockIndex, FindUndoPos, LoadBlockIndexDB, LookupBlockIndex, WriteBlockUndo, WriteBlock, CheckBlockDataAvailability, IsBlockPruned, DeletePruneLock, ReadBlock, ReadRawBlock, ReadBlockUndo},
    CCoinsViewCache::SpendCoin, CheckTransaction, sequence-lock helpers, PoW helpers, and policy/package/RBF/TRUC/ephemeral standardness helpers.

Diagnostics

Diagnostic Classification Action
ProcessNewBlock ignored in net processing intentional but unclear Store result and debug-log false at src/net_processing.cpp:3429.
LoadGenesisBlock ignored after reindex likely bug Fatal error and return if retry fails at src/node/blockstorage.cpp:1299.
PreciousBlock ignored in RPC suspicious Check bool plus state at src/rpc/blockchain.cpp:1720.
InvalidateBlock ignored in RPC likely bug Check bool plus state; genesis invalidation now returns invalid state at src/validation.cpp:3521, with regression test at src/test/blockchain_tests.cpp:127.
ActivateBestChain ignored in invalidate/reconsider RPC suspicious Check bool plus state at src/rpc/blockchain.cpp:1743.
ProcessNewBlockHeaders ignored in submitheader intentional but unclear Throw if false with otherwise valid state at src/rpc/mining.cpp:1138.
FlushStateToDisk(PERIODIC) ignored after mempool/package admission suspicious Log warning, do not change admission result, at src/validation.cpp:1800 and src/validation.cpp:1834.
FlushStateToDisk(NONE) ignored in AcceptBlock likely bug Return false on flush/prune failure at src/validation.cpp:4386.
ResizeCoinsCaches ignored in snapshot activation likely bug Return util::Error at src/validation.cpp:5656.
ResizeCoinsCaches ignored in cache rebalance intentional but unclear Added logging helper at src/validation.cpp:6084.
SpendCoin, DeletePruneLock, NotifyHeaderTip, MaybeValidateSnapshot harmless Removed exploratory annotations.
Test/bench ignored returns from retained annotations harmless/test harness Converted to BOOST_REQUIRE, Assert, explicit tolerated false, or benchmark sink.

Annotations Kept
Kept [[nodiscard]] on the high-signal validation, chainstate, blockstorage I/O, consensus tx, PoW, package/policy/RBF/TRUC, and mempool acceptance return values in validation.h, validation.cpp, node/blockstorage.h, consensus/*, pow.h, and policy/
*.

Annotations Removed
Removed exploratory [[nodiscard]] from CCoinsViewCache::SpendCoin, BlockManager::DeletePruneLock, ChainstateManager::NotifyHeaderTip, ChainstateManager::MaybeValidateSnapshot, and GetSynchronizationState.

Verification

  • cmake --build build-ubsan -j2: PASS before changes, PASS final.
  • Annotated production rebuild initially failed as intended with ignored-result diagnostics; after fixes, cmake --build build-ubsan --target bitcoind bitcoin-cli bitcoin-chainstate libbitcoinkernel -j2: PASS.
  • cmake --build build-ubsan --target test_bitcoin -j2: PASS.
  • Focused unit tests passed: chainstate_write_tests, validation_chainstate_tests, validation_chainstatemanager_tests, blockchain_tests/invalidate_block, interfaces_tests/findCommonAncestor, transaction_tests/tx_valid, validation_block_tests/
    processnewblock_signals_ordering.
  • git diff --check: PASS.
  • Note: test_bitcoin in this UBSan build emits pre-existing sanitizer reports in crypto/secp256k1 startup paths; focused test exit statuses were still pass. One combined Boost filter command failed with “no test cases matching filter” and was
    rerun as separate tests.

Open Questions

  • Whether InvalidateBlock(genesis) should use a different BlockValidationResult or RPC error code than the current invalid-state/database-error path.
  • Whether periodic mempool flush failure should ever affect AcceptToMemoryPool / package admission results, instead of warning only.
  • Whether MaybeRebalanceCaches() should become fallible rather than logging ResizeCoinsCaches failures.
  • Whether maintainers prefer landing the retained broad [[nodiscard]] annotations together or splitting validation/blockstorage/policy groups.

l0rinc added 5 commits May 12, 2026 15:46
Return an invalid block validation state when `InvalidateBlock` is asked to invalidate genesis instead of returning false with a valid state.

Extend the existing invalidation unit test to cover the genesis case so callers can reliably surface this failure.
Check the boolean result from manual block and header validation APIs instead of relying only on `BlockValidationState`.

This lets RPC callers surface failures where the callee returns false without changing the validation state.
Stop import processing with a fatal error if the post-reindex `LoadGenesisBlock` retry fails.

This avoids continuing after the recovery path that is meant to ensure the genesis block exists did not succeed.
Check validation-internal `FlushStateToDisk` and `ResizeCoinsCaches` results where failure was previously ignored.

Propagate failures from block acceptance and snapshot activation, and log failures in periodic mempool flush and cache rebalance paths where the public API result cannot currently express them.
Annotate high-signal validation, block storage, consensus, PoW, and policy helpers whose return values carry success, failure, status, or optional result information.

Update existing call sites and tests to explicitly consume those results so future ignored validation outcomes are caught at compile time.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant