aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_core
diff options
context:
space:
mode:
Diffstat (limited to 'src/cryptonote_core')
-rw-r--r--src/cryptonote_core/blockchain.cpp19
-rw-r--r--src/cryptonote_core/blockchain.h7
-rw-r--r--src/cryptonote_core/cryptonote_core.cpp11
-rw-r--r--src/cryptonote_core/cryptonote_core.h7
4 files changed, 42 insertions, 2 deletions
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp
index e00908125..d4a7831dc 100644
--- a/src/cryptonote_core/blockchain.cpp
+++ b/src/cryptonote_core/blockchain.cpp
@@ -129,7 +129,7 @@ static const uint64_t testnet_hard_fork_version_1_till = 624633;
//------------------------------------------------------------------
Blockchain::Blockchain(tx_memory_pool& tx_pool) :
m_db(), m_tx_pool(tx_pool), m_hardfork(NULL), m_timestamps_and_difficulties_height(0), m_current_block_cumul_sz_limit(0),
- m_enforce_dns_checkpoints(false), m_max_prepare_blocks_threads(4), m_db_blocks_per_sync(1), m_db_sync_mode(db_async), m_fast_sync(true), m_show_time_stats(false), m_sync_counter(0), m_cancel(false)
+ m_enforce_dns_checkpoints(false), m_max_prepare_blocks_threads(4), m_db_blocks_per_sync(1), m_db_sync_mode(db_async), m_db_default_sync(false), m_fast_sync(true), m_show_time_stats(false), m_sync_counter(0), m_cancel(false)
{
LOG_PRINT_L3("Blockchain::" << __func__);
}
@@ -4037,12 +4037,29 @@ bool Blockchain::for_all_txpool_txes(std::function<bool(const crypto::hash&, con
void Blockchain::set_user_options(uint64_t maxthreads, uint64_t blocks_per_sync, blockchain_db_sync_mode sync_mode, bool fast_sync)
{
+ if (sync_mode == db_defaultsync)
+ {
+ m_db_default_sync = true;
+ sync_mode = db_async;
+ }
m_db_sync_mode = sync_mode;
m_fast_sync = fast_sync;
m_db_blocks_per_sync = blocks_per_sync;
m_max_prepare_blocks_threads = maxthreads;
}
+void Blockchain::safesyncmode(const bool onoff)
+{
+ /* all of this is no-op'd if the user set a specific
+ * --db-sync-mode at startup.
+ */
+ if (m_db_default_sync)
+ {
+ m_db->safesyncmode(onoff);
+ m_db_sync_mode = onoff ? db_nosync : db_async;
+ }
+}
+
HardFork::State Blockchain::get_hard_fork_state() const
{
return m_hardfork->get_state();
diff --git a/src/cryptonote_core/blockchain.h b/src/cryptonote_core/blockchain.h
index 7fa78584b..b8ea657b4 100644
--- a/src/cryptonote_core/blockchain.h
+++ b/src/cryptonote_core/blockchain.h
@@ -65,6 +65,7 @@ namespace cryptonote
*/
enum blockchain_db_sync_mode
{
+ db_defaultsync, //!< user didn't specify, use db_async
db_sync, //!< handle syncing calls instead of the backing db, synchronously
db_async, //!< handle syncing calls instead of the backing db, asynchronously
db_nosync //!< Leave syncing up to the backing db (safest, but slowest because of disk I/O)
@@ -701,6 +702,11 @@ namespace cryptonote
blockchain_db_sync_mode sync_mode, bool fast_sync);
/**
+ * @brief Put DB in safe sync mode
+ */
+ void safesyncmode(const bool onoff);
+
+ /**
* @brief set whether or not to show/print time statistics
*
* @param stats the new time stats setting
@@ -932,6 +938,7 @@ namespace cryptonote
blockchain_db_sync_mode m_db_sync_mode;
bool m_fast_sync;
bool m_show_time_stats;
+ bool m_db_default_sync;
uint64_t m_db_blocks_per_sync;
uint64_t m_max_prepare_blocks_threads;
uint64_t m_fake_pow_calc_time;
diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp
index a7f6ca36c..c406dd0b4 100644
--- a/src/cryptonote_core/cryptonote_core.cpp
+++ b/src/cryptonote_core/cryptonote_core.cpp
@@ -322,7 +322,7 @@ namespace cryptonote
const std::string filename = folder.string();
// default to fast:async:1
- blockchain_db_sync_mode sync_mode = db_async;
+ blockchain_db_sync_mode sync_mode = db_defaultsync;
uint64_t blocks_per_sync = 1;
try
@@ -355,11 +355,15 @@ namespace cryptonote
sync_mode = db_nosync;
}
else if(options[0] == "fast")
+ {
db_flags = DBF_FAST;
+ sync_mode = db_async;
+ }
else if(options[0] == "fastest")
{
db_flags = DBF_FASTEST;
blocks_per_sync = 1000; // default to fastest:async:1000
+ sync_mode = db_async;
}
else
db_flags = DEFAULT_FLAGS;
@@ -1039,6 +1043,11 @@ namespace cryptonote
m_miner.on_synchronized();
}
//-----------------------------------------------------------------------------------------------
+ void core::safesyncmode(const bool onoff)
+ {
+ m_blockchain_storage.safesyncmode(onoff);
+ }
+ //-----------------------------------------------------------------------------------------------
bool core::add_new_block(const block& b, block_verification_context& bvc)
{
return m_blockchain_storage.add_new_block(b, bvc);
diff --git a/src/cryptonote_core/cryptonote_core.h b/src/cryptonote_core/cryptonote_core.h
index 84f59919e..f565afd87 100644
--- a/src/cryptonote_core/cryptonote_core.h
+++ b/src/cryptonote_core/cryptonote_core.h
@@ -621,6 +621,13 @@ namespace cryptonote
void on_synchronized();
/**
+ * @copydoc Blockchain::safesyncmode
+ *
+ * 2note see Blockchain::safesyncmode
+ */
+ void safesyncmode(const bool onoff);
+
+ /**
* @brief sets the target blockchain height
*
* @param target_blockchain_height the height to set