fix: clippy warnings, or_fun_call and unnecessary_lazy_evaluations (#846)

This commit is contained in:
Kim, JinSan
2023-01-13 19:10:02 +09:00
committed by GitHub
parent e6ca4c56c6
commit c4bafe809b
8 changed files with 28 additions and 38 deletions

View File

@ -240,7 +240,7 @@ async fn handle_events(mut events: impl Stream<Item = NodeEvent> + Unpin) {
},
NodeEvent::Network(NetworkEvent::SessionClosed { peer_id, reason }) => {
state.connected_peers -= 1;
let reason = reason.map(|s| s.to_string()).unwrap_or("None".to_string());
let reason = reason.map(|s| s.to_string()).unwrap_or_else(|| "None".to_string());
warn!(target: "reth::cli", connected_peers = state.connected_peers, peer_id = %peer_id, %reason, "Peer disconnected.");
},
NodeEvent::Pipeline(PipelineEvent::Running { stage_id, stage_progress }) => {
@ -266,7 +266,7 @@ async fn handle_events(mut events: impl Stream<Item = NodeEvent> + Unpin) {
}
},
_ = interval.tick() => {
let stage = state.current_stage.map(|id| id.to_string()).unwrap_or("None".to_string());
let stage = state.current_stage.map(|id| id.to_string()).unwrap_or_else(|| "None".to_string());
info!(target: "reth::cli", connected_peers = state.connected_peers, %stage, checkpoint = state.current_checkpoint, "Status");
}
}

View File

@ -205,9 +205,10 @@ pub async fn run_test(path: PathBuf) -> eyre::Result<()> {
tracing::trace!("Our storage:{:?}", storage);
for (address, test_account) in state.iter() {
// check account
let our_account = tx.get::<tables::PlainAccountState>(*address)?.ok_or(
eyre!("Account is missing: {address} expected: {:?}", test_account),
)?;
let our_account =
tx.get::<tables::PlainAccountState>(*address)?.ok_or_else(|| {
eyre!("Account is missing: {address} expected: {:?}", test_account)
})?;
if test_account.balance.0 != our_account.balance {
return Err(eyre!(
"Account {address} balance diff, expected {} got {}",
@ -244,15 +245,19 @@ pub async fn run_test(path: PathBuf) -> eyre::Result<()> {
for (JsonU256(key), JsonU256(value)) in test_account.storage.iter() {
let our_value = storage
.get(address)
.ok_or(eyre!(
"Missing storage from test {storage:?} got {:?}",
test_account.storage
))?
.ok_or_else(|| {
eyre!(
"Missing storage from test {storage:?} got {:?}",
test_account.storage
)
})?
.get(key)
.ok_or(eyre!(
"Slot is missing from table {storage:?} got:{:?}",
test_account.storage
))?;
.ok_or_else(|| {
eyre!(
"Slot is missing from table {storage:?} got:{:?}",
test_account.storage
)
})?;
if value != our_value {
return Err(eyre!(
"Storage diff we got {address}: {storage:?} but expect: {:?}",