aboutsummaryrefslogtreecommitdiff
path: root/src/coins.cpp
AgeCommit message (Collapse)Author
2024-08-08Reduce cache lookups in CCoinsViewCache::FetchCoinLőrinc
Enhanced efficiency and readability of CCoinsViewCache::FetchCoin by replacing separate find() and emplace() calls with a single try_emplace(), reducing map lookups and potential insertions.
2024-08-05Add linked-list test to CCoinsViewCache::SanityCheckPieter Wuille
2024-08-05coins: move Sync logic to CoinsViewCacheCursorAndrew Toth
Erase spent cache entries and clear flags of unspent entries inside the BatchWrite loop, instead of an additional loop after BatchWrite. Co-Authored-By: Pieter Wuille <pieter@wuille.net>
2024-08-05coins: pass linked list of flagged entries to BatchWriteAndrew Toth
BatchWrite now iterates through the linked list of flagged entries instead of the entire coinsCache map. Co-Authored-By: l0rinc <pap.lorinc@gmail.com>
2024-08-02refactor: require self and sentinel parameters for AddFlagsAndrew Toth
No behavior change. Prepares for adding the CoinsCachePairs to a linked list when flagged.
2024-08-01refactor: disallow setting flags in CCoinsCacheEntry constructorsAndrew Toth
No behavior change because any entries that are added in EmplaceCoinInternalDANGER have DIRTY assigned to them after, and if they are not inserted then they will not be modified as before. This prepares moving the cache entry flags field to private access. Co-Authored-By: Martin Leitner-Ankerl <martin.ankerl@gmail.com>
2024-08-01refactor: encapsulate flags setting with AddFlags and ClearFlagsAndrew Toth
No behavior change. This prepares moving the cache entry flags field to private access.
2024-08-01refactor: encapsulate flags access for dirty and fresh checksAndrew Toth
No behavior change. This prepares moving the cache entry flags field to private access. Co-Authored-By: l0rinc <pap.lorinc@gmail.com>
2024-06-10log: use error level for critical log messagesMarcoFalke
As per doc/developer-notes#logging, LogError should be used for severe problems that require the node to shut down. Co-Authored-By: stickies-v <stickies-v@protonmail.com>
2023-11-21Use Txid in COutpointdergoegge
2023-11-16Include version.h in fewer placesAnthony Towns
2023-11-16serialize: Drop useless version param from GetSerializeSize()Anthony Towns
2023-10-09Merge bitcoin/bitcoin#26331: Implement `CCoinsViewErrorCatcher::HaveCoin` ↵Andrew Chow
and check disk space periodically ed52e71176fc97c6ed01e3eebd85acdec54b4448 Periodically check disk space to avoid corruption (Aurèle Oulès) 7fe537f7a48675b1d25542bee6f390d665547580 Implement CCoinsViewErrorCatcher::HaveCoin (Aurèle Oulès) Pull request description: Attempt to fix #26112. As suggested by sipa in https://github.com/bitcoin/bitcoin/issues/26112#issuecomment-1249683401: > CCoinsViewErrorCatcher, the wrapper class used around CCoinsViewDB that's supposed to detect these problems and forcefully exit the application, has an override for GetCoins. But in CheckTxInputs, HaveInputs is first invoked, which on its turn calls HaveCoin. HaveCoin is implemented in CCoinsViewDB, but not in CCoinsViewErrorCatcher, and thus the disk read exception escapes. > A solution may be to just add an override for HaveCoin in CCoinsViewErrorCatcher. I implemented `CCoinsViewErrorCatcher::HaveCoin` and also added a periodic disk space check that shutdowns the node if there is not enough space left on disk, the minimum here is 50MB. For reviewers, it's possible to saturate disk space to test the PR by creating large files with `fallocate -l 50G test.bin` ACKs for top commit: achow101: ACK ed52e71176fc97c6ed01e3eebd85acdec54b4448 w0xlt: Code Review ACK https://github.com/bitcoin/bitcoin/pull/26331/commits/ed52e71176fc97c6ed01e3eebd85acdec54b4448 sipa: utACK ed52e71176fc97c6ed01e3eebd85acdec54b4448 Tree-SHA512: 456aa7b996023df42b4fbb5158ee429d9abf7374b7b1ec129b21aea1188ad19be8da4ae8e0edd90b85b7a3042b8e44e17d3742e33808a4234d5ddbe9bcef1b78
2023-03-23Use PoolAllocator for CCoinsMapMartin Leitner-Ankerl
In my benchmarks, using this pool allocator for CCoinsMap gives about 20% faster `-reindex-chainstate` with -dbcache=5000 with practically the same memory usage. The change in max RSS changed was 0.3%. The `validation_flush_tests` tests need to be updated because memory allocation is now done in large pools instead of one node at a time, so the limits need to be updated accordingly.
2023-03-23Call ReallocateCache() on each Flush()Martin Leitner-Ankerl
This frees up all associated memory with the map, not only the nodes. This is necessary in preparation for using the PoolAllocator for CCoinsMap, which does not actually free any memory on clear().
2023-02-02Add deterministic mode to CCoinsViewCachePieter Wuille
2023-02-01Add CCoinsViewCache::SanityCheck() and use it in fuzz testPieter Wuille
2023-01-31clang-tidy: Fix `modernize-use-default-member-init` in headersHennadii Stepanov
See https://clang.llvm.org/extra/clang-tidy/checks/modernize/use-default-member-init.html
2023-01-30Add assertions that BatchWrite(erase=true) erasesPieter Wuille
2023-01-30Follow coding style for named argumentsPieter Wuille
2023-01-20coins: add Sync() method to allow flush without cacheCoins dropJames O'Beirne
In certain circumstances, we may want to flush to disk without emptying `cacheCoins`, which affects performance. UTXO snapshot activation is one such case. This method is currently unused and this commit does not change any behavior. Incorporates feedback from John Newbery. Co-authored-by: Suhas Daftuar <sdaftuar@gmail.com>
2022-12-24scripted-diff: Bump copyright headersHennadii Stepanov
-BEGIN VERIFY SCRIPT- ./contrib/devtools/copyright_header.py update ./ -END VERIFY SCRIPT- Commits of previous years: - 2021: f47dda2c58b5d8d623e0e7ff4e74bc352dfa83d7 - 2020: fa0074e2d82928016a43ca408717154a1c70a4db - 2019: aaaaad6ac95b402fe18d019d67897ced6b316ee0
2022-10-19Implement CCoinsViewErrorCatcher::HaveCoinAurèle Oulès
2022-08-19Merge bitcoin/bitcoin#25707: refactor: Make const references to avoid ↵MacroFake
unnecessarily copying objects and enable two clang-tidy checks ae7ae36d311a869b3bda41d29dc0e47fade77d28 tidy: Enable two clang-tidy checks (Aurèle Oulès) 081b0e53e3adca7ea57d23e5fcd9db4b86415a72 refactor: Make const refs vars where applicable (Aurèle Oulès) Pull request description: I added const references to some variables to avoid unnecessarily copying objects. Also added two clang-tidy checks : [performance-for-range-copy](https://releases.llvm.org/11.1.0/tools/clang/tools/extra/docs/clang-tidy/checks/performance-for-range-copy.html) and [performance-unnecessary-copy-initialization](https://releases.llvm.org/12.0.0/tools/clang/tools/extra/docs/clang-tidy/checks/performance-unnecessary-copy-initialization.html). ACKs for top commit: vasild: ACK ae7ae36d311a869b3bda41d29dc0e47fade77d28 MarcoFalke: review ACK ae7ae36d311a869b3bda41d29dc0e47fade77d28 Tree-SHA512: f6ac6b0cd0eee1e0c34d2f186484bc0f7ec6071451cccb33fa88a67d93d92b304e2fac378b88f087e94657745bca4e966dbc443759587400eb01b1f3061fde8c
2022-07-27refactor: Make const refs vars where applicableAurèle Oulès
This avoids initializing variables with the copy-constructor of a non-trivially copyable type.
2022-07-21tracing: do not use `coin` after move in `CCoinsViewCache::AddCoin`Seibart Nedor
2021-12-30scripted-diff: Bump copyright headersHennadii Stepanov
-BEGIN VERIFY SCRIPT- ./contrib/devtools/copyright_header.py update ./ -END VERIFY SCRIPT- Commits of previous years: * 2020: fa0074e2d82928016a43ca408717154a1c70a4db * 2019: aaaaad6ac95b402fe18d019d67897ced6b316ee0
2021-11-28[tracing] tracepoints to utxocache add, spent and uncacheArnab Sen
Signed-off-by: Arnab Sen <arnabsen1729@gmail.com>
2021-06-17refactor: wrap CCoinsViewCursor in unique_ptrJames O'Beirne
Specifically with CCoinsViewDB, if a raw cursor is allocated and not freed, a cryptic leveldb assertion failure occurs on CCoinsViewDB destruction. See: https://github.com/google/leveldb/issues/142#issuecomment-414418135
2021-02-12simplify ChainstateManager::SnapshotBlockhash() return semanticsJames O'Beirne
Don't return null snapshotblockhash values to avoid caller complexity/confusion.
2021-01-13Merge #19935: Move SaltedHashers to separate file and add some new onesWladimir J. van der Laan
281fd1a4a032cded7f9ea9857e3e99fc793c714b Replace KeyIDHasher with SaltedSipHasher (Andrew Chow) 210b693db66e7c5b618014b5a287aee15af00045 Add generic SaltedSipHasher (Andrew Chow) 95e61c1cf2a91d041c8025306ba36f0ea2806894 Move Hashers to util/hasher.{cpp/h} (Andrew Chow) Pull request description: There are existing `SaltedOutPointHasher` and `SaltedTxidHasher` classes used for `std::unordered_map` and `std::unordered_set` that could be useful in other places in the codebase. So we these to their own `saltedhash.{cpp/h}` file. An existing `KeyIDHasher` is moved there too. Additionally, `ScriptIDHasher`, `SaltedPubkeyHasher`, and `SaltedScriptHasher` are added so that they can be used in future work. `KeyIDHasher` and `ScriptIDHasher` are not salted so that equality comparisons of maps and sets keyed by `CKeyID` and `CScriptID` will actually work. Split from #19602 (and a few other PRs/branches I have). ACKs for top commit: laanwj: Code review ACK 281fd1a4a032cded7f9ea9857e3e99fc793c714b jonatack: ACK 281fd1a4a032cded7f9ea9857e3e99fc793c714b, code review, debug build and ran bitcoind after rebasing to master @ dff0f6f753ea fjahr: utACK 281fd1a4a032cded7f9ea9857e3e99fc793c714b Tree-SHA512: bb03b231ccf3c9ecefc997b8da9c3770af4819f9be5b0a72997a103864e84046a2ac39b8eadf0dc9247bdccd53f86f433642e3a098882e6748341a9e7736271b
2020-12-31scripted-diff: Bump copyright headersMarcoFalke
-BEGIN VERIFY SCRIPT- ./contrib/devtools/copyright_header.py update ./ -END VERIFY SCRIPT-
2020-11-10Move Hashers to util/hasher.{cpp/h}Andrew Chow
Move the hashers that we use for hash tables to a common place. Moved hashers: - SaltedTxidHasher - SaltedOutpointHasher - FilterHeaderHasher - SignatureCacheHasher - BlockHasher
2020-07-01Add CChainState::ResizeCoinsCachesJames O'Beirne
Also adds CCoinsViewCache::ReallocateCache() to attempt to free memory that the cacheCoins's allocator may be hanging onto when downsizing the cache. Adds `CChainState::m_coins{tip,db}_cache_size_bytes` data members so that we can reference cache size on a per-chainstate basis for flushing.
2020-05-03Remove CCoinsViewCache::GetValueIn(...)practicalswift
2020-04-21[docs] use consistent naming for possible_overwriteJohn Newbery
And other general comment improvements for adding coins.
2020-04-21[docs] Improve commenting in coins.cpp|hJohn Newbery
Remove references to 'pruned' coins, which don't exist since the move to per-txout coins db.
2019-12-30scripted-diff: Bump copyright of files changed in 2019MarcoFalke
-BEGIN VERIFY SCRIPT- ./contrib/devtools/copyright_header.py update ./ -END VERIFY SCRIPT-
2019-07-21move-onlyish: move CCoinsViewErrorCatcher out of init.cppJames O'Beirne
and into coins.cpp. This move is necessary so that we can later include a CCoinsViewErrorCatcher instance under CChainState. Co-authored-by: MarcoFalke <falke.marco@gmail.com>
2018-11-05Extract CSipHasher to it's own file in crypto/ directory.Jim Posen
This is a move-only commit with the exception of changes to includes.
2018-09-11Drop unused GetType() from CSizeComputerBen Woosley
2018-07-27Update copyright headers to 2018DrahtBot
2018-01-03Increment MIT Licence copyright header year on files modified in 2017Akira Takizawa
2017-11-16Remove includes in .cpp files for things the corresponding .h file already ↵practicalswift
included
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-09-16Small refactor of CCoinsViewCache::BatchWrite()Dan Raviv
std::unordered_map::erase( const_iterator pos ) returns an iterator to the element following the removed one. Use that to optimize (probably minor-performance-wise, and definitely code-structure-wise) the implementation of CCoinsViewCache::BatchWrite().
2017-08-16Use nullptr instead of zero (0) as the null pointer constantpracticalswift
2017-07-14Remove confusing MAX_BLOCK_BASE_SIZE.Gregory Maxwell
Some people keep thinking that MAX_BLOCK_BASE_SIZE is a separate size limit from the weight limit when it fact it is superfluous, and used in early tests before the witness data has been validated or just to compute worst case sizes. The size checks that use it would not behave any differently consensus wise if they were eliminated completely. Its correct value is not independently settable but is a function of the weight limit and weight formula. This patch just eliminates it and uses the scale factor as required to compute the worse case constants. It also moves the weight factor out of primitives into consensus, which is a more logical place for it.
2017-06-28Merge #10148: Use non-atomic flushing with block replayWladimir J. van der Laan
176c021 [qa] Test non-atomic chainstate writes (Suhas Daftuar) d6af06d Dont create pcoinsTip until after ReplayBlocks. (Matt Corallo) eaca1b7 Random db flush crash simulator (Pieter Wuille) 0580ee0 Adapt memory usage estimation for flushing (Pieter Wuille) 013a56a Non-atomic flushing using the blockchain as replay journal (Pieter Wuille) b3a279c [MOVEONLY] Move LastCommonAncestor to chain (Pieter Wuille) Tree-SHA512: 47ccc62303f9075c44d2a914be75bd6969ff881a857a2ff1227f05ec7def6f4c71c46680c5a28cb150c814999526797dc05cf2701fde1369c06169f46eccddee
2017-06-26Simplify return values of GetCoin/HaveCoin(InCache)Pieter Wuille
This removes the possibility for GetCoin/HaveCoin/HaveCoinInCache to return true while the respective coin is spent. By doing it across all calls, some extra checks can be eliminated. coins_tests is modified to call HaveCoin sometimes before and sometimes after AccessCoin. A further change is needed because the semantics for GetCoin slightly changed, causing a pruned entry in the parent cache to not be pulled into the child in FetchCoin.