aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_core/blockchain.cpp
diff options
context:
space:
mode:
authorHoward Chu <hyc@symas.com>2017-08-19 19:36:51 +0100
committerHoward Chu <hyc@symas.com>2017-08-20 16:30:28 +0100
commit9a859844f496158b8237bbd08ff0f608dc5a6385 (patch)
tree01b471ca8a5f334112bd777a10962853aedbffe3 /src/cryptonote_core/blockchain.cpp
parentDB cleanup (diff)
downloadmonero-9a859844f496158b8237bbd08ff0f608dc5a6385.tar.xz
Toggle SAFE syncmode on and off automatically
If monerod is started with default sync mode, set it to SAFE after synchronization completes. Set it back to FAST if synchronization restarts (e.g. because another peer has a longer blockchain). If monerod is started with an explicit sync mode, none of this automation takes effect.
Diffstat (limited to 'src/cryptonote_core/blockchain.cpp')
-rw-r--r--src/cryptonote_core/blockchain.cpp19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp
index 14a990131..b3096e473 100644
--- a/src/cryptonote_core/blockchain.cpp
+++ b/src/cryptonote_core/blockchain.cpp
@@ -126,7 +126,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__);
}
@@ -4034,12 +4034,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();