aboutsummaryrefslogtreecommitdiff
path: root/src/blockchain_utilities
diff options
context:
space:
mode:
Diffstat (limited to 'src/blockchain_utilities')
-rw-r--r--src/blockchain_utilities/blockchain_import.cpp16
-rw-r--r--src/blockchain_utilities/blocksdat_file.cpp15
-rw-r--r--src/blockchain_utilities/blocksdat_file.h3
3 files changed, 23 insertions, 11 deletions
diff --git a/src/blockchain_utilities/blockchain_import.cpp b/src/blockchain_utilities/blockchain_import.cpp
index cb9154f29..bc7489a0d 100644
--- a/src/blockchain_utilities/blockchain_import.cpp
+++ b/src/blockchain_utilities/blockchain_import.cpp
@@ -191,7 +191,7 @@ int check_flush(cryptonote::core &core, std::vector<block_complete_entry> &block
}
hashes.push_back(cryptonote::get_block_hash(block));
}
- core.prevalidate_block_hashes(core.get_blockchain_storage().get_db().height(), hashes);
+ core.prevalidate_block_hashes(core.get_blockchain_storage().get_db().height(), hashes, {});
std::vector<block> pblocks;
if (!core.prepare_handle_incoming_blocks(blocks, pblocks))
@@ -217,7 +217,7 @@ int check_flush(cryptonote::core &core, std::vector<block_complete_entry> &block
if(tvc.m_verifivation_failed)
{
MERROR("transaction verification failed, tx_id = "
- << epee::string_tools::pod_to_hex(get_blob_hash(tx_blob)));
+ << epee::string_tools::pod_to_hex(get_blob_hash(tx_blob.blob)));
core.cleanup_handle_incoming_blocks();
return 1;
}
@@ -468,13 +468,17 @@ int import_from_file(cryptonote::core& core, const std::string& import_file_path
{
cryptonote::blobdata block;
cryptonote::block_to_blob(bp.block, block);
- std::vector<cryptonote::blobdata> txs;
+ std::vector<tx_blob_entry> txs;
for (const auto &tx: bp.txs)
{
- txs.push_back(cryptonote::blobdata());
- cryptonote::tx_to_blob(tx, txs.back());
+ txs.push_back({cryptonote::blobdata(), crypto::null_hash});
+ cryptonote::tx_to_blob(tx, txs.back().blob);
}
- blocks.push_back({block, txs});
+ block_complete_entry bce;
+ bce.pruned = false;
+ bce.block = std::move(block);
+ bce.txs = std::move(txs);
+ blocks.push_back(bce);
int ret = check_flush(core, blocks, false);
if (ret)
{
diff --git a/src/blockchain_utilities/blocksdat_file.cpp b/src/blockchain_utilities/blocksdat_file.cpp
index f56ff5f94..df3c6cafc 100644
--- a/src/blockchain_utilities/blocksdat_file.cpp
+++ b/src/blockchain_utilities/blocksdat_file.cpp
@@ -99,17 +99,23 @@ bool BlocksdatFile::initialize_file(uint64_t block_stop)
return true;
}
-void BlocksdatFile::write_block(const crypto::hash& block_hash)
+void BlocksdatFile::write_block(const crypto::hash& block_hash, uint64_t weight)
{
m_hashes.push_back(block_hash);
+ m_weights.push_back(weight);
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, (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;
+ const std::string data_hashes(hash.data, sizeof(hash));
+ *m_raw_data_file << data_hashes;
+ crypto::cn_fast_hash(m_weights.data(), HASH_OF_HASHES_STEP * sizeof(uint64_t), hash);
+ memmove(m_weights.data(), m_weights.data() + HASH_OF_HASHES_STEP, (m_weights.size() - HASH_OF_HASHES_STEP) * sizeof(uint64_t));
+ m_weights.resize(m_weights.size() - HASH_OF_HASHES_STEP);
+ const std::string data_weights(hash.data, sizeof(hash));
+ *m_raw_data_file << data_weights;
}
}
@@ -154,7 +160,8 @@ bool BlocksdatFile::store_blockchain_raw(Blockchain* _blockchain_storage, tx_mem
{
// this method's height refers to 0-based height (genesis block = height 0)
crypto::hash hash = m_blockchain_storage->get_block_id_by_height(m_cur_height);
- write_block(hash);
+ uint64_t weight = m_blockchain_storage->get_db().get_block_weight(m_cur_height);
+ write_block(hash, weight);
if (m_cur_height % NUM_BLOCKS_PER_CHUNK == 0) {
num_blocks_written += NUM_BLOCKS_PER_CHUNK;
}
diff --git a/src/blockchain_utilities/blocksdat_file.h b/src/blockchain_utilities/blocksdat_file.h
index 315713424..72b7afc17 100644
--- a/src/blockchain_utilities/blocksdat_file.h
+++ b/src/blockchain_utilities/blocksdat_file.h
@@ -72,10 +72,11 @@ protected:
bool open_writer(const boost::filesystem::path& file_path, uint64_t block_stop);
bool initialize_file(uint64_t block_stop);
bool close();
- void write_block(const crypto::hash &block_hash);
+ void write_block(const crypto::hash &block_hash, uint64_t weight);
private:
uint64_t m_cur_height; // tracks current height during export
std::vector<crypto::hash> m_hashes;
+ std::vector<uint64_t> m_weights;
};