Skip to content

improve printSlot formatting#181

Merged
g11tech merged 3 commits intoblockblaz:mainfrom
anshalshukla:pretty_print
Sep 15, 2025
Merged

improve printSlot formatting#181
g11tech merged 3 commits intoblockblaz:mainfrom
anshalshukla:pretty_print

Conversation

@anshalshukla
Copy link
Copy Markdown
Collaborator

Closes #103

Copilot AI review requested due to automatic review settings September 14, 2025 10:56
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR improves the formatting of the printSlot function to provide a more comprehensive and visually appealing chain status display. The changes replace a simple one-line log message with a detailed ASCII table format that shows additional blockchain state information.

  • Enhanced chain status display with structured ASCII table formatting
  • Added comprehensive blockchain state information including justified/finalized checkpoints and timeliness status
  • Improved hex formatting for block roots and state information

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +190 to 216
self.logger.info(
\\+===============================================================+
\\ CHAIN STATUS
\\+===============================================================+
\\ Current Slot: {d} | Head Slot: {d} | Behind: {d}
\\+---------------------------------------------------------------+
\\ Head Block Root: 0x{any}
\\ Parent Block Root: 0x{any}
\\ State Root: 0x{any}
\\ Timely: {s}
\\+---------------------------------------------------------------+
\\ Latest Justified: Slot {d:>6} | Root: 0x{any}
\\ Latest Finalized: Slot {d:>6} | Root: 0x{any}
\\+===============================================================+
, .{
slot,
fcHead.blockRoot,
fcHead.slot,
blocksBehind,
std.fmt.fmtSliceHexLower(&fcHead.blockRoot),
std.fmt.fmtSliceHexLower(&fcHead.parentRoot),
std.fmt.fmtSliceHexLower(&fcHead.stateRoot),
if (isTimely) "YES" else "NO",
justified.slot,
std.fmt.fmtSliceHexLower(&justified.root),
finalized.slot,
std.fmt.fmtSliceHexLower(&finalized.root),
});
Copy link

Copilot AI Sep 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ASCII table formatting uses hardcoded spacing that may not align properly with different slot number lengths or terminal widths. Consider using dynamic width calculation or a more flexible formatting approach to ensure consistent alignment across different data ranges.

Copilot uses AI. Check for mistakes.

// Calculate chain progress
const blocksBehind = if (slot > fcHead.slot) slot - fcHead.slot else 0;
const isTimely = fcHead.timeliness;
Copy link

Copilot AI Sep 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable name isTimely suggests a boolean, but fcHead.timeliness may not be a boolean type. Consider using a more descriptive name like timelinessStatus or ensure proper boolean conversion if needed.

Copilot uses AI. Check for mistakes.
const finalized = self.forkChoice.fcStore.latest_finalized;

// Calculate chain progress
const blocksBehind = if (slot > fcHead.slot) slot - fcHead.slot else 0;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

snake case variable is best practical follow the guide https://ziglang.org/documentation/0.14.1/#Style-Guide

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the reference, I've updated it.

@g11tech
Copy link
Copy Markdown
Member

g11tech commented Sep 14, 2025

can you snapshot for how it prints?

@anshalshukla
Copy link
Copy Markdown
Collaborator Author

image

I've written a testcase for this, it's not a functional test, just an easy way to visualize the output. I can revert the commit if you think it's something we don't want to include in the codebase.

Copy link
Copy Markdown
Member

@g11tech g11tech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approving even though we might improve the formatting to be a bit more succinct which is more of a UX problem

@noopur23 create a task : come up with a succinct representation for printing the chain status and assign it to me

@g11tech g11tech merged commit 6ca0b6c into blockblaz:main Sep 15, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

reformat/pretty print the chain status in printSlot which is called at the start of the third interval (post attestation period)

4 participants