diff --git a/bin/reth/src/commands/db/diff.rs b/bin/reth/src/commands/db/diff.rs index 864d237931..493dc17b59 100644 --- a/bin/reth/src/commands/db/diff.rs +++ b/bin/reth/src/commands/db/diff.rs @@ -1,19 +1,9 @@ -use std::{ - collections::HashMap, - fmt::Debug, - fs::{self, File}, - hash::Hash, - io::Write, - path::{Path, PathBuf}, -}; - -use crate::utils::DbTool; -use clap::Parser; - use crate::{ args::DatabaseArgs, dirs::{DataDirPath, PlatformPath}, + utils::DbTool, }; +use clap::Parser; use reth_db::{ cursor::DbCursorRO, database::Database, mdbx::DatabaseArguments, open_db_read_only, table::Table, transaction::DbTx, AccountChangeSet, AccountHistory, AccountsTrie, @@ -22,6 +12,14 @@ use reth_db::{ PlainStorageState, PruneCheckpoints, Receipts, StorageChangeSet, StorageHistory, StoragesTrie, SyncStage, SyncStageProgress, Tables, TransactionBlock, Transactions, TxHashNumber, TxSenders, }; +use std::{ + collections::HashMap, + fmt::Debug, + fs::{self, File}, + hash::Hash, + io::Write, + path::{Path, PathBuf}, +}; use tracing::info; #[derive(Parser, Debug)] diff --git a/bin/reth/src/commands/db/snapshots/receipts.rs b/bin/reth/src/commands/db/snapshots/receipts.rs index e235983bc4..203e021d37 100644 --- a/bin/reth/src/commands/db/snapshots/receipts.rs +++ b/bin/reth/src/commands/db/snapshots/receipts.rs @@ -3,7 +3,7 @@ use super::{ Command, Compression, PerfectHashingFunction, }; use rand::{seq::SliceRandom, Rng}; -use reth_db::{open_db_read_only, snapshot::ReceiptMask}; +use reth_db::{mdbx::DatabaseArguments, open_db_read_only, snapshot::ReceiptMask}; use reth_interfaces::db::LogLevel; use reth_primitives::{ snapshot::{Filters, InclusionFilter}, @@ -13,8 +13,6 @@ use reth_provider::{ providers::SnapshotProvider, BlockNumReader, ProviderError, ProviderFactory, ReceiptProvider, TransactionsProvider, TransactionsProviderExt, }; - -use reth_db::mdbx::DatabaseArguments; use std::{ path::{Path, PathBuf}, sync::Arc, diff --git a/bin/reth/src/commands/db/snapshots/transactions.rs b/bin/reth/src/commands/db/snapshots/transactions.rs index 7e5d30605d..e7600c92b6 100644 --- a/bin/reth/src/commands/db/snapshots/transactions.rs +++ b/bin/reth/src/commands/db/snapshots/transactions.rs @@ -3,7 +3,7 @@ use super::{ Command, Compression, PerfectHashingFunction, }; use rand::{seq::SliceRandom, Rng}; -use reth_db::{open_db_read_only, snapshot::TransactionMask}; +use reth_db::{mdbx::DatabaseArguments, open_db_read_only, snapshot::TransactionMask}; use reth_interfaces::db::LogLevel; use reth_primitives::{ snapshot::{Filters, InclusionFilter}, @@ -13,8 +13,6 @@ use reth_provider::{ providers::SnapshotProvider, BlockNumReader, ProviderError, ProviderFactory, TransactionsProvider, TransactionsProviderExt, }; - -use reth_db::mdbx::DatabaseArguments; use std::{ path::{Path, PathBuf}, sync::Arc, diff --git a/bin/reth/src/commands/db/tui.rs b/bin/reth/src/commands/db/tui.rs index 85fbeb079b..841440a470 100644 --- a/bin/reth/src/commands/db/tui.rs +++ b/bin/reth/src/commands/db/tui.rs @@ -160,32 +160,22 @@ where /// Move to the next list selection fn next(&mut self) { - let i = match self.list_state.selected() { - Some(i) => { - if i >= self.entries.len() - 1 { - 0 - } else { - i + 1 - } - } - None => 0, - }; - self.list_state.select(Some(i)); + self.list_state.select(Some( + self.list_state + .selected() + .map(|i| if i >= self.entries.len() - 1 { 0 } else { i + 1 }) + .unwrap_or(0), + )); } /// Move to the previous list selection fn previous(&mut self) { - let i = match self.list_state.selected() { - Some(i) => { - if i == 0 { - self.entries.len() - 1 - } else { - i - 1 - } - } - None => 0, - }; - self.list_state.select(Some(i)); + self.list_state.select(Some( + self.list_state + .selected() + .map(|i| if i == 0 { self.entries.len() - 1 } else { i - 1 }) + .unwrap_or(0), + )); } fn reset(&mut self) { @@ -194,22 +184,18 @@ where /// Fetch the next page of items fn next_page(&mut self) { - if self.skip + self.count >= self.total_entries { - return + if self.skip + self.count < self.total_entries { + self.skip += self.count; + self.fetch_page(); } - - self.skip += self.count; - self.fetch_page(); } /// Fetch the previous page of items fn previous_page(&mut self) { - if self.skip == 0 { - return + if self.skip > 0 { + self.skip = self.skip.saturating_sub(self.count); + self.fetch_page(); } - - self.skip = self.skip.saturating_sub(self.count); - self.fetch_page(); } /// Go to a specific page. diff --git a/crates/storage/db/src/tables/utils.rs b/crates/storage/db/src/tables/utils.rs index d76808f8ad..331f2905c2 100644 --- a/crates/storage/db/src/tables/utils.rs +++ b/crates/storage/db/src/tables/utils.rs @@ -49,15 +49,16 @@ where T::Key: Decode, T::Value: Decompress, { - let key = match kv.0 { - Cow::Borrowed(k) => Decode::decode(k)?, - Cow::Owned(k) => Decode::decode(k)?, - }; - let value = match kv.1 { - Cow::Borrowed(v) => Decompress::decompress(v)?, - Cow::Owned(v) => Decompress::decompress_owned(v)?, - }; - Ok((key, value)) + Ok(( + match kv.0 { + Cow::Borrowed(k) => Decode::decode(k)?, + Cow::Owned(k) => Decode::decode(k)?, + }, + match kv.1 { + Cow::Borrowed(v) => Decompress::decompress(v)?, + Cow::Owned(v) => Decompress::decompress_owned(v)?, + }, + )) } /// Helper function to decode only a value from a `(key, value)` pair.