Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Aug 13, 2013

Conversation

TheBlueMatt
Copy link
Contributor

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.

@BitcoinPullTester
Copy link

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.

@Diapolo
Copy link

Diapolo commented May 17, 2013

I think it would be nice to not just use our default cryptic message, but provide some details (not only for this new condition).

@mikehearn
Copy link
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.

@TheBlueMatt
Copy link
Contributor Author

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.

@BitcoinPullTester
Copy link

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.

@mikehearn
Copy link
Contributor

Looks good to me.

@sipa
Copy link
Member

sipa commented Jun 22, 2013

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?

@wtogami
Copy link
Contributor

wtogami commented Jul 4, 2013

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.

@wtogami
Copy link
Contributor

wtogami commented Jul 6, 2013

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?

@luke-jr
Copy link
Member

luke-jr commented Jul 17, 2013

@TheBlueMatt Rebase needed.

@TheBlueMatt
Copy link
Contributor Author

@wtogami Hmm...I dont see any fork messages during -reindex, are you talking about a -reindex on a corrupted chainstate?

@TheBlueMatt
Copy link
Contributor Author

Rebased, moved code to main.cpp, because its not like that file isnt already too full.

@BitcoinPullTester
Copy link

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.

}

// We define a condition which we should warn the user about as a fork of at least 7 blocks
// who's tip is within 72 blocks (+/- 12 hours if no one mines it) of ours
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whose

@mikehearn
Copy link
Contributor

LGTM. Can we merge this now?

@wtogami
Copy link
Contributor

wtogami commented Jul 24, 2013

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?

@gmaxwell
Copy link
Contributor

Please do not further overload checkpoints. ... but yea, warning during reindex is obviously not good. :)

@luke-jr
Copy link
Member

luke-jr commented Jul 24, 2013

Probably a condition of this should be "at least one block in the fork must have been rejected by us"?

@gavinandresen
Copy link
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).

@wtogami
Copy link
Contributor

wtogami commented Jul 25, 2013

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

litecoin-project@286c31b
litecoin-project@76cf1ab
litecoin-project@e751fad
Add these back to litecoin-0.8.3.6 and -reindex to see noisy warnings.

@wtogami
Copy link
Contributor

wtogami commented Aug 9, 2013

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?

@gavinandresen
Copy link
Contributor

ACK. I re-indexed an old chain that has lots of forks and got no scary warnings.

gavinandresen added a commit that referenced this pull request Aug 13, 2013
Detect any sufficiently long fork and alert the user just like any other alert
@gavinandresen gavinandresen merged commit 8fa9b5c into bitcoin:master Aug 13, 2013
@mikehearn
Copy link
Contributor

I updated BIP50 with the fact that this is done. Great work Matt!

@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants