aboutsummaryrefslogtreecommitdiff
path: root/src/validation.cpp
AgeCommit message (Collapse)Author
2017-11-30Merge #10493: Use range-based for loops (C++11) when looping over map elementsMarcoFalke
680bc2cbb Use range-based for loops (C++11) when looping over map elements (practicalswift) Pull request description: Before this commit: ```c++ for (std::map<T1, T2>::iterator x = y.begin(); x != y.end(); ++x) { T1 z = (*x).first; … } ``` After this commit: ```c++ for (auto& x : y) { T1 z = x.first; … } ``` Tree-SHA512: 954b136b7f5e6df09f39248a6b530fd9baa9ab59d7c2c7eb369fd4afbb591b7a52c92ee25f87f1745f47b41d6828b7abfd395b43daf84a55b4e6a3d45015e3a0
2017-11-29Merge #11737: Document partial validation in ConnectBlock()Wladimir J. van der Laan
9d811dc Document partial validation in ConnectBlock() (Suhas Daftuar) Pull request description: `ConnectBlock()` relies on validation that happens in `ContextualCheckBlock()` and `ContextualCheckBlockHeader()`. This has implications for implementing consensus changes and handling software upgrade to ensure that nodes upgrading their software end up enforcing all the consensus rules. Tree-SHA512: 36a252af2221b0e5d5d6f8d5f8b16f8b566ca0db2d56242130a5523302c8757599ac234594a6a946c1689b260d18a32c2c7f8c3831304e78b9832e2ce5ac435a
2017-11-21Fix: Open files read only if requestedAndras Elso
2017-11-20Document partial validation in ConnectBlock()Suhas Daftuar
ConnectBlock() relies on validation that happens in ContextualCheckBlock() and ContextualCheckBlockHeader(). This has implications for implementing consensus changes and handling software upgrade to ensure that nodes upgrading their software end up enforcing all the consensus rules.
2017-11-16scripted-diff: Replace #include "" with #include <> (ryanofsky)MeshCollider
-BEGIN VERIFY SCRIPT- for f in \ src/*.cpp \ src/*.h \ src/bench/*.cpp \ src/bench/*.h \ src/compat/*.cpp \ src/compat/*.h \ src/consensus/*.cpp \ src/consensus/*.h \ src/crypto/*.cpp \ src/crypto/*.h \ src/crypto/ctaes/*.h \ src/policy/*.cpp \ src/policy/*.h \ src/primitives/*.cpp \ src/primitives/*.h \ src/qt/*.cpp \ src/qt/*.h \ src/qt/test/*.cpp \ src/qt/test/*.h \ src/rpc/*.cpp \ src/rpc/*.h \ src/script/*.cpp \ src/script/*.h \ src/support/*.cpp \ src/support/*.h \ src/support/allocators/*.h \ src/test/*.cpp \ src/test/*.h \ src/wallet/*.cpp \ src/wallet/*.h \ src/wallet/test/*.cpp \ src/wallet/test/*.h \ src/zmq/*.cpp \ src/zmq/*.h do base=${f%/*}/ relbase=${base#src/} sed -i "s:#include \"\(.*\)\"\(.*\):if test -e \$base'\\1'; then echo \"#include <\"\$relbase\"\\1>\\2\"; else echo \"#include <\\1>\\2\"; fi:e" $f done -END VERIFY SCRIPT-
2017-11-15Merge #10286: Call wallet notify callbacks in scheduler thread (without cs_main)Wladimir J. van der Laan
89f0312 Remove redundant pwallet nullptr check (Matt Corallo) c4784b5 Add a dev notes document describing the new wallet RPC blocking (Matt Corallo) 3ea8b75 Give ZMQ consistent order with UpdatedBlockTip on scheduler thread (Matt Corallo) cb06edf Fix wallet RPC race by waiting for callbacks in sendrawtransaction (Matt Corallo) e545ded Also call other wallet notify callbacks in scheduler thread (Matt Corallo) 17220d6 Use callbacks to cache whether wallet transactions are in mempool (Matt Corallo) 5d67a78 Add calls to CWallet::BlockUntilSyncedToCurrentChain() in RPCs (Matt Corallo) 5ee3172 Add CWallet::BlockUntilSyncedToCurrentChain() (Matt Corallo) 0b2f42d Add CallFunctionInQueue to wait on validation interface queue drain (Matt Corallo) 2b4b345 Add ability to assert a lock is not held in DEBUG_LOCKORDER (Matt Corallo) 0343676 Call TransactionRemovedFromMempool in the CScheduler thread (Matt Corallo) a7d3936 Add a CValidationInterface::TransactionRemovedFromMempool (Matt Corallo) Pull request description: Based on #10179, this effectively reverts #9583, regaining most of the original speedups of #7946. This concludes the work of #9725, #10178, and #10179. See individual commit messages for more information. Tree-SHA512: eead4809b0a75d1fb33b0765174ff52c972e45040635e38cf3686cef310859c1e6b3c00e7186cbd17374c6ae547bfbd6c1718fe36f26c76ba8a8b052d6ed7bc9
2017-11-09Use unique_ptr for pcoinscatcher/pcoinsdbview/pcoinsTip/pblocktreepracticalswift
* pcoinscatcher (CCoinsViewErrorCatcher) * pcoinsdbview (CCoinsViewDB) * pcoinsTip (CCoinsViewCache) * pblocktree (CBlockTreeDB) * Remove variables shadowing pcoinsdbview
2017-11-08trivial: Fix typo – alreardy → alreadypracticalswift
2017-11-07Merge #11389: Support having SegWit always active in regtest (sipa, ajtowns, ↵MarcoFalke
jnewbery) d61845818 Have SegWit active by default (Pieter Wuille) 4bd89210a Unit tests for always-active versionbits. (Anthony Towns) d07ee77ab Always-active versionbits support (Pieter Wuille) 18e071841 [consensus] Pin P2SH activation to block 173805 on mainnet (John Newbery) 526023aa7 Improve handling of BIP9Deployment limits (Anthony Towns) Pull request description: Most tests shouldn't have to deal with the now-historical SegWit activation transition (and other deployments, but SegWit is certainly the hardest one to accomodate). This PR makes a versionbits starttime of -1 equal to "always active", and enables it by default for SegWit on regtest. Individual tests can override this by using the existing `-vbparams` option. A few unit tests and functional tests are adapted to indeed override vbparams, as they specifically test the transition. This is in preparation for wallet SegWit support, but I thought having earlier eyes on it would be useful. Tree-SHA512: 3f07a7b41cf46476e6c7a5c43244e68c9f41d223482cedaa4c02a3a7b7cd0e90cbd06b84a1f3704620559636a2268f5767d4c52d09c1b354945737046f618fe5
2017-11-06[consensus] Pin P2SH activation to block 173805 on mainnetJohn Newbery
2017-11-01Merge #11531: Check that new headers are not a descendant of an invalid ↵Wladimir J. van der Laan
block (more effeciently) f3d4adf Make p2p-acceptablock not an extended test (Matt Corallo) 00dcda6 [qa] test that invalid blocks on an invalid chain get a disconnect (Matt Corallo) 015a525 Reject headers building on invalid chains by tracking invalidity (Matt Corallo) 932f118 Accept unrequested blocks with work equal to our tip (Matt Corallo) 3d9c70c Stop always storing blocks from whitelisted peers (Matt Corallo) 3b4ac43 Rewrite p2p-acceptblock in preparation for slight behavior changes (Matt Corallo) Pull request description: @sdaftuar pointed out that the version in #11487 was somewhat DoS-able as someone could feed you a valid chain that forked off the the last checkpoint block and force you to do lots of work just walking backwards across blocks for each new block they gave you. We came up with a few proposals but settled on the one implemented here as likely the simplest without obvious DoS issues. It uses our existing on-load mapBlockIndex walk to make sure everything that descends from an invalid block is marked as such, and then simply caches blocks which we attempted to connect but which were found to be invalid. To avoid DoS issues during IBD, this will need to depend on #11458. Includes tests from #11487. Tree-SHA512: 46aff8332908e122dae72ceb5fe8cd241902c2281a87f58a5fb486bf69d46458d84a096fdcb5f3e8e07fbcf7466232b10c429f4d67855425f11b38ac0bf612e1
2017-10-31Reject headers building on invalid chains by tracking invalidityMatt Corallo
This tracks the set of all known invalid-themselves blocks (ie blocks which we attempted to connect but which were found to be invalid). This is used to cheaply check if new headers build on an invalid chain. While we're at it we also resolve an edge-case in invalidateblock on pruned nodes which results in them needing a reindex if they fail to reorg.
2017-10-31Accept unrequested blocks with work equal to our tipMatt Corallo
This is a simple change that makes our accept requirements the same as our request requirements, (ever so slightly) further decoupling our consensus logic from our FindNextBlocksToDownload logic in net_processing.
2017-10-27Disconnect outbound peers relaying invalid headersSuhas Daftuar
2017-10-19Don't process unrequested, low-work blocksSuhas Daftuar
A peer could try to waste our resources by sending us unrequested blocks with low work, eg to fill up our disk. Since e2652002b6011f793185d473f87f1730c625593b we no longer request blocks until we know we're on a chain with more than nMinimumChainWork (our anti-DoS threshold), but we would still process unrequested blocks that had more work than our tip. This commit fixes that behavior.
2017-10-19Avoid slow transaction search with txindex enabledJoão Barbosa
2017-10-18Merge #11062: [mempool] Mark mempool import fails that were found in mempool ↵Pieter Wuille
as 'already there' 258d33b41 [mempool] Mark unaccepted txs present in mempool as 'already there'. (Karl-Johan Alm) Pull request description: I was investigating the reasons for failed imports in mempool and noticed that `LoadMempool()` and `pwallet->postInitProcess()` (for all wallets) are executed concurrently. The wallet will end up importing transactions that `LoadMempool()` later tries to import; the latter will fail due to the tx already being in the mempool. This PR changes the log message, adding an additional "already there" entry. For transactions not accepted into mempool, a check if they are in the mempool is done first, and if found, they are counted as 'already there', otherwise counted as 'failed'. Also slight rewording for consistency (successes, failed, expired, ... -> succeeded, failed, expired). Tree-SHA512: 1a6134a25260917f2768365e0dfd8b278fe3f8287cab38bb028b7de3d517718a2d37696186dc7a23ceab338cc755fbbe7d45358ee94e573610fddd2a0620d6e5
2017-10-13Also call other wallet notify callbacks in scheduler threadMatt Corallo
This runs Block{Connected,Disconnected}, SetBestChain, Inventory, and TransactionAddedToMempool on the background scheduler thread. Of those, only BlockConnected is used outside of Wallet/ZMQ, and is used only for orphan transaction removal in net_processing, something which does not need to be synchronous with anything else. This partially reverts #9583, re-enabling some of the gains from #7946. This does not, however, re-enable the gains achieved by repeatedly releasing cs_main between each transaction processed.
2017-10-12Merge #10898: Fix invalid checks (NULL checks after dereference, redundant ↵Wladimir J. van der Laan
checks, etc.) 76fed83 Avoid NULL pointer dereference when _walletModel is NULL (which is valid) (practicalswift) 4971a9a Use two boolean literals instead of re-using variable (practicalswift) b5fb339 Remove duplicate uriParts.size() > 0 check (practicalswift) 7466991 Remove redundant check (!ecc is always true) (practicalswift) 55224af Remove redundant NULL checks after new (practicalswift) Pull request description: Contains: * Remove redundant `NULL` checks after throwing `new` * Remove redundant check (`!ecc` is always true) * Remove duplicate `uriParts.size() > 0` check * Use two boolean literals instead of re-using variable Tree-SHA512: 30e9af8a9d5c8184836f8267b492aeb4e26eca171a3be08f634b3f39b3055b9fa9f06623f6c69b294ca13bf99743f7645cfac2b25e014ff74687bd085a997895
2017-10-11Merge #8498: Near-Bugfix: Optimization: Minimize the number of times it is ↵Wladimir J. van der Laan
checked that no money... 4e955c5 Near-Bugfix: Reestablish consensus check removed in 8d7849b (Jorge Timón) 3e8c916 Introduce CheckInputsAndUpdateCoins static wrapper in txmempool.cpp (Jorge Timón) 832e074 Optimization: Minimize the number of times it is checked that no money is created (Jorge Timón) 3f0ee3e Proper indentation for CheckTxInputs and other minor fixes (Jorge Timón) Pull request description: ...is created by individual transactions to 2 places (but call only once in each): - ConnectBlock ( before calculated fees per txs twice ) - AcceptToMemoryPoolWorker ( before called CheckTxInputs 4 times and calculated fees per tx one extra time ) Also call tx.GetValueOut() only once per call of CheckTxInputs (instead of 2) For more motivation: ~~https://github.com/bitcoin/bitcoin/blob/master/src/main.cpp#L1493~~ https://github.com/jtimon/bitcoin/compare/0.13-consensus-inputs...jtimon:0.13-consensus-inputs-comments EDIT: partially replaces #6445 Near-Bugfix as pointed out in https://github.com/bitcoin/bitcoin/pull/8498#discussion_r124346132 Tree-SHA512: c71188e7c7c2425c9170ed7b803896755a92fd22f43b136eedaa6e554106696f0b10271d0ef0d0127c1eaafbc31d12eb19143df4f1b6882feecedf6ef05ea346
2017-10-09Use range-based for loops (C++11) when looping over map elementspracticalswift
Before this commit: for (std::map<T1, T2>::iterator x = y.begin(); x != y.end(); ++x) { } After this commit: for (auto& x : y) { }
2017-10-09Merge #11367: [rpc] getblockchaininfo: add size_on_disk, prune_target_sizeWladimir J. van der Laan
b7dfc6c [rpc] getblockchaininfo: add size_on_disk, prune_target_size, automatic_pruning (Daniel Edgecumbe) Pull request description: Tree-SHA512: c255c27d6c922434d203ffdefda0dd3dddbd765b6a9cce5f80f5af5cb0b1c11c8aff6f4d00e96a326701d0bc81aace2f216fd1985675aa979f76c16f564a6cf6
2017-10-05Merge #11107: Fix races in AppInitMain and others with lock and atomic boolsMarcoFalke
c626dcb50 Make fUseCrypto atomic (MeshCollider) 731065b11 Consistent parameter names in txdb.h (MeshCollider) 35aeabec6 Make fReindex atomic to avoid race (MeshCollider) 58d91af59 Fix race for mapBlockIndex in AppInitMain (MeshCollider) Pull request description: Fixes https://github.com/bitcoin/bitcoin/issues/11106 Also makes fReindex atomic as suggested in @TheBlueMatt comment below, and makes fUseCrypto atomic as suggested in 10916 https://github.com/bitcoin/bitcoin/pull/11107/commits/d291e7635b0ef4156c2805c6c4ee1adad91f0307 just renames the parameters in the txdb header file to make them consistent with those used in the cpp file, noticed it when looking for uses of fReindex Tree-SHA512: b378aa7289fd505b76565cd4d48dcdc04ac5540283ea1c80442170b0f13cb6df771b1a94dd54b7fec3478a7b4668c224ec9d795f16937782724c5d020edd3a42
2017-10-04Merge #11406: Add state message print to AcceptBlock failure message.Wladimir J. van der Laan
6643b80 Add state message print to AcceptBlock failure message. (Matt Corallo) Pull request description: This should make it easier to debug issues where the CheckBlock at the top of ProcessNewBlock fails (which does not print, in contrast to AcceptBlock, which always prints). This was motivated by #11371 which appears to be exactly such a case, and is not debuggable from the information provided. Not sure how much this would have helped in that case, but it is kinda weird that we can reject a block without ever printing why. Tree-SHA512: 7a1c2c76080b810212da885c38e091609e409c62918cc326bb36a1096e09b2ae7e26fd4bdaefd79863d2894e2823e463005700a524940f177a59ef09f589b2f1
2017-10-02Remove redundant NULL checks after newpracticalswift
2017-09-29[rpc] getblockchaininfo: add size_on_disk, prune_target_size, automatic_pruningDaniel Edgecumbe
Fix pruneheight help text. Move fPruneMode block to match output ordering with help text. Add functional tests for new fields in getblockchaininfo.
2017-09-29Merge #11309: Minor cleanups for AcceptToMemoryPoolMarcoFalke
bf64c3cb3 Ignore transactions added to mempool during a reorg for fee estimation purposes. (Alex Morcos) 04f78ab5b Do not reject based on mempool min fee when bypass_limits is set. (Alex Morcos) fd849e1b0 Change AcceptToMemoryPool function signature (Alex Morcos) Pull request description: First commit just removes default arguments from `AcceptToMemoryPool` and consolidates two arguments, it does not change behavior. Second commit finally fixes the fact that we're not meant to reject based on mempool min fee when adding a transaction from a disconnected block during a reorg as mentioned [here](https://github.com/bitcoin/bitcoin/pull/9602#issue-202197849) Third commit makes fee estimation ignore transactions added from a disconnected block during a reorg. I think this was another source of fee estimates returning estimates below 1000 sat/kB as in #11303. Tree-SHA512: 30925ca8b341915bb214f1d2590b36b7931f2e125b7660150e38ae70338f00db5aa7f1608546dddb181446924177eb7cf62ea8bd2583068acc074d6c3f86bc0c
2017-09-26Add state message print to AcceptBlock failure message.Matt Corallo
This should make it easier to debug issues where the CheckBlock at the top of ProcessNewBlock fails (which does not print, in contrast to AcceptBlock, which always prints).
2017-09-22Merge #10953: [Refactor] Combine scriptPubKey and amount as CTxOut in ↵Pieter Wuille
CScriptCheck 3a131b724 Rename out to m_tx_out in CScriptCheck (Johnson Lau) e91211878 [Refactor] Combine scriptPubKey and amount as CTxOut in CScriptCheck (Johnson Lau) Pull request description: This simplifies CScriptCheck by combining scriptPubKey and amount Tree-SHA512: 6422363cf5394c6cfefb30c1709db6def63230b809cc7697887e4a2e8c684149208edf91dd139e031b9fe732776b2db59305f77c3cba6f333b11cceb39ef0cc2
2017-09-22Rename out to m_tx_out in CScriptCheckJohnson Lau
2017-09-20Near-Bugfix: Reestablish consensus check removed in 8d7849bJorge Timón
in 8d7849b6db5f54dc32fe4f8c6c7283068473cd21 This can potentially prevent an overflow that could at least in theory allow the creation of money.
2017-09-20Optimization: Minimize the number of times it is checked that no money is ↵Jorge Timón
created by individual transactions to 2 places (but call only once in each): - ConnectBlock ( before calculated fees per txs twice ) - AcceptToMemoryPoolWorker ( before called CheckTxInputs 4 times and calculated fees per tx one extra time ) Also call tx.GetValueOut() only once per call of CheckTxInputs (instead of 2)
2017-09-20Merge #11132: Document assumptions that are being made to avoid NULL pointer ↵Wladimir J. van der Laan
dereferences fdc3293 Document assumptions that are being made to avoid NULL pointer dereferences (practicalswift) Pull request description: Document assumptions (via `assert(…)`:s) that are being made avoid `NULL` pointer dereferences. Rationale: * Make it clear to human reviewers and non-human static analyzers that what might look like potential `NULL` pointer dereferences are written the way they are intentionally (these cases are currently flagged by various static analyzers). Tree-SHA512: b424328195e2680e1e4ec546298f718c49e5ad182147dc004de580693db1b50eec4065e1c4f232bdb302baa12954265a50ba21cb5ba4ff30248535b2de778672
2017-09-15Trivial: Fix validation commentsDan Raviv
- Move comment about transaction/block weight calculation so it applies not only to the GetBlockWeight function but also to GetTransactionWeight - Fix comment in validation.cpp referencing future deployment of BIP113. It has already been deployed. - The doc comment for BLOCK_DOWNLOAD_WINDOW wasn't updated since pruning was introduced, so it still refers to pruning as something that might happen in the future. A larger BLOCK_DOWNLOAD_WINDOW window would now, indeed, make pruning harder.
2017-09-12Ignore transactions added to mempool during a reorg for fee estimation purposes.Alex Morcos
2017-09-12Do not reject based on mempool min fee when bypass_limits is set.Alex Morcos
This should have always been the case, but we will correctly trim to size after a reorg which is when bypass_limits is set.
2017-09-12Change AcceptToMemoryPool function signatureAlex Morcos
Combine fLimitFree and fOverrideMempoolLimit into a single boolean: bypass_limits. This is used to indicate that mempool limiting based on feerate should be bypassed. It is used when readding transactions from a reorg and then the mempool is trimmed to size after all transactions are added and they can be evaluated in the context of their descendants. No changes to behavior.
2017-09-07Merge #10770: Drop upgrade-cancel callback registration for a generic ↵Jonas Schnelli
"cancelable" ee4d1493e Drop upgrade-cancel callback registration for a generic "resumeable" (Matt Corallo) Pull request description: Instead of passing a StartShutdown reference all the way up from txdb, give ShowProgress a "cancelable" boolean, as StartShutdown is pretty much always what you'll want to use to cancel. Use the same boolean to allow cancel during initial block verification. Tree-SHA512: 515817aaa4b9e3e856200e00be9c2d44ecfa2d4f288fe3e02116105fe85de2650c13076ee7e45396ec1ce6ab45e53b0477cddda7cfdee5b3bd0589cb81a4c346
2017-09-07Make fReindex atomic to avoid raceMeshCollider
2017-09-06Merge #11238: Add assertions before potential null deferencesWladimir J. van der Laan
c00199244 Fix potential null dereferences (MeshCollider) Pull request description: Picked up by the static analyzer [Facebook Infer](http://fbinfer.com/) which I was playing around with for another research project. Just adding some asserts before dereferencing potentially null pointers. Tree-SHA512: 9c01dab2d21bce75c7c7ef867236654ab538318a1fb39f96f09cdd2382a05be1a6b2db0a1169a94168864e82ffeae0686a383db6eba799742bdd89c37ac74397
2017-09-06Merge #11099: [RPC][mempool]: Add savemempool RPCMarcoFalke
1aa97ee08 Add savemempool RPC (Lawrence Nahum) 467cbbcbf Add return value to DumpMempool (Lawrence Nahum) Pull request description: Adds a simple parameterless rpc command to dump the mempool. Rationale: Sometimes there can be a crash for whatever reason (bug, power loss, etc) causing the mempool.dat file to not be saved. This change allows to script/cron the rpc call to have more regular saves to the file as well as cli/ad-hoc. This should solve issue https://github.com/bitcoin/bitcoin/issues/11086 Tree-SHA512: e856ae9777425a4521279c9b58e69285d8e374790bebefd3284cf91931eac0e456f86224f427a087a01bf70440bf6e439fa02c8a34940eb1046ae473e98b6aaa
2017-09-06Document assumptions that are being made to avoid NULL pointer dereferencespracticalswift
2017-09-06Add return value to DumpMempoolLawrence Nahum
2017-09-05Allow setting nMinimumChainWork on command lineSuhas Daftuar
2017-09-04[mempool] Mark unaccepted txs present in mempool as 'already there'.Karl-Johan Alm
On startup, the wallets will start pumping wallet transactions into the mempool in a different thread while LoadMempool() is running. This will sometimes result in transactions "failing" to be accepted into mempool, but only for the reason that they were already put there by a wallet. The log message for mempool load would note this as a 'failure' to import, which was misleading; it should instead mark it as the transaction already being in the mempool.
2017-08-30[Refactor] Combine scriptPubKey and amount as CTxOut in CScriptCheckJohnson Lau
2017-08-28Merge #10303: [bench] Include ms/blk stats in Connect* benchmarks.Wladimir J. van der Laan
a473eff [bench] Replace 0.00(000)1 with MICRO/MILLI #defines in validation.cpp. (Karl-Johan Alm) 5f850b0 [bench] Include ms/blk stats in Connect* benchmarks. (Karl-Johan Alm) Pull request description: Display the average per block runtime for the various benchmarked times in the block connect functions to give an overview of long(er) term time distribution statistics. Tree-SHA512: 3d6f24f6b9e3dbb448a647e2cda8e7b90ad6a16d4821f49f426a8e1ebc3ce5a0cf0a8cde82213e293affba441615702dfe50822c8c818e282af03bfe383d83e0
2017-08-23Fix potential null dereferencesMeshCollider
2017-08-20Drop upgrade-cancel callback registration for a generic "resumeable"Matt Corallo
Instead of passing a StartShutdown reference all the way up from txdb, give ShowProgress a "resumeable" boolean, which is used to inform the user if the action will be resumed, but cancel is always allowed by just calling StartShutdown().
2017-08-16Declare single-argument (non-converting) constructors "explicit"practicalswift
In order to avoid unintended implicit conversions.