aboutsummaryrefslogtreecommitdiff
path: root/src/blockchain_db/lmdb
Commit message (Collapse)AuthorAgeFilesLines
...
* BlockchainLMDB: Add sanity check for inconsistent statewarptangent2016-02-131-2/+13
| | | | | This hasn't been known to occur in block-level txn abort, but throw exception if it does.
* BlockchainLMDB: Call destructor on allocated txn if setup failswarptangent2016-02-131-0/+8
|
* BlockchainLMDB: Replace remaining txn pointer NULLs with nullptrwarptangent2016-02-131-9/+9
| | | | For consistency.
* Make HardFork object available to BlockchainDB and derived DB implementationswarptangent2016-02-081-0/+2
| | | | | | This will later allow the HardFork object's DB update functions to be called when the DB transaction that persists across block add/remove is open.
* BlockchainDB/LMDB: Refactor block-scope DB txn handling for add blockwarptangent2016-02-081-19/+1
| | | | Move block-scope txn start and stop from BlockchainLMDB to BlockchainDB.
* BlockchainDB/LMDB/BDB: Extract DB txn functions for block add/removewarptangent2016-02-082-0/+42
|
* BlockchainLMDB: Allow two HardFork functions to update DB during block addwarptangent2016-02-081-4/+4
| | | | Note that this doesn't yet cause them to be called during block add.
* BlockchainLMDB: extract txn macros used during block add/removewarptangent2016-02-081-0/+26
|
* fake_core: Check if hard fork subdbs need reset at startwarptangent2016-02-081-2/+8
|
* blockchain_import: Add --drop-hard-fork commandwarptangent2016-02-082-0/+14
|
* db_lmdb: Continue when tx has no outputswarptangent2016-01-191-4/+6
|
* Fix hf when import with verify offHoward Chu2016-01-152-0/+22
| | | | Delete the hf tables, so the next open will rescan and regenerate
* fixed copyrights with bad year referencesRiccardo Spagni2015-12-312-2/+2
|
* Merge pull request #572Riccardo Spagni2015-12-301-3/+9
|\ | | | | | | | | | | | | b39aae7 Tweak 45800a25e9374e63caaabba05c89585c86acd668 (hyc) 4a5a5ff blockchain: always stop the ioservice before returning (moneromooo-monero) 78b65cf db_lmdb: safety close db at exit (moneromooo-monero) 45800a2 db_lmdb: fix a strdup/delete[] mistmatch (moneromooo-monero)
| * Tweak 45800a25e9374e63caaabba05c89585c86acd668hyc2015-12-291-5/+5
| | | | | | | | trivial cleanup
| * db_lmdb: safety close db at exitmoneromooo-monero2015-12-281-0/+3
| | | | | | | | | | | | Noticed by hyc Also set m_open to false when closed
| * db_lmdb: fix a strdup/delete[] mistmatchmoneromooo-monero2015-12-281-3/+6
| |
* | BlockchainDB: skip fixup check if read-only databasewarptangent2015-12-262-0/+16
|/
* Merge pull request #565Riccardo Spagni2015-12-261-0/+4
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 79beed2 tests: fix various tests by using parameters better suited to monero (moneromooo-monero) d0a8362 tests: fix some double spending tests (moneromooo-monero) 2358d0d tests: use 255 as a "too high" block version (moneromooo-monero) f33a88c blockchain: fix a few block addition bugs (moneromooo-monero) a9ff11c blockchain: fix an off by one error in unlocked time check (moneromooo-monero) f294be3 blockchain: reinstate double spending checks in check_tx_inputs (moneromooo-monero) 737b6d6 blockchain: make some flag twiddling code closer to the original (moneromooo-monero) 81cb0fc blockchain: fix bitflipping test with quantized block rewards (moneromooo-monero) 22ddf09 blockchain: add missing m_tx_pool.on_blockchain_dec (moneromooo-monero) d837c0c blockchain: fix switch to alternative blockchain for more than one block (moneromooo-monero) 5cec076 blockchain: add a missing validity check to rollback_blockchain_switching (moneromooo-monero) 3cabdb5 core: catch exceptions from get_output_key (moneromooo-monero) 5eef645 db: throw when given a non txout_to_key output to add (moneromooo-monero)
| * db: throw when given a non txout_to_key output to addmoneromooo-monero2015-12-251-0/+4
| | | | | | | | | | | | The check was explicit in the original version, so it seems safer to make it explicit here, especially as it is now done implicitely in a different place, away from the original check.
* | BlockchainLMDB: When removing, find amount output index fast by starting at endwarptangent2015-12-241-4/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This improves blockchain reorganization time by allowing one of the more expensive DB lookups when popping a block to not have to seek through a long dup list in the "output_amounts" subdb. This is most noticeable for HDDs. As before, the dup list is still walked if necessary (but in reverse), and the global output index still confirmed to be the one looked for. But under proper use, the result will be found at the end of the dup list, so we start there. Removing an amount output index is always done in the context of popping a block, so the global output index being looked for should be the last one in that amount key's dup list. Even if the txs themselves aren't removed in reverse order (supposed to be according to original implementation), the specified amount output index will still be near the end, because the txs are in the same block. TEST: Pop blocks with blockchain_import. Blocks should be successfully removed with no errors shown. bitmonerod should be able to start syncing from the reduced blockchain height.
* | BlockchainLMDB: Remove tx outputs in reverse orderwarptangent2015-12-241-5/+5
|/ | | | | | | Data should be removed in the reverse order it was added. This matches the order of removal in blockchain_storage::pop_transaction_from_global_index.
* Replace tabs with two spaces for consistency with rest of codebasewarptangent2015-12-152-238/+238
| | | | Remove trailing whitespace in same files.
* db_lmdb: always use a batch tx if possiblemoneromooo-monero2015-12-141-290/+127
| | | | | | Also wrap that code in two prefix/suffix macros so they are easier to use and not forget. Also add consts to returned data casts where applicable.
* Merge pull request #532Riccardo Spagni2015-12-131-68/+74
|\ | | | | | | 79ff6a5 Add LMDB error string to database transaction exception message (warptangent)
| * Add LMDB error string to database transaction exception messagewarptangent2015-12-131-68/+74
| | | | | | | | | | | | | | | | | | | | When throwing an exception from being unable to begin an LMDB transaction, include the reason. It's often been due to a write transaction attempted within a write transaction (batch mode), but there can be other reasons such as write transaction attempted while database was opened read only, or environment's map needs to be resized.
* | Merge pull request #531Riccardo Spagni2015-12-131-2/+28
|\ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | cbded43 core_tests: fix ring_signature_1 tests (moneromooo-monero) c3d208f core_tests: bump default test fee to 0.02 monero (moneromooo-monero) 10da0a0 add a --fakechain argument for tests (moneromooo-monero) eee44e6 unit_tests: fix block reward test using post hard fork settings (moneromooo-monero) 595893f blockchain: log block (not chain) height in "BLOCK SUCCESFULLY ADDED" (moneromooo-monero) 2369968 blockchain: fix off by one in get_blocks (moneromooo-monero) 8af913a db_lmdb: implement BlockchainLMDB::reset (moneromooo-monero) 4833f4f db_bdb: implement BlockchainBDB::reset (moneromooo-monero) 18bf06e tx_pool: fix "minumim" typo in message (moneromooo-monero) 44f1267 tests: fix a typo in test name (moneromooo-monero) 1494557 db_lmdb: create all needed directories, not just the leaf one (moneromooo-monero) 015b68a db_bdb: create all needed directories, not just the leaf one (moneromooo-monero) f141869 tests: remove data-dir argument registration (moneromooo-monero)
| * | db_lmdb: implement BlockchainLMDB::resetmoneromooo-monero2015-12-131-1/+27
| | | | | | | | | | | | It is needed by the core tests
| * | db_lmdb: create all needed directories, not just the leaf onemoneromooo-monero2015-12-131-1/+1
| |/
* / Fix data refs in read-only txnsHoward Chu2015-12-101-16/+42
|/ | | | | | Data is only guaranteed to be valid within the lifetime of a txn. You cannot use data returned from LMDB after the txn ends. Also, fixed a missing txn.commit BlockchainLMDB::get_tx_unlock_time()
* blockchain_db: fixup missing key images in early DB versionmoneromooo-monero2015-12-062-0/+9
| | | | | | | | | | | Early DB versions did not store key images for inputs if the transaction spending them had no outputs (ie, all fee). This is not correct, as this would allow these outputs to be double spent. This was fixed in 533acc30eda7792c802ea8b6417917fa99b8bc2b a few months ago, but databases having synced blocks 2021612 and 685498 with a faulty version will be missing those key images in the spent keys database. This code checks for this, and adds those key images if they are missing.
* Remove some old/obsolete/unused codemoneromooo-monero2015-10-272-124/+0
| | | | git history's here if needed to get any of this back
* db_lmdb: add versioning, to detect incompatible format changesmoneromooo-monero2015-10-262-8/+85
|
* Add functions to iterate through blocks, txes, outputs, key imagesmoneromooo-monero2015-10-252-0/+164
|
* blockchain_db: use the DNE exceptions where appropriatemoneromooo-monero2015-10-251-9/+9
|
* hardfork: most state now saved to the DBmoneromooo-monero2015-09-202-0/+133
| | | | | There will be a delay on first load of an existing blockchain as it gets reparsed for this state data.
* Merge pull request #363Riccardo Spagni2015-08-102-15/+0
|\ | | | | | | | | 4f19e68 blockchain: factor get_num_outpouts(amount) calls (moneromooo-monero) 275894c blockchain: always select random outs using triangular distribution (moneromooo-monero)
| * blockchain: always select random outs using triangular distributionmoneromooo-monero2015-08-092-15/+0
| | | | | | | | | | | | | | It was only used by the older blockchain_storage. We also move the code to the calling blockchain level, to avoid replicating the code in every DB implementation. This also makes the get_random_out method obsolete, and we delete it.
* | Fix estimation of batch storage size when no blocks existwarptangent2015-08-041-11/+28
|/ | | | | | | | | | | | | | | | | | | | | | If there's no blocks in database (m_height == 0): Don't assign incorrect block range to check. Skip average block size check. Test: Run blockchain_converter with an existing source blockchain.bin and a non-existent LMDB destination database. The converter creates a BlockchainLMDB instance with zero height, due to not being initialized with a genesis block, normally done by Blockchain::init(). While different than the behavior of bitmonerod, blockchain_import, and blockchain_export, the initialization hasn't been strictly necessary. The db batch size estimation normally uses an average block size, or a default minimum block size, whichever is greater. In this case, as there's no existing blocks to check for an average block size, the default should be used.
* Add batch support to BlockchainLMDB::get_output_keywarptangent2015-07-161-6/+12
| | | | | This allows blockchain_import to work with batch and verify modes enabled (the default).
* Removed on_idle() calls to Blockchain::store_blockchain() for lmdb.NoodleDoodleNoodleDoodleNoodleDoodleNoo2015-07-151-4/+3
| | | | Added option to cache tx-input verification results.
* Fixed binary size issue due to embedded checkpoint data.NoodleDoodleNoodleDoodleNoodleDoodleNoo2015-07-151-0/+1
| | | | | Fixed OSX compilation issues due to random lmdb resize points. Fixed infinite loop bug when calling core::get_block_template(..).
* ** CHANGES ARE EXPERIMENTAL (FOR TESTING ONLY)NoodleDoodleNoodleDoodleNoodleDoodleNoo2015-07-152-126/+373
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Bockchain: 1. Optim: Multi-thread long-hash computation when encountering groups of blocks. 2. Optim: Cache verified txs and return result from cache instead of re-checking whenever possible. 3. Optim: Preload output-keys when encoutering groups of blocks. Sort by amount and global-index before bulk querying database and multi-thread when possible. 4. Optim: Disable double spend check on block verification, double spend is already detected when trying to add blocks. 5. Optim: Multi-thread signature computation whenever possible. 6. Patch: Disable locking (recursive mutex) on called functions from check_tx_inputs which causes slowdowns (only seems to happen on ubuntu/VMs??? Reason: TBD) 7. Optim: Removed looped full-tx hash computation when retrieving transactions from pool (???). 8. Optim: Cache difficulty/timestamps (735 blocks) for next-difficulty calculations so that only 2 db reads per new block is needed when a new block arrives (instead of 1470 reads). Berkeley-DB: 1. Fix: 32-bit data errors causing wrong output global indices and failure to send blocks to peers (etc). 2. Fix: Unable to pop blocks on reorganize due to transaction errors. 3. Patch: Large number of transaction aborts when running multi-threaded bulk queries. 4. Patch: Insufficient locks error when running full sync. 5. Patch: Incorrect db stats when returning from an immediate exit from "pop block" operation. 6. Optim: Add bulk queries to get output global indices. 7. Optim: Modified output_keys table to store public_key+unlock_time+height for single transaction lookup (vs 3) 8. Optim: Used output_keys table retrieve public_keys instead of going through output_amounts->output_txs+output_indices->txs->output:public_key 9. Optim: Added thread-safe buffers used when multi-threading bulk queries. 10. Optim: Added support for nosync/write_nosync options for improved performance (*see --db-sync-mode option for details) 11. Mod: Added checkpoint thread and auto-remove-logs option. 12. *Now usable on 32-bit systems like RPI2. LMDB: 1. Optim: Added custom comparison for 256-bit key tables (minor speed-up, TBD: get actual effect) 2. Optim: Modified output_keys table to store public_key+unlock_time+height for single transaction lookup (vs 3) 3. Optim: Used output_keys table retrieve public_keys instead of going through output_amounts->output_txs+output_indices->txs->output:public_key 4. Optim: Added support for sync/writemap options for improved performance (*see --db-sync-mode option for details) 5. Mod: Auto resize to +1GB instead of multiplier x1.5 ETC: 1. Minor optimizations for slow-hash for ARM (RPI2). Incomplete. 2. Fix: 32-bit saturation bug when computing next difficulty on large blocks. [PENDING ISSUES] 1. Berkely db has a very slow "pop-block" operation. This is very noticeable on the RPI2 as it sometimes takes > 10 MINUTES to pop a block during reorganization. This does not happen very often however, most reorgs seem to take a few seconds but it possibly depends on the number of outputs present. TBD. 2. Berkeley db, possible bug "unable to allocate memory". TBD. [NEW OPTIONS] (*Currently all enabled for testing purposes) 1. --fast-block-sync arg=[0:1] (default: 1) a. 0 = Compute long hash per block (may take a while depending on CPU) b. 1 = Skip long-hash and verify blocks based on embedded known good block hashes (faster, minimal CPU dependence) 2. --db-sync-mode arg=[[safe|fast|fastest]:[sync|async]:[nblocks_per_sync]] (default: fastest:async:1000) a. safe = fdatasync/fsync (or equivalent) per stored block. Very slow, but safest option to protect against power-out/crash conditions. b. fast/fastest = Enables asynchronous fdatasync/fsync (or equivalent). Useful for battery operated devices or STABLE systems with UPS and/or systems with battery backed write cache/solid state cache. Fast - Write meta-data but defer data flush. Fastest - Defer meta-data and data flush. Sync - Flush data after nblocks_per_sync and wait. Async - Flush data after nblocks_per_sync but do not wait for the operation to finish. 3. --prep-blocks-threads arg=[n] (default: 4 or system max threads, whichever is lower) Max number of threads to use when computing long-hash in groups. 4. --show-time-stats arg=[0:1] (default: 1) Show benchmark related time stats. 5. --db-auto-remove-logs arg=[0:1] (default: 1) For berkeley-db only. Auto remove logs if enabled. **Note: lmdb and berkeley-db have changes to the tables and are not compatible with official git head version. At the moment, you need a full resync to use this optimized version. [PERFORMANCE COMPARISON] **Some figures are approximations only. Using a baseline machine of an i7-2600K+SSD+(with full pow computation): 1. The optimized lmdb/blockhain core can process blocks up to 585K for ~1.25 hours + download time, so it usually takes 2.5 hours to sync the full chain. 2. The current head with memory can process blocks up to 585K for ~4.2 hours + download time, so it usually takes 5.5 hours to sync the full chain. 3. The current head with lmdb can process blocks up to 585K for ~32 hours + download time and usually takes 36 hours to sync the full chain. Averate procesing times (with full pow computation): lmdb-optimized: 1. tx_ave = 2.5 ms / tx 2. block_ave = 5.87 ms / block memory-official-repo: 1. tx_ave = 8.85 ms / tx 2. block_ave = 19.68 ms / block lmdb-official-repo (0f4a036437fd41a5498ee5e74e2422ea6177aa3e) 1. tx_ave = 47.8 ms / tx 2. block_ave = 64.2 ms / block **Note: The following data denotes processing times only (does not include p2p download time) lmdb-optimized processing times (with full pow computation): 1. Desktop, Quad-core / 8-threads 2600k (8Mb) - 1.25 hours processing time (--db-sync-mode=fastest:async:1000). 2. Laptop, Dual-core / 4-threads U4200 (3Mb) - 4.90 hours processing time (--db-sync-mode=fastest:async:1000). 3. Embedded, Quad-core / 4-threads Z3735F (2x1Mb) - 12.0 hours processing time (--db-sync-mode=fastest:async:1000). lmdb-optimized processing times (with per-block-checkpoint) 1. Desktop, Quad-core / 8-threads 2600k (8Mb) - 10 minutes processing time (--db-sync-mode=fastest:async:1000). berkeley-db optimized processing times (with full pow computation) 1. Desktop, Quad-core / 8-threads 2600k (8Mb) - 1.8 hours processing time (--db-sync-mode=fastest:async:1000). 2. RPI2. Improved from estimated 3 months(???) into 2.5 days (*Need 2AMP supply + Clock:1Ghz + [usb+ssd] to achieve this speed) (--db-sync-mode=fastest:async:1000). berkeley-db optimized processing times (with per-block-checkpoint) 1. RPI2. 12-15 hours (*Need 2AMP supply + Clock:1Ghz + [usb+ssd] to achieve this speed) (--db-sync-mode=fastest:async:1000).
* Experimental BDB workaround optimizationsNoodleDoodleNoodleDoodleNoodleDoodleNoo2015-07-151-0/+5
|
* Check and resize if needed at batch transaction startwarptangent2015-07-122-5/+109
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This currently only affects blockchain_import and blockchain_converter. When the number of blocks expected for the batch transaction is provided, make an estimate of the DB space needed. If not enough free space remains, resize the DB. The estimate is made based on: - the average size of the last 500 blocks, or if larger, a min. block size of 4k - a factor for the expanded size a block occupies in the DB across the sub-dbs/tables - a safety factor (1.7) to allow for a "reasonable" average block size increase over the batch Increase the DB size by whichever is greater: the estimated size needed or a minimum increase size, currently 128 MB. The conservative factors in the estimate help in testing that the resize occurs when needed, and without gratuitous size increases. For common use, the safety factor and minimum increase size could reasonably be increased. For testing, setting DEFAULT_MAPSIZE (blockchain_db/lmdb/db_lmdb.h) to 1 << 27 (128 MB) and recompiling will ensure DB resizes take place sooner and more frequently.
* Optionally allow DB to know expected number of blocks at batch transaction startwarptangent2015-07-112-2/+2
| | | | This will assist in a DB resize check.
* Merge pull request #297Riccardo Spagni2015-05-301-38/+75
|\ | | | | | | | | | | 5680604 Replace hardcoded value with existing constant of same value (warptangent) f37ee2f Update database resize behavior (warptangent) f85cd8e Include database error in more error messages (warptangent)
| * Replace hardcoded value with existing constant of same valuewarptangent2015-05-301-1/+1
| | | | | | | | This was likely the intent.
| * Update database resize behaviorwarptangent2015-05-301-2/+20
| | | | | | | | | | | | | | On an existing database, don't set LMDB map size to be the initial size for a new database. Check if resize is needed at startup.
| * Include database error in more error messageswarptangent2015-05-301-35/+54
| |