aboutsummaryrefslogtreecommitdiff
path: root/src/blockchain_db
Commit message (Collapse)AuthorAgeFilesLines
* updated copyright yearRiccardo Spagni2015-12-311-1/+1
|
* fixed copyrights with bad year referencesRiccardo Spagni2015-12-317-7/+7
|
* 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-266-0/+32
|/
* Merge pull request #565Riccardo Spagni2015-12-262-0/+8
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-252-0/+8
| | | | | | | | | | | | 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.
* | BlockchainDB: Remove txs in reverse orderwarptangent2015-12-241-3/+5
| | | | | | | | | | | | | | | | Data should be removed in the reverse order it was added. Not doing so breaks assumptions and can cause problems in other DB implementations. This matches the order of tx removal in blockchain_storage::purge_block_data_from_blockchain.
* | 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.
* Add missing semicolons after log statementsmoneromooo-monero2015-12-191-3/+3
|
* Replace tabs with two spaces for consistency with rest of codebasewarptangent2015-12-154-265/+265
| | | | 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-132-4/+69
|\ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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_bdb: implement BlockchainBDB::resetmoneromooo-monero2015-12-131-1/+40
| | | | | | | | | | | | It is needed by the core tests
| * | db_lmdb: create all needed directories, not just the leaf onemoneromooo-monero2015-12-131-1/+1
| | |
| * | db_bdb: 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()
* Merge pull request #524Riccardo Spagni2015-12-081-3/+3
|\ | | | | | | 1c8262c db_bdb: move log_set_config call before open (moneromooo-monero)
| * db_bdb: move log_set_config call before openmoneromooo-monero2015-12-071-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a precaution for older Berkeley DB versions. - smooth reports an issue running with 4.7: DB_ENV->log_set_config: DB_LOG_IN_MEMORY: method not permitted after handle's open method - this works just fine with 5.3 - we do not use DB_LOG_IN_MEMORY, but we use DB_LOG_AUTO_REMOVE - libdb docs say some flags must be set before open, and some may be set at any time, but never say some must be set after open - moving the call to log_set_config before open works with 5.3 Therefore, it seems best to move the call before open.
* | Merge pull request #523Riccardo Spagni2015-12-081-0/+34
|\ \ | | | | | | | | | 8620b31 db_bdb: support for libdb without DB_FORCESYNC (moneromooo-monero)
| * | db_bdb: support for libdb without DB_FORCESYNCmoneromooo-monero2015-12-071-0/+34
| |/
* / blockchain_db: fixup missing key images in early DB versionmoneromooo-monero2015-12-066-0/+602
|/ | | | | | | | | | | 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.
* blockchain_db: make the indexing base a BlockchainDB virtual functionmoneromooo-monero2015-12-052-0/+5
|
* db_bdb: read 32 bit heights from keysmoneromooo-monero2015-12-041-1/+1
| | | | | Keys in Berkeley DB are 32 bits. We don't want to read random bits in the high part.
* Revert "db_bdb: record numbers for recno databases start at 1"moneromooo-monero2015-11-131-3/+3
| | | | | | | | | | It looks like some of the indices passed to the DB access functions are already bumped by 1. Moreover, the existing code was not throwing DB errors with 0 keys, and this is unlikely if it really was using 0 keys. Last, this patch broke sync from scratch in at least one case. So I'm calling it bad and reverting it. This reverts commit bfc97401ae81bb30278a318de7f048c653bf6582.
* Remove some old/obsolete/unused codemoneromooo-monero2015-10-275-156/+0
| | | | git history's here if needed to get any of this back
* db_bdb: add versioning, to detect incompatible format changesmoneromooo-monero2015-10-262-0/+83
|
* 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-255-0/+294
|
* db_bdb: record numbers for recno databases start at 1moneromooo-monero2015-10-251-3/+3
|
* db_bdb: DB_KEYEMPTY is also not found for non-top recon fieldsmoneromooo-monero2015-10-251-2/+2
|
* blockchain_db: use the DNE exceptions where appropriatemoneromooo-monero2015-10-252-17/+19
|
* db_bdb: fix hard fork keysmoneromooo-monero2015-10-041-4/+4
| | | | | Berkeley DB requires RECNO keys to be 32 bits, and forbids a key value of 0.
* hardfork: most state now saved to the DBmoneromooo-monero2015-09-205-0/+224
| | | | | There will be a delay on first load of an existing blockchain as it gets reparsed for this state data.
* blockchain_db: match tx addition semantics to original codemoneromooo-monero2015-08-111-8/+24
| | | | | | | The original code removed key images from a tx from the blockchain when an non to-key nor gen input was found in that tx. Additionally, the remainder of the tx data was added to the blockchain only after the double spend check passed.
* Merge pull request #364Riccardo Spagni2015-08-101-10/+7
|\ | | | | | | 533acc3 blockchain_db: store key images for tx without outputs too (moneromooo-monero)
| * blockchain_db: store key images for tx without outputs toomoneromooo-monero2015-08-091-10/+7
| |
* | Merge pull request #363Riccardo Spagni2015-08-105-34/+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-095-34/+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-157-604/+1004
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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).