rpc: add null assert #7493

pull dcousens wants to merge 1 commits into bitcoin:master from dcousens:patch-1 changing 1 files +3 −1
  1. dcousens commented at 11:31 PM on February 9, 2016: contributor

    reference #6393

    Is that what you meant @laanwj ?

  2. rpc: add null assert
    reference #6393
    0077cbf754
  3. in src/rpc/blockchain.cpp:None in 0077cbf754
     669 | +        assert(block);
     670 | +        
     671 | +        while (block->pprev && (block->pprev->nStatus & BLOCK_HAVE_DATA))
     672 |              block = block->pprev;
     673 |  
     674 |          obj.push_back(Pair("pruneheight",        block->nHeight));
    


    luke-jr commented at 11:47 PM on February 9, 2016:

    I don't know the context of this PR, but it seems to me this should just be block?block->nHeight:0


    dcousens commented at 1:44 AM on February 11, 2016:

    @luke-jr I think it won't always be 0 since & BLOCK_HAVE_DATA would fail for the first pruned block, hence, the last "pruned" block.


    luke-jr commented at 1:58 AM on February 11, 2016:

    In that case, block won't be NULL... (I assume you're familiar with the trinary operator?)


    dcousens commented at 2:22 AM on February 11, 2016:

    Do you mean the ternary operator?


    dcousens commented at 2:25 AM on February 11, 2016:

    And yes, I understand the block won't be NULL... I'm not sure I understand what your point is?

  4. luke-jr commented at 11:47 PM on February 9, 2016: member

    Also, the commit message here sucks. Please explain what it's supposed to do and why...

  5. laanwj commented at 10:22 AM on February 10, 2016: member

    What I meant in #6393 was that when execution reaches the part of AppInit2() where the RPC server is unlocked (meaning SetRPCWarmupFinished() is called), the code has made sure that chainActive.Tip() is not null. It either has successfully indexed the genesis block, or exit with an error. See also #5243.

    This means that checks (or assertions) for chainActive.Tip() are not necessary in the RPC code (or anywhere else if AppInit2 is finished). No need to add this. Luckily, because there are tons of places in the code where it is blindly assumed that the tip contains a block.

  6. dcousens commented at 1:43 AM on February 11, 2016: contributor

    Well, as was pointed out in #6393 the block && check is pointless given the immediate de-reference afterwards.

  7. laanwj commented at 7:41 AM on February 11, 2016: member

    But it doesn't really hurt either. I see no reason for changing this code.

  8. laanwj closed this on Feb 11, 2016

  9. dcousens deleted the branch on Feb 11, 2016
  10. MarcoFalke locked this on Sep 8, 2021

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-21 21:15 UTC

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