Give a better error message if system clock is bad #6489

pull casey wants to merge 1 commits into bitcoin:master from casey:bad-system-time-fix changing 1 files +12 −0
  1. casey commented at 9:49 PM on July 28, 2015: contributor

    Fixes #2007

    This checks to see if the system clock appears to be bad and gives a helpful error message. If the user's clock is set incorrectly, hopefully they'll abort, fix it, and then save themselves a fruitless resync.

    I wasn't sure if I needed to grab cs_main before accessing chainActive.Tip(), is that correct?

  2. sipa commented at 10:08 PM on July 28, 2015: member

    You do need cs_main for that.

  3. in src/init.cpp:None in 1498f60bf1 outdated
    1224 | @@ -1225,6 +1225,19 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
    1225 |                      LogPrintf("Prune: pruned datadir may not have more than %d blocks; -checkblocks=%d may fail\n",
    1226 |                          MIN_BLOCKS_TO_KEEP, GetArg("-checkblocks", 288));
    1227 |                  }
    1228 | +
    1229 | +                {
    1230 | +                    LOCK(cs_main);
    1231 | +                    CBlockIndex* tip = chainActive.Tip();
    1232 | +                    CBlock block;
    1233 | +                    if (tip && ReadBlockFromDisk(block, tip)) {
    


    laanwj commented at 6:23 AM on July 29, 2015:

    Any specific reason to read the block from disk here? Reminder: tip itself, a CBlockIndex, also has nTime


    casey commented at 3:42 PM on July 29, 2015:

    Ahh, okay. Fixed.

  4. laanwj commented at 6:23 AM on July 29, 2015: member

    Concept ACK

  5. laanwj added the label UTXO Db and Indexes on Jul 29, 2015
  6. casey commented at 3:48 PM on July 29, 2015: contributor

    Updated the commit to use chainActive.Tip()->nTime directly

  7. in src/init.cpp:None in ebe2f98605 outdated
    1224 | @@ -1225,6 +1225,16 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
    1225 |                      LogPrintf("Prune: pruned datadir may not have more than %d blocks; -checkblocks=%d may fail\n",
    1226 |                          MIN_BLOCKS_TO_KEEP, GetArg("-checkblocks", 288));
    1227 |                  }
    1228 | +
    1229 | +                {
    1230 | +                    LOCK(cs_main);
    1231 | +                    CBlockIndex* tip = chainActive.Tip();
    1232 | +                    if (tip && tip->nTime > GetAdjustedTime() + 2 * 60 * 60) {
    1233 | +                        strLoadError = _("The block database contains a block which appears to be from the future. This may be due to your computer's date and time being set incorrectly. Only rebuild the block database if you are sure that your computer's date and time are correct");
    


    bensussman commented at 3:08 PM on July 30, 2015:

    Is there no styleguide for the bitcoin codebase that says ">250 character lines are just TOO LONG @casey"?!


    casey commented at 3:33 PM on July 30, 2015:

    This string is going to be translated via gettext (that's what the "_" is for) so it's better than it appear in the source as one line, as opposed to being broken up.


    laanwj commented at 6:53 AM on July 31, 2015:

    @bensussman To answer your question: no, there is no such rule. See https://github.com/bitcoin/bitcoin/blob/master/doc/developer-notes.md @casey Using multiple "line" "line2" line3" does not affect translation IIRC if you specify only one _, eg:

    strLoadError = _("The block database contains a block which appears to be from the future. "
        "This may be due to your computer's date and time being set incorrectly. "
        "Only rebuild the block database if you are sure that your computer's date and time are correct");
    
  8. Give a better error message if system clock is bad
    Fixes #2007
    
    This checks to see if the system clock appears to be bad and gives a
    helpful error message. If the user's clock is set incorrectly, hopefully
    they'll abort, fix it, and then save themselves a fruitless resync.
    f261f19b4b
  9. casey commented at 7:13 PM on August 3, 2015: contributor

    Changed to use less ridiculously long strings.

  10. laanwj commented at 7:49 PM on August 3, 2015: member

    utACK

  11. sipa commented at 8:10 PM on August 3, 2015: member

    utACK

  12. fanquake commented at 12:03 AM on August 4, 2015: member

    utACK

    On Tuesday, August 4, 2015, Pieter Wuille notifications@github.com wrote:

    utACK

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

  13. laanwj merged this on Aug 5, 2015
  14. laanwj closed this on Aug 5, 2015

  15. laanwj referenced this in commit c9c017adf6 on Aug 5, 2015
  16. in src/init.cpp:None in f261f19b4b
    1229 | +                {
    1230 | +                    LOCK(cs_main);
    1231 | +                    CBlockIndex* tip = chainActive.Tip();
    1232 | +                    if (tip && tip->nTime > GetAdjustedTime() + 2 * 60 * 60) {
    1233 | +                        strLoadError = _("The block database contains a block which appears to be from the future. "
    1234 | +                                "This may be due to your computer's date and time being set incorrectly. "
    


    Diapolo commented at 9:01 AM on August 5, 2015:

    computer's is some weird grammar, no?


    unknown commented at 12:57 PM on August 5, 2015:

    Not really. It indicates that the computer is the owner of the date & time, which in this case it is.

  17. zkbot referenced this in commit f1aeaec471 on Mar 21, 2018
  18. zkbot referenced this in commit 4fc490c430 on Dec 4, 2019
  19. zkbot referenced this in commit 868c63f92d on Dec 4, 2019
  20. 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-04-18 09:15 UTC

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