From 59c2cdd525a91bb4a38b5ad39df9294328a8ac30 Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Thu, 25 Jul 2024 16:20:45 +0800 Subject: [PATCH] Apply PR code review suggestions Signed-off-by: Eval EXEC --- chain/src/consume_unverified.rs | 8 +- devtools/block_sync/draw_sync_chart.py | 180 ------------------------- sync/src/types/mod.rs | 1 - 3 files changed, 3 insertions(+), 186 deletions(-) delete mode 100755 devtools/block_sync/draw_sync_chart.py diff --git a/chain/src/consume_unverified.rs b/chain/src/consume_unverified.rs index 85ea2a44dc..cf09abdaba 100644 --- a/chain/src/consume_unverified.rs +++ b/chain/src/consume_unverified.rs @@ -68,13 +68,13 @@ impl ConsumeUnverifiedBlocks { pub(crate) fn start(mut self) { loop { - let _trace_begin_loop = minstant::Instant::now(); + let trace_begin_loop = minstant::Instant::now(); select! { recv(self.unverified_block_rx) -> msg => match msg { Ok(unverified_task) => { // process this unverified block if let Some(handle) = ckb_metrics::handle() { - handle.ckb_chain_consume_unverified_block_waiting_block_duration.observe(_trace_begin_loop.elapsed().as_secs_f64()) + handle.ckb_chain_consume_unverified_block_waiting_block_duration.observe(trace_begin_loop.elapsed().as_secs_f64()) } let _ = self.tx_pool_controller.suspend_chunk_process(); @@ -98,7 +98,7 @@ impl ConsumeUnverifiedBlocks { let _ = self.tx_pool_controller.continue_chunk_process(); }, Err(err) => { - info!("truncate_block_tx has been closed,err: {}", err); + info!("truncate_block_tx has been closed, err: {}", err); return; }, }, @@ -883,8 +883,6 @@ impl ConsumeUnverifiedBlockProcessor { self.shared.store_snapshot(Arc::clone(&new_snapshot)); - // NOTE: Dont update tx-pool when truncate - Ok(()) } } diff --git a/devtools/block_sync/draw_sync_chart.py b/devtools/block_sync/draw_sync_chart.py deleted file mode 100755 index e9b164a440..0000000000 --- a/devtools/block_sync/draw_sync_chart.py +++ /dev/null @@ -1,180 +0,0 @@ -#!/usr/bin/env python3 -import matplotlib.pyplot as plt -import re -import datetime -import tqdm -import argparse - -from matplotlib.ticker import MultipleLocator - -def parse_sync_statics(log_file): - """ - parse sync statics from log file - sample: - 2023-09-01 06:54:45.096 +00:00 verify_blocks INFO ckb_chain::chain block: 811224, hash: 0x00f54aaadd1a36339e69a10624dec3250658100ffd5773a7e9f228bb9a96187e, epoch: 514(841/1800), total_diff: 0x59a4a071ba9f0de59d, txs: 1 - """ - duration = [] - height = [] - base_timestamp = 0 - - print("reading file: ", log_file) - total_lines = len(open(log_file, 'r').readlines()) - print("total lines: ", total_lines) - - with open(log_file, 'r') as f: - # pbar = tqdm.tqdm(total=total_lines) - for line_idx, line in enumerate(f): - # pbar.update(1) - if line_idx == 0: - timestamp_str = re.search(r'^(\S+ \S+)', line).group(1) # Extract the timestamp string - timestamp = datetime.datetime.strptime(timestamp_str, "%Y-%m-%d %H:%M:%S.%f").timestamp() - base_timestamp = timestamp - - - if line.find('INFO ckb_chain::chain block: ') != -1: - - block_number = int(re.search(r'block: (\d+)', line).group(1)) # Extract the block number using regex - - if line_idx == 0 or block_number % 10_000 == 0: - timestamp_str = re.search(r'^(\S+ \S+)', line).group(1) # Extract the timestamp string - timestamp = datetime.datetime.strptime(timestamp_str, "%Y-%m-%d %H:%M:%S.%f").timestamp() - timestamp = int(timestamp - base_timestamp) - duration.append(timestamp / 60 / 60) - height.append(block_number) - - # pbar.close() - - return duration, height - - -parser = argparse.ArgumentParser( - description='Draw CKB Sync progress Chart. Usage: ./draw_sync_chart.py --ckb_log ./run1.log ./run2.log --label branch_develop branch_async --result_path /tmp/compare_result.png') -parser.add_argument('--ckb_log', metavar='ckb_log_file', type=str, - action='store', nargs='+', required=True, - help='the ckb node log file path') -parser.add_argument('--label', metavar='label', type=str, - action='store', nargs='+', required=True, - help='what label should be put on the chart') -parser.add_argument('--result_path', type=str, nargs=1, action='store', - help='where to save the result chart') - -args = parser.parse_args() -assert len(args.ckb_log) == len(args.label) - -tasks = zip(args.ckb_log, args.label) - -result_path = args.result_path[0] -fig, ax = plt.subplots(1, 1, figsize=(10, 8)) - -lgs = [] - -def process_task(task): - ckb_log_file, label = task - print("ckb_log_file: ", ckb_log_file) - print("label: ", label) - duration, height = parse_sync_statics(ckb_log_file) - return (duration, height, label) - - -tasks = [(ckb_log_file, label) for ckb_log_file, label in tasks] - - -import multiprocessing -with multiprocessing.Pool() as pool: - results = pool.map(process_task, tasks) - -alabels = [] - -import matplotlib.ticker as ticker - -vlabels = [] - -for duration, height, label in results: -# for ckb_log_file, label in tasks: -# print("ckb_log_file: ", ckb_log_file) -# print("label: ", label) -# duration, height = parse_sync_statics(ckb_log_file) - - - lg = ax.scatter(duration, height, s=1, label=label) - ax.plot(duration, height, label=label) - - - lgs.append(lg) - - ax.hlines([11_500_000], 0, max(duration), colors="gray", linestyles="dashed") - - for i, h in enumerate(height): - if i == len(height) -1 : - alabels.append(((duration[i],h),label)) - - if h == 11_500_000: - vlabels.append((duration[i],h)) - - - ax.get_yaxis().get_major_formatter().set_scientific(False) - ax.get_yaxis().get_major_formatter().set_useOffset(False) - - ax.margins(0) - - ax.set_axisbelow(True) - - ax.xaxis.grid(color='gray', linestyle='solid', which='major') - ax.yaxis.grid(color='gray', linestyle='solid', which='major') - - ax.xaxis.grid(color='gray', linestyle='dashed', which='minor') - ax.yaxis.grid(color='gray', linestyle='dashed', which='minor') - - xminorLocator = MultipleLocator(1.0) - ax.xaxis.set_major_locator(xminorLocator) - - yminorLocator = MultipleLocator(500_000) - ax.yaxis.set_major_locator(yminorLocator) - - - # plt.xticks(ax.get_xticks(), ax.get_xticklabels(which='both')) - # plt.setp(ax.get_xticklabels(which='both'), rotation=30, horizontalalignment='right') - -# sort alabsle by .0.1 -alabels.sort(key=lambda x: x[0][0]) -vlabels.sort(key=lambda x: x[0]) - -lheight=40 -loffset=-40 -count=len(alabels) -for (duration,h), label in alabels: - - ax.annotate(label, - fontsize=8, - xy=(duration, h), xycoords='data', - xytext=(loffset, lheight), textcoords='offset points', - bbox=dict(boxstyle="round", fc="0.9"), - arrowprops=dict(arrowstyle="->"), - horizontalalignment='center', verticalalignment='bottom') - loffset += round(80/count,0) - if loffset <0: - lheight += 20 - elif loffset > 0: - lheight -= 20 - -for index, (duration, h) in enumerate(vlabels): - ax.vlines([duration], 0, h, colors="black", linestyles="dashed") - voff=-60 - if index % 2 == 0: - voff=-75 - ax.annotate(round(duration, 1), - fontsize=8, - xy=(duration, 0), xycoords='data', - xytext=(0, voff), textcoords='offset points', - bbox=dict(boxstyle="round", fc="0.9"), - arrowprops=dict(arrowstyle="-"), - horizontalalignment='center', verticalalignment='bottom') - - -plt.axhline(y=11_500_000, color='blue', linestyle='--') - -# plt.legend(tuple(lgs), tuple(args.label), loc='upper left', shadow=True) -plt.title('CKB Block Sync progress Chart') -plt.xlabel('Timecost (hours)') -plt.ylabel('Block Height') -plt.savefig(result_path, bbox_inches='tight', dpi=300) diff --git a/sync/src/types/mod.rs b/sync/src/types/mod.rs index 5d5cd9ffb8..223bea1f54 100644 --- a/sync/src/types/mod.rs +++ b/sync/src/types/mod.rs @@ -1322,7 +1322,6 @@ pub struct SyncState { pending_get_block_proposals: DashMap>, pending_get_headers: RwLock>, pending_compact_blocks: Mutex, - // orphan_block_pool: OrphanBlockPool, /* In-flight items for which we request to peers, but not got the responses yet */ inflight_proposals: DashMap,