Skip to content

Commit

Permalink
fix fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
al8n committed Sep 20, 2023
1 parent 7fd4476 commit bac5bfc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 30 deletions.
54 changes: 25 additions & 29 deletions nomos-core/src/block/debug_happy.rs
Original file line number Diff line number Diff line change
@@ -1,39 +1,35 @@
use std::{
fs::File,
hash::Hash,
sync::OnceLock,
};
use consensus_engine::{Qc, AggregateQc, View};
use consensus_engine::{AggregateQc, Qc, View};
use parking_lot::Mutex;
use std::{fs::File, hash::Hash, sync::OnceLock};

static TEMP_DEBUG_FILE: OnceLock<Mutex<File>> = OnceLock::new();

pub fn debug_file() -> &'static Mutex<File> {
// Unwrap because we will only use this function in tests, panic anyway.
TEMP_DEBUG_FILE.get_or_init(|| Mutex::new(tempfile::tempfile().unwrap()))
// Unwrap because we will only use this function in tests, panic anyway.
TEMP_DEBUG_FILE.get_or_init(|| Mutex::new(tempfile::tempfile().unwrap()))
}

impl<Tx: Clone + Eq + Hash, Blob: Clone + Eq + Hash> Drop for super::Block<Tx, Blob> {
fn drop(&mut self) {
let header = self.header();
// We need to persist the block to disk before dropping it
// if there is a aggregated qc when testing happy path
if let Qc::Aggregated(qcs) = &header.parent_qc {
#[derive(serde::Serialize)]
struct Info<'a> {
id: String,
view: View,
qcs: &'a AggregateQc,
}
fn drop(&mut self) {
let header = self.header();
// We need to persist the block to disk before dropping it
// if there is a aggregated qc when testing happy path
if let Qc::Aggregated(qcs) = &header.parent_qc {
#[derive(serde::Serialize)]
struct Info<'a> {
id: String,
view: View,
qcs: &'a AggregateQc,
}

let mut file = debug_file().lock();
let info = Info {
id: format!("{}", header.id),
view: header.view,
qcs,
};
// Use pretty print to make it easier to read, because we need the this for debugging.
serde_json::to_writer_pretty(&mut *file, &info).unwrap();
let mut file = debug_file().lock();
let info = Info {
id: format!("{}", header.id),
view: header.view,
qcs,
};
// Use pretty print to make it easier to read, because we need the this for debugging.
serde_json::to_writer_pretty(&mut *file, &info).unwrap();
}
}
}
}
}
2 changes: 1 addition & 1 deletion nomos-core/src/block/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,4 @@ impl<
}

#[cfg(feature = "debug-happy")]
mod debug_happy;
mod debug_happy;

0 comments on commit bac5bfc

Please sign in to comment.