mirror of
https://codeberg.org/anoncontributorxmr/monero.git
synced 2024-11-27 05:13:25 +01:00
Merge pull request #4164
8e24533
blockchain: some batch tx scanning speedup (moneromooo-monero)
This commit is contained in:
commit
fd3b71129b
@ -4042,6 +4042,7 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::vector<block_complete
|
|||||||
TIME_MEASURE_START(prepare);
|
TIME_MEASURE_START(prepare);
|
||||||
bool stop_batch;
|
bool stop_batch;
|
||||||
uint64_t bytes = 0;
|
uint64_t bytes = 0;
|
||||||
|
size_t total_txs = 0;
|
||||||
|
|
||||||
// Order of locking must be:
|
// Order of locking must be:
|
||||||
// m_incoming_tx_lock (optional)
|
// m_incoming_tx_lock (optional)
|
||||||
@ -4070,6 +4071,7 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::vector<block_complete
|
|||||||
{
|
{
|
||||||
bytes += tx_blob.size();
|
bytes += tx_blob.size();
|
||||||
}
|
}
|
||||||
|
total_txs += entry.txs.size();
|
||||||
}
|
}
|
||||||
while (!(stop_batch = m_db->batch_start(blocks_entry.size(), bytes))) {
|
while (!(stop_batch = m_db->batch_start(blocks_entry.size(), bytes))) {
|
||||||
m_blockchain_lock.unlock();
|
m_blockchain_lock.unlock();
|
||||||
@ -4129,7 +4131,7 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::vector<block_complete
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
blocks[i].push_back(block);
|
blocks[i].push_back(std::move(block));
|
||||||
std::advance(it, 1);
|
std::advance(it, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4150,7 +4152,7 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::vector<block_complete
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
blocks[i].push_back(block);
|
blocks[i].push_back(std::move(block));
|
||||||
std::advance(it, 1);
|
std::advance(it, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4206,6 +4208,7 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::vector<block_complete
|
|||||||
std::map<uint64_t, std::vector<uint64_t>> offset_map;
|
std::map<uint64_t, std::vector<uint64_t>> offset_map;
|
||||||
// [output] stores all output_data_t for each absolute_offset
|
// [output] stores all output_data_t for each absolute_offset
|
||||||
std::map<uint64_t, std::vector<output_data_t>> tx_map;
|
std::map<uint64_t, std::vector<output_data_t>> tx_map;
|
||||||
|
std::vector<std::pair<cryptonote::transaction, crypto::hash>> txes(total_txs);
|
||||||
|
|
||||||
#define SCAN_TABLE_QUIT(m) \
|
#define SCAN_TABLE_QUIT(m) \
|
||||||
do { \
|
do { \
|
||||||
@ -4215,6 +4218,7 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::vector<block_complete
|
|||||||
} while(0); \
|
} while(0); \
|
||||||
|
|
||||||
// generate sorted tables for all amounts and absolute offsets
|
// generate sorted tables for all amounts and absolute offsets
|
||||||
|
size_t tx_index = 0;
|
||||||
for (const auto &entry : blocks_entry)
|
for (const auto &entry : blocks_entry)
|
||||||
{
|
{
|
||||||
if (m_cancel)
|
if (m_cancel)
|
||||||
@ -4222,12 +4226,15 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::vector<block_complete
|
|||||||
|
|
||||||
for (const auto &tx_blob : entry.txs)
|
for (const auto &tx_blob : entry.txs)
|
||||||
{
|
{
|
||||||
crypto::hash tx_hash = null_hash;
|
if (tx_index >= txes.size())
|
||||||
crypto::hash tx_prefix_hash = null_hash;
|
SCAN_TABLE_QUIT("tx_index is out of sync");
|
||||||
transaction tx;
|
transaction &tx = txes[tx_index].first;
|
||||||
|
crypto::hash &tx_prefix_hash = txes[tx_index].second;
|
||||||
|
++tx_index;
|
||||||
|
|
||||||
if (!parse_and_validate_tx_from_blob(tx_blob, tx, tx_hash, tx_prefix_hash))
|
if (!parse_and_validate_tx_base_from_blob(tx_blob, tx))
|
||||||
SCAN_TABLE_QUIT("Could not parse tx from incoming blocks.");
|
SCAN_TABLE_QUIT("Could not parse tx from incoming blocks.");
|
||||||
|
cryptonote::get_transaction_prefix_hash(tx, tx_prefix_hash);
|
||||||
|
|
||||||
auto its = m_scan_table.find(tx_prefix_hash);
|
auto its = m_scan_table.find(tx_prefix_hash);
|
||||||
if (its != m_scan_table.end())
|
if (its != m_scan_table.end())
|
||||||
@ -4313,9 +4320,8 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::vector<block_complete
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int total_txs = 0;
|
|
||||||
|
|
||||||
// now generate a table for each tx_prefix and k_image hashes
|
// now generate a table for each tx_prefix and k_image hashes
|
||||||
|
tx_index = 0;
|
||||||
for (const auto &entry : blocks_entry)
|
for (const auto &entry : blocks_entry)
|
||||||
{
|
{
|
||||||
if (m_cancel)
|
if (m_cancel)
|
||||||
@ -4323,14 +4329,12 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::vector<block_complete
|
|||||||
|
|
||||||
for (const auto &tx_blob : entry.txs)
|
for (const auto &tx_blob : entry.txs)
|
||||||
{
|
{
|
||||||
crypto::hash tx_hash = null_hash;
|
if (tx_index >= txes.size())
|
||||||
crypto::hash tx_prefix_hash = null_hash;
|
SCAN_TABLE_QUIT("tx_index is out of sync");
|
||||||
transaction tx;
|
const transaction &tx = txes[tx_index].first;
|
||||||
|
const crypto::hash &tx_prefix_hash = txes[tx_index].second;
|
||||||
|
++tx_index;
|
||||||
|
|
||||||
if (!parse_and_validate_tx_from_blob(tx_blob, tx, tx_hash, tx_prefix_hash))
|
|
||||||
SCAN_TABLE_QUIT("Could not parse tx from incoming blocks.");
|
|
||||||
|
|
||||||
++total_txs;
|
|
||||||
auto its = m_scan_table.find(tx_prefix_hash);
|
auto its = m_scan_table.find(tx_prefix_hash);
|
||||||
if (its == m_scan_table.end())
|
if (its == m_scan_table.end())
|
||||||
SCAN_TABLE_QUIT("Tx not found on scan table from incoming blocks.");
|
SCAN_TABLE_QUIT("Tx not found on scan table from incoming blocks.");
|
||||||
|
Loading…
Reference in New Issue
Block a user