Skip to content

Commit c453c14

Browse files
zclawzzclawz
andauthored
fix: skip STF re-processing for blocks already known to fork choice (#671)
* fix: skip STF re-processing for blocks already known to fork choice (closes #669) * fix: also skip STF re-processing in processCachedDescendants if block already known to fork choice --------- Co-authored-by: zclawz <zclawz@openclaw.ai>
1 parent b5f43c7 commit c453c14

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

pkgs/node/src/node.zig

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,17 @@ pub const BeamNode = struct {
391391
// Try to process each descendant
392392
for (descendants_to_process.items) |descendant_root| {
393393
if (self.network.getFetchedBlock(descendant_root)) |cached_block| {
394+
// Skip if already known to fork choice — same guard as processBlockByRootChunk
395+
if (self.chain.forkChoice.hasBlock(descendant_root)) {
396+
self.logger.debug(
397+
"cached block 0x{x} is already known to fork choice, skipping re-processing",
398+
.{&descendant_root},
399+
);
400+
_ = self.network.removeFetchedBlock(descendant_root);
401+
self.processCachedDescendants(descendant_root);
402+
continue;
403+
}
404+
394405
self.logger.debug(
395406
"Attempting to process cached block 0x{x}",
396407
.{&descendant_root},
@@ -602,6 +613,19 @@ pub const BeamNode = struct {
602613
});
603614
}
604615

616+
// Skip STF re-processing if the block is already known to fork choice
617+
// (e.g. the checkpoint sync anchor block — it is the trust root and does not
618+
// need state-transition re-processing; re-processing it would cause an infinite
619+
// fetch loop because onBlock would always see it as "already processed").
620+
if (self.chain.forkChoice.hasBlock(block_root)) {
621+
self.logger.debug(
622+
"block 0x{x} is already known to fork choice, skipping re-processing",
623+
.{&block_root},
624+
);
625+
self.processCachedDescendants(block_root);
626+
return;
627+
}
628+
605629
// Try to add the block to the chain
606630
const missing_roots = self.chain.onBlock(signed_block.*, .{}) catch |err| {
607631
// Check if the error is due to missing parent

0 commit comments

Comments
 (0)