Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upConsensus: Remove calls to error() and FormatStateMessage() #7287
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 |
|
Squashed fixes. |
|
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(); | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
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"); | |||
This comment has been minimized.
This comment has been minimized.
laanwj
Jan 29, 2016
Member
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.
This comment has been minimized.
This comment has been minimized.
jtimon
Jan 29, 2016
Author
Member
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.
This comment has been minimized.
This comment has been minimized.
laanwj
Jan 29, 2016
Member
I do think the old messages in all these cases are more informative than the two-word codes, which are documented nowhere.
This comment has been minimized.
This comment has been minimized.
jtimon
Jan 29, 2016
Author
Member
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...
| @@ -3565,7 +3544,8 @@ bool CVerifyDB::VerifyDB(const CChainParams& chainparams, CCoinsView *coinsview, | |||
| return error("VerifyDB(): *** ReadBlockFromDisk failed at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString()); | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
jtimon
Jan 29, 2016
Author
Member
Yes and neither do I in the other 5 occurrences of the string "VerifyDB():" in this function. The goal of this PR is not to fix that. I only do it in the line below because I had to touch that line anyway. But I'd rather not cause more conflicts than necessary.
Of course somebody else can cleanup the whole function (or the whole file) in some other PR (preferably after #7310 ).
This comment has been minimized.
This comment has been minimized.
laanwj
Jan 29, 2016
Member
Sure, just wondered if there was a reason for doing this change only in one place, but that seems a good reason.
| 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())); |
This comment has been minimized.
This comment has been minimized.
laanwj
Jan 29, 2016
Member
strprintf: Only one %s, but two arguments (this likely causes the travis issue)
This comment has been minimized.
This comment has been minimized.
jtimon
Jan 29, 2016
Author
Member
Good catch, I didn't really need to even touch that line to fix your nit...
… consensus code in main
|
Updated fixing a mistake introduced with the latest changes, thanks for noticing so quickly @laanwj |
|
Tested ACK 93fc58c |
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.
…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
jtimon commentedJan 4, 2016
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().