Review report

core: PR #36520

1 minor finding · 1 suggestion

Earlier concerns neither republished nor resolved: 1 suggestion. See the Run archive for their assessments.

Findings

Link

[minor] · A tip-height change can leave a wallet stuck in the loading state

If the active tip drops during wallet loading, getBlockHash can throw an exception that bypasses in-process load handling, leaving the wallet unavailable until restart.

Location: src/node/interfaces.cpp:599 (head).

Details and suggested fix

CWallet::AttachChain registers for validation notifications, then reads the tip height and hash separately without holding cs_main across both calls. If the active tip drops between those reads, such as during a concurrent invalidateblock, getBlockHash throws std::out_of_range. This exception is not caught by the std::runtime_error handlers in LoadWalletInternal and LoadWallets. For loadwallet, the loading name is therefore not removed, so retries report “Wallet already loading.” The wallet also remains registered for validation callbacks with its database open, but is absent from context.wallets. The window is narrow and requires authenticated RPC or a reorg to a lower tip height; the resulting local wallet cannot be reloaded until restart. To avoid this, read the height and hash under one lock or ensure AttachChain disconnects notifications and the loading state is cleaned up when an exception escapes.


Optional improvements

Link

[suggestion] · A negative max_height can make hasBlocks dereference a null pointer

A negative max_height can crash hasBlocks; the in-tree caller rejects it, so production impact is unconfirmed.

Location: src/test/interfaces_tests.cpp:181 (head).

Details and suggested fix

For a known block hash, hasBlocks(hash, 0, -1) calls GetAncestor(-1), which returns nullptr, then dereferences that pointer in the loop condition. The in-tree rescanblockchain caller rejects negative stop heights, so no in-tree caller is known to trigger this. A client of the proposed Chain IPC interface could pass a negative value. Return false when GetAncestor returns nullptr, and add !chain->hasBlocks(tip_hash, 0, -1) to invalidArguments.


Coverage details

Earlier concerns

Earlier reports raised these, with the titles and severities shown there. This review neither republished nor resolved them.