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

Make logging for validation optional #6519

Merged
merged 6 commits into from Aug 11, 2015

Conversation

laanwj
Copy link
Member

@laanwj laanwj commented Aug 5, 2015

Avoid ERROR messages like ERROR: AcceptToMemoryPool : non-final. Logging of incoming transaction validation failures can be enabled optionally with-debug=mempoolrej.

Also introduces a consistent format for transaction validation failures that always includes the txid.

2015-08-05 13:25:26 txfail 4e5014c4084aab04aac280e4dc6e26ffbc76ea0feb817b98a1a67d8b18d4e80b: AcceptToMemoryPool: inputs already spent

I have opted for this approach instead of the one outlined in #5794 to remove all messages, because they provide extra troubleshooting information.

Fixes #5794.

@sipa
Copy link
Member

sipa commented Aug 5, 2015

Hmm, have you considered to not print the error immediately, but only report through ValidationState, and then have ProcessMessage choose (optionally) to report the error string it, if any?

That's also more compatible with future modularization of the consensus code, where you want to do the actual logging externally.

@laanwj
Copy link
Member Author

laanwj commented Aug 5, 2015

Yes let's do that...

Add a field `strDebugMessage` which can be passed to DoS or Invalid,
and queried using GetDebugMessage() to add extra troubleshooting
information to the validation state.
@laanwj laanwj force-pushed the 2015_08_validation_error_spam branch from 72a3bb7 to 0cbeb26 Compare August 6, 2015 08:07
@laanwj
Copy link
Member Author

laanwj commented Aug 6, 2015

Done. CValidationState is augmented with optional debug information, which is logged upstream where possible.

This makes the change larger than originally intended, but the end result is better.
See commit messages/details for more information.

N.B.: I've also removed the logging in CScriptCheck::operator()(). This is consistent but I'm uncertain about this, because this means that the script error is no longer logged in case of verification through CCheckQueue (so in the case of blocks). However it is logged when called directly from CheckInputs (https://github.com/bitcoin/bitcoin/blob/master/src/main.cpp#L1394).

{
return strprintf("%s%s (code %i)",
state.GetRejectReason(),
state.GetDebugMessage().empty() ? "" : (", "+state.GetDebugMessage()),
Copy link
Member

Choose a reason for hiding this comment

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

No closing bracket?

Copy link
Member Author

Choose a reason for hiding this comment

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

The bracket is not in the string.

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed the parenthesis around ", "+... - they made the code harder to read instead of easier.

@sipa
Copy link
Member

sipa commented Aug 6, 2015

@laanwj That's not very consistent, as I think that means it will be printed with -par=1 and not with other values. I don't know of a better solution, though.

@laanwj
Copy link
Member Author

laanwj commented Aug 6, 2015

@sipa So we just call par=1 mode 'safe mode with debugging'. Voila.

@sipa
Copy link
Member

sipa commented Aug 6, 2015

Untested ACK (but see nit about closing bracket).

@laanwj laanwj force-pushed the 2015_08_validation_error_spam branch from 0cbeb26 to 72f7864 Compare August 6, 2015 10:12
@dexX7
Copy link
Contributor

dexX7 commented Aug 7, 2015

Also introduces a consistent format for transaction validation failures that always includes the txid.

Great PR, I'm running it for some hours, and this is really useful!

* for transactions, to signal internal conditions. They cannot and should not
* be sent over the P2P network.
*/
static const unsigned int REJECT_INTERNAL = 0x100;
/** local "reject" message codes for RPC which can not be triggered by p2p trasactions */
Copy link
Member

Choose a reason for hiding this comment

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

This comment isn't accurate is it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Correct. This comment only holds for HIGHFEE.

@morcos
Copy link
Member

morcos commented Aug 10, 2015

I really like this idea, there are going to be a whole slew of new possible reject reasons with 6470 and with limited mempool chains. It will be nice to be able to output them in debugging situations.

@dcousens
Copy link
Contributor

concept ACK

@skarra
Copy link

skarra commented Aug 11, 2015

👍

Add status codes specific to AcceptToMempool procession of transactions.
These can never happen due to block validation, and must never be sent
over the P2P network. Add assertions where appropriate.
It is necessary to be able to concisely log a validation state.
Convert CValidationState to a human-readable message for logging.
Remove unnecessary direct logging in CheckTransaction,
AcceptToMemoryPool, CheckTxInputs, CScriptCheck::operator()

All status information should be returned in the CValidationState.
Relevant debug information is also added to the CValidationState using
the recently introduced debug message.

Do keep the "BUG! PLEASE REPORT THIS! ConnectInputs failed against MANDATORY but not STANDARD flags"
error as it is meant to appear as bug in the log.
Add detailed state information to the errors, as it is no longer being
logged downstream.

Also add the state information to mempool rejection debug message in
ProcessMessages.
Move mempool rejections to debug category `mempoolrej`, to make it possible
to show them without enabling the entire category `mempool` which is
high volume.
@laanwj laanwj force-pushed the 2015_08_validation_error_spam branch from 72f7864 to 7f1f8f5 Compare August 11, 2015 15:30
@laanwj laanwj merged commit 7f1f8f5 into bitcoin:master Aug 11, 2015
laanwj added a commit that referenced this pull request Aug 11, 2015
7f1f8f5 Move mempool rejections to new debug category (Wladimir J. van der Laan)
66daed5 Add information to errors in ConnectBlock, CheckBlock (Wladimir J. van der Laan)
6cab808 Remove most logging from transaction validation (Wladimir J. van der Laan)
9003c7c Add function to convert CValidationState to a human-readable message (Wladimir J. van der Laan)
dc58258 Introduce REJECT_INTERNAL codes for local AcceptToMempool errors (Wladimir J. van der Laan)
fbf44e6 Add debug message to CValidationState for optional extra information (Wladimir J. van der Laan)
* for transactions, to signal internal conditions. They cannot and should not
* be sent over the P2P network.
*/
static const unsigned int REJECT_INTERNAL = 0x100;
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious, was the duplication of the REJECT_HIGHFEE value intentional?

@jtimon
Copy link
Contributor

jtimon commented Sep 3, 2015

I've been trying to "move error messages up" for consensus and policy functions in different ways and with multiple attempts since at least January 15th 2015 (the first version of #5669 which also moved CheckTransaction to consensus/consensus did that).
I would have appreciated to be asked for review on this one. Now it's too late to complain about its flaws but I still will do it.

luke-jr pushed a commit to luke-jr/bitcoin that referenced this pull request Nov 30, 2015
It is necessary to be able to concisely log a validation state.
Convert CValidationState to a human-readable message for logging.

Github-Pull: bitcoin#6519
Rebased-From: 9003c7c
luke-jr pushed a commit to luke-jr/bitcoin that referenced this pull request Dec 8, 2015
It is necessary to be able to concisely log a validation state.
Convert CValidationState to a human-readable message for logging.

Github-Pull: bitcoin#6519
Rebased-From: 9003c7c
laanwj added a commit to laanwj/bitcoin that referenced this pull request Feb 24, 2016
Continues "Make logging for validation optional" from bitcoin#6519.

The idea there was to remove all ERROR logging of rejected transaction,
and move it to one message in the class 'mempoolrej' which logs the
state message (and debug info). The superfluous ERRORs in the log
"terrify" users, see for example issue bitcoin#5794.

Unfortunately a lot of new logging was introduced in bitcoin#6871 (RBF) and
 bitcoin#7287 (misc refactoring). This pull updates that new code.
furszy added a commit to PIVX-Project/PIVX that referenced this pull request Jun 20, 2020
ca489c9 [Tests] Fix expected error messages (random-zebra)
9f84c52 Consensus: Remove calls to error() and FormatStateMessage() (random-zebra)
0e4d964 Move mempool rejections to new debug category (random-zebra)
e0db16d Add information to errors in ConnectBlock, CheckBlock (random-zebra)
d4ed81c Remove most logging from transaction validation (random-zebra)
94b2577 Add function to convert CValidationState to a human-readable message (random-zebra)
1ddc88f Introduce REJECT_INTERNAL codes for local AcceptToMempool errors (random-zebra)
55e00a2 Add debug message to CValidationState for optional extra information (random-zebra)
05cf74b Add absurdly high fee message to validation state (for RPC propagation) (random-zebra)

Pull request description:

  - change `CValidationState::chRejectCode` to int
  - add `CValidationState::strDebugMessage` for optional information
  - add `FormatStateMessage` function to convert CValidationState to a human-readable message
  - introduce REJECT_INTERNAL rejection codes for ATMP and make their logging optional
  - remove unnecessary direct logging in `CheckTransaction`, `AcceptToMemoryPool`, `CheckTxInputs`, `CScriptCheck::operator()`
  - add detailed state information to the errors in `CheckBlock` and `ConnectBlock`

  Backported from:

  - bitcoin#5913
  - bitcoin#6519
  - bitcoin#7287

ACKs for top commit:
  Fuzzbawls:
    ACK ca489c9
  furszy:
    re ACK ca489c9 and merging

Tree-SHA512: ab972801fa45c2f84abf84790b0f0f22dc5668e170f51785f3cfbf806bda7988f55bbd43c24ae591ffe3bd62190f6cd99a3b640373c431ab92c0ddcabea1c999
zkbot added a commit to zcash/zcash that referenced this pull request Aug 17, 2021
ZIP 239 preparations 4

Cherry-picked from the following upstream PRs:
- bitcoin/bitcoin#5913
  - Replaces #3111.
  - Includes an extra commit included by upstream in the merge outside the PR.
- bitcoin/bitcoin#6519
- bitcoin/bitcoin#7179
- bitcoin/bitcoin#7853
- bitcoin/bitcoin#7960
@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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Downgrade ERROR to something less less terrifying?
8 participants