test: Verify findCommonAncestor always initializes outputs #18660

pull ryanofsky wants to merge 1 commits into bitcoin:master from ryanofsky:pr/commoninit changing 2 files +8 −0
  1. ryanofsky commented at 9:10 PM on April 15, 2020: member

    Also add code comment to clarify surprising code noted by practicalswift #18657 (comment)

  2. test: Verify findCommonAncestor always initializes outputs
    Also add code comment to clarify surprising code noted by practicalswift
    https://github.com/bitcoin/bitcoin/pull/18657#issuecomment-614278450
    9986608ba9
  3. MarcoFalke commented at 9:32 PM on April 15, 2020: member

    ACK 9986608ba93de040490ee0d5584ea33e605f1df0

  4. DrahtBot added the label Tests on Apr 15, 2020
  5. practicalswift commented at 8:11 AM on April 16, 2020: contributor

    Concept ACK

    Thanks for addressing this.

    ACK on the addition of the test, but for the chain.cpp change I suggest using the following equivalent formulation which removes the need for the clarifying comment (and as an added bonus avoids static analyser warnings for static analysers using the AutoSAR ruleset :)):

    diff --git a/src/interfaces/chain.cpp b/src/interfaces/chain.cpp
    index c8311b298..ed2142884 100644
    --- a/src/interfaces/chain.cpp
    +++ b/src/interfaces/chain.cpp
    @@ -275,7 +275,10 @@ public:
             const CBlockIndex* block1 = LookupBlockIndex(block_hash1);
             const CBlockIndex* block2 = LookupBlockIndex(block_hash2);
             const CBlockIndex* ancestor = block1 && block2 ? LastCommonAncestor(block1, block2) : nullptr;
    -        return FillBlock(ancestor, ancestor_out, lock) & FillBlock(block1, block1_out, lock) & FillBlock(block2, block2_out, lock);
    +        const bool ancestor_filled = FillBlock(ancestor, ancestor_out, lock);
    +        const bool block1_filled = FillBlock(block1, block1_out, lock);
    +        const bool block2_filled = FillBlock(block2, block2_out, lock);
    +        return ancestor_filled && block1_filled && block2_filled;
         }
         void findCoins(std::map<COutPoint, Coin>& coins) override { return FindCoins(m_node, coins); }
         double guessVerificationProgress(const uint256& block_hash) override
    
  6. jonatack commented at 11:39 AM on April 16, 2020: member

    ACK 9986608ba93de04 modulo @practicalswift's #18660 (comment)

  7. ryanofsky commented at 3:27 PM on April 16, 2020: member

    I suggest using the following equivalent formulation which removes the need for the clarifying comment

    Readability is subjective, but to me that suggestion is less readable, more verbose, and less clear that the evaluations are intentional not accidental. Comments are useful when they convey intent.

  8. MarcoFalke commented at 3:45 PM on April 16, 2020: member

    This is adding documentation and tests. Should be good to merge with two ACKs. If the AutoSAR static analyser can't read the comment that the & are desired, it should probably be fixed upstream.

  9. MarcoFalke merged this on Apr 16, 2020
  10. MarcoFalke closed this on Apr 16, 2020

  11. promag commented at 12:00 AM on April 17, 2020: member

    ACK 9986608ba93de040490ee0d5584ea33e605f1df0.

    In both could have checked ancestor_out hash is null.

  12. Fabcien referenced this in commit 7d707861f7 on Jan 15, 2021
  13. DrahtBot locked this on Feb 15, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-16 18:14 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me