aboutsummaryrefslogtreecommitdiff
path: root/src/db.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Fix a few "Uninitialized scalar field" warningsWladimir J. van der Laan2014-08-281-1/+1
| | | | | | Fix a few warnings reported by Coverity. None of these is critical, but making sure that class fields are initialized can avoid heisenbugs.
* Split up util.cpp/hWladimir J. van der Laan2014-08-261-0/+2
| | | | | | | | | | | | | | | | Split up util.cpp/h into: - string utilities (hex, base32, base64): no internal dependencies, no dependency on boost (apart from foreach) - money utilities (parsesmoney, formatmoney) - time utilities (gettime*, sleep, format date): - and the rest (logging, argument parsing, config file parsing) The latter is basically the environment and OS handling, and is stripped of all utility functions, so we may want to rename it to something else than util.cpp/h for clarity (Matt suggested osinterface). Breaks dependency of sha256.cpp on all the things pulled in by util.
* unified and better log/error messages for CDBEnv/CDBPhilip Kaufmann2014-04-011-23/+22
|
* Wrap create_directory calls in try...catch blocks.Brandon Dahler2014-03-311-1/+1
| | | | | | Ignores any exceptions thrown if directory exists, otherwise re-throws exception. Rebased-By: Wladimir J. van der Laan <[email protected]>
* Get rid of C99 PRI?64 usage in source filesWladimir J. van der Laan2014-02-241-1/+1
| | | | | | | | | | | | | | | | | | | | | | | Amend to d5f1e72. It turns out that BerkelyDB was including inttypes.h indirectly, so we cannot fix this with just macros. Trivial commit: apply the following script to all .cpp and .h files: # Middle sed -i 's/"PRIx64"/x/g' "$1" sed -i 's/"PRIu64"/u/g' "$1" sed -i 's/"PRId64"/d/g' "$1" # Initial sed -i 's/PRIx64"/"x/g' "$1" sed -i 's/PRIu64"/"u/g' "$1" sed -i 's/PRId64"/"d/g' "$1" # Trailing sed -i 's/"PRIx64/x"/g' "$1" sed -i 's/"PRIu64/u"/g' "$1" sed -i 's/"PRId64/d"/g' "$1" After this commit, `git grep` for PRI.64 should turn up nothing except the defines in util.h.
* Don't use PRIx64 formatting derives from inttypes.hWladimir J. van der Laan2014-02-221-1/+0
| | | | | | | | | | | | As the tinyformat-based formatting system (introduced in b77dfdc) is type-safe, no special format characters are needed to specify sizes. Tinyformat can support (ignore) the C99 prefixes such as "ll" but chokes on MSVC's inttypes.h defines prefixes such as "I64X". So don't include inttypes.h and define our own for compatibility. (an alternative would be to sweep the entire codebase using sed -i to get rid of the size specifiers but this has less diff impact)
* Copyright header updates s/2013/2014 on files whose last git commit was done ↵gubatron2014-02-091-1/+1
| | | | | | in 2014. contrib/devtools/fix-copyright-headers.py script to be able to perform this maintenance task with ease during the rest of the year, every year. Modifications to contrib/devtools/README.md to document what fix-copyright-headers.py does.
* Remove redundant .c_str()sWladimir J. van der Laan2014-01-231-8/+8
| | | | | | | After the tinyformat switch sprintf() family functions support passing actual std::string objects. Remove unnecessary c_str calls (236 of them) in logging and formatting.
* Move CAddrDB frrom db to netWladimir J. van der Laan2013-12-041-110/+0
| | | | | | | | | This was a leftover from the times in which peers.dat depended in BDB. Other functions in db.cpp still depend on BerkelyDB, to be able to compile without BDB this (small) functionality needs to be moved to another file.
* Cleanup code using forward declarations.Brandon Dahler2013-11-101-9/+14
| | | | | | | | | Use misc methods of avoiding unnecesary header includes. Replace int typedefs with int##_t from stdint.h. Replace PRI64[xdu] with PRI[xdu]64 from inttypes.h. Normalize QT_VERSION ifs where possible. Resolve some indirect dependencies as direct ones. Remove extern declarations from .cpp files.
* Bump Year Number to 2013super32013-10-201-1/+1
|
* Replace printf with LogPrintf / LogPrintGavin Andresen2013-09-181-15/+15
|
* Bugfix: Move boost/version include from db.cpp to walletdb.cpp where ↵Luke Dashjr2013-07-151-1/+0
| | | | BOOST_VERSION is used
* Introduce a CChainParameters singleton class and regtest mode.Mike Hearn2013-06-191-6/+5
| | | | | | | | | | | | | The new class is accessed via the Params() method and holds most things that vary between main, test and regtest networks. The regtest mode has two purposes, one is to run the bitcoind/bitcoinj comparison tool which compares two separate implementations of the Bitcoin protocol looking for divergence. The other is that when run, you get a local node which can mine a single block instantly, which is highly convenient for testing apps during development as there's no need to wait 10 minutes for a block on the testnet.
* Get rid of db dependencies on mainEric Lombrozo2013-06-051-4/+7
|
* Don't attempt to resize vector to negative size.Robert Backhaus2013-05-291-0/+2
|
* Merge pull request #2410 from gmaxwell/salvageharderGavin Andresen2013-05-071-2/+11
|\ | | | | Make explicitly requested salvage operations keep going when there is an error.
| * Make explicitly requested salvage operations keep going when there is an error.Gregory Maxwell2013-03-241-2/+11
| | | | | | | | | | In my tests corrupted wallets would often result in BDB dropping an error just due to duplicate records being found, which appears harmless.
* | Remove database/ after clean shutdownPieter Wuille2013-04-241-4/+6
| |
* | Clean up shutdown processGavin Andresen2013-04-031-5/+3
| |
* | Rename util.h Sleep --> MilliSleepGavin Andresen2013-04-031-1/+1
| | | | | | | | | | | | | | | | Two reasons for this change: 1. Need to always use boost::thread's sleep, even on Windows, so the sleeps can be interrupted (prior code used Windows' built-in Sleep). 2. I always forgot what units the old Sleep took.
* | Don't use -dbcache for BDB anymorePieter Wuille2013-03-291-4/+3
|/ | | | | | | | | | -dbcache was originally used to set the maximum buffer size in the BDB environment, and was later changed to set the chainstate cache and leveldb caches. No need to use it for BDB now that only the wallet remains there. This should reduce memory allocation (but not necessarily memory usage) a bit.
* Bitcoin-Qt: fix crash on Windows caused by CDBEnv::EnvShutdown()Philip Kaufmann2012-11-181-2/+5
| | | | | | | | | - can be triggerd by just adding -proxy=crashme with 0.7.1 - crash occured, when AppInit2() was left with return false; after the first call to bitdb.open() (Step 6 in init) - this is caused by GetDataDir() or .string() in CDBEnv::EnvShutdown() called via the bitdb global destructor - init fDbEnvInit and fMockDb to false in CDBEnv::CDBEnv()
* simplify CDBEnv::Open() / fix small glitchesPhilip Kaufmann2012-11-101-7/+5
| | | | | | | - remove pathEnv from CDBEnv, as this attribute is not needed - change path parameter in ::Open() to a reference - make nDbCache variable an unsigned integer - remove a missplaced ";" behin ::IsMock()
* Remove -detachdb and stop's detach argument.Pieter Wuille2012-11-041-17/+3
| | | | | | | | As the only BDB database left is the wallet, and it is always detached. Also remove IsChainFile() predicate and related chainfile-specific logic.
* Merge pull request #1916 from jgarzik/caddrdb-bugGregory Maxwell2012-10-201-5/+7
|\ | | | | Fix: CAddrMan: verify pchMessageStart file marker, before reading address data
| * CAddrMan: verify pchMessageStart file marker, before reading address dataJeff Garzik2012-10-081-5/+7
| | | | | | | | | | This avoids the case where you read the address data, before noticing it is the wrong network.
* | LevelDB block and coin databasesPieter Wuille2012-10-201-279/+0
| | | | | | | | | | | | | | | | Split off CBlockTreeDB and CCoinsViewDB into txdb-*.{cpp,h} files, implemented by either LevelDB or BDB. Based on code from earlier commits by Mike Hearn in his leveldb branch.
* | Use singleton block tree database instancePieter Wuille2012-10-201-15/+15
| |
* | Prepare database format for multi-stage block processingPieter Wuille2012-10-201-2/+8
| | | | | | | | | | This commit adds a status field and a transaction counter to the block indexes.
* | Automatically reorganize at startup to best known blockPieter Wuille2012-10-201-1/+0
| | | | | | | | | | | | | | | | | | | | | | Given that the block tree database (chain.dat) and the active chain database (coins.dat) are entirely separate now, it becomes legal to swap one with another instance without affecting the other. This commit introduces a check in the startup code that detects the presence of a better chain in chain.dat that has not been activated yet, and does so efficiently (in batch, while reusing the blk???.dat files).
* | Batch block connection during IBDPieter Wuille2012-10-201-24/+65
| | | | | | | | | | | | | | During the initial block download (or -loadblock), delay connection of new blocks a bit, and perform them in a single action. This reduces the load on the database engine, as subsequent blocks often update an earlier block's transaction already.
* | UltraprunePieter Wuille2012-10-201-184/+61
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This switches bitcoin's transaction/block verification logic to use a "coin database", which contains all unredeemed transaction output scripts, amounts and heights. The name ultraprune comes from the fact that instead of a full transaction index, we only (need to) keep an index with unspent outputs. For now, the blocks themselves are kept as usual, although they are only necessary for serving, rescanning and reorganizing. The basic datastructures are CCoins (representing the coins of a single transaction), and CCoinsView (representing a state of the coins database). There are several implementations for CCoinsView. A dummy, one backed by the coins database (coins.dat), one backed by the memory pool, and one that adds a cache on top of it. FetchInputs, ConnectInputs, ConnectBlock, DisconnectBlock, ... now operate on a generic CCoinsView. The block switching logic now builds a single cached CCoinsView with changes to be committed to the database before any changes are made. This means no uncommitted changes are ever read from the database, and should ease the transition to another database layer which does not support transactions (but does support atomic writes), like LevelDB. For the getrawtransaction() RPC call, access to a txid-to-disk index would be preferable. As this index is not necessary or even useful for any other part of the implementation, it is not provided. Instead, getrawtransaction() uses the coin database to find the block height, and then scans that block to find the requested transaction. This is slow, but should suffice for debug purposes.
* | Multiple blocks per filePieter Wuille2012-10-201-1/+24
| | | | | | | | | | | | | | | | | | | | | | Change the block storage layer again, this time with multiple files per block, but tracked by txindex.dat database entries. The file format is exactly the same as the earlier blk00001.dat, but with smaller files (128 MiB for now). The database entries track how many bytes each block file already uses, how many blocks are in it, which range of heights is present and which range of dates.
* | One file per blockPieter Wuille2012-10-201-12/+3
| | | | | | | | | | Refactor of the block storage code, which now stores one file per block. This will allow easier pruning, as blocks can be removed individually.
* | Handle corrupt wallets gracefully.Gavin Andresen2012-10-081-0/+72
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Corrupt wallets used to cause a DB_RUNRECOVERY uncaught exception and a crash. This commit does three things: 1) Runs a BDB verify early in the startup process, and if there is a low-level problem with the database: + Moves the bad wallet.dat to wallet.timestamp.bak + Runs a 'salvage' operation to get key/value pairs, and writes them to a new wallet.dat + Continues with startup. 2) Much more tolerant of serialization errors. All errors in deserialization are reported by tolerated EXCEPT for errors related to reading keypairs or master key records-- those are reported and then shut down, so the user can get help (or recover from a backup). 3) Adds a new -salvagewallet option, which: + Moves the wallet.dat to wallet.timestamp.bak + extracts ONLY keypairs and master keys into a new wallet.dat + soft-sets -rescan, to recreate transaction history This was tested by randomly corrupting testnet wallets using a little python script I wrote (https://gist.github.com/3812689)
* | Handle incompatible BDB environmentsGavin Andresen2012-10-081-12/+7
|/ | | | | | | | | | Before, opening a -datadir that was created with a new version of Berkeley DB would result in an un-caught DB_RUNRECOVERY exception. After these changes, the error is caught and the user is told that there is a problem and is told how to try to recover from it.
* Trim trailing whitespace for src/*.{h,cpp}Jeff Garzik2012-09-181-2/+2
|
* Removed duplicated lockxanatos2012-08-271-4/+1
| | | Around line 167 there is already a LOCK(bitdb.cs_db) that covers everything. Re-locking is useless.
* Run BDB disk-less for test_bitcoinLuke Dashjr2012-07-111-3/+50
|
* Merge pull request #1304 from rebroad/ShowBlockTimestampJeff Garzik2012-07-051-1/+3
|\ | | | | Show block timestamp
| * Show the timestamp for the block.R E Broadley2012-05-291-1/+3
| | | | | | | | wrap lines
* | Remove CTxDB::ReadOwnerTxes.Pieter Wuille2012-06-201-60/+0
|/ | | | It seems it wasn't ever used since 0.1.5.
* Refactor: add IsChainFile helper. LoadBlockIndex() code movement.Jeff Garzik2012-05-231-63/+81
|
* Merge branch 'dbenv' into tmpJeff Garzik2012-05-221-85/+97
|\ | | | | | | | | Conflicts: src/db.cpp
| * Further CDBEnv encapsulation work.Jeff Garzik2012-05-191-13/+11
| |
| * CDB::CDB: properly initialize activeTxn to NULLJeff Garzik2012-05-191-1/+2
| |
| * Remove unused nested BDB transaction supportJeff Garzik2012-05-191-3/+3
| |
| * Encapsulate BDB environment inside new CDBEnv classJeff Garzik2012-05-191-64/+77
| | | | | | | | | | | | | | | | Cleans up and organizes several scattered functions and variables related to the BDB env. Class CDBInit() existed to provide a guaranteed-via-C++-destructor cleanup of the db environment. A formal CDBEnv class provides all of this inside a single wrapper.
* | Prevent crashes due to missing or corrupted database recordsJeff Garzik2012-05-221-2/+14
| | | | | | | | | | | | | | Any problems seen during deserialization will throw an uncaught exception, crashing the entire bitcoin process. Properly return an error instead, so that we may at least log the error and gracefully shutdown other portions of the app.