doc: Better explain GetAncestor check for m_failed_blocks in AcceptBlockHeader #13930

pull Sjors wants to merge 1 commits into bitcoin:master from Sjors:2018/08/validation-chainsplain changing 1 files +23 −3
  1. Sjors commented at 7:11 pm on August 9, 2018: member

    Salvaged (but slightly modified) from #12138, the comment there was really helpful to wrap my head around that part of the code.

    In addition, a naive reader like yours truly will first think IsValid(BLOCK_VALID_SCRIPTS) means the previous block was invalid. But IIUC that’s not what it means. Instead, it means the block hasn’t been checked for validity at the BLOCK_VALID_SCRIPTS level yet. So in that case the existing text “previous block index isn’t valid” is wrong.

  2. Sjors force-pushed on Aug 9, 2018
  3. Sjors commented at 7:24 pm on August 9, 2018: member
  4. fanquake added the label Docs on Aug 10, 2018
  5. fanquake added the label Validation on Aug 10, 2018
  6. in src/validation.cpp:3400 in e99f3d9b0c outdated
    3399+         *    \
    3400+         *      B1 - C1 - D1 - E1
    3401+         *
    3402+         * In the case that we attempted to reorg from E1 to F2, only to find
    3403+         * C2 to be invalid, we would mark D2, E2, and F2 as BLOCK_FAILED_CHILD
    3404+         * but NOT D3 (it was not in any of our candidate sets at the time).
    


    jamesob commented at 3:47 pm on August 10, 2018:
    Is this true because ConnectTip was never called on D3, meaning it was never added to m_failed_blocks by way of InvalidBlockFound? If that is the case, it may be worth making a more detailed note of that on this line; took me a few minutes of digging in the code to evaluate this claim.
  7. jamesob commented at 3:47 pm on August 10, 2018: member
  8. Sjors commented at 4:53 pm on August 10, 2018: member

    Responding here, so it doesn’t disappear when I rebase. @jamesob wrote:

    Is this true because ConnectTip was never called on D3, meaning it was never added to m_failed_blocks by way of InvalidBlockFound? If that is the case, it may be worth making a more detailed note of that on this line; took me a few minutes of digging in the code to evaluate this claim.

    That’s how I understand it, and it also took me a few reads :-)

    We add stuff to m_failed_blocks here:

    In both case that’s only the block itself, so C2, children aren’t touched. Presumably they just remain BLOCK_VALID_TREE.

    The only two other places where BLOCK_FAILED_CHILD is set are LoadBlockIndex (only called at launch) and FindMostWorkChain, which only traverses from the candidate block down to the bad block via ->pprev.

    If we learned about D3 after E1 was connected, it has less work than E1 - assuming equal difficulty - and therefore we would not have tried to connect it. Then when F2 comes in it does have more work, so now we try to connect it, which is when we find out C2 is invalid. So then we mark F2…C2 invalid, still ignoring D3.

    I think we should use the block height as the number in this chart, to emphasize relative difficulty

  9. sdaftuar commented at 5:30 pm on August 10, 2018: member

    utACK, thanks for improving this comment.

    If you want to explain things even further, you could note that the reason we bypass this logic when pindexPrev has been validated up to BLOCK_VALID_SCRIPTS is just a performance optimization, so that in the common case of adding a new block to the tip, we don’t have to iterate over the failed blocks list.

    Also to be totally pedantic, while D3 won’t be marked BLOCK_FAILED_CHILD since we never tried to connect it, it should be marked as such the next time we restart bitcoind (in LoadBlockIndex).

  10. Explain GetAncestor check for m_failed_blocks in AcceptBlockHeader 66e15e8f97
  11. Sjors force-pushed on Sep 4, 2018
  12. Sjors commented at 8:51 am on September 4, 2018: member
    Expanded the comment to take the above into account.
  13. TheBlueMatt commented at 5:41 pm on November 30, 2018: member
    ACK
  14. MarcoFalke renamed this:
    Better explain GetAncestor check for m_failed_blocks in AcceptBlockHeader
    doc: Better explain GetAncestor check for m_failed_blocks in AcceptBlockHeader
    on Dec 22, 2018
  15. MarcoFalke merged this on Dec 22, 2018
  16. MarcoFalke closed this on Dec 22, 2018

  17. MarcoFalke referenced this in commit e2dfeb0146 on Dec 22, 2018
  18. Sjors deleted the branch on Dec 23, 2018
  19. PastaPastaPasta referenced this in commit 021fb4905d on Jun 27, 2021
  20. PastaPastaPasta referenced this in commit bb34e9d287 on Jun 28, 2021
  21. PastaPastaPasta referenced this in commit a47278fbdd on Jun 29, 2021
  22. PastaPastaPasta referenced this in commit 42776d0db8 on Jul 1, 2021
  23. PastaPastaPasta referenced this in commit 045e9c87ce on Jul 1, 2021
  24. PastaPastaPasta referenced this in commit 28ff288386 on Jul 1, 2021
  25. UdjinM6 referenced this in commit 7c634146e0 on Jul 5, 2021
  26. PastaPastaPasta referenced this in commit 9e6c0d0524 on Jul 8, 2021
  27. DrahtBot 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: 2024-12-18 15:12 UTC

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