Skip to content

Commit

Permalink
chore: simplify DisplayBlocksChain (#7624)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes authored Apr 13, 2024
1 parent 96e3619 commit 4d79967
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
1 change: 0 additions & 1 deletion crates/net/downloaders/src/file_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@ mod tests {
},
test_utils::TestConsensus,
};
use reth_primitives::SealedHeader;
use reth_provider::test_utils::create_test_provider_factory;
use std::sync::Arc;

Expand Down
26 changes: 8 additions & 18 deletions crates/storage/provider/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,26 +325,16 @@ pub struct DisplayBlocksChain<'a>(pub &'a BTreeMap<BlockNumber, SealedBlockWithS

impl<'a> fmt::Display for DisplayBlocksChain<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if self.0.len() <= 3 {
write!(f, "[")?;
let mut iter = self.0.values().map(|block| block.num_hash());
if let Some(block_num_hash) = iter.next() {
write!(f, "{block_num_hash:?}")?;
for block_num_hash_iter in iter {
write!(f, ", {block_num_hash_iter:?}")?;
}
}
write!(f, "]")?;
let mut list = f.debug_list();
let mut values = self.0.values().map(|block| block.num_hash());
if values.len() <= 3 {
list.entries(values);
} else {
write!(
f,
"[{:?}, ..., {:?}]",
self.0.values().next().unwrap().num_hash(),
self.0.values().last().unwrap().num_hash()
)?;
list.entry(&values.next().unwrap());
list.entry(&format_args!("..."));
list.entry(&values.next_back().unwrap());
}

Ok(())
list.finish()
}
}

Expand Down

0 comments on commit 4d79967

Please sign in to comment.