chain: Do not fill out parameters in findCommonAncestor(...) if ancestor is not found #18657

pull practicalswift wants to merge 1 commits into bitcoin:master from practicalswift:out-parameters-in-findCommonAncestor changing 2 files +3 −2
  1. practicalswift commented at 7:58 PM on April 15, 2020: contributor

    This is a follow-up to #17954 which was merged yesterday.

    See post-merge comments in #17954 for context:

    Oh, I didn't see this during review. I read the method as nothing is filled when the ancestor is not found. I.e. I read the & as &&. Is there any caller that depends on this edge case?

  2. chain: Do not fill out parameters in findCommonAncestor(...) if ancestor is not found f8bfda16eb
  3. ryanofsky commented at 8:43 PM on April 15, 2020: member

    I don't think this is a good change. I would prefer to just add a test making sure the API works as designed instead of making the API leave behind uninitialized output variables and be awkward to use and then document the awkwardness. Here is the test I would add:

    --- a/src/test/interfaces_tests.cpp
    +++ b/src/test/interfaces_tests.cpp
    @@ -116,6 +116,12 @@ BOOST_AUTO_TEST_CASE(findCommonAncestor)
         BOOST_CHECK_EQUAL(orig_height, orig_tip->nHeight);
         BOOST_CHECK_EQUAL(fork_height, orig_tip->nHeight - 10);
         BOOST_CHECK_EQUAL(fork_hash, active[fork_height]->GetBlockHash());
    +
    +    uint256 active_hash, orig_hash;
    +    BOOST_CHECK(!chain->findCommonAncestor(active.Tip()->GetBlockHash(), {}, {}, FoundBlock().hash(active_hash), {}));
    +    BOOST_CHECK(!chain->findCommonAncestor({}, orig_tip->GetBlockHash(), {}, {}, FoundBlock().hash(orig_hash)));
    +    BOOST_CHECK_EQUAL(active_hash, active.Tip()->GetBlockHash());
    +    BOOST_CHECK_EQUAL(orig_hash, orig_tip->GetBlockHash());
     }
     
     BOOST_AUTO_TEST_CASE(hasBlocks)
    

    The PR description here is also not justifying the change, only linking to a long discussion thread. The only apparent reason for this change is is that it makes the code "AutoSAR" and "MISRA" complaint. I haven't heard of these things and didn't know my PRs were supposed to comply with them. If they are, I'd like to see automated compliance tests or notes in the developer guide with testing instructions.

    Code review ACK f8bfda16ebefda40efd66eeb0225c353a88d8e53, in case other reviewers think this PR is an improvement and want to merge it. Despite the fact that this PR may leave FoundBlock output variables uninitialized, I don't think it causes any bugs

  4. practicalswift commented at 9:02 PM on April 15, 2020: contributor

    @ryanofsky The justification is to minimise surprising code: apparently both @MarcoFalke and I were somewhat surprised by the current formulation. Perhaps the intentional use of & instead of && was clear to other reviewers.

    No one is claiming that we are following AutoSAR, or that you should have thought about AutoSAR when submitting your PR :)

  5. practicalswift closed this on Apr 15, 2020

  6. ryanofsky referenced this in commit 9986608ba9 on Apr 15, 2020
  7. ryanofsky commented at 9:14 PM on April 15, 2020: member

    @ryanofsky The justification is to minimise surprising code: apparently both @MarcoFalke and I were somewhat surprised by the current formulation

    Thanks for finding this and pointing it out. It's a good catch that uncovered a gap in test coverage and point of potential confusion. I didn't like this particular solution to the problem, but I posted another one in https://github.com/bitcoin/bitcoin/pull/18660

  8. MarcoFalke referenced this in commit f4c0ad4aef on Apr 16, 2020
  9. sidhujag referenced this in commit beac3c37dc on Apr 16, 2020
  10. sidhujag referenced this in commit ed005fa151 on Apr 19, 2020
  11. janus referenced this in commit 66dddf7868 on Nov 8, 2020
  12. Fabcien referenced this in commit 7d707861f7 on Jan 15, 2021
  13. practicalswift deleted the branch on Apr 10, 2021
  14. DrahtBot locked this on Aug 16, 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 15:14 UTC

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