Skip to content

Commit 4b860c6

Browse files
committed
Remove the redundant handling of stale blocks below the max reorg depth (they are rejected by the chainstate anyway)
1 parent ff1c2ef commit 4b860c6

File tree

2 files changed

+6
-44
lines changed

2 files changed

+6
-44
lines changed

build-tools/fork-detection/detector.py

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,11 @@
5656
]
5757

5858
ENDED_UP_ON_A_FORK_FLAG_NAME = "ended_up_on_a_fork"
59-
STALE_BLOCK_BELOW_REORG_LIMIT_FLAG_NAME = "stale_block_below_reorg_limit"
6059
NO_INCOMING_BLOCKS_WHILE_ON_STALE_CHAIN_FLAG_NAME = "no_incoming_blocks_while_on_stale_chain"
6160

6261
NODE_OUTPUT_LINE_NEW_TIP_REGEX = re.compile(
6362
r"NEW TIP in chainstate (?P<block_id>[0-9A-Fa-f]+) with height (?P<height>\d+), timestamp: (?P<timestamp>\d+)"
6463
)
65-
NODE_OUTPUT_LINE_STALE_BLOCK_RECEIVED_REGEX = re.compile(
66-
r"Received stale block (?P<block_id>[0-9A-Fa-f]+) with height (?P<height>\d+), timestamp: (?P<timestamp>\d+)"
67-
)
6864

6965
# The regex used to decide whether a node's output line should be printed to the console
7066
# (we want to avoid debug and info lines since they're both too noisy during sync and put extra
@@ -159,10 +155,10 @@ def do_full_sync(self):
159155
self.restore_peer_db()
160156

161157
node_proc_env = os.environ.copy()
162-
# Note: "chainstate_verbose_block_ids=debug" allows to catch the "Received stale block" line
163-
# and also forces certain block-processing functions in chainstate to print full block ids.
164-
# We avoid using the "normal" debug log, because it's too noisy, e.g. even
165-
# "info,chainstate=debug" produces hundreds of megabytes of logs during the full sync.
158+
# Note: "chainstate_verbose_block_ids=debug" forces certain block-processing functions
159+
# in chainstate to print full block ids. We avoid using the "normal" debug log, because
160+
# it's too noisy, e.g. even "info,chainstate=debug" produces hundreds of megabytes of
161+
# logs during the full sync.
166162
node_proc_env["RUST_LOG"] = "info,chainstate_verbose_block_ids=debug"
167163

168164
node_proc = subprocess.Popen(
@@ -236,24 +232,6 @@ def on_node_output_line_or_timeout(line: Optional[str]):
236232
)
237233
log_func(f"Tip reached, height = {height}{extra}")
238234
return False
239-
240-
elif (stale_block_received_match := NODE_OUTPUT_LINE_STALE_BLOCK_RECEIVED_REGEX.search(line)) is not None:
241-
block_id = stale_block_received_match.group("block_id")
242-
height = int(stale_block_received_match.group("height"))
243-
244-
log.warn(f"Stale block received at height {height}: {block_id}")
245-
246-
if actual_tip_height - height >= MAX_REORG_DEPTH:
247-
# Note: this may mean 2 things:
248-
# a) If we're on the proper chain, then we've found a peer who is on
249-
# a fork, in which case we definitely want to create this flag.
250-
# b) If we're on a fork, then the stale block may be from the proper
251-
# chain, in which case the flag creation is redundant, because the code
252-
# above or below should catch this situation; but it's not harmful either.
253-
self.touch_flag(
254-
STALE_BLOCK_BELOW_REORG_LIMIT_FLAG_NAME,
255-
f"height={height}, block id={block_id}"
256-
)
257235
else:
258236
seconds_since_last_tip = (
259237
cur_seconds_since_epoch - last_tip_arrival_time

chainstate/src/detail/mod.rs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,8 @@ type ChainstateEventHandler = EventHandler<ChainstateEvent>;
9494

9595
pub type OrphanErrorHandler = dyn Fn(&BlockError) + Send + Sync;
9696

97-
/// A tracing target that either forces full block ids to be printed where they're normally
98-
/// printed in the abbreviated form, or just makes block ids be printed where normally they won't
99-
/// be.
97+
/// A tracing target that forces full block ids to be printed in certain places where they're
98+
/// normally printed in the abbreviated form.
10099
pub const CHAINSTATE_TRACING_TARGET_VERBOSE_BLOCK_IDS: &str = "chainstate_verbose_block_ids";
101100

102101
#[must_use]
@@ -635,21 +634,6 @@ impl<S: BlockchainStorage, V: TransactionVerificationStrategy> Chainstate<S, V>
635634

636635
self.update_initial_block_download_flag()
637636
.map_err(BlockError::BestBlockIdQueryError)?;
638-
} else {
639-
if tracing::event_enabled!(tracing::Level::DEBUG, CHAINSTATE_TRACING_TARGET_VERBOSE_BLOCK_IDS) {
640-
// FIXME: return custom enum from attempt_to_process_block
641-
let chainstate_ref = self.make_db_tx_ro().map_err(BlockError::from)?;
642-
let bi = get_existing_block_index(&chainstate_ref, &block_id)?;
643-
644-
tracing::debug!(
645-
target: CHAINSTATE_TRACING_TARGET_VERBOSE_BLOCK_IDS,
646-
"Received stale block {:x} with height {}, timestamp: {} ({})",
647-
bi.block_id(),
648-
bi.block_height(),
649-
bi.block_timestamp(),
650-
bi.block_timestamp().into_time(),
651-
)
652-
}
653637
}
654638

655639
Ok(result)

0 commit comments

Comments
 (0)