@@ -168,6 +168,11 @@ namespace cryptonote
168
168
, " How many blocks to sync at once during chain synchronization (0 = adaptive)."
169
169
, 0
170
170
};
171
+ static const command_line::arg_descriptor<size_t > arg_batch_max_weight = {
172
+ " batch-max-weight"
173
+ , " How many megabytes to sync in one batch during chain synchronization, default is 20 max"
174
+ , (BATCH_MAX_WEIGHT)
175
+ };
171
176
static const command_line::arg_descriptor<std::string> arg_check_updates = {
172
177
" check-updates"
173
178
, " Check for new versions of monero: [disabled|notify|download|update]"
@@ -335,6 +340,7 @@ namespace cryptonote
335
340
command_line::add_arg (desc, arg_fast_block_sync);
336
341
command_line::add_arg (desc, arg_show_time_stats);
337
342
command_line::add_arg (desc, arg_block_sync_size);
343
+ command_line::add_arg (desc, arg_batch_max_weight);
338
344
command_line::add_arg (desc, arg_check_updates);
339
345
command_line::add_arg (desc, arg_no_fluffy_blocks);
340
346
command_line::add_arg (desc, arg_test_dbg_lock_sleep);
@@ -691,6 +697,17 @@ namespace cryptonote
691
697
if (block_sync_size > BLOCKS_SYNCHRONIZING_MAX_COUNT)
692
698
MERROR (" Error --block-sync-size cannot be greater than " << BLOCKS_SYNCHRONIZING_MAX_COUNT);
693
699
700
+ if (block_sync_size)
701
+ MWARNING (" When --block-sync-size defined, the --batch-max-weight is not going to have any effect." );
702
+
703
+ batch_max_weight = command_line::get_arg (vm, arg_batch_max_weight);
704
+ if (batch_max_weight > BATCH_MAX_ALLOWED_WEIGHT) {
705
+ MERROR (" Error --batch-max-weight cannot be greater than " << BATCH_MAX_ALLOWED_WEIGHT << " [mB]" );
706
+ batch_max_weight = BATCH_MAX_ALLOWED_WEIGHT;
707
+ }
708
+
709
+ batch_max_weight *= 1000000 ; // transfer it to byte.
710
+
694
711
MGINFO (" Loading checkpoints" );
695
712
696
713
// load json & DNS checkpoints, and verify them
@@ -1214,16 +1231,37 @@ namespace cryptonote
1214
1231
return true ;
1215
1232
}
1216
1233
// -----------------------------------------------------------------------------------------------
1217
- size_t core::get_block_sync_size (uint64_t height) const
1234
+ size_t core::get_block_sync_size (uint64_t height, const uint64_t average_blocksize_of_biggest_batch ) const
1218
1235
{
1219
- static const uint64_t quick_height = m_nettype == TESTNET ? 801219 : m_nettype == MAINNET ? 1220516 : 0 ;
1220
1236
size_t res = 0 ;
1221
1237
if (block_sync_size > 0 )
1222
1238
res = block_sync_size;
1223
- else if (height >= quick_height)
1224
- res = BLOCKS_SYNCHRONIZING_DEFAULT_COUNT;
1225
- else
1226
- res = BLOCKS_SYNCHRONIZING_DEFAULT_COUNT_PRE_V4;
1239
+ else {
1240
+ size_t number_of_blocks = BLOCKS_MEDIAN_WINDOW;
1241
+ std::vector<uint64_t > last_n_blocks_weights;
1242
+ m_blockchain_storage.get_last_n_blocks_weights (last_n_blocks_weights, number_of_blocks);
1243
+ uint64_t median_weight = epee::misc_utils::median (last_n_blocks_weights);
1244
+ MINFO (" Last " << number_of_blocks
1245
+ << " blocks median size is " << median_weight
1246
+ << " bytes and the max average blocksize in the queue is " << average_blocksize_of_biggest_batch << " bytes" );
1247
+ uint64_t projected_blocksize = (average_blocksize_of_biggest_batch > median_weight) ? average_blocksize_of_biggest_batch : median_weight;
1248
+ if ((projected_blocksize * BLOCKS_MEDIAN_WINDOW) < batch_max_weight) {
1249
+ res = BLOCKS_MEDIAN_WINDOW;
1250
+ MINFO (" blocks are tiny, " << projected_blocksize << " bytes, sync " << res << " blocks in next batch" );
1251
+ }
1252
+ else if (projected_blocksize >= batch_max_weight) {
1253
+ res = 1 ;
1254
+ MINFO (" blocks are projected to surpass " << batch_max_weight << " bytes, syncing just a single block in next batch" );
1255
+ }
1256
+ else if (projected_blocksize > BLOCKS_HUGE_THRESHOLD_SIZE) {
1257
+ res = 1 ;
1258
+ MINFO (" blocks are huge, sync just a single block in next batch" );
1259
+ }
1260
+ else {
1261
+ res = batch_max_weight / projected_blocksize;
1262
+ MINFO (" projected blocksize is " << projected_blocksize << " bytes, sync " << res << " blocks in next batch" );
1263
+ }
1264
+ }
1227
1265
1228
1266
static size_t max_block_size = 0 ;
1229
1267
if (max_block_size == 0 )
0 commit comments