Use const where appropriate in tx_pool
This commit is contained in:
parent
9872d205ff
commit
4d25350a82
3 changed files with 36 additions and 50 deletions
|
@ -452,7 +452,8 @@ namespace cryptonote
|
||||||
//-----------------------------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------------------------
|
||||||
bool core::get_pool_transactions(std::list<transaction>& txs)
|
bool core::get_pool_transactions(std::list<transaction>& txs)
|
||||||
{
|
{
|
||||||
return m_mempool.get_transactions(txs);
|
m_mempool.get_transactions(txs);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
//-----------------------------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------------------------
|
||||||
bool core::get_short_chain_history(std::list<crypto::hash>& ids)
|
bool core::get_short_chain_history(std::list<crypto::hash>& ids)
|
||||||
|
|
|
@ -204,22 +204,20 @@ namespace cryptonote
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------
|
||||||
size_t tx_memory_pool::get_transactions_count()
|
size_t tx_memory_pool::get_transactions_count() const
|
||||||
{
|
{
|
||||||
CRITICAL_REGION_LOCAL(m_transactions_lock);
|
CRITICAL_REGION_LOCAL(m_transactions_lock);
|
||||||
return m_transactions.size();
|
return m_transactions.size();
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------
|
||||||
bool tx_memory_pool::get_transactions(std::list<transaction>& txs)
|
void tx_memory_pool::get_transactions(std::list<transaction>& txs) const
|
||||||
{
|
{
|
||||||
CRITICAL_REGION_LOCAL(m_transactions_lock);
|
CRITICAL_REGION_LOCAL(m_transactions_lock);
|
||||||
BOOST_FOREACH(const auto& tx_vt, m_transactions)
|
BOOST_FOREACH(const auto& tx_vt, m_transactions)
|
||||||
txs.push_back(tx_vt.second.tx);
|
txs.push_back(tx_vt.second.tx);
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------
|
||||||
bool tx_memory_pool::get_transaction(const crypto::hash& id, transaction& tx)
|
bool tx_memory_pool::get_transaction(const crypto::hash& id, transaction& tx) const
|
||||||
{
|
{
|
||||||
CRITICAL_REGION_LOCAL(m_transactions_lock);
|
CRITICAL_REGION_LOCAL(m_transactions_lock);
|
||||||
auto it = m_transactions.find(id);
|
auto it = m_transactions.find(id);
|
||||||
|
@ -239,7 +237,7 @@ namespace cryptonote
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------
|
||||||
bool tx_memory_pool::have_tx(const crypto::hash &id)
|
bool tx_memory_pool::have_tx(const crypto::hash &id) const
|
||||||
{
|
{
|
||||||
CRITICAL_REGION_LOCAL(m_transactions_lock);
|
CRITICAL_REGION_LOCAL(m_transactions_lock);
|
||||||
if(m_transactions.count(id))
|
if(m_transactions.count(id))
|
||||||
|
@ -247,7 +245,7 @@ namespace cryptonote
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------
|
||||||
bool tx_memory_pool::have_tx_keyimges_as_spent(const transaction& tx)
|
bool tx_memory_pool::have_tx_keyimges_as_spent(const transaction& tx) const
|
||||||
{
|
{
|
||||||
CRITICAL_REGION_LOCAL(m_transactions_lock);
|
CRITICAL_REGION_LOCAL(m_transactions_lock);
|
||||||
BOOST_FOREACH(const auto& in, tx.vin)
|
BOOST_FOREACH(const auto& in, tx.vin)
|
||||||
|
@ -259,23 +257,23 @@ namespace cryptonote
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------
|
||||||
bool tx_memory_pool::have_tx_keyimg_as_spent(const crypto::key_image& key_im)
|
bool tx_memory_pool::have_tx_keyimg_as_spent(const crypto::key_image& key_im) const
|
||||||
{
|
{
|
||||||
CRITICAL_REGION_LOCAL(m_transactions_lock);
|
CRITICAL_REGION_LOCAL(m_transactions_lock);
|
||||||
return m_spent_key_images.end() != m_spent_key_images.find(key_im);
|
return m_spent_key_images.end() != m_spent_key_images.find(key_im);
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------
|
||||||
void tx_memory_pool::lock()
|
void tx_memory_pool::lock() const
|
||||||
{
|
{
|
||||||
m_transactions_lock.lock();
|
m_transactions_lock.lock();
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------
|
||||||
void tx_memory_pool::unlock()
|
void tx_memory_pool::unlock() const
|
||||||
{
|
{
|
||||||
m_transactions_lock.unlock();
|
m_transactions_lock.unlock();
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------
|
||||||
bool tx_memory_pool::is_transaction_ready_to_go(tx_details& txd)
|
bool tx_memory_pool::is_transaction_ready_to_go(tx_details& txd) const
|
||||||
{
|
{
|
||||||
//not the best implementation at this time, sorry :(
|
//not the best implementation at this time, sorry :(
|
||||||
//check is ring_signature already checked ?
|
//check is ring_signature already checked ?
|
||||||
|
@ -339,38 +337,25 @@ namespace cryptonote
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------
|
||||||
std::string tx_memory_pool::print_pool(bool short_format)
|
std::string tx_memory_pool::print_pool(bool short_format) const
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
CRITICAL_REGION_LOCAL(m_transactions_lock);
|
CRITICAL_REGION_LOCAL(m_transactions_lock);
|
||||||
BOOST_FOREACH(transactions_container::value_type& txe, m_transactions)
|
for (const transactions_container::value_type& txe : m_transactions) {
|
||||||
{
|
const tx_details& txd = txe.second;
|
||||||
if(short_format)
|
ss << "id: " << txe.first << std::endl;
|
||||||
{
|
if (!short_format) {
|
||||||
tx_details& txd = txe.second;
|
ss << obj_to_json_str(*const_cast<transaction*>(&txd.tx)) << std::endl;
|
||||||
ss << "id: " << txe.first << ENDL
|
}
|
||||||
<< "blob_size: " << txd.blob_size << ENDL
|
ss << "blob_size: " << txd.blob_size << std::endl
|
||||||
<< "fee: " << txd.fee << ENDL
|
<< "fee: " << print_money(txd.fee) << std::endl
|
||||||
<< "kept_by_block: " << (txd.kept_by_block ? "true":"false") << ENDL
|
<< "kept_by_block: " << (txd.kept_by_block ? 'T' : 'F') << std::endl
|
||||||
<< "max_used_block_height: " << txd.max_used_block_height << ENDL
|
<< "max_used_block_height: " << txd.max_used_block_height << std::endl
|
||||||
<< "max_used_block_id: " << txd.max_used_block_id << ENDL
|
<< "max_used_block_id: " << txd.max_used_block_id << std::endl
|
||||||
<< "last_failed_height: " << txd.last_failed_height << ENDL
|
<< "last_failed_height: " << txd.last_failed_height << std::endl
|
||||||
<< "last_failed_id: " << txd.last_failed_id << ENDL;
|
<< "last_failed_id: " << txd.last_failed_id << std::endl;
|
||||||
}else
|
|
||||||
{
|
|
||||||
tx_details& txd = txe.second;
|
|
||||||
ss << "id: " << txe.first << ENDL
|
|
||||||
<< obj_to_json_str(txd.tx) << ENDL
|
|
||||||
<< "blob_size: " << txd.blob_size << ENDL
|
|
||||||
<< "fee: " << txd.fee << ENDL
|
|
||||||
<< "kept_by_block: " << (txd.kept_by_block ? "true":"false") << ENDL
|
|
||||||
<< "max_used_block_height: " << txd.max_used_block_height << ENDL
|
|
||||||
<< "max_used_block_id: " << txd.max_used_block_id << ENDL
|
|
||||||
<< "last_failed_height: " << txd.last_failed_height << ENDL
|
|
||||||
<< "last_failed_id: " << txd.last_failed_id << ENDL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------
|
||||||
|
|
|
@ -35,22 +35,22 @@ namespace cryptonote
|
||||||
//gets tx and remove it from pool
|
//gets tx and remove it from pool
|
||||||
bool take_tx(const crypto::hash &id, transaction &tx, size_t& blob_size, uint64_t& fee);
|
bool take_tx(const crypto::hash &id, transaction &tx, size_t& blob_size, uint64_t& fee);
|
||||||
|
|
||||||
bool have_tx(const crypto::hash &id);
|
bool have_tx(const crypto::hash &id) const;
|
||||||
bool on_blockchain_inc(uint64_t new_block_height, const crypto::hash& top_block_id);
|
bool on_blockchain_inc(uint64_t new_block_height, const crypto::hash& top_block_id);
|
||||||
bool on_blockchain_dec(uint64_t new_block_height, const crypto::hash& top_block_id);
|
bool on_blockchain_dec(uint64_t new_block_height, const crypto::hash& top_block_id);
|
||||||
void on_idle();
|
void on_idle();
|
||||||
|
|
||||||
void lock();
|
void lock() const;
|
||||||
void unlock();
|
void unlock() const;
|
||||||
|
|
||||||
// load/store operations
|
// load/store operations
|
||||||
bool init(const std::string& config_folder);
|
bool init(const std::string& config_folder);
|
||||||
bool deinit();
|
bool deinit();
|
||||||
bool fill_block_template(block &bl, size_t median_size, uint64_t already_generated_coins, size_t &total_size, uint64_t &fee);
|
bool fill_block_template(block &bl, size_t median_size, uint64_t already_generated_coins, size_t &total_size, uint64_t &fee);
|
||||||
bool get_transactions(std::list<transaction>& txs);
|
void get_transactions(std::list<transaction>& txs) const;
|
||||||
bool get_transaction(const crypto::hash& h, transaction& tx);
|
bool get_transaction(const crypto::hash& h, transaction& tx) const;
|
||||||
size_t get_transactions_count();
|
size_t get_transactions_count() const;
|
||||||
std::string print_pool(bool short_format);
|
std::string print_pool(bool short_format) const;
|
||||||
|
|
||||||
/*bool flush_pool(const std::strig& folder);
|
/*bool flush_pool(const std::strig& folder);
|
||||||
bool inflate_pool(const std::strig& folder);*/
|
bool inflate_pool(const std::strig& folder);*/
|
||||||
|
@ -83,17 +83,17 @@ namespace cryptonote
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool remove_stuck_transactions();
|
bool remove_stuck_transactions();
|
||||||
bool have_tx_keyimg_as_spent(const crypto::key_image& key_im);
|
bool have_tx_keyimg_as_spent(const crypto::key_image& key_im) const;
|
||||||
bool have_tx_keyimges_as_spent(const transaction& tx);
|
bool have_tx_keyimges_as_spent(const transaction& tx) const;
|
||||||
bool remove_transaction_keyimages(const transaction& tx);
|
bool remove_transaction_keyimages(const transaction& tx);
|
||||||
static bool have_key_images(const std::unordered_set<crypto::key_image>& kic, const transaction& tx);
|
static bool have_key_images(const std::unordered_set<crypto::key_image>& kic, const transaction& tx);
|
||||||
static bool append_key_images(std::unordered_set<crypto::key_image>& kic, const transaction& tx);
|
static bool append_key_images(std::unordered_set<crypto::key_image>& kic, const transaction& tx);
|
||||||
|
|
||||||
bool is_transaction_ready_to_go(tx_details& txd);
|
bool is_transaction_ready_to_go(tx_details& txd) const;
|
||||||
typedef std::unordered_map<crypto::hash, tx_details > transactions_container;
|
typedef std::unordered_map<crypto::hash, tx_details > transactions_container;
|
||||||
typedef std::unordered_map<crypto::key_image, std::unordered_set<crypto::hash> > key_images_container;
|
typedef std::unordered_map<crypto::key_image, std::unordered_set<crypto::hash> > key_images_container;
|
||||||
|
|
||||||
epee::critical_section m_transactions_lock;
|
mutable epee::critical_section m_transactions_lock;
|
||||||
transactions_container m_transactions;
|
transactions_container m_transactions;
|
||||||
key_images_container m_spent_key_images;
|
key_images_container m_spent_key_images;
|
||||||
epee::math_helper::once_a_time_seconds<30> m_remove_stuck_tx_interval;
|
epee::math_helper::once_a_time_seconds<30> m_remove_stuck_tx_interval;
|
||||||
|
|
Loading…
Reference in a new issue