diff --git a/src/cryptonote_core/tx_pool.cpp b/src/cryptonote_core/tx_pool.cpp index 1aa228dde..d7c31efd5 100644 --- a/src/cryptonote_core/tx_pool.cpp +++ b/src/cryptonote_core/tx_pool.cpp @@ -799,7 +799,6 @@ namespace cryptonote CRITICAL_REGION_LOCAL(m_transactions_lock); CRITICAL_REGION_LOCAL1(m_blockchain); - LockedTXN lock(m_blockchain.get_db()); txs.reserve(m_blockchain.get_txpool_tx_count()); m_blockchain.for_all_txpool_txes([this, now, &txs, &change_timestamps, &next_check](const crypto::hash &txid, const txpool_tx_meta_t &meta, const cryptonote::blobdata_ref *){ // 0 fee transactions are never relayed @@ -850,16 +849,32 @@ namespace cryptonote return true; }, false, relay_category::relayable); - for (auto& elem : change_timestamps) + if (!change_timestamps.empty()) { - /* These transactions are still in forward or stem state, so the field - represents the next time a relay should be attempted. Will be - overwritten when the state is upgraded to stem, fluff or block. This - function is only called every ~2 minutes, so this resetting should be - unnecessary, but is primarily a precaution against potential changes - to the callback routines. */ - elem.second.last_relayed_time = now + get_relay_delay(elem.second.last_relayed_time, elem.second.receive_time); - m_blockchain.update_txpool_tx(elem.first, elem.second); + LockedTXN db_lock(m_blockchain.get_db()); + bool made_an_update = false; + for (auto& elem : change_timestamps) + { + /* These transactions are still in forward or stem state, so the field + represents the next time a relay should be attempted. Will be + overwritten when the state is upgraded to stem, fluff or block. This + function is only called every ~2 minutes, so this resetting should be + unnecessary, but is primarily a precaution against potential changes + to the callback routines. */ + elem.second.last_relayed_time = now + get_relay_delay(elem.second.last_relayed_time, elem.second.receive_time); + try + { + m_blockchain.update_txpool_tx(elem.first, elem.second); + made_an_update = true; + } + catch (...) + { + MDEBUG("Got an exception while updating txpool meta for relayable tx " << elem.first << ", ignoring..."); + continue; + } + } + if (made_an_update) + db_lock.commit(); } m_next_check = time_t(next_check);