Detect any sufficiently long fork and alert the user just like any other alert #2658

pull TheBlueMatt wants to merge 3 commits into bitcoin:master from TheBlueMatt:forkalert changing 2 files +89 −7
  1. TheBlueMatt commented at 9:29 pm on May 16, 2013: member

    Tested with BitcoindComparisonTool (which generates a large fork) and -alertnotify script successfully notified me and I get the relevant warnings in getinfo

    You’ll get the usually cryptic error: “errors” : “Warning: Displayed transactions may not be correct! You may need to upgrade, or other nodes may need to upgrade.” and alertnotify will be called with Warning: Large-work fork detected. You may need to upgrade, or other nodes may need to upgrade.

  2. BitcoinPullTester commented at 10:05 pm on May 16, 2013: none
    Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/3457681627384baf41c7b1d809d87a52a2c94e07 for binaries and test log. This test script verifies pulls every time they are updated. It, however, dies sometimes and fails to test properly. If you are waiting on a test, please check timestamps to verify that the test.log is moving at http://jenkins.bluematt.me/pull-tester/current/ Contact BlueMatt on freenode if something looks broken.
  3. Diapolo commented at 5:59 am on May 17, 2013: none
    I think it would be nice to not just use our default cryptic message, but provide some details (not only for this new condition).
  4. mikehearn commented at 10:22 pm on May 17, 2013: contributor
    Overall looks good to me. Agree with Diapolo that the log message could be more helpful, like by including the fork block hash and stating why transactions may be incorrect.
  5. TheBlueMatt commented at 1:20 am on May 18, 2013: member
    OK, rewrote the alert messages, now you get: ‘Warning: Large-work fork detected, forking after block $HASH’ for %s in -alertnotify “CheckForkWarningConditions: Warning: Large valid fork found\n forking the chain at height %d (%s)\n lasting to height %d (%s).\n” in debug.log for large valid-work fork “CheckForkWarningConditions: Warning: Found invalid chain at least ~6 blocks longer than our best chain.\n” for the previous warning condition. and translated versions of either “Warning: We do not appear to fully agree with our peers! You may need to upgrade, or other nodes may need to upgrade.” for large, valid fork or “Warning: The network does not appear to fully agree! Some miners appear to be experiencing issues.” for the previous warning condition. in getinfo/status bar.
  6. BitcoinPullTester commented at 1:47 am on May 18, 2013: none
    Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/7c4ad5d8dffb116cbb8c2e429f19452cbb056d38 for binaries and test log. This test script verifies pulls every time they are updated. It, however, dies sometimes and fails to test properly. If you are waiting on a test, please check timestamps to verify that the test.log is moving at http://jenkins.bluematt.me/pull-tester/current/ Contact BlueMatt on freenode if something looks broken.
  7. mikehearn commented at 10:00 am on June 5, 2013: contributor
    Looks good to me.
  8. sipa commented at 7:47 pm on June 22, 2013: member

    I think this code belongs in main rather than alert (rationale: it needs access to the current chainstate, which is maintained by main - alert shouldn’t need a dependency on that).

    Code in general looks good, but needs a rebase.

    Also, I expect the most common case for a message like this to be a locally corrupted database. Maybe that is worth mentioning is the text?

  9. wtogami commented at 10:18 am on July 4, 2013: contributor
    Interesting … “CheckForkWarningConditions: Warning: Large valid fork found\n forking the chain at height” can happen with a daemon that does not fail if your database is corrupted in just the right way. Sorry I don’t have a copy of the corrupted database to demonstrate this. I can imagine this will be a false alarm for someone in the future, and it would be ideal if the daemon had a way to differentiate between database corruption and a genuine problem on the network.
  10. wtogami commented at 9:05 am on July 6, 2013: contributor
    Also note that this puts lots of needlessly scary-looking warnings in debug.log during a reindex. Perhaps it should be silent during a reindex if prior to the last checkpoint?
  11. luke-jr commented at 4:14 am on July 17, 2013: member
    @TheBlueMatt Rebase needed.
  12. TheBlueMatt commented at 9:45 am on July 22, 2013: member
    @wtogami Hmm…I dont see any fork messages during -reindex, are you talking about a -reindex on a corrupted chainstate?
  13. Detect any sufficiently long fork and add a warning.
    Such a fork is defined as being at least 7 blocks long and
    having a tip which is within 72 blocks of our best block.
    b8585384da
  14. Call the -alertnotify script when we see a long or invalid fork. f89faa2584
  15. Better warning/"alert" messages for large-work forks. f65e7092a2
  16. TheBlueMatt commented at 10:14 am on July 22, 2013: member
    Rebased, moved code to main.cpp, because its not like that file isnt already too full.
  17. BitcoinPullTester commented at 0:59 am on July 23, 2013: none
    Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/f65e7092a200ee6e9453058c3dafbab62d9b4dcc for binaries and test log. This test script verifies pulls every time they are updated. It, however, dies sometimes and fails to test properly. If you are waiting on a test, please check timestamps to verify that the test.log is moving at http://jenkins.bluematt.me/pull-tester/current/ Contact BlueMatt on freenode if something looks broken.
  18. in src/main.cpp: in f65e7092a2
    1440+            break;
    1441+        pfork = pfork->pprev;
    1442+    }
    1443+
    1444+    // We define a condition which we should warn the user about as a fork of at least 7 blocks
    1445+    // who's tip is within 72 blocks (+/- 12 hours if no one mines it) of ours
    


    mikehearn commented at 6:25 pm on July 23, 2013:
    whose
  19. mikehearn commented at 6:26 pm on July 23, 2013: contributor
    LGTM. Can we merge this now?
  20. wtogami commented at 5:59 am on July 24, 2013: contributor
    Is the patch intended to warn about forks during the -reindex process where it is unnecessarily scary? Can it be somehow silent about forks until after the last checkpoint?
  21. gmaxwell commented at 6:21 am on July 24, 2013: contributor
    Please do not further overload checkpoints. … but yea, warning during reindex is obviously not good. :)
  22. luke-jr commented at 6:30 am on July 24, 2013: member
    Probably a condition of this should be “at least one block in the fork must have been rejected by us”?
  23. gavinandresen commented at 6:18 am on July 25, 2013: contributor

    RE: warning during reindex: suppressing the alert if best-other-tip-time is more than a day (a week? or maybe if max(other-tip-time, best-tip-time) is…) in the past is probably the right thing to do: reasoning would be we don’t care about old fork events that have long-since been resolved.

    But before implementing that, can we get a block index that demonstrates false positives during a reindex? (I’ve got a corrupt chain that I’ll copy and then reindex if somebody else doesn’t beat me to it).

  24. wtogami commented at 7:20 am on July 25, 2013: contributor

    I removed these three patches from litecoin-0.8.x not because it was broken, but from concern that it would unnecessarily scare people with false positives that appeared to me during a normal reindex. Although I am not entirely certain it was the type of false positive you are asking for. I didn’t investigate too hard as it seemed best to simply remove the patches for the upcoming release meant to minimize risk.

    https://github.com/litecoin-project/litecoin/commits/exp-mark11b litecoin-0.8.3.6 is comprised of a merge of the following two branches https://github.com/litecoin-project/litecoin/commits/exp-mark11 litecoin specific commits on top of bitcoin-0.8.3 https://github.com/litecoin-project/litecoin/commits/exp-btc09backports Select bitcoin-0.9 cherry-picks applied on top of bitcoin-0.8.3

    https://github.com/litecoin-project/litecoin/commit/286c31b45450eee0817de1ab7704c0911965eeb9 https://github.com/litecoin-project/litecoin/commit/76cf1ab0802677a000aad8188667f1f3345baf24 https://github.com/litecoin-project/litecoin/commit/e751fad2f78bcef601a601cc755809e98c7f0821 Add these back to litecoin-0.8.3.6 and -reindex to see noisy warnings.

  25. wtogami commented at 9:52 am on August 9, 2013: contributor

    https://github.com/litecoin-project/litecoin/tree/exp-forkalert FYI: I tested it yesterday after re-applying the three patches above (an older version of this PR that applied cleanly to bitcoin-0.8.3, prior to the recent rebase). A fresh Litecoin blockchain sync and a subsequent -reindex both were uneventful.

    A month ago I saw loud and scary warnings during -reindex twice in a row. I don’t know what is different now. Would a fresh sync with additional checkpoints result in a different local blockchain sans historic forks? Whatever the issue, I am unable to reproduce it with this freshly synced chain now.

    #2658 (comment) A month ago I had a corrupted database that exhibited a great many errors in the log but did not crash. sipa’s post immediately before it said, “Also, I expect the most common case for a message like this to be a locally corrupted database. Maybe that is worth mentioning is the text?”

    Was his question addressed?

  26. gavinandresen commented at 6:33 am on August 13, 2013: contributor
    ACK. I re-indexed an old chain that has lots of forks and got no scary warnings.
  27. gavinandresen referenced this in commit 8fa9b5cc45 on Aug 13, 2013
  28. gavinandresen merged this on Aug 13, 2013
  29. gavinandresen closed this on Aug 13, 2013

  30. mikehearn commented at 9:01 am on August 13, 2013: contributor
    I updated BIP50 with the fact that this is done. Great work Matt!
  31. 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-23 21:12 UTC

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