Merge pull request #1911

91d41090 tx_pool: ensure txes loaded from poolstate.bin have their txid cached (moneromooo-monero)
aaeb164c tx_pool: remove transactions if they're in the blockchain (moneromooo-monero)
558cfc31 core, wallet: faster tx pool scanning (moneromooo-monero)
f065234b core: cache tx and block hashes in the respective classes (moneromooo-monero)
This commit is contained in:
Riccardo Spagni 2017-03-23 11:46:57 +02:00
commit a73a886cb1
No known key found for this signature in database
GPG key ID: 55432DF31CCD4FCD
14 changed files with 312 additions and 109 deletions

View file

@ -1036,7 +1036,13 @@ namespace cryptonote
m_mempool.get_transactions(txs);
return true;
}
//-----------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------
bool core::get_pool_transaction_hashes(std::vector<crypto::hash>& txs) const
{
m_mempool.get_transaction_hashes(txs);
return true;
}
//-----------------------------------------------------------------------------------------------
bool core::get_pool_transaction(const crypto::hash &id, transaction& tx) const
{
return m_mempool.get_transaction(id, tx);

View file

@ -396,6 +396,13 @@ namespace cryptonote
*/
bool get_pool_transactions(std::list<transaction>& txs) const;
/**
* @copydoc tx_memory_pool::get_transactions
*
* @note see tx_memory_pool::get_transactions
*/
bool get_pool_transaction_hashes(std::vector<crypto::hash>& txs) const;
/**
* @copydoc tx_memory_pool::get_transaction
*

View file

@ -132,6 +132,9 @@ namespace cryptonote
//lock
tx.unlock_time = height + CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW;
tx.vin.push_back(in);
tx.hash_valid = tx.blob_size_valid = false;
//LOG_PRINT("MINER_TX generated ok, block_reward=" << print_money(block_reward) << "(" << print_money(block_reward - fee) << "+" << print_money(fee)
// << "), current_block_size=" << current_block_size << ", already_generated_coins=" << already_generated_coins << ", tx_id=" << get_transaction_hash(tx), LOG_LEVEL_2);
return true;
@ -451,6 +454,8 @@ namespace cryptonote
MCINFO("construct_tx", "transaction_created: " << get_transaction_hash(tx) << ENDL << obj_to_json_str(tx) << ENDL);
}
tx.hash_valid = tx.blob_size_valid = false;
return true;
}
//---------------------------------------------------------------
@ -487,6 +492,7 @@ namespace cryptonote
bl.timestamp = 0;
bl.nonce = nonce;
miner::find_nonce_for_given_block(bl, 1, 0);
bl.hash_valid = false;
return true;
}
//---------------------------------------------------------------

View file

@ -423,6 +423,13 @@ namespace cryptonote
txs.push_back(tx_vt.second.tx);
}
//------------------------------------------------------------------
void tx_memory_pool::get_transaction_hashes(std::vector<crypto::hash>& txs) const
{
CRITICAL_REGION_LOCAL(m_transactions_lock);
for(const auto& tx_vt: m_transactions)
txs.push_back(get_transaction_hash(tx_vt.second.tx));
}
//------------------------------------------------------------------
//TODO: investigate whether boolean return is appropriate
bool tx_memory_pool::get_transactions_and_spent_keys_info(std::vector<tx_info>& tx_infos, std::vector<spent_key_image_info>& key_image_infos) const
{
@ -710,13 +717,22 @@ namespace cryptonote
size_t n_removed = 0;
size_t tx_size_limit = get_transaction_size_limit(version);
for (auto it = m_transactions.begin(); it != m_transactions.end(); ) {
bool remove = false;
const crypto::hash &txid = get_transaction_hash(it->second.tx);
if (it->second.blob_size >= tx_size_limit) {
LOG_PRINT_L1("Transaction " << get_transaction_hash(it->second.tx) << " is too big (" << it->second.blob_size << " bytes), removing it from pool");
LOG_PRINT_L1("Transaction " << txid << " is too big (" << it->second.blob_size << " bytes), removing it from pool");
remove = true;
}
else if (m_blockchain.have_tx(txid)) {
LOG_PRINT_L1("Transaction " << txid << " is in the blockchain, removing it from pool");
remove = true;
}
if (remove) {
remove_transaction_keyimages(it->second.tx);
auto sorted_it = find_tx_in_sorted_container(it->first);
auto sorted_it = find_tx_in_sorted_container(txid);
if (sorted_it == m_txs_by_fee_and_receive_time.end())
{
LOG_PRINT_L1("Removing tx " << it->first << " from tx pool, but it was not found in the sorted txs container!");
LOG_PRINT_L1("Removing tx " << txid << " from tx pool, but it was not found in the sorted txs container!");
}
else
{

View file

@ -233,6 +233,13 @@ namespace cryptonote
*/
void get_transactions(std::list<transaction>& txs) const;
/**
* @brief get a list of all transaction hashes in the pool
*
* @param txs return-by-reference the list of transactions
*/
void get_transaction_hashes(std::vector<crypto::hash>& txs) const;
/**
* @brief get information about all transactions and key images in the pool
*