Support -checkmempool=N, which runs checks once every N transactions #6776

pull sipa wants to merge 1 commits into bitcoin:master from sipa:fraccheck changing 3 files +12 −6
  1. sipa commented at 9:40 pm on October 7, 2015: member
  2. in src/init.cpp: in 55ca7f1ac0 outdated
    836@@ -837,7 +837,10 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
    837         InitWarning(_("Warning: Unsupported argument -benchmark ignored, use -debug=bench."));
    838 
    839     // Checkmempool and checkblockindex default to true in regtest mode
    840-    mempool.setSanityCheck(GetBoolArg("-checkmempool", chainparams.DefaultConsistencyChecks()));
    841+    int ratio = std::min<int>(std::max<int>(GetArg("-checkmempool", chainparams.DefaultConsistencyChecks() ? 1 : 0), 0), 1000000);
    


    dcousens commented at 1:03 am on October 8, 2015:
    I feel like this would be clearer as two (or at least one) if conditionals.
  3. dcousens commented at 1:04 am on October 8, 2015: contributor
    What is the behaviour currently? How often does a sanity check run right now?
  4. sipa commented at 1:07 am on October 8, 2015: member

    Right now runs for every transaction if -checkmempool is specified, otherwise never.

    So the behaviour for =0 and =1 remains the same, but higher number can be used for lower test frequency.

  5. in src/txmempool.cpp: in 55ca7f1ac0 outdated
    552@@ -553,7 +553,10 @@ void CTxMemPool::clear()
    553 
    554 void CTxMemPool::check(const CCoinsViewCache *pcoins) const
    555 {
    556-    if (!fSanityCheck)
    557+    if (nCheckFrequency == 0)
    558+        return;
    559+
    560+    if (insecure_rand() >= nCheckFrequency)
    


    dcousens commented at 1:44 am on October 8, 2015:

    What is the range of insecure_rand?

    edit:2^32?


    sipa commented at 5:01 pm on October 20, 2015:
    Yes.
  6. dcousens commented at 1:45 am on October 8, 2015: contributor
    utACK
  7. in src/txmempool.h: in 55ca7f1ac0 outdated
    337@@ -338,7 +338,7 @@ class CTxMemPool
    338      * check does nothing.
    339      */
    340     void check(const CCoinsViewCache *pcoins) const;
    341-    void setSanityCheck(bool _fSanityCheck) { fSanityCheck = _fSanityCheck; }
    342+    void setSanityCheck(double dFrequency = 1.0) { nCheckFrequency = dFrequency * 4294967296.0; }
    


    jonasschnelli commented at 7:04 am on October 8, 2015:
    Not sure: but would’t it be more clean to use ULONG_MAX here? Also not sure: if using 4294967296 instead of 4294967295(= ULONG_MAX) wouldn’t this result in autocast to uint64_t?

    sipa commented at 7:06 am on October 8, 2015:
    Note the .0, making it a double constant rather than an int.

    sipa commented at 7:07 am on October 8, 2015:
    Also, ULONG_MAX gives the maximum value of an unsigned long. Here we need the number of possible values in a uint32_t. That is by definition 2^32.

    Diapolo commented at 9:00 am on October 31, 2015:
    IMHO this value should’ve taken a small comment :).
  8. jonasschnelli commented at 7:09 am on October 8, 2015: contributor

    Nice. utACK (code review).

    Travis issue is unrelated.

  9. laanwj added the label Mempool on Oct 8, 2015
  10. sdaftuar commented at 4:56 pm on October 20, 2015: member
    ACK. Looks like travis needs to be bumped?
  11. Support -checkmempool=N, which runs checks on average once every N transactions ab1f56072a
  12. sipa force-pushed on Oct 20, 2015
  13. morcos commented at 5:02 pm on October 20, 2015: member
    utACK
  14. sipa merged this on Oct 28, 2015
  15. sipa closed this on Oct 28, 2015

  16. sipa referenced this in commit e06c14fb59 on Oct 28, 2015
  17. gmaxwell commented at 2:12 am on October 28, 2015: contributor
    This has a bug: -checkmempool=1 never checks due to integer overflow in the nCheckFrequency= dFrequency*4294967296 and nCheckFrequency is uint32_t, so the result ends up 0.
  18. zkbot referenced this in commit 6d6b780969 on Feb 20, 2018
  19. zkbot referenced this in commit 49274558c6 on Feb 20, 2018
  20. furszy referenced this in commit eb00d0f62f on Jun 14, 2020
  21. 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 21:12 UTC

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