3 minor findings · 8 suggestions
Earlier concerns neither republished nor resolved: 2 minor findings · 1 suggestion. See the Run archive for their assessments.
Findings
[minor] · Verification failures log the successful load result
Verification failures still return nullptr, but the diagnostic uses the already-successful load result and omits the failure reason.
Location: src/kernel/bitcoinkernel.cpp:1292 (head).
Details and suggested fix
After LoadChainstate() succeeds, the verification branch checks verify_result but formats load_result, which has already passed its own check. Verification failures such as a corrupted block database, a future-dated tip, or insufficient dbcache are therefore logged with nothing after the colon. Pass verify_result to ErrorString. Interrupted verification also needs a message: VerifyLoadedChainstate now returns a bare Interrupted{}, so preserve a message on that path or log one when IsInterrupted(*verify_result).
[minor] · A throwing Result construction can destroy an unconstructed success value
During exception unwinding, Result may destroy uninitialized success storage; no current caller that reaches this case was identified.
Location: src/util/result.h:161 (head).
Details and suggested fix
SuccessHolder() leaves m_success inactive, but its destructor destroys that member whenever no error is engaged. The Result constructors construct the success or error value later in the constructor body. If construction throws, the base destructor can call m_success.~SuccessType() before that object's lifetime begins. This can happen if the SuccessType constructor throws or if allocation fails while constructing error data; update() has a similar window when it changes states. Track whether m_success is alive separately from the error state, or record the new state only after construction succeeds, and test with a throwing success constructor. Result<void> is unaffected. In bitcoind, allocation failure terminates through new_handler_terminate, and no current caller with a throwing success or error constructor was identified, so production impact is unconfirmed.
[minor] · The derived-to-base test deletes through a non-virtual base destructor
The new unit test has undefined behavior when the converted unique_ptr is destroyed.
Location: src/test/result_tests.cpp:280 (head).
Details and suggested fix
DerivedToBaseFn converts Result<std::unique_ptr<Derived>> to Result<std::unique_ptr<NoCopyNoMove>>. When the result is destroyed, std::default_delete<NoCopyNoMove> deletes the Derived through a NoCopyNoMove*. Because NoCopyNoMove has no virtual destructor, this delete-expression has undefined behavior, even though Derived adds no members and both types have the same size. Give the test base a virtual destructor, or use separate polymorphic test types, so the conversion remains covered without invalid deletion.
Optional improvements
[suggestion] · Copying a non-const Result lvalue silently moves from it
A non-const lvalue copy that failed to compile before now compiles and leaves the source Result moved-from.
Location: src/util/result.h:216 (head).
Details and suggested fix
The base class deleted Result(const Result&), but the constrained Result(O&&) constructor also accepts O = Result& and beats the implicitly deleted copy constructor for a non-const lvalue. Thus auto b = a; or Result<U> b{a}; now compiles and moves a's success value and messages. Likewise, operator>> returns an rvalue reference even when its source is an lvalue, so auto x = a >> dst; moves from a. Constrain the converting constructor to rvalues and return std::forward<SrcResult>(src) from operator>>. Checked-in callers pass prvalues, implicitly moved locals or parameters, or operator>> results of rvalues, so they would still compile.
[suggestion] · Test setup accepts interrupted chainstate operations
An interrupted LoadChainstate or VerifyLoadedChainstate now passes setup assertions that previously rejected it.
Location: src/test/util/setup_common.cpp:375 (head).
Details and suggested fix
LoadChainstate and VerifyLoadedChainstate represent interruption as a success value containing Interrupted{}, so bool(result) is true. LoadVerifyActivateChainstate checks only Assert(load_result) and Assert(verify_result). The previous assertions required ChainstateLoadStatus::SUCCESS and rejected interruption. An interrupted load can now pass setup, set setChainstateLoaded(true), and fail later at a less obvious point. Assert both that each result is successful and that it is not interrupted, and update the ChainstateLoadError comment to state that success also requires !IsInterrupted(*result).
[suggestion] · A failed reindex retry reports the stale first error with the retry error
If the reindex retry also fails, the init error begins with the error that prompted the retry.
Location: src/init.cpp:1965 (head).
Details and suggested fix
result.update(InitAndLoadChainstate(...)) merges messages, appending the retry's messages to the existing ones. If the retry fails, InitError(util::ErrorString(result)) displays both errors joined by a space, such as “Error loading block database Error opening block database.” The first error describes the condition the reindex was meant to fix and may be mistaken for the current cause. If only the retry error should be shown, keep the retry outcome in a separate variable and report that. If the combined trace is intended, explain that behavior in the commit message, since the commit is labelled a refactor.
[suggestion] · Tests do not cover custom ResultTraits merging
The value-merging behavior named in the PR title could regress to plain replacement without any test failing.
Location: src/test/result_tests.cpp:216 (head).
Details and suggested fix
move() routes success-to-success and error-to-error updates through detail::ResultUpdate, which uses ResultTraits<T>::update and empty when defined. The only specialization that defines those methods is ResultTraits<Messages>. check_update uses int, FnError, and NoCopy, which fall back to move assignment, and no test updates one error result with another. Replacing either ResultUpdate call with plain move assignment would therefore still pass. Add a test type whose ResultTraits::update accumulates and whose empty recognizes a sentinel. Test success-to-success and error-to-error updates, including that an empty source leaves the destination unchanged.
[suggestion] · The snapshot-cleanup branch shadows the accumulating result
This branch bypasses the merge pattern used elsewhere in LoadChainstate, so future messages from this call would be dropped.
Location: src/node/chainstate.cpp:236 (head).
Details and suggested fix
auto result{CompleteChainstateInitialization(chainman, options)}; declares a new variable that shadows the outer result. On failure, the inner result is returned and any messages already in the outer result are dropped. On success, the inner result, including any warnings, is discarded and the outer result is returned. Nothing is lost today: CompleteChainstateInitialization produces no messages on success, and the outer result has none at this point. Use result.update(CompleteChainstateInitialization(chainman, options)); as on line 199 to accumulate messages consistently. -Wshadow is not enabled, so the compiler will not flag this.
[suggestion] · Result comments refer to nonexistent types
Comments refer to FailType, InfoType, and util::Info, which this class does not have.
Location: src/util/result.h:358 (head).
Details and suggested fix
The constructor comment says remaining arguments go to the “FailType constructor.” The update(T&&) comment cites util::Info, and the operator>> comment says it moves InfoType and MessagesType values. The class uses SuccessType, ErrorType, and MessagesType; this tree has no InfoType or util::Info. Replace the references with the applicable ErrorType or MessagesType, and omit util::Info until the follow-up that adds it.
[suggestion] · JoinMessages copies both message vectors
Each ErrorString call with messages copies all error and warning strings before joining them.
Location: src/util/messages.cpp:16 (head).
Details and suggested fix
{messages.errors, messages.warnings} creates an initializer list of vectors, copying both vectors and their strings on each JoinMessages call. The loop variable is also named messages, shadowing the parameter. Iterate over pointers, for example for (const auto* list : {&messages.errors, &messages.warnings}), to preserve the errors-then-warnings order and spacing without copying.
[suggestion] · InitAndLoadChainstate has external linkage
Changing the return type also removed static, making this init.cpp-only helper an externally linked symbol.
Location: src/init.cpp:1400 (head).
Details and suggested fix
The previous declaration was static ChainstateLoadResult InitAndLoadChainstate(. The new declaration changes the return type and drops static. No header declares the function, and its only callers are in init.cpp, so it has external linkage unnecessarily and loses the unused-function diagnostics available with internal linkage. Restore static.
Earlier concerns
Earlier reports raised these, with the titles and severities shown there. This review neither republished nor resolved them.
- [minor]: Preserve the verification interruption diagnostic
- [suggestion]: Should the warning downgrade be scoped to the reported false positive?
- [minor]: Require an explicit error mapping during conversion