MOVEONLY: Consensus: Move most of consensus functions (pre-block) #6051

pull jtimon wants to merge 1 commits into bitcoin:master from jtimon:consensus_moveonly changing 8 files +404 −341
  1. jtimon commented at 11:12 pm on April 22, 2015: contributor

    Dependencies:

    • MOVEONLY: Move constants to consensus.h #5696
    • Separate CValidationState from main #5669
    • Consensus: Refactor: Separate CheckFinalTx from main::IsFinalTx #6063
    • Consensus: Decouple ContextualCheckBlockHeader from checkpoints #5975
    • Separate Consensus::CheckTxInputs and GetSpendHeight in CheckInputs #6061

    I’m sorry for killing commit ids and creating new PRs so easily around this, but I really needed to explore different ways serializing/parallelizing this. And my conlusion is that everything gets more readable if we do the moveonly first, it is specially important for libconsensus API proposals and how could they potentially change bitcoin core’s storage more readable. Since Script is already exposed, I think the remaining types to be verified by libconsensus are: Transaction, BlockHeader and Block.

    For each one of them we will want to expose a full verification function. Additionally, we may want to expose checks in phases, for example, in the way that is already separated in bitcoin core, mostly to prevent DoS attacks and to put policy checks in between (ie: context-less checks before storage-dependent checks, expensive script validation the last thing, etc). I don’t think the intermediary checks will generate a lot of discussion, since if we can reach the full validation version for each of the types with proper C APIs, exposing any subset of the checks will probably be easy. So I will focus on the full validation functions for now and calling them VerifyTx, VerifyHeader and VerifyBlock respectively.

    But this is not moving everything necessary for libconsensus. Before it is possible for libconsensus to expose full block verification, it has to be able to verify block headers and transactions independently. So we know VerifyBlock comes after VerifyTx and VerifyHeader, but we don’t know whether VerifyTx or VerifyHeader will be ready first. Because they depend on discussions about CCoinsViewCache and CBlockIndex respectively about how to expose its storage, which may require or fit well with structural changes in how bitcoin core stores them, for example, if UTXO commitments are going to be softforked in some way, the API for VerifyTx should be forward compatible with that, which may delay its exposure.

    And because we don’t want to unnecessarily make libbitcoin bigger unless something more it’s going to be exposed, I thought that having two cpp files could be useful, I named them txverify.cpp and blockverify.cpp but it’s open to bikesheding. The point is that when one is ready you can add it to libconsensus while leaving the other in the server building module.

    Once they’re both ready, a last moveonly commit after this one will be required to expose a C API for full block rule validation, that new code can go in blockverify.cpp

    The intention of moving all the function declarations that we know we will need (for example, main::CheckBlock) without moving the actual code to a cpp in the same commit is to minimize the number of include restructuring commits, they can all be done right after this PR. Alternatively the block declarations can be delayed, but I believe that it’s worth it to move all transaction and header declarations in the same commmit since it doesn’t take that much to move it all fast (see the non-moveonly commits in this PR, they’re quite trivial).

  2. jtimon commented at 0:55 am on April 23, 2015: contributor
    Closing until #5696 is resolved
  3. jtimon closed this on Apr 23, 2015

  4. jtimon reopened this on Apr 23, 2015

  5. jtimon force-pushed on Apr 23, 2015
  6. jtimon force-pushed on Apr 24, 2015
  7. jtimon force-pushed on Apr 26, 2015
  8. jtimon force-pushed on Apr 26, 2015
  9. laanwj commented at 2:07 pm on April 30, 2015: member
    Are you sure GetBlockProof is not part of consensus? e.g. it’s used in AddToBlockIndex to determine the total amount of work on a chain. It’s the only function left in pow.h which is kind of unfortunate.
  10. jtimon commented at 4:17 pm on April 30, 2015: contributor
    The highest level function I’m contemplating would be VerifyBlock and that’s not necessary for it. It’s certainly not necessary for VerifyHeader. That’s used to chose the longest chain, so it’s seems more part of the index than validation rules. Maybe in the future we can expose that too somehow, but one step at a tine…
  11. laanwj commented at 12:50 pm on May 1, 2015: member
    But nChainWork (computed using GetBlockProof) is used in e.g. ActivateBestChain(Step), which choose the best chain. @theuni what’s your opinion here?
  12. sipa commented at 12:53 pm on May 1, 2015: member

    Depends on whether we define consensus as (conceptually) a black box that just says whether a particular chain is valid or not, or whether we include the mechanism for determining which of possible valid chains as well.

    I don’t really have an opinion here, apart from that I think separating these two concerns in the code makes sense - whether we expose that in libconsensus or not.

  13. laanwj commented at 12:59 pm on May 1, 2015: member
    Ok fair enough. But I do think this destroys the purpose of pow.cpp/pow.h. The goal was to have the proof-of-work functions in one place. Now one function is left in that file…
  14. jtimon commented at 7:43 am on May 2, 2015: contributor
    well yes, my plan was to destroy pow and move the remaining function to chain.o, but zince there’s more stuff being created there…
  15. laanwj added the label Improvement on May 6, 2015
  16. jtimon force-pushed on May 6, 2015
  17. jtimon force-pushed on May 10, 2015
  18. ghost commented at 6:18 pm on May 10, 2015: none

    Built and ran tests ACK

    edit: happy to do more, but I wasn’t sure where to begin testing this, aside from writing my own tests

  19. jtimon force-pushed on May 15, 2015
  20. jtimon commented at 2:13 pm on May 15, 2015: contributor
    Rebased
  21. jtimon force-pushed on May 15, 2015
  22. jtimon force-pushed on May 17, 2015
  23. jtimon force-pushed on May 27, 2015
  24. jtimon commented at 2:29 pm on May 27, 2015: contributor
    Rebased with one less dependency (2 commits less).
  25. jtimon force-pushed on Jun 2, 2015
  26. jtimon commented at 11:18 am on June 2, 2015: contributor
    Rebased again. Only 2 PR dependencies to go, ping #5975 and #6061.
  27. jtimon force-pushed on Jun 4, 2015
  28. jtimon commented at 7:21 pm on June 4, 2015: contributor
    Needed rebase
  29. jtimon force-pushed on Jun 10, 2015
  30. jtimon renamed this:
    DEPENDENT: MOVEONLY: Move most of consensus functions (pre-block)
    MOVEONLY: Move most of consensus functions (pre-block)
    on Jun 10, 2015
  31. jtimon force-pushed on Jun 10, 2015
  32. jtimon commented at 4:19 pm on June 10, 2015: contributor
    Rebased. All PR dependencies merged or replaced with equivalent commits. Now this is purely move only.
  33. jtimon force-pushed on Jun 12, 2015
  34. jtimon commented at 9:17 am on June 12, 2015: contributor
    Squashed the 2 moveonly commits.
  35. theuni commented at 11:20 pm on June 17, 2015: member

    Confirmed move-only with the exception of

    0-    set<COutPoint> vInOutPoints;
    1+    std::set<COutPoint> vInOutPoints;
    

    which is obviously fine.

    I didn’t bother checking includes and function prototypes though.

  36. jtimon renamed this:
    MOVEONLY: Move most of consensus functions (pre-block)
    Consensus: MOVEONLY: Move most of consensus functions (pre-block)
    on Jun 25, 2015
  37. jtimon renamed this:
    Consensus: MOVEONLY: Move most of consensus functions (pre-block)
    MOVEONLY: Consensus: Move most of consensus functions (pre-block)
    on Jun 26, 2015
  38. jtimon force-pushed on Jul 6, 2015
  39. jtimon commented at 10:52 pm on July 6, 2015: contributor
    Rebased
  40. MOVEONLY: Move some consensus functions to consensus/consensus.h
    Functions definitions are moved to 2 independent files:
    
    To consensus/txverify.cpp:
    
    from main.cpp:
    -CheckTransaction
    -Consensus::CheckTxInputs
    -GetLegacySigOpCount
    -GetP2SHSigOpCount
    -IsFinalTx
    
    To consensus/blockverify.cpp
    
    from main.cpp:
    -CheckBlockHeader
    -ContextualCheckBlockHeader
    -IsSuperMajority
    
    from pow.cpp:
    -CalculateNextWorkRequired
    -CheckProofOfWork
    -GetNextWorkRequired
    a45e8253f5
  41. jtimon force-pushed on Jul 7, 2015
  42. jtimon commented at 11:16 am on July 12, 2015: contributor

    I’m having second thoughts about txverify.cpp + blockverify.cpp vs policy.cpp. If we don’t care about exposing verifyTx or verifyHeader before verifyBlock is ready, then we can just have policy.cpp and we can move more things at the same time (CheckBlock, ContextualCheckBlock and GetBlockSubsidy, for example).

    Do we care about being able to expose VerifyTx without being prepared to also expose VerifyHeader and VerifyBlock? Do we care about being able to expose VerifyHeader without being prepared to also expose VerifyTx and VerifyBlock?

    Thoughts?

  43. jtimon commented at 11:56 pm on July 15, 2015: contributor
    Closing for now.
  44. jtimon closed this on Jul 15, 2015

  45. 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-11-17 09:12 UTC

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