From df98f370c7e851d92e9b8867ab3272ba2472c572 Mon Sep 17 00:00:00 2001 From: wowario Date: Wed, 13 Aug 2025 07:44:07 +0300 Subject: [PATCH] update average block sizes table --- src/common/util.cpp | 31 +++-------- utils/block_size_average.sh | 107 ++++++++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+), 24 deletions(-) create mode 100755 utils/block_size_average.sh diff --git a/src/common/util.cpp b/src/common/util.cpp index f3b39fe43..e3d86c862 100644 --- a/src/common/util.cpp +++ b/src/common/util.cpp @@ -1360,30 +1360,13 @@ std::string get_nix_version_display_string() // importance. static const uint32_t average_block_sizes[] = { - 442, 1211, 1445, 1763, 2272, 8217, 5603, 9999, 16358, 10805, 5290, 4362, - 4325, 5584, 4515, 5008, 4789, 5196, 7660, 3829, 6034, 2925, 3762, 2545, - 2437, 2553, 2167, 2761, 2015, 1969, 2350, 1731, 2367, 2078, 2026, 3518, - 2214, 1908, 1780, 1640, 1976, 1647, 1921, 1716, 1895, 2150, 2419, 2451, - 2147, 2327, 2251, 1644, 1750, 1481, 1570, 1524, 1562, 1668, 1386, 1494, - 1637, 1880, 1431, 1472, 1637, 1363, 1762, 1597, 1999, 1564, 1341, 1388, - 1530, 1476, 1617, 1488, 1368, 1906, 1403, 1695, 1535, 1598, 1318, 1234, - 1358, 1406, 1698, 1554, 1591, 1758, 1426, 2389, 1946, 1533, 1308, 2701, - 1525, 1653, 3580, 1889, 2913, 8164, 5154, 3762, 3356, 4360, 3589, 4844, - 4232, 3781, 3882, 5924, 10790, 7185, 7442, 8214, 8509, 7484, 6939, 7391, - 8210, 15572, 39680, 44810, 53873, 54639, 68227, 63428, 62386, 68504, - 83073, 103858, 117573, 98089, 96793, 102337, 94714, 129568, 251584, - 132026, 94579, 94516, 95722, 106495, 121824, 153983, 162338, 136608, - 137104, 109872, 91114, 84757, 96339, 74251, 94314, 143216, 155837, - 129968, 120201, 109913, 101588, 97332, 104611, 95310, 93419, 113345, - 100743, 92152, 57565, 22533, 37564, 21823, 19980, 18277, 18402, 14344, - 12142, 15842, 13677, 17631, 18294, 22270, 41422, 39296, 36688, 33512, - 33831, 27582, 22276, 27516, 27317, 25505, 24426, 20566, 23045, 26766, - 28185, 26169, 27011, 28642, 34994, 34442, 30682, 34357, 31640, 41167, - 41301, 48616, 51075, 55061, 49909, 44606, 47091, 53828, 42520, 39023, - 55245, 56145, 51119, 60398, 71821, 48142, 60310, 56041, 54176, 66220, - 56336, 55248, 56656, 63305, 54029, 77136, 71902, 71618, 83587, 81068, - 69062, 54848, 53681, 53555, - 50616 // Blocks 2,400,000 to 2,409,999 in July 2021 + 23956, 8606, 6156, 5778, 6549, 10028, 10207, 5681, 12915, 13680, 11402, + 9194, 12082, 10496, 11879, 10304, 10356, 8433, 8252, 12264, 7143, 8484, + 9226, 8726, 6961, 6082, 4234, 3712, 4307, 4324, 6758, 13616, 11376, 4091, + 3157, 4450, 2966, 2264, 2290, 2046, 2156, 1902, 1966, 2354, 2295, 2126, 1977, + 1728, 1591, 1968, 1426, 1280, 1372, 1266, 1399, 2044, 1320, 1100, 1084, 1384, + 1183, 2458, 1285, 1501, 1270, 1222, 1284, 1246, 1552, 1431, 1325, 1774, 2771, + 2855, 1394, 1388, 2882 // Blocks 0 to 760,486 in August 2025 }; const uint64_t block_range_size = 10000; diff --git a/utils/block_size_average.sh b/utils/block_size_average.sh new file mode 100755 index 000000000..5cb6cba71 --- /dev/null +++ b/utils/block_size_average.sh @@ -0,0 +1,107 @@ +#!/bin/bash + +RPC_URL="http://127.0.0.1:34568/json_rpc" +MAX_RETRIES=3 +SLEEP_BETWEEN_REQUESTS=0.1 +BLOCK_RANGE_SIZE=10000 +OUTPUT_FILE="average_block_sizes.txt" + +# Get current blockchain height +get_current_height() { + local retry=0 + while [[ $retry -lt $MAX_RETRIES ]]; do + response=$(curl -s -X POST $RPC_URL -d '{"jsonrpc":"2.0","id":"0","method":"get_block_count"}' -H 'Content-Type: application/json') + if [[ $? -eq 0 ]]; then + height=$(echo "$response" | jq -r '.result.count') + if [[ -n "$height" && "$height" != "null" ]]; then + echo $((height - 1)) # Return 0-based height + return 0 + fi + fi + ((retry++)) + sleep $SLEEP_BETWEEN_REQUESTS + done + echo "Error: Failed to get blockchain height after $MAX_RETRIES attempts" >&2 + exit 1 +} + +# Get block sizes for a range +get_block_sizes() { + local start=$1 + local end=$2 + local retry=0 + + while [[ $retry -lt $MAX_RETRIES ]]; do + response=$(curl -s -X POST $RPC_URL -d "{\"jsonrpc\":\"2.0\",\"id\":\"0\",\"method\":\"get_block_headers_range\",\"params\":{\"start_height\":$start,\"end_height\":$end}}" -H 'Content-Type: application/json') + if [[ $? -eq 0 ]]; then + sizes=$(echo "$response" | jq -r '.result.headers[].block_size') + if [[ -n "$sizes" ]]; then + echo "$sizes" + return 0 + fi + fi + ((retry++)) + sleep $SLEEP_BETWEEN_REQUESTS + done + echo "Error: Failed to get blocks $start-$end after $MAX_RETRIES attempts" >&2 + return 1 +} + +main() { + current_height=$(get_current_height) + echo "Current blockchain height: $current_height" + + ranges=$((current_height / BLOCK_RANGE_SIZE)) + echo "Processing $ranges ranges of $BLOCK_RANGE_SIZE blocks each..." + + echo -n "[" > "$OUTPUT_FILE" + first_range=true + + for ((i=0; i<=ranges; i++)); do + start=$((i * BLOCK_RANGE_SIZE)) + end=$((start + BLOCK_RANGE_SIZE - 1)) + + # Cap the end at current height + if [[ $end -gt $current_height ]]; then + end=$current_height + fi + + # Status update every 1000 blocks within the range + for ((j=start; j<=end; j+=1000)); do + checkpoint=$((j + 1000 - 1)) + if [[ $checkpoint -gt $end ]]; then + checkpoint=$end + fi + echo "Processing blocks $j to $checkpoint ..." + done + + sizes=$(get_block_sizes $start $end) + if [[ $? -ne 0 ]]; then + continue + fi + + # Calculate average + count=0 + sum=0 + for size in $sizes; do + sum=$((sum + size)) + ((count++)) + done + + if [[ $count -gt 0 ]]; then + average=$((sum / count)) + if [[ "$first_range" = false ]]; then + echo -n ", " >> "$OUTPUT_FILE" + fi + echo -n "$average" >> "$OUTPUT_FILE" + first_range=false + fi + + sleep $SLEEP_BETWEEN_REQUESTS + done + + echo "]" >> "$OUTPUT_FILE" + echo "Done! Averages saved to $OUTPUT_FILE" +} + +main