aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_core
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2017-02-21 00:51:13 +0200
committerRiccardo Spagni <ric@spagni.net>2017-02-21 00:51:13 +0200
commit675434ffab89fd22b03398ae2075fee42ed643e0 (patch)
tree3d3b3f12ded75b623db2c96e3d5bcc6ab38e3c56 /src/cryptonote_core
parentMerge pull request #1752 (diff)
parentGet rid of directory lock (diff)
downloadmonero-675434ffab89fd22b03398ae2075fee42ed643e0.tar.xz
Merge pull request #1748
bed2d9f2 Get rid of directory lock (Howard Chu) 2e913676 Handle map resizes from other processes (Howard Chu) bf1348b7 Can't cache num_txs or num_outputs either (Howard Chu) dc53e9ee Add a few read txns to streamline (Howard Chu)
Diffstat (limited to 'src/cryptonote_core')
-rw-r--r--src/cryptonote_core/blockchain.cpp4
-rw-r--r--src/cryptonote_core/cryptonote_core.cpp40
-rw-r--r--src/cryptonote_core/cryptonote_core.h18
3 files changed, 4 insertions, 58 deletions
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp
index a81286632..d5fefffcd 100644
--- a/src/cryptonote_core/blockchain.cpp
+++ b/src/cryptonote_core/blockchain.cpp
@@ -1986,12 +1986,14 @@ bool Blockchain::find_blockchain_supplement(const std::list<crypto::hash>& qbloc
return false;
}
+ m_db->block_txn_start(true);
resp.total_height = get_current_blockchain_height();
size_t count = 0;
for(size_t i = resp.start_height; i < resp.total_height && count < BLOCKS_IDS_SYNCHRONIZING_DEFAULT_COUNT; i++, count++)
{
resp.m_block_ids.push_back(m_db->get_block_hash_from_height(i));
}
+ m_db->block_txn_stop();
return true;
}
//------------------------------------------------------------------
@@ -2022,6 +2024,7 @@ bool Blockchain::find_blockchain_supplement(const uint64_t req_start_block, cons
}
}
+ m_db->block_txn_start(true);
total_height = get_current_blockchain_height();
size_t count = 0;
for(size_t i = start_height; i < total_height && count < max_count; i++, count++)
@@ -2032,6 +2035,7 @@ bool Blockchain::find_blockchain_supplement(const uint64_t req_start_block, cons
get_transactions(blocks.back().first.tx_hashes, blocks.back().second, mis);
CHECK_AND_ASSERT_MES(!mis.size(), false, "internal error, transaction from block not found");
}
+ m_db->block_txn_stop();
return true;
}
//------------------------------------------------------------------
diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp
index b940dba3c..239ef5d84 100644
--- a/src/cryptonote_core/cryptonote_core.cpp
+++ b/src/cryptonote_core/cryptonote_core.cpp
@@ -219,40 +219,6 @@ namespace cryptonote
return m_blockchain_storage.get_alternative_blocks_count();
}
//-----------------------------------------------------------------------------------------------
- bool core::lock_db_directory(const boost::filesystem::path &path)
- {
- // boost doesn't like locking directories...
- const boost::filesystem::path lock_path = path / ".daemon_lock";
-
- try
- {
- // ensure the file exists
- std::ofstream(lock_path.string(), std::ios::out).close();
-
- db_lock = boost::interprocess::file_lock(lock_path.string().c_str());
- LOG_PRINT_L1("Locking " << lock_path.string());
- if (!db_lock.try_lock())
- {
- LOG_ERROR("Failed to lock " << lock_path.string());
- return false;
- }
- return true;
- }
- catch (const std::exception &e)
- {
- LOG_ERROR("Error trying to lock " << lock_path.string() << ": " << e.what());
- return false;
- }
- }
- //-----------------------------------------------------------------------------------------------
- bool core::unlock_db_directory()
- {
- db_lock.unlock();
- db_lock = boost::interprocess::file_lock();
- LOG_PRINT_L1("Blockchain directory successfully unlocked");
- return true;
- }
- //-----------------------------------------------------------------------------------------------
bool core::init(const boost::program_options::variables_map& vm, const cryptonote::test_options *test_options)
{
start_time = std::time(nullptr);
@@ -284,11 +250,6 @@ namespace cryptonote
// make sure the data directory exists, and try to lock it
CHECK_AND_ASSERT_MES (boost::filesystem::exists(folder) || boost::filesystem::create_directories(folder), false,
std::string("Failed to create directory ").append(folder.string()).c_str());
- if (!lock_db_directory (folder))
- {
- LOG_ERROR ("Failed to lock " << folder);
- return false;
- }
// check for blockchain.bin
try
@@ -440,7 +401,6 @@ namespace cryptonote
m_miner.stop();
m_mempool.deinit();
m_blockchain_storage.deinit();
- unlock_db_directory();
return true;
}
//-----------------------------------------------------------------------------------------------
diff --git a/src/cryptonote_core/cryptonote_core.h b/src/cryptonote_core/cryptonote_core.h
index fe1d11916..1463c2feb 100644
--- a/src/cryptonote_core/cryptonote_core.h
+++ b/src/cryptonote_core/cryptonote_core.h
@@ -763,24 +763,6 @@ namespace cryptonote
*/
bool relay_txpool_transactions();
- /**
- * @brief locks a file in the BlockchainDB directory
- *
- * @param path the directory in which to place the file
- *
- * @return true if lock acquired successfully, otherwise false
- */
- bool lock_db_directory(const boost::filesystem::path &path);
-
- /**
- * @brief unlocks the db directory
- *
- * @note see lock_db_directory()
- *
- * @return true
- */
- bool unlock_db_directory();
-
bool m_test_drop_download = true; //!< whether or not to drop incoming blocks (for testing)
uint64_t m_test_drop_download_height = 0; //!< height under which to drop incoming blocks, if doing so