mirror of
https://github.com/monero-project/monero.git
synced 2025-08-14 08:15:25 -04:00
Merge pull request #4769
5808530f
blockchain: remove unused output_scan_worker parameter (moneromooo-monero)1426209a
blockchain: don't run threads if we have just one function to run (moneromooo-monero)6f7a5fd4
db_lmdb: slight speedup getting array data from the blockchain (moneromooo-monero)99fbe100
db_lmdb: save some string copies for readonly db keys/values (moneromooo-monero)bf31447e
tx_pool: speed up take_tx for transactions from blocks (moneromooo-monero)4f005a77
tx_pool: remove unnecessary get_transaction_hash (moneromooo-monero)593ef598
perf_timer: call reserve on new timer array (moneromooo-monero)6ecc99ad
core: avoid unnecessary tx/blob conversions (moneromooo-monero)00cc1a16
unit_tests: notify test special case for the usual weirdo (moneromooo-monero)
This commit is contained in:
commit
0cc3fc3756
11 changed files with 68 additions and 52 deletions
|
@ -3786,8 +3786,7 @@ bool Blockchain::cleanup_handle_incoming_blocks(bool force_sync)
|
|||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//FIXME: unused parameter txs
|
||||
void Blockchain::output_scan_worker(const uint64_t amount, const std::vector<uint64_t> &offsets, std::vector<output_data_t> &outputs, std::unordered_map<crypto::hash, cryptonote::transaction> &txs) const
|
||||
void Blockchain::output_scan_worker(const uint64_t amount, const std::vector<uint64_t> &offsets, std::vector<output_data_t> &outputs) const
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -4164,21 +4163,19 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::vector<block_complete
|
|||
offsets.second.erase(last, offsets.second.end());
|
||||
}
|
||||
|
||||
// [output] stores all transactions for each tx_out_index::hash found
|
||||
std::vector<std::unordered_map<crypto::hash, cryptonote::transaction>> transactions(amounts.size());
|
||||
|
||||
// gather all the output keys
|
||||
threads = tpool.get_max_concurrency();
|
||||
if (!m_db->can_thread_bulk_indices())
|
||||
threads = 1;
|
||||
|
||||
if (threads > 1)
|
||||
if (threads > 1 && amounts.size() > 1)
|
||||
{
|
||||
tools::threadpool::waiter waiter;
|
||||
|
||||
for (size_t i = 0; i < amounts.size(); i++)
|
||||
{
|
||||
uint64_t amount = amounts[i];
|
||||
tpool.submit(&waiter, boost::bind(&Blockchain::output_scan_worker, this, amount, std::cref(offset_map[amount]), std::ref(tx_map[amount]), std::ref(transactions[i])), true);
|
||||
tpool.submit(&waiter, boost::bind(&Blockchain::output_scan_worker, this, amount, std::cref(offset_map[amount]), std::ref(tx_map[amount])), true);
|
||||
}
|
||||
waiter.wait(&tpool);
|
||||
}
|
||||
|
@ -4187,7 +4184,7 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::vector<block_complete
|
|||
for (size_t i = 0; i < amounts.size(); i++)
|
||||
{
|
||||
uint64_t amount = amounts[i];
|
||||
output_scan_worker(amount, offset_map[amount], tx_map[amount], transactions[i]);
|
||||
output_scan_worker(amount, offset_map[amount], tx_map[amount]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4254,9 +4251,9 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::vector<block_complete
|
|||
return true;
|
||||
}
|
||||
|
||||
void Blockchain::add_txpool_tx(transaction &tx, const txpool_tx_meta_t &meta)
|
||||
void Blockchain::add_txpool_tx(const crypto::hash &txid, const cryptonote::blobdata &blob, const txpool_tx_meta_t &meta)
|
||||
{
|
||||
m_db->add_txpool_tx(tx, meta);
|
||||
m_db->add_txpool_tx(txid, blob, meta);
|
||||
}
|
||||
|
||||
void Blockchain::update_txpool_tx(const crypto::hash &txid, const txpool_tx_meta_t &meta)
|
||||
|
|
|
@ -916,11 +916,9 @@ namespace cryptonote
|
|||
* @param amount the amount
|
||||
* @param offsets the indices (indexed to the amount) of the outputs
|
||||
* @param outputs return-by-reference the outputs collected
|
||||
* @param txs unused, candidate for removal
|
||||
*/
|
||||
void output_scan_worker(const uint64_t amount,const std::vector<uint64_t> &offsets,
|
||||
std::vector<output_data_t> &outputs, std::unordered_map<crypto::hash,
|
||||
cryptonote::transaction> &txs) const;
|
||||
std::vector<output_data_t> &outputs) const;
|
||||
|
||||
/**
|
||||
* @brief computes the "short" and "long" hashes for a set of blocks
|
||||
|
@ -939,7 +937,7 @@ namespace cryptonote
|
|||
*/
|
||||
std::list<std::pair<block_extended_info,std::vector<crypto::hash>>> get_alternative_chains() const;
|
||||
|
||||
void add_txpool_tx(transaction &tx, const txpool_tx_meta_t &meta);
|
||||
void add_txpool_tx(const crypto::hash &txid, const cryptonote::blobdata &blob, const txpool_tx_meta_t &meta);
|
||||
void update_txpool_tx(const crypto::hash &txid, const txpool_tx_meta_t &meta);
|
||||
void remove_txpool_tx(const crypto::hash &txid);
|
||||
uint64_t get_txpool_tx_count(bool include_unrelayed_txes = true) const;
|
||||
|
|
|
@ -909,7 +909,7 @@ namespace cryptonote
|
|||
}
|
||||
|
||||
const size_t weight = get_transaction_weight(results[i].tx, it->size());
|
||||
ok &= add_new_tx(results[i].tx, results[i].hash, results[i].prefix_hash, weight, tvc[i], keeped_by_block, relayed, do_not_relay);
|
||||
ok &= add_new_tx(results[i].tx, results[i].hash, tx_blobs[i], results[i].prefix_hash, weight, tvc[i], keeped_by_block, relayed, do_not_relay);
|
||||
if(tvc[i].m_verifivation_failed)
|
||||
{MERROR_VER("Transaction verification failed: " << results[i].hash);}
|
||||
else if(tvc[i].m_verifivation_impossible)
|
||||
|
@ -1127,7 +1127,7 @@ namespace cryptonote
|
|||
blobdata bl;
|
||||
t_serializable_object_to_blob(tx, bl);
|
||||
size_t tx_weight = get_transaction_weight(tx, bl.size());
|
||||
return add_new_tx(tx, tx_hash, tx_prefix_hash, tx_weight, tvc, keeped_by_block, relayed, do_not_relay);
|
||||
return add_new_tx(tx, tx_hash, bl, tx_prefix_hash, tx_weight, tvc, keeped_by_block, relayed, do_not_relay);
|
||||
}
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
size_t core::get_blockchain_total_transactions() const
|
||||
|
@ -1135,7 +1135,7 @@ namespace cryptonote
|
|||
return m_blockchain_storage.get_total_transactions();
|
||||
}
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
bool core::add_new_tx(transaction& tx, const crypto::hash& tx_hash, const crypto::hash& tx_prefix_hash, size_t tx_weight, tx_verification_context& tvc, bool keeped_by_block, bool relayed, bool do_not_relay)
|
||||
bool core::add_new_tx(transaction& tx, const crypto::hash& tx_hash, const cryptonote::blobdata &blob, const crypto::hash& tx_prefix_hash, size_t tx_weight, tx_verification_context& tvc, bool keeped_by_block, bool relayed, bool do_not_relay)
|
||||
{
|
||||
if (keeped_by_block)
|
||||
get_blockchain_storage().on_new_tx_from_block(tx);
|
||||
|
@ -1153,7 +1153,7 @@ namespace cryptonote
|
|||
}
|
||||
|
||||
uint8_t version = m_blockchain_storage.get_current_hard_fork_version();
|
||||
return m_mempool.add_tx(tx, tx_hash, tx_weight, tvc, keeped_by_block, relayed, do_not_relay, version);
|
||||
return m_mempool.add_tx(tx, tx_hash, blob, tx_weight, tvc, keeped_by_block, relayed, do_not_relay, version);
|
||||
}
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
bool core::relay_txpool_transactions()
|
||||
|
|
|
@ -783,13 +783,14 @@ namespace cryptonote
|
|||
* @copydoc add_new_tx(transaction&, tx_verification_context&, bool)
|
||||
*
|
||||
* @param tx_hash the transaction's hash
|
||||
* @param blob the transaction as a blob
|
||||
* @param tx_prefix_hash the transaction prefix' hash
|
||||
* @param tx_weight the weight of the transaction
|
||||
* @param relayed whether or not the transaction was relayed to us
|
||||
* @param do_not_relay whether to prevent the transaction from being relayed
|
||||
*
|
||||
*/
|
||||
bool add_new_tx(transaction& tx, const crypto::hash& tx_hash, const crypto::hash& tx_prefix_hash, size_t tx_weight, tx_verification_context& tvc, bool keeped_by_block, bool relayed, bool do_not_relay);
|
||||
bool add_new_tx(transaction& tx, const crypto::hash& tx_hash, const cryptonote::blobdata &blob, const crypto::hash& tx_prefix_hash, size_t tx_weight, tx_verification_context& tvc, bool keeped_by_block, bool relayed, bool do_not_relay);
|
||||
|
||||
/**
|
||||
* @brief add a new transaction to the transaction pool
|
||||
|
|
|
@ -111,7 +111,7 @@ namespace cryptonote
|
|||
|
||||
}
|
||||
//---------------------------------------------------------------------------------
|
||||
bool tx_memory_pool::add_tx(transaction &tx, /*const crypto::hash& tx_prefix_hash,*/ const crypto::hash &id, size_t tx_weight, tx_verification_context& tvc, bool kept_by_block, bool relayed, bool do_not_relay, uint8_t version)
|
||||
bool tx_memory_pool::add_tx(transaction &tx, /*const crypto::hash& tx_prefix_hash,*/ const crypto::hash &id, const cryptonote::blobdata &blob, size_t tx_weight, tx_verification_context& tvc, bool kept_by_block, bool relayed, bool do_not_relay, uint8_t version)
|
||||
{
|
||||
// this should already be called with that lock, but let's make it explicit for clarity
|
||||
CRITICAL_REGION_LOCAL(m_transactions_lock);
|
||||
|
@ -247,9 +247,11 @@ namespace cryptonote
|
|||
memset(meta.padding, 0, sizeof(meta.padding));
|
||||
try
|
||||
{
|
||||
if (kept_by_block)
|
||||
m_parsed_tx_cache.insert(std::make_pair(id, tx));
|
||||
CRITICAL_REGION_LOCAL1(m_blockchain);
|
||||
LockedTXN lock(m_blockchain);
|
||||
m_blockchain.add_txpool_tx(tx, meta);
|
||||
m_blockchain.add_txpool_tx(id, blob, meta);
|
||||
if (!insert_key_images(tx, id, kept_by_block))
|
||||
return false;
|
||||
m_txs_by_fee_and_receive_time.emplace(std::pair<double, std::time_t>(fee / (double)tx_weight, receive_time), id);
|
||||
|
@ -288,12 +290,13 @@ namespace cryptonote
|
|||
|
||||
try
|
||||
{
|
||||
if (kept_by_block)
|
||||
m_parsed_tx_cache.insert(std::make_pair(id, tx));
|
||||
CRITICAL_REGION_LOCAL1(m_blockchain);
|
||||
LockedTXN lock(m_blockchain);
|
||||
const crypto::hash txid = get_transaction_hash(tx);
|
||||
m_blockchain.remove_txpool_tx(txid);
|
||||
m_blockchain.add_txpool_tx(tx, meta);
|
||||
if (!insert_key_images(tx, txid, kept_by_block))
|
||||
m_blockchain.remove_txpool_tx(id);
|
||||
m_blockchain.add_txpool_tx(id, blob, meta);
|
||||
if (!insert_key_images(tx, id, kept_by_block))
|
||||
return false;
|
||||
m_txs_by_fee_and_receive_time.emplace(std::pair<double, std::time_t>(fee / (double)tx_weight, receive_time), id);
|
||||
}
|
||||
|
@ -324,9 +327,11 @@ namespace cryptonote
|
|||
{
|
||||
crypto::hash h = null_hash;
|
||||
size_t blob_size = 0;
|
||||
if (!get_transaction_hash(tx, h, blob_size) || blob_size == 0)
|
||||
cryptonote::blobdata bl;
|
||||
t_serializable_object_to_blob(tx, bl);
|
||||
if (bl.size() == 0 || !get_transaction_hash(tx, h))
|
||||
return false;
|
||||
return add_tx(tx, h, get_transaction_weight(tx, blob_size), tvc, keeped_by_block, relayed, do_not_relay, version);
|
||||
return add_tx(tx, h, bl, get_transaction_weight(tx, bl.size()), tvc, keeped_by_block, relayed, do_not_relay, version);
|
||||
}
|
||||
//---------------------------------------------------------------------------------
|
||||
size_t tx_memory_pool::get_txpool_weight() const
|
||||
|
@ -467,7 +472,12 @@ namespace cryptonote
|
|||
return false;
|
||||
}
|
||||
cryptonote::blobdata txblob = m_blockchain.get_txpool_tx_blob(id);
|
||||
if (!parse_and_validate_tx_from_blob(txblob, tx))
|
||||
auto ci = m_parsed_tx_cache.find(id);
|
||||
if (ci != m_parsed_tx_cache.end())
|
||||
{
|
||||
tx = ci->second;
|
||||
}
|
||||
else if (!parse_and_validate_tx_from_blob(txblob, tx))
|
||||
{
|
||||
MERROR("Failed to parse tx from txpool");
|
||||
return false;
|
||||
|
@ -910,6 +920,7 @@ namespace cryptonote
|
|||
{
|
||||
CRITICAL_REGION_LOCAL(m_transactions_lock);
|
||||
m_input_cache.clear();
|
||||
m_parsed_tx_cache.clear();
|
||||
return true;
|
||||
}
|
||||
//---------------------------------------------------------------------------------
|
||||
|
@ -917,6 +928,7 @@ namespace cryptonote
|
|||
{
|
||||
CRITICAL_REGION_LOCAL(m_transactions_lock);
|
||||
m_input_cache.clear();
|
||||
m_parsed_tx_cache.clear();
|
||||
return true;
|
||||
}
|
||||
//---------------------------------------------------------------------------------
|
||||
|
|
|
@ -107,7 +107,7 @@ namespace cryptonote
|
|||
* @param id the transaction's hash
|
||||
* @param tx_weight the transaction's weight
|
||||
*/
|
||||
bool add_tx(transaction &tx, const crypto::hash &id, size_t tx_weight, tx_verification_context& tvc, bool kept_by_block, bool relayed, bool do_not_relay, uint8_t version);
|
||||
bool add_tx(transaction &tx, const crypto::hash &id, const cryptonote::blobdata &blob, size_t tx_weight, tx_verification_context& tvc, bool kept_by_block, bool relayed, bool do_not_relay, uint8_t version);
|
||||
|
||||
/**
|
||||
* @brief add a transaction to the transaction pool
|
||||
|
@ -584,6 +584,8 @@ private:
|
|||
size_t m_txpool_weight;
|
||||
|
||||
mutable std::unordered_map<crypto::hash, std::tuple<bool, tx_verification_context, uint64_t, crypto::hash>> m_input_cache;
|
||||
|
||||
std::unordered_map<crypto::hash, transaction> m_parsed_tx_cache;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue