diff options
author | Riccardo Spagni <ric@spagni.net> | 2017-10-15 17:23:50 +0200 |
---|---|---|
committer | Riccardo Spagni <ric@spagni.net> | 2017-10-15 17:23:50 +0200 |
commit | 5ea20d694430d6db9d4721137bd1165b1fa3f6ec (patch) | |
tree | 3cfc2a7adc6c562c39fe1f6e2a690b7dc7896b32 /src/blockchain_utilities | |
parent | Merge pull request #2056 (diff) | |
parent | precomputed block hashes are now in blocks of N (currently 256) (diff) | |
download | monero-5ea20d694430d6db9d4721137bd1165b1fa3f6ec.tar.xz |
Merge pull request #2469
7adceee6 precomputed block hashes are now in blocks of N (currently 256) (moneromooo-monero)
Diffstat (limited to 'src/blockchain_utilities')
-rw-r--r-- | src/blockchain_utilities/blockchain_import.cpp | 20 | ||||
-rw-r--r-- | src/blockchain_utilities/blocksdat_file.cpp | 14 | ||||
-rw-r--r-- | src/blockchain_utilities/blocksdat_file.h | 1 |
3 files changed, 32 insertions, 3 deletions
diff --git a/src/blockchain_utilities/blockchain_import.cpp b/src/blockchain_utilities/blockchain_import.cpp index d6302ea1d..895ea9147 100644 --- a/src/blockchain_utilities/blockchain_import.cpp +++ b/src/blockchain_utilities/blockchain_import.cpp @@ -169,6 +169,26 @@ int check_flush(cryptonote::core &core, std::list<block_complete_entry> &blocks, if (!force && blocks.size() < db_batch_size) return 0; + // wait till we can verify a full HOH without extra, for speed + uint64_t new_height = core.get_blockchain_storage().get_db().height() + blocks.size(); + if (!force && new_height % HASH_OF_HASHES_STEP) + return 0; + + std::list<crypto::hash> hashes; + for (const auto &b: blocks) + { + cryptonote::block block; + if (!parse_and_validate_block_from_blob(b.block, block)) + { + MERROR("Failed to parse block: " + << epee::string_tools::pod_to_hex(get_blob_hash(b.block))); + core.cleanup_handle_incoming_blocks(); + return 1; + } + hashes.push_back(cryptonote::get_block_hash(block)); + } + core.prevalidate_block_hashes(core.get_blockchain_storage().get_db().height(), hashes); + core.prepare_handle_incoming_blocks(blocks); for(const block_complete_entry& block_entry: blocks) diff --git a/src/blockchain_utilities/blocksdat_file.cpp b/src/blockchain_utilities/blocksdat_file.cpp index 63224225f..32e93345e 100644 --- a/src/blockchain_utilities/blocksdat_file.cpp +++ b/src/blockchain_utilities/blocksdat_file.cpp @@ -82,7 +82,7 @@ bool BlocksdatFile::open_writer(const boost::filesystem::path& file_path, uint64 bool BlocksdatFile::initialize_file(uint64_t block_stop) { - const uint32_t nblocks = block_stop + 1; + const uint32_t nblocks = (block_stop + 1) / HASH_OF_HASHES_STEP; unsigned char nblocksc[4]; nblocksc[0] = nblocks & 0xff; @@ -101,8 +101,16 @@ bool BlocksdatFile::initialize_file(uint64_t block_stop) void BlocksdatFile::write_block(const crypto::hash& block_hash) { - const std::string data(block_hash.data, sizeof(block_hash)); - *m_raw_data_file << data; + m_hashes.push_back(block_hash); + while (m_hashes.size() >= HASH_OF_HASHES_STEP) + { + crypto::hash hash; + crypto::cn_fast_hash(m_hashes.data(), HASH_OF_HASHES_STEP * sizeof(crypto::hash), hash); + memmove(m_hashes.data(), m_hashes.data() + HASH_OF_HASHES_STEP * sizeof(crypto::hash), (m_hashes.size() - HASH_OF_HASHES_STEP) * sizeof(crypto::hash)); + m_hashes.resize(m_hashes.size() - HASH_OF_HASHES_STEP); + const std::string data(hash.data, sizeof(hash)); + *m_raw_data_file << data; + } } bool BlocksdatFile::close() diff --git a/src/blockchain_utilities/blocksdat_file.h b/src/blockchain_utilities/blocksdat_file.h index 0a5913058..d43811772 100644 --- a/src/blockchain_utilities/blocksdat_file.h +++ b/src/blockchain_utilities/blocksdat_file.h @@ -76,4 +76,5 @@ protected: private: uint64_t m_cur_height; // tracks current height during export + std::vector<crypto::hash> m_hashes; }; |