-
Notifications
You must be signed in to change notification settings - Fork 37.8k
Consensus: Remove calls to error() and FormatStateMessage() #7287
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
Why get rid of FormatMoney? That seems like a regression of sorts. |
There's no reason for utilmoneystr.o to be part of libconsensus. |
My 'regression' comment was regarding type encapsulation. It should not be assumed that CAmount is a type understood by sprintf. |
I can restore the call to FormatMoney there and make utilmoneystr.o part of libconsensus only for one that reject reason line if that is preferred. Also, the python tests are failing because I have improved the information provided by the reject reason in jtimon@8512490#diff-7ec3c68a81efff79b6ca22ac1f1eabbaR2989 |
b3518dc
to
7a7ed08
Compare
Squashed fixes. |
7a7ed08
to
3fa51ee
Compare
3fa51ee
to
a22b7a4
Compare
Rebased (1) |
@@ -814,12 +814,13 @@ bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState &state, const C | |||
bool* pfMissingInputs, bool fOverrideMempoolLimit, bool fRejectAbsurdFee, | |||
std::vector<uint256>& vHashTxnToUncache) | |||
{ | |||
uint256 hash = tx.GetHash(); |
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.
could be const
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.
will change.
concept ACK, utACK a22b7a4 |
@@ -2909,13 +2909,11 @@ bool CheckBlockHeader(const CBlockHeader& block, CValidationState& state, bool f | |||
{ | |||
// Check proof of work matches claimed amount | |||
if (fCheckPOW && !CheckProofOfWork(block.GetHash(), block.nBits, Params().GetConsensus())) | |||
return state.DoS(50, error("CheckBlockHeader(): proof of work failed"), | |||
REJECT_INVALID, "high-hash"); | |||
return state.DoS(50, false, REJECT_INVALID, "high-hash"); |
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.
Not sure if it makes sense in this case, depends on whether the extra explanation offered is worthwhile, but instead of deleting the error message here you could pass it to DoS as strDebugMessage
. That's why that field was introduced.
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.
Sure, I can set that field wherever we think it's valuable. Please, point out the cases where you think it's worth it and I'll happily change 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.
I do think the old messages in all these cases are more informative than the two-word codes, which are documented nowhere.
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.
In all cases? I think I disagree, but I don't care enough to discuss it, I'll change all of them to use all the long messages.
The non-documented codes can be grep, but I think at some point we could just use ConsensusError_t that could replace ScriptError_t. Anyway, one step at a time...
450c06f
to
8d77743
Compare
tx.GetHash().ToString(), | ||
FormatStateMessage(state)); | ||
return state.Invalid(false, state.GetRejectCode(), state.GetRejectReason(), | ||
strprintf("Transaction check failed (tx hash %s)", tx.GetHash().ToString(), 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.
strprintf: Only one %s, but two arguments (this likely causes the travis issue)
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.
Good catch, I didn't really need to even touch that line to fix your nit...
… consensus code in main
8d77743
to
93fc58c
Compare
Updated fixing a mistake introduced with the latest changes, thanks for noticing so quickly @laanwj |
Tested ACK 93fc58c |
93fc58c Consensus: Remove calls to error() and FormatStateMessage() from some consensus code in main (Jorge Timón)
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.
…eMessage() 93fc58c Consensus: Remove calls to error() and FormatStateMessage() from some consensus code in main (Jorge Timón)
…eMessage() 93fc58c Consensus: Remove calls to error() and FormatStateMessage() from some consensus code in main (Jorge Timón)
…rmatStateMessage() dashpay/dash@93fc58c Consensus: Remove calls to error() and FormatStateMessage() from some consensus code in main (Jorge Timón)
This was accidently changed to 10 while backporting bitcoin#7287 and causes test failures in p2p-fullblocktest.py
This was accidently changed to 10 while backporting bitcoin#7287 and causes test failures in p2p-fullblocktest.py
This was accidently changed to 10 while backporting bitcoin#7287 and causes test failures in p2p-fullblocktest.py
This was accidently changed to 10 while backporting bitcoin#7287 and causes test failures in p2p-fullblocktest.py
…nTestFramework (#3277) * [tests] Change feature_block.py to use BitcoinTestFramework * [tests] Fix flake8 warnings in feature_block.py * [tests] Tidy up feature_block.py - move all helper methods to the end - remove block, create_tx and create_and_sign_tx shortcuts - remove --runbarelyexpensive option, since it defaults to True and it's unlikely that anyone ever runs the test with this option set to false. * [tests] Add logging to feature_block.py * [tests] Improve assert message when wait_until() fails * Merge bitcoin#13048: [tests] Fix feature_block flakiness c1d7420 [tests] Fix feature_block flakiness (John Newbery) Pull request description: feature_block.py occasionally fails on Travis. I believe this is due to a a race condition when reconnecting to bitcoind after a subtest that expects disconnection. If the test runs ahead and sends the INV for the subsequent test before we've received the initial sync getheaders, then we may end up sending two headers messages - one as a response to the initial sync getheaders and one in response to the INV getheaders. If both of those headers fail validation with a DoS score of 50 or higher, then we'll unexpectedly be disconnected. There is only one validation failure that has a DoS score bewteen 50 and 100, which is high-hash. That's why the test is failing immediately after the "Reject a block with invalid work" subtest. Fix is to wait for the initial getheaders from the peer before we start populating our blockstore. That way we won't have any invalid headers to respond to it with. Tree-SHA512: dc17d795fcfaf0f8c0bf1e9732b5e11fbc8febbfafba4c231b7c13a5404a2c297dcd703a7a75bc7f353c893e12efc87f424f2201abd47ba5268af32d4d2e841f * Temporarely rename MAX_BLOCK_SIZE -> MAX_BLOCK_BASE_SIZE We'll undo this after the next commit. This avoids merge many conflicts and makes reviewing easier. * Rename MAX_BLOCK_BASE_SIZE back to MAX_BLOCK_SIZE * Use DoS score of 100 for bad-blk-sigops This was accidently changed to 10 while backporting bitcoin#7287 and causes test failures in p2p-fullblocktest.py * Use allowOptimisticSend=true when sending reject messages This fixes test failures in p2p-fullblocktest.py which expects reject messages to be sent/received before connections get closed. * Fix p2p-fullblocktest.py - CBlock and friends are still in test_framework.mininode - "-whitelist" causes connections to not be dropped, which in turn causes sync_blocks with reconnect=True to fail - "bad-cb-amount" does not cause a ban in Dash, so reconnect must be False - Dash already bans when a header is received which is a child of an invalid header, causing block requests to never happen * Backport missing changes from bitcoin#13003 bitcoin#13003 was backported out of order which causes missed changes. * Bump p2p-fullblocktest timeouts * Increase RPC timeout in p2p-fullblocktest.py Co-authored-by: John Newbery <jonnynewbs@gmail.com> Co-authored-by: MarcoFalke <falke.marco@gmail.com>
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
…nTestFramework (dashpay#3277) * [tests] Change feature_block.py to use BitcoinTestFramework * [tests] Fix flake8 warnings in feature_block.py * [tests] Tidy up feature_block.py - move all helper methods to the end - remove block, create_tx and create_and_sign_tx shortcuts - remove --runbarelyexpensive option, since it defaults to True and it's unlikely that anyone ever runs the test with this option set to false. * [tests] Add logging to feature_block.py * [tests] Improve assert message when wait_until() fails * Merge bitcoin#13048: [tests] Fix feature_block flakiness c1d7420 [tests] Fix feature_block flakiness (John Newbery) Pull request description: feature_block.py occasionally fails on Travis. I believe this is due to a a race condition when reconnecting to bitcoind after a subtest that expects disconnection. If the test runs ahead and sends the INV for the subsequent test before we've received the initial sync getheaders, then we may end up sending two headers messages - one as a response to the initial sync getheaders and one in response to the INV getheaders. If both of those headers fail validation with a DoS score of 50 or higher, then we'll unexpectedly be disconnected. There is only one validation failure that has a DoS score bewteen 50 and 100, which is high-hash. That's why the test is failing immediately after the "Reject a block with invalid work" subtest. Fix is to wait for the initial getheaders from the peer before we start populating our blockstore. That way we won't have any invalid headers to respond to it with. Tree-SHA512: dc17d795fcfaf0f8c0bf1e9732b5e11fbc8febbfafba4c231b7c13a5404a2c297dcd703a7a75bc7f353c893e12efc87f424f2201abd47ba5268af32d4d2e841f * Temporarely rename MAX_BLOCK_SIZE -> MAX_BLOCK_BASE_SIZE We'll undo this after the next commit. This avoids merge many conflicts and makes reviewing easier. * Rename MAX_BLOCK_BASE_SIZE back to MAX_BLOCK_SIZE * Use DoS score of 100 for bad-blk-sigops This was accidently changed to 10 while backporting bitcoin#7287 and causes test failures in p2p-fullblocktest.py * Use allowOptimisticSend=true when sending reject messages This fixes test failures in p2p-fullblocktest.py which expects reject messages to be sent/received before connections get closed. * Fix p2p-fullblocktest.py - CBlock and friends are still in test_framework.mininode - "-whitelist" causes connections to not be dropped, which in turn causes sync_blocks with reconnect=True to fail - "bad-cb-amount" does not cause a ban in Dash, so reconnect must be False - Dash already bans when a header is received which is a child of an invalid header, causing block requests to never happen * Backport missing changes from bitcoin#13003 bitcoin#13003 was backported out of order which causes missed changes. * Bump p2p-fullblocktest timeouts * Increase RPC timeout in p2p-fullblocktest.py Co-authored-by: John Newbery <jonnynewbs@gmail.com> Co-authored-by: MarcoFalke <falke.marco@gmail.com>
Remove calls to error() and FormatStateMessage()
and FormatMoney()from some consensus code in main.This is necessary because libconsensus cannot depend on util.cpp, which exposes globals among other things. Doing this before moving this consensus code out of main allows consensus/consensus.cpp to never depend on util.cpp and it removes the necessity to make FormatStateMessage() non-static to call it, temporarily, from consensus/consensus.cpp.
This also restores some error reporting that seems to have been lost, maybe while moving to use FormatStateMessage().