check bad-prevblk is right error for invalid descendants #15965

pull zenosage wants to merge 1 commits into bitcoin:master from zenosage:bad-prevblk changing 2 files +2 −1
  1. zenosage commented at 8:18 PM on May 6, 2019: contributor

    I am confused reading this code block if (!pindexPrev->IsValid(BLOCK_VALID_SCRIPTS)) {... Then I find bad-prevblk is returned twice. One here and one above if (pindexPrev->nStatus & BLOCK_FAILED_MASK)...

    To disambiguate, I change bad-prevblk to bad-prevblk-desc and verify that this is the right error being tested in p2p_unrequested_blocks. This the only place this behavior is tested I think.

  2. zenosage commented at 8:19 PM on May 6, 2019: contributor

    How to add Test label to this PR? Do I need permission?

  3. DrahtBot added the label Tests on May 6, 2019
  4. DrahtBot added the label Validation on May 6, 2019
  5. DrahtBot added the label Needs rebase on May 6, 2019
  6. MarcoFalke removed the label Tests on May 6, 2019
  7. check bad-prevblk is right error for invalid descendants 1e1e895276
  8. zenosage force-pushed on May 8, 2019
  9. DrahtBot removed the label Needs rebase on May 8, 2019
  10. DrahtBot commented at 2:02 AM on May 9, 2019: member

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    No conflicts as of last run.

  11. sdaftuar commented at 1:11 AM on May 17, 2019: member

    I'm not sure what the goal here is, but I think there may be a misunderstanding -- there should be no logical difference between the failure you're changing and the one above it. Note the comment above, specifically:

             * In any case D3 will also be marked as BLOCK_FAILED_CHILD at restart
             * in LoadBlockIndex.	      
    

    So I think the code is correct as-is.

  12. zenosage commented at 4:11 PM on May 22, 2019: contributor

    Goal is debugging and understanding. I can not determine which section of code is throwing the same error. This is a design flaw I think? If there is no logical difference between this and above, then why duplicate logic?

  13. sdaftuar commented at 4:51 PM on May 22, 2019: member

    The goal of the logic you're looking at is to determine whether a new block descends from an invalid one. This is complex due to the intricacies of how block validation occurs.

    If the direct parent of a new block is known to be invalid, then that is detected immediately in this chunk of code:

    if (pindexPrev->nStatus & BLOCK_FAILED_MASK)
                return state.Invalid(ValidationInvalidReason::BLOCK_INVALID_PREV, error("%s: prev block invalid", __func__), REJECT_INVALID, "bad-prevblk");	
    

    However, as explained in the comment directly above the code you're changing, there are situations where the parent of a block may descend from some other known-invalid block, but the parent itself has not yet been validated and so is not yet marked as invalid. This code that loops through m_failed_blocks looking for an invalid ancestor is for this case. Logically, this is no different than the direct parent being invalid but not yet having been marked as such.

  14. zenosage commented at 12:09 AM on June 22, 2019: contributor

    My understanding is this: If node has continuous chain of headers A -> ... -> D -> ... -> Z so that D is invalid, all block after D will hit first case. If node does not has continuous chain of headers A and D only and D is invalid blocks after D will hit second case.

    Your logic is this: Both cases is bad previous block so treat error message and code the same. This is despite different checks.

    Do I have that correct?

  15. zenosage commented at 12:13 AM on June 22, 2019: contributor

    Is first case redundant? Just a optimization?

  16. laanwj commented at 1:38 PM on August 29, 2019: member

    Closing this PR, there's no agreement to change this, it looks more like a question.

  17. laanwj closed this on Aug 29, 2019

  18. DrahtBot locked this on Dec 16, 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-22 09:14 UTC

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