validation: remove redundant check on pindex #20868

pull jarolrod wants to merge 1 commits into bitcoin:master from jarolrod:redundant-check-validation changing 1 files +2 −4
  1. jarolrod commented at 8:06 PM on January 6, 2021: member

    This removes a redundant check on pindex being a nullptr. By the time we get to this step pindex is always a nullptr as the branch where it has been set would have already returned.

    Closes #19223

  2. DrahtBot added the label Validation on Jan 6, 2021
  3. mjdietzx commented at 9:40 PM on January 6, 2021: contributor

    Concept ACK

  4. Zero-1729 commented at 10:09 PM on January 6, 2021: contributor

    ACK

  5. ajtowns commented at 5:22 AM on January 7, 2021: member

    Perhaps make it:

         BlockMap::iterator miSelf = m_block_index.find(hash);
    -    CBlockIndex *pindex = nullptr;
         if (hash != chainparams.GetConsensus().hashGenesisBlock) {
             if (miSelf != m_block_index.end()) {
                 // Block header is already known.
    -            pindex = miSelf->second;
    +            CBlockIndex *pindex = miSelf->second;
                 if (ppindex)
                     *ppindex = pindex;
                 if (pindex->nStatus & BLOCK_FAILED_MASK) {
    @@ -3621,7 +3620,7 @@ bool BlockManager::AcceptBlockHeader(const CBlockHeader& block, BlockValidationS
                 }
             }
         }
    -    pindex = AddToBlockIndex(block);
    +    CBlockIndex *pindex = AddToBlockIndex(block);
    

    so it's clear that the earlier pindex and the later pindex are independent?

  6. jarolrod force-pushed on Jan 8, 2021
  7. jarolrod commented at 8:58 PM on January 8, 2021: member

    updated 1574879a7b06e570c9943de02e6efcc74817d44a -> 8be1a34f56ab8cb76b2d29b081c77c052bbad191

    addressed @ajtowns comment. Thanks for the tip!

  8. in src/validation.cpp:3623 in 8be1a34f56 outdated
    3619 | @@ -3621,8 +3620,7 @@ bool BlockManager::AcceptBlockHeader(const CBlockHeader& block, BlockValidationS
    3620 |              }
    3621 |          }
    3622 |      }
    3623 | -    if (pindex == nullptr)
    3624 | -        pindex = AddToBlockIndex(block);
    3625 | +    CBlockIndex *pindex = AddToBlockIndex(block);
    


    promag commented at 2:06 PM on January 10, 2021:

    nit, CBlockIndex* pindex = ..., same in L3554.

  9. promag commented at 2:07 PM on January 10, 2021: member

    Code review ACK 8be1a34f56ab8cb76b2d29b081c77c052bbad191.

  10. theStack approved
  11. theStack commented at 2:52 PM on January 10, 2021: member

    Code review ACK 8be1a34f56ab8cb76b2d29b081c77c052bbad191 🥃

  12. DrahtBot commented at 11:45 AM on January 13, 2021: member

    <!--4a62be1de6b64f3ed646cdc7932c8cf5-->

    🕵️ @sipa has been requested to review this pull request as specified in the REVIEWERS file.

  13. validation: remove redundant check on pindex
    This removes a conditional that checks if pindex is equal to nullptr.
    This check is redundant because the branch where pindex is set returns at an earlier time. Additionaly, The independence of the earlier and later pindex is made clearer.
    c943282b5e
  14. jarolrod force-pushed on Jan 13, 2021
  15. theStack approved
  16. theStack commented at 4:26 PM on January 13, 2021: member

    re-ACK c943282b5e6312537f885c811d43120ce2f5b766

  17. jarolrod commented at 4:28 PM on January 13, 2021: member

    updated 8be1a34f56ab8cb76b2d29b081c77c052bbad191 -> c943282b5e6312537f885c811d43120ce2f5b766

    Moved placement of pointer from name to type based on @promag suggestion

  18. Zero-1729 commented at 6:05 AM on January 14, 2021: contributor

    re-ACK c943282

  19. ajtowns commented at 6:52 AM on January 14, 2021: member

    ACK c943282b5e6312537f885c811d43120ce2f5b766 - code review only

  20. decryp2kanon commented at 6:00 PM on January 19, 2021: contributor

    Concept ACK

  21. MarcoFalke commented at 9:56 AM on February 1, 2021: member

    review ACK c943282b5e6312537f885c811d43120ce2f5b766 📨

    <details><summary>Show signature and timestamp</summary>

    Signature:

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA512
    
    review ACK c943282b5e6312537f885c811d43120ce2f5b766 📨
    -----BEGIN PGP SIGNATURE-----
    
    iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
    pUhzXQwAyGILsbFtO9WYGBALSWon9GjpoziL7M+3LqQBj7D21YVmRmCZAL4FV8+8
    ++ebIBccAaI84vRn+TAjY74UYHv55EsxnwbZQzY44KivRc6kWUlf1AubA16WrW0z
    jl3uP4qImGpy2nflWUjGsKkVtWg+Y/fAmgM0v2HiEGRsz+GmyidMpeIqFSjd07A4
    uyavf+dC3BK8q9kM7EYhH7lZxlrbti9cdtM5f8gfccYWJg33tpBrEJAwJ0EXKjEh
    6vYTEf7XYXlSX3FZQZ9q2fyyUecvfo05+G15anfGSGqzKnE5u4n438VamUuQtM3b
    yQyMddEnmI0iodXOIRGtZhuxwFh7RDdyPUdG//fPqhHrvN4/7LG3vP1aBAO0MRZU
    kT+pQWxvHHgCun7hgu4SCfdAMP2vFZ0aPTatj98KQ/t4wMJcboEVAL6l7c1aeOgU
    GM/S9HoT3mjiV8VZTZ4ykC1HcgZFHRaSWiBRseJ8GmAg7DLKkTu9d/LFkX8VqdSY
    pxX7K5l9
    =o4SE
    -----END PGP SIGNATURE-----
    

    Timestamp of file with hash 76e16b7b369644db399a29534fee3202bd7da8a1fc17996983ad5d72b5c4ff4a -

    </details>

  22. MarcoFalke merged this on Feb 1, 2021
  23. MarcoFalke closed this on Feb 1, 2021

  24. jarolrod deleted the branch on Feb 1, 2021
  25. sidhujag referenced this in commit 8c9e35cddd on Feb 2, 2021
  26. Fabcien referenced this in commit 602209d248 on Jul 21, 2022
  27. 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-26 09:14 UTC

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