mirror of
https://codeberg.org/anoncontributorxmr/monero.git
synced 2024-11-23 11:23:26 +01:00
core: sync database based on bytes added, not blocks added
Blocks have a very wide range, whereas actual size is the relevant quantity to consider when syncing
This commit is contained in:
parent
0dddfeacc9
commit
b278b83860
@ -87,8 +87,8 @@ const command_line::arg_descriptor<std::string> arg_db_type = {
|
||||
};
|
||||
const command_line::arg_descriptor<std::string> arg_db_sync_mode = {
|
||||
"db-sync-mode"
|
||||
, "Specify sync option, using format [safe|fast|fastest]:[sync|async]:[nblocks_per_sync]."
|
||||
, "fast:async:1000"
|
||||
, "Specify sync option, using format [safe|fast|fastest]:[sync|async]:[<nblocks_per_sync>[blocks]|<nbytes_per_sync>[bytes]]."
|
||||
, "fast:async:250000000bytes"
|
||||
};
|
||||
const command_line::arg_descriptor<bool> arg_db_salvage = {
|
||||
"db-salvage"
|
||||
|
@ -156,7 +156,7 @@ static const struct {
|
||||
//------------------------------------------------------------------
|
||||
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_current_block_cumul_sz_median(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_db_default_sync(false), 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_sync_on_blocks(true), m_db_sync_threshold(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_bytes_to_sync(0), m_cancel(false),
|
||||
m_difficulty_for_next_block_top_hash(crypto::null_hash),
|
||||
m_difficulty_for_next_block(1)
|
||||
{
|
||||
@ -3877,11 +3877,13 @@ bool Blockchain::cleanup_handle_incoming_blocks(bool force_sync)
|
||||
store_blockchain();
|
||||
m_sync_counter = 0;
|
||||
}
|
||||
else if (m_db_blocks_per_sync && m_sync_counter >= m_db_blocks_per_sync)
|
||||
else if (m_db_sync_threshold && ((m_db_sync_on_blocks && m_sync_counter >= m_db_sync_threshold) || (!m_db_sync_on_blocks && m_bytes_to_sync >= m_db_sync_threshold)))
|
||||
{
|
||||
MDEBUG("Sync threshold met, syncing");
|
||||
if(m_db_sync_mode == db_async)
|
||||
{
|
||||
m_sync_counter = 0;
|
||||
m_bytes_to_sync = 0;
|
||||
m_async_service.dispatch(boost::bind(&Blockchain::store_blockchain, this));
|
||||
}
|
||||
else if(m_db_sync_mode == db_sync)
|
||||
@ -4071,6 +4073,7 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::vector<block_complete
|
||||
bytes += tx_blob.size();
|
||||
}
|
||||
}
|
||||
m_bytes_to_sync += bytes;
|
||||
while (!(stop_batch = m_db->batch_start(blocks_entry.size(), bytes))) {
|
||||
m_blockchain_lock.unlock();
|
||||
m_tx_pool.unlock();
|
||||
@ -4419,7 +4422,7 @@ bool Blockchain::for_all_txpool_txes(std::function<bool(const crypto::hash&, con
|
||||
return m_db->for_all_txpool_txes(f, include_blob, include_unrelayed_txes);
|
||||
}
|
||||
|
||||
void Blockchain::set_user_options(uint64_t maxthreads, uint64_t blocks_per_sync, blockchain_db_sync_mode sync_mode, bool fast_sync)
|
||||
void Blockchain::set_user_options(uint64_t maxthreads, bool sync_on_blocks, uint64_t sync_threshold, blockchain_db_sync_mode sync_mode, bool fast_sync)
|
||||
{
|
||||
if (sync_mode == db_defaultsync)
|
||||
{
|
||||
@ -4428,7 +4431,8 @@ void Blockchain::set_user_options(uint64_t maxthreads, uint64_t blocks_per_sync,
|
||||
}
|
||||
m_db_sync_mode = sync_mode;
|
||||
m_fast_sync = fast_sync;
|
||||
m_db_blocks_per_sync = blocks_per_sync;
|
||||
m_db_sync_on_blocks = sync_on_blocks;
|
||||
m_db_sync_threshold = sync_threshold;
|
||||
m_max_prepare_blocks_threads = maxthreads;
|
||||
}
|
||||
|
||||
|
@ -729,11 +729,12 @@ namespace cryptonote
|
||||
* @brief sets various performance options
|
||||
*
|
||||
* @param maxthreads max number of threads when preparing blocks for addition
|
||||
* @param blocks_per_sync number of blocks to cache before syncing to database
|
||||
* @param sync_on_blocks whether to sync based on blocks or bytes
|
||||
* @param sync_threshold number of blocks/bytes to cache before syncing to database
|
||||
* @param sync_mode the ::blockchain_db_sync_mode to use
|
||||
* @param fast_sync sync using built-in block hashes as trusted
|
||||
*/
|
||||
void set_user_options(uint64_t maxthreads, uint64_t blocks_per_sync,
|
||||
void set_user_options(uint64_t maxthreads, bool sync_on_blocks, uint64_t sync_threshold,
|
||||
blockchain_db_sync_mode sync_mode, bool fast_sync);
|
||||
|
||||
/**
|
||||
@ -1017,11 +1018,13 @@ namespace cryptonote
|
||||
bool m_fast_sync;
|
||||
bool m_show_time_stats;
|
||||
bool m_db_default_sync;
|
||||
uint64_t m_db_blocks_per_sync;
|
||||
bool m_db_sync_on_blocks;
|
||||
uint64_t m_db_sync_threshold;
|
||||
uint64_t m_max_prepare_blocks_threads;
|
||||
uint64_t m_fake_pow_calc_time;
|
||||
uint64_t m_fake_scan_time;
|
||||
uint64_t m_sync_counter;
|
||||
uint64_t m_bytes_to_sync;
|
||||
std::vector<uint64_t> m_timestamps;
|
||||
std::vector<difficulty_type> m_difficulties;
|
||||
uint64_t m_timestamps_and_difficulties_height;
|
||||
|
@ -439,9 +439,10 @@ namespace cryptonote
|
||||
MGINFO("Loading blockchain from folder " << folder.string() << " ...");
|
||||
|
||||
const std::string filename = folder.string();
|
||||
// default to fast:async:1
|
||||
// default to fast:async:1 if overridden
|
||||
blockchain_db_sync_mode sync_mode = db_defaultsync;
|
||||
uint64_t blocks_per_sync = 1;
|
||||
bool sync_on_blocks = true;
|
||||
uint64_t sync_threshold = 1;
|
||||
|
||||
if (m_nettype == FAKECHAIN)
|
||||
{
|
||||
@ -491,7 +492,7 @@ namespace cryptonote
|
||||
else if(options[0] == "fastest")
|
||||
{
|
||||
db_flags = DBF_FASTEST;
|
||||
blocks_per_sync = 1000; // default to fastest:async:1000
|
||||
sync_threshold = 1000; // default to fastest:async:1000
|
||||
sync_mode = db_sync_mode_is_default ? db_defaultsync : db_async;
|
||||
}
|
||||
else
|
||||
@ -509,9 +510,22 @@ namespace cryptonote
|
||||
if(options.size() >= 3 && !safemode)
|
||||
{
|
||||
char *endptr;
|
||||
uint64_t bps = strtoull(options[2].c_str(), &endptr, 0);
|
||||
if (*endptr == '\0')
|
||||
blocks_per_sync = bps;
|
||||
uint64_t threshold = strtoull(options[2].c_str(), &endptr, 0);
|
||||
if (*endptr == '\0' || !strcmp(endptr, "blocks"))
|
||||
{
|
||||
sync_on_blocks = true;
|
||||
sync_threshold = threshold;
|
||||
}
|
||||
else if (!strcmp(endptr, "bytes"))
|
||||
{
|
||||
sync_on_blocks = false;
|
||||
sync_threshold = threshold;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR("Invalid db sync mode: " << options[2]);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (db_salvage)
|
||||
@ -528,7 +542,7 @@ namespace cryptonote
|
||||
}
|
||||
|
||||
m_blockchain_storage.set_user_options(blocks_threads,
|
||||
blocks_per_sync, sync_mode, fast_sync);
|
||||
sync_on_blocks, sync_threshold, sync_mode, fast_sync);
|
||||
|
||||
const std::pair<uint8_t, uint64_t> regtest_hard_forks[3] = {std::make_pair(1, 0), std::make_pair(Blockchain::get_hard_fork_heights(MAINNET).back().version, 1), std::make_pair(0, 0)};
|
||||
const cryptonote::test_options regtest_test_options = {
|
||||
|
Loading…
Reference in New Issue
Block a user