diff --git a/crates/cli/commands/src/db/diff.rs b/crates/cli/commands/src/db/diff.rs index fc04489eb4..b22930302f 100644 --- a/crates/cli/commands/src/db/diff.rs +++ b/crates/cli/commands/src/db/diff.rs @@ -10,7 +10,7 @@ use reth_node_core::{ dirs::{DataDirPath, PlatformPath}, }; use std::{ - collections::HashMap, + collections::BTreeMap, fmt::Debug, fs::{self, File}, hash::Hash, @@ -109,15 +109,20 @@ where info!(""); info!("Diff results for {table}:"); + // analyze the result and print some stats + let discrepancies = result.discrepancies.len(); + let extra_elements = result.extra_elements.len(); + + if discrepancies == 0 && extra_elements == 0 { + info!("No discrepancies or extra elements found in table {table}"); + return Ok(()); + } + // create directory and open file fs::create_dir_all(output_dir.as_ref())?; let file_name = format!("{table}.txt"); let mut file = File::create(output_dir.as_ref().join(file_name.clone()))?; - // analyze the result and print some stats - let discrepancies = result.discrepancies.len(); - let extra_elements = result.extra_elements.len(); - // Make a pretty summary header for the table writeln!(file, "Diff results for {table}")?; @@ -155,7 +160,7 @@ where } for discrepancy in result.discrepancies.values() { - writeln!(file, "{discrepancy:?}")?; + writeln!(file, "{discrepancy:#?}")?; } if extra_elements > 0 { @@ -163,7 +168,7 @@ where } for extra_element in result.extra_elements.values() { - writeln!(file, "{extra_element:?}")?; + writeln!(file, "{extra_element:#?}")?; } let full_file_name = output_dir.as_ref().join(file_name); @@ -257,10 +262,10 @@ where T::Key: Hash, { /// All elements of the database that are different - discrepancies: HashMap>, + discrepancies: BTreeMap>, /// Any extra elements, and the table they are in - extra_elements: HashMap>, + extra_elements: BTreeMap>, } impl Default for TableDiffResult @@ -269,7 +274,7 @@ where T::Key: Hash, { fn default() -> Self { - Self { discrepancies: HashMap::default(), extra_elements: HashMap::default() } + Self { discrepancies: BTreeMap::default(), extra_elements: BTreeMap::default() } } }