From 03bcd6f68c88b4c544b0d0f6d82ea071c3be8550 Mon Sep 17 00:00:00 2001 From: 0xfffc <0xfffc0000@proton.me> Date: Mon, 24 Feb 2025 05:39:20 +0000 Subject: [PATCH] src: fix issues Co-authored-by: nahuhh --- src/cryptonote_config.h | 7 +++---- src/cryptonote_core/cryptonote_core.cpp | 16 +++++++++------- .../cryptonote_protocol_handler.h | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/cryptonote_config.h b/src/cryptonote_config.h index 08aa778a7d7..129b8055ccb 100644 --- a/src/cryptonote_config.h +++ b/src/cryptonote_config.h @@ -98,10 +98,9 @@ #define BLOCKS_SYNCHRONIZING_DEFAULT_COUNT_PRE_V4 100 //by default, blocks count in blocks downloading #define BLOCKS_SYNCHRONIZING_DEFAULT_COUNT 20 //by default, blocks count in blocks downloading #define BLOCKS_SYNCHRONIZING_MAX_COUNT 2048 //must be a power of 2, greater than 128, equal to SEEDHASH_EPOCH_BLOCKS -#define BLOCKS_MEDIAN_WINDOW 100 //by default, compute median weights of last 100 blocks -#define BATCH_MAX_WEIGHT 20 //by default, maximum size of batch in [mB] -#define BATCH_MAX_ALLOWED_WEIGHT 50 //maximum allowed size of batch in [mB] -#define BLOCKS_HUGE_THRESHOLD_SIZE ((BATCH_MAX_WEIGHT * 1000000) / 2) //blocks that we consider huge [B] +#define BATCH_MAX_WEIGHT 10 //by default, maximum size of batch in [mB] +#define BATCH_MAX_ALLOWED_WEIGHT 50 //maximum allowed size of batch in [mB] +#define BLOCKS_MEDIAN_WINDOW CRYPTONOTE_REWARD_BLOCKS_WINDOW //compute median weights of last 100 blocks #define CRYPTONOTE_MEMPOOL_TX_LIVETIME (86400*3) //seconds, three days #define CRYPTONOTE_MEMPOOL_TX_FROM_ALT_BLOCK_LIVETIME 604800 //seconds, one week diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp index a634540cf4e..8b1baa4e32f 100644 --- a/src/cryptonote_core/cryptonote_core.cpp +++ b/src/cryptonote_core/cryptonote_core.cpp @@ -170,7 +170,7 @@ namespace cryptonote }; static const command_line::arg_descriptor arg_batch_max_weight = { "batch-max-weight" - , "How many megabytes to sync in one batch during chain synchronization, default is 20 max" + , "How many megabytes to sync in one batch during chain synchronization, default is 10" , (BATCH_MAX_WEIGHT) }; static const command_line::arg_descriptor arg_check_updates = { @@ -706,6 +706,11 @@ namespace cryptonote batch_max_weight = BATCH_MAX_ALLOWED_WEIGHT; } + if ((batch_max_weight == 0)) { + MINFO("Using default --batch-max-weight of " << BATCH_MAX_WEIGHT << " [mB]"); + batch_max_weight = BATCH_MAX_WEIGHT; + } + batch_max_weight *= 1000000; // transfer it to byte. MGINFO("Loading checkpoints"); @@ -1245,17 +1250,14 @@ namespace cryptonote << " blocks median size is " << median_weight << " bytes and the max average blocksize in the queue is " << average_blocksize_of_biggest_batch << " bytes"); uint64_t projected_blocksize = (average_blocksize_of_biggest_batch > median_weight) ? average_blocksize_of_biggest_batch : median_weight; + uint64_t blocks_huge_threshold = (batch_max_weight / 2); if ((projected_blocksize * BLOCKS_MEDIAN_WINDOW) < batch_max_weight) { res = BLOCKS_MEDIAN_WINDOW; MINFO("blocks are tiny, " << projected_blocksize << " bytes, sync " << res << " blocks in next batch"); } - else if (projected_blocksize >= batch_max_weight) { - res = 1; - MINFO("blocks are projected to surpass " << batch_max_weight << " bytes, syncing just a single block in next batch"); - } - else if (projected_blocksize > BLOCKS_HUGE_THRESHOLD_SIZE) { + else if (projected_blocksize >= blocks_huge_threshold) { res = 1; - MINFO("blocks are huge, sync just a single block in next batch"); + MINFO("blocks are projected to surpass 50% of " << batch_max_weight << " bytes, syncing just a single block in next batch"); } else { res = batch_max_weight / projected_blocksize; diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.h b/src/cryptonote_protocol/cryptonote_protocol_handler.h index cf976067eab..c1086319b9c 100644 --- a/src/cryptonote_protocol/cryptonote_protocol_handler.h +++ b/src/cryptonote_protocol/cryptonote_protocol_handler.h @@ -113,7 +113,7 @@ namespace cryptonote void log_connections(); std::list get_connections(); const block_queue &get_block_queue() const { return m_block_queue; } - const std::uint64_t max_average_of_blocksize_in_queue() { + std::uint64_t max_average_of_blocksize_in_queue() { std::vector average_blocksize{0}; m_block_queue.foreach([&](const cryptonote::block_queue::span &span) { average_blocksize.push_back(span.size / span.nblocks);