From 0263dd2d23679cf5564d34011de02d5fd5f96650 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sun, 31 Jul 2016 20:09:44 +0100 Subject: core: add some locking around pool use --- src/cryptonote_core/blockchain.cpp | 4 +++- src/cryptonote_core/tx_pool.cpp | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index 547f2d4c2..f6f56b086 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -2869,6 +2869,8 @@ void Blockchain::return_tx_to_pool(const std::vector &txs) //------------------------------------------------------------------ bool Blockchain::flush_txes_from_pool(const std::list &txids) { + CRITICAL_REGION_LOCAL(m_tx_pool); + bool res = true; for (const auto &txid: txids) { @@ -2877,7 +2879,7 @@ bool Blockchain::flush_txes_from_pool(const std::list &txids) uint64_t fee; bool relayed; LOG_PRINT_L1("Removing txid " << txid << " from the pool"); - if(!m_tx_pool.take_tx(txid, tx, blob_size, fee, relayed)) + if(m_tx_pool.have_tx(txid) && !m_tx_pool.take_tx(txid, tx, blob_size, fee, relayed)) { LOG_PRINT_L0("Failed to remove txid " << txid << " from the pool"); res = false; diff --git a/src/cryptonote_core/tx_pool.cpp b/src/cryptonote_core/tx_pool.cpp index e7d3908e5..dcbb7cc04 100644 --- a/src/cryptonote_core/tx_pool.cpp +++ b/src/cryptonote_core/tx_pool.cpp @@ -662,6 +662,7 @@ namespace cryptonote //--------------------------------------------------------------------------------- size_t tx_memory_pool::validate(uint8_t version) { + CRITICAL_REGION_LOCAL(m_transactions_lock); size_t n_removed = 0; size_t tx_size_limit = (version < 2 ? TRANSACTION_SIZE_LIMIT_V1 : TRANSACTION_SIZE_LIMIT_V2); for (auto it = m_transactions.begin(); it != m_transactions.end(); ) { -- cgit v1.2.3