Remove GetSpendHeight #23630

pull MarcoFalke wants to merge 1 commits into bitcoin:master from MarcoFalke:2111-noSpendHeight changing 2 files +4 −16
  1. MarcoFalke commented at 3:42 pm on November 29, 2021: member

    It is unclear what the goal of the helper is, as the caller already knows the spend height before calling the helper.

    Also, in case the coins view is corrupted, LookupBlockIndex will return nullptr. Dereferencing a nullptr is UB.

    Fix both issues by removing it. Also, add a sanity check, which aborts if the coins view is corrupted.

  2. laanwj added the label Mempool on Nov 29, 2021
  3. darosior commented at 11:31 am on November 30, 2021: member
    ACK fa6a0f9a7c00015e70c9805faf45685ac300f61e
  4. in src/validation.cpp:737 in fa6a0f9a7c outdated
    719@@ -718,7 +720,7 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
    720     if (!CheckSequenceLocks(m_active_chainstate.m_chain.Tip(), m_view, tx, STANDARD_LOCKTIME_VERIFY_FLAGS, &lp))
    721         return state.Invalid(TxValidationResult::TX_PREMATURE_SPEND, "non-BIP68-final");
    722 
    723-    if (!Consensus::CheckTxInputs(tx, state, m_view, m_active_chainstate.m_blockman.GetSpendHeight(m_view), ws.m_base_fees)) {
    724+    if (!Consensus::CheckTxInputs(tx, state, m_view, m_active_chainstate.m_chain.Height() + 1, ws.m_base_fees)) {
    


    laanwj commented at 9:47 am on December 2, 2021:
    Maybe move/adapt the comment about the spend height for checking being one more than the current best block height here?

    MarcoFalke commented at 3:00 pm on December 2, 2021:
    thx, done
  5. Remove GetSpendHeight
    It is unclear what the goal of the helper is, as the caller already
    knows the spend height before calling the helper.
    
    Also, in case the coins view is corrupted, LookupBlockIndex will return
    nullptr. Dereferencing a nullptr is UB.
    
    Fix both issues by removing it. Also, add a sanity check, which aborts
    if the coins view is corrupted.
    fa3942fc4c
  6. MarcoFalke force-pushed on Dec 2, 2021
  7. laanwj commented at 7:54 pm on December 2, 2021: member
    Code review ACK fa3942fc4c66d7624bd3578d1e7f4a6a7721c11a
  8. jamesob commented at 9:17 pm on December 2, 2021: member

    I’m pretty sure I’m ACK on this, but just to be sure (and as a helpful reminder):

    • what are the cases where coins_view.GetBestBlock() differs from chaintip? Is that only on startup when we’re recovering from a crash that happened before we could write the coins down to disk?
    • do we have any reason to believe this (BestBlock != tip) could happen during mempool acceptance, or is there some kind of explicit guard against that?
  9. ryanofsky approved
  10. ryanofsky commented at 10:02 pm on December 2, 2021: member

    Code review ACK fa3942fc4c66d7624bd3578d1e7f4a6a7721c11a. I’m not aware of cases where coins GetBestBlock could be different from active chain tip, and asset seems sufficient to guarantee PR doesn’t change behavior if that doesn’t happen.

    Removing GetSpendHeight was also discussed in #21055 (review)

  11. DrahtBot commented at 4:50 am on December 3, 2021: member

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

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #23581 (Move BlockManager to node/blockstorage by MarcoFalke)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  12. MarcoFalke commented at 8:46 am on December 3, 2021: member

    do we have any reason to believe this (BestBlock != tip) could happen during mempool acceptance, or is there some kind of explicit guard against that?

    I’ve added the assert in this commit, if that is what you mean with guard?

  13. MarcoFalke commented at 9:10 am on December 3, 2021: member
    To clarify on master, if the assumption didn’t hold we’d silently run out of consensus (potentially via UB). With this patch the node will crash.
  14. fanquake merged this on Dec 3, 2021
  15. fanquake closed this on Dec 3, 2021

  16. MarcoFalke deleted the branch on Dec 3, 2021
  17. jamesob commented at 3:07 pm on December 3, 2021: member

    Post-merge ACK https://github.com/bitcoin/bitcoin/pull/23630/commits/fa3942fc4c66d7624bd3578d1e7f4a6a7721c11a

    I was a little unclear on how this change might interact with reorgs, but I verified that the coins view’s BestBlock is updated lock-step with the tip in DisconnectBlock(). It seems there is a brief period during ReplayBlocks() during which it isn’t clear to me that the two are lockstep (https://github.com/jamesob/bitcoin/blob/785f9cc46a43661c63a5ec56a9e82f4ce9d42f44/src/validation.cpp#L4277-L4287), but of course ReplayBlocks() is called in init before the chainstate is fully initialized.

    Otherwise (based on a grep of SetBestBlock()), the best block should be fully in sync with the tip.

  18. sidhujag referenced this in commit f7d9c4f58c on Dec 3, 2021
  19. pg156 commented at 3:31 am on December 4, 2021: none

    Otherwise (based on a grep of SetBestBlock()), the best block should be fully in sync with the tip.

    Could you elaborate on this for my learning? It is not obvious to me why this is the case from the grep result. Thank you.

  20. MarcoFalke referenced this in commit dca9ab48b8 on Dec 6, 2021
  21. RandyMcMillan referenced this in commit beb5236dd0 on Dec 23, 2021
  22. Fabcien referenced this in commit 150344e02b on Nov 10, 2022
  23. DrahtBot locked this on Dec 4, 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: 2024-11-21 15:12 UTC

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