Skip to content

Commit 1ae734c

Browse files
committed
fix: get missing blocks from fc
1 parent 35acebc commit 1ae734c

1 file changed

Lines changed: 32 additions & 28 deletions

File tree

pkgs/node/src/chain.zig

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -636,12 +636,24 @@ pub const BeamChain = struct {
636636
self.node_registry.getNodeNameFromPeerId(sender_peer_id),
637637
});
638638

639-
if (!hasBlock) {
639+
if (hasBlock) {
640+
self.module_logger.debug("reprocessing locally produced block to add signed proposer attestation: blockroot=0x{x} slot={d} proposer={d}", .{
641+
&block_root,
642+
block.slot,
643+
block.proposer_index,
644+
});
645+
} else {
646+
self.module_logger.debug("processing block not locally produced before publishing: blockroot=0x{x} slot={d} proposer={d}", .{
647+
&block_root,
648+
block.slot,
649+
block.proposer_index,
650+
});
651+
640652
// Validation errors propagate to node.zig for context-aware logging
641653
try self.validateBlock(block, true);
642654

643655
// If the forkchoice clock hasn't yet ticked to this block's slot,
644-
// onBlock would reject it with FutureSlot. Queue the block and
656+
// onBlock would reject it with FutureSlot. Queue the block and
645657
// replay it from onInterval once the clock has advanced.
646658
if (block.slot * constants.INTERVALS_PER_SLOT > self.forkChoice.fcStore.time) {
647659
self.module_logger.debug(
@@ -673,36 +685,28 @@ pub const BeamChain = struct {
673685
cloned.deinit();
674686
}
675687
}
688+
}
676689

677-
const missing_roots = self.onBlock(signed_block, .{
678-
.blockRoot = block_root,
679-
}) catch |err| {
680-
self.module_logger.err("error processing block for slot={d} root=0x{x}: {any}", .{
681-
block.slot,
682-
&block_root,
683-
err,
684-
});
685-
return err;
686-
};
687-
// followup with additional housekeeping tasks
688-
self.onBlockFollowup(true, &signed_block);
689-
// NOTE: ownership of `missing_roots` is transferred to the caller (BeamNode),
690-
// which is responsible for freeing it after optionally fetching those roots.
691-
692-
// Return both the block root and missing attestation roots so the node can:
693-
// 1. Call processCachedDescendants(block_root) to retry any cached children
694-
// 2. Fetch missing attestation head blocks via RPC
695-
return .{
696-
.processed_block_root = block_root,
697-
.missing_attestation_roots = missing_roots,
698-
};
699-
} else {
700-
self.module_logger.debug("skipping processing the already present block slot={d} blockroot=0x{x}", .{
690+
// Call onBlock even when block is already in FC so we get missing_roots and can trigger
691+
// processCachedDescendants / fetchBlockByRoots (same pattern as publishBlock in node.zig).
692+
const missing_roots = self.onBlock(signed_block, .{
693+
.blockRoot = block_root,
694+
}) catch |err| {
695+
self.module_logger.err("error processing block for slot={d} root=0x{x}: {any}", .{
701696
block.slot,
702697
&block_root,
698+
err,
703699
});
704-
}
705-
return .{};
700+
return err;
701+
};
702+
703+
self.onBlockFollowup(true, &signed_block);
704+
705+
// NOTE: ownership of `missing_roots` is transferred to the caller (BeamNode).
706+
return .{
707+
.processed_block_root = block_root,
708+
.missing_attestation_roots = missing_roots,
709+
};
706710
},
707711
.attestation => |signed_attestation| {
708712
const slot = signed_attestation.message.slot;

0 commit comments

Comments
 (0)