-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Make logging for validation optional #6519
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
Conversation
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. |
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.
72a3bb7
to
0cbeb26
Compare
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. N.B.: I've also removed the logging in |
{ | ||
return strprintf("%s%s (code %i)", | ||
state.GetRejectReason(), | ||
state.GetDebugMessage().empty() ? "" : (", "+state.GetDebugMessage()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No closing bracket?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@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. |
@sipa So we just call par=1 mode 'safe mode with debugging'. Voila. |
Untested ACK (but see nit about closing bracket). |
0cbeb26
to
72f7864
Compare
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 */ |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
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. |
concept ACK |
👍 |
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.
72f7864
to
7f1f8f5
Compare
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; |
There was a problem hiding this comment.
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?
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). |
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
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
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.
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
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
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.
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.