Move TestBlockValidity into a background thread #7167

pull jameshilliard wants to merge 5 commits into bitcoin:master from jameshilliard:TBVBackground changing 3 files +17 −4
  1. jameshilliard commented at 12:00 AM on December 4, 2015: contributor

    GBT now appears to return before TBV is complete.

  2. Move TestBlockValidity into a background thread 4bbaf7945b
  3. gmaxwell commented at 12:07 AM on December 4, 2015: contributor

    This doesn't crash immediately from the use after free with the CValidationstate escaping its scope?

  4. jameshilliard commented at 12:30 AM on December 4, 2015: contributor

    Didn't crash for me....odd...tests passed on OSX(which is what I tested the change on), but not other OS's should it have failed?

  5. Move CValidationState inside of validationThread 3c5b30482c
  6. jameshilliard commented at 1:03 AM on December 4, 2015: contributor

    Hmm, so it appeared to crash sometimes, hopefully this should fix it.

  7. luke-jr commented at 1:34 AM on December 4, 2015: member

    You still have a race on block.

  8. jameshilliard commented at 1:36 AM on December 4, 2015: contributor

    Yeah, I think I'm missing a lock, which lock does TBV need to be under?

  9. morcos commented at 1:43 AM on December 4, 2015: member

    So what will catch the runtime_error that is thrown if it fails? Previously the RPC code caught that and returned an JSON-RPC error, but the node kept running.

  10. replace throw with assert f0d8bbe307
  11. jameshilliard commented at 2:31 AM on December 4, 2015: contributor

    @morcos I changed it to an assert so that it should shutdown instead

  12. pstratem commented at 3:56 AM on December 4, 2015: contributor

    Please gate this on an option off by default. On Dec 3, 2015 6:31 PM, "jameshilliard" notifications@github.com wrote:

    @morcos https://github.com/morcos I changed it to an assert so that it should shutdown instead

    — Reply to this email directly or view it on GitHub #7167 (comment).

  13. jameshilliard commented at 4:03 AM on December 4, 2015: contributor

    @pstratem If it's off by default a miner could keep mining on invalid templates without realizing anything is wrong.

  14. pstratem commented at 4:08 AM on December 4, 2015: contributor

    I'm asking for background vs inline to be selectable.

    So you always call TestBlockValidity, the question just being when. On Dec 3, 2015 8:04 PM, "jameshilliard" notifications@github.com wrote:

    @pstratem https://github.com/pstratem If it's off by default a miner could keep mining on invalid templates without realizing anything is wrong.

    — Reply to this email directly or view it on GitHub #7167 (comment).

  15. Move TestBlockValidity to getblocktemplate 46eb2bc8b8
  16. jameshilliard commented at 6:36 AM on December 4, 2015: contributor

    Well I moved TBV to be inside of getblocktemplate, the only tests that seem to be failing now are the ones that expect TBV to be inside of CNB.

  17. disable tests that depend on removed std::runtime_error 48f4ceea46
  18. jameshilliard commented at 1:09 AM on December 5, 2015: contributor

    I'm thinking the easiest way to do this is to copy the block generated by CNB for the TBV thread and use a modified version of TBV that doesn't depend on the cs_main lock, is it possible to test the block well enough without the cs_main lock?

  19. sipa commented at 3:00 AM on December 5, 2015: member

    There is no way you can do TBV without cs_main, as it needs to access the UTXO set.

  20. jameshilliard commented at 3:13 AM on December 5, 2015: contributor

    @sipa does it do the check based on the current UTXO set only or is it possible for it to do the check based off a historical UTXO set? ie so the thread can be run in the background with a trylock waiting for GBT to release its lock?

  21. pstratem commented at 3:23 AM on December 5, 2015: contributor

    @jameshilliard the only way to make the test act truly in parallel would be to re-implement the utxo database as a proper mvcc database...

  22. jameshilliard commented at 3:27 AM on December 5, 2015: contributor

    @pstratem it doesn't need to be parallel so much as not block CNB/GBT

  23. sipa commented at 3:35 AM on December 5, 2015: member

    And not block with other calls to ProcessNewBlock.

  24. jameshilliard commented at 3:39 AM on December 5, 2015: contributor

    What types of failures are we worried about in regards to CNB? Would it be reasonably safe to skip checks that depend on the UTXO set?

  25. sipa commented at 3:44 AM on December 5, 2015: member

    If you skip checks based on the UTXO set, it cannot do anything. It can't do double-spend detection, script evaluation, fee/subsidy calculations, ...

  26. sipa commented at 3:48 AM on December 5, 2015: member

    The new CNB code is already intended to never ever produce an invalid block. TBV is a last-resort validation to be sure the code is working right. If you're going to skip checks, it is no longer useful; you could just as well not do any checks at all.

    So, no, you need cs_main. And you need to make sure no ProcessBlock happened in between either.

  27. jameshilliard commented at 3:50 AM on December 5, 2015: contributor

    @sipa Yeah, I wasn't sure if we are trying to protect against mempool errors or more just formatting errors.

  28. laanwj added the label Mining on Feb 16, 2016
  29. sipa commented at 6:44 AM on May 17, 2016: member

    Closing, as this is not a viable strategy.

    I think there are alternatives possible (like not running TBV for every block, or running TBV while still holding cs_main, before after returning from the RPC), but maybe it's just much less needed with the much faster 0.12 CNB?

  30. sipa closed this on May 17, 2016

  31. MarcoFalke 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: 2026-05-02 12:15 UTC

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