Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

impl Display for SyncStatus #9254

Merged
merged 7 commits into from
Jun 28, 2023
Merged

impl Display for SyncStatus #9254

merged 7 commits into from
Jun 28, 2023

Conversation

posvyatokum
Copy link
Member

Implement Display for SyncStatus that is only different from Debug in StateSync variant, i.e. it does not write potentially huge HashMap.
Use it in tracing of client.sync_status to remove noise from logs.

@posvyatokum posvyatokum requested a review from nikurt June 27, 2023 09:42
@posvyatokum posvyatokum requested a review from a team as a code owner June 27, 2023 09:42
impl std::fmt::Display for SyncStatus {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
SyncStatus::StateSync(hash, _) => write!(f, "StateSync {{ hash: {:?} }}", hash),
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be possible to format StateSync with the use of this function (to be made public)?

fn format_shard_sync_phase_per_shard(

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe the better way if to define ShardSyncDownload::debug using format_shard_sync_phase()

@nagisa
Copy link
Collaborator

nagisa commented Jun 27, 2023

it does not write potentially huge HashMap

A better way to achieve this is to use the alternate formatting flag (#) and make the decision within the Debug implementation still. Display is meant to be used for end-user facing output (I’d imagine in this case that would be e.g. a nicely formatted table)

@posvyatokum
Copy link
Member Author

I suspect I made things worse, here is a summary:

  1. Moved state sync status formatting functions closer to structure definitions to avoid circular dependencies. Now I can use it.
  2. Changed accessing element 0 in the formatting function to safe getter, because the localnet test was failing otherwise.
  3. I generally listened to @nagisa's comment, but I don't know how to redefine Debug for just one variant and I didn't want to 'print' all variants by hand, so I added extra structure just to define pretty debugging. This prompted little refactoring around client.
  4. I didn't find a way to pass # flag in tracing the way we pass ? or %, so changed the debug line that started it all a little.

@nagisa
Copy link
Collaborator

nagisa commented Jun 28, 2023

I didn't find a way to pass # flag in tracing the way we pass ? or %, so changed the debug line that started it all a little.

Ah, you’re right – tracing only provides means to use plain Debug or plain Display formatting. That’s unfortunate. A work-around that @mina86 was fond of is to add a newtype struct that would modify how printing is done for tracing specifically (so e.g. you’d have a PrintWithHashMap<'a>(&'a InnerT) for one kind of output and PrintWithoutHashMap<'a>(&'a InnerT) for the other), but I think using format! is reasonable enough as well if the performance of tracing that particular line isn’t a huge concern.

@posvyatokum posvyatokum merged commit 5e23504 into master Jun 28, 2023
@posvyatokum posvyatokum deleted the display-sync-status branch June 28, 2023 14:45
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.

3 participants