diff --git a/cli/src/main.rs b/cli/src/main.rs index 851d8befd..8b2892b7a 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -91,9 +91,10 @@ pub fn parse_args(matches: &ArgMatches<'_>) -> Result())?; if lamports < minimum_balance { - Err(WalletError::BadParameter(format!( + return Err(WalletError::BadParameter(format!( "need atleast {} lamports for stake account to be rent exempt, provided lamports: {}", minimum_balance, lamports - )))?; + )) + .into()); } let ixs = stake_instruction::create_stake_account_with_lockup( @@ -486,9 +487,10 @@ pub fn process_show_stake_account( ) -> ProcessResult { let stake_account = rpc_client.get_account(stake_account_pubkey)?; if stake_account.owner != solana_stake_api::id() { - Err(WalletError::RpcRequestError( + return Err(WalletError::RpcRequestError( format!("{:?} is not a stake account", stake_account_pubkey).to_string(), - ))?; + ) + .into()); } fn show_authorized(authorized: &Authorized) { println!("authorized staker: {}", authorized.staker); @@ -537,7 +539,8 @@ pub fn process_show_stake_account( Err(err) => Err(WalletError::RpcRequestError(format!( "Account data could not be deserialized to stake state: {:?}", err - )))?, + )) + .into()), } } diff --git a/cli/src/validator_info.rs b/cli/src/validator_info.rs index 09e9c25a1..3d61efbce 100644 --- a/cli/src/validator_info.rs +++ b/cli/src/validator_info.rs @@ -92,13 +92,14 @@ fn verify_keybase( if client.head(&url).send()?.status().is_success() { Ok(()) } else { - Err(format!("keybase_username could not be confirmed at: {}. Please add this pubkey file to your keybase profile to connect", url))? + Err(format!("keybase_username could not be confirmed at: {}. Please add this pubkey file to your keybase profile to connect", url).into()) } } else { Err(format!( "keybase_username could not be parsed as String: {}", keybase_username - ))? + ) + .into()) } } @@ -136,7 +137,8 @@ fn parse_validator_info( Err(format!( "account {} found, but could not be parsed as ValidatorInfo", pubkey - ))? + ) + .into()) } } diff --git a/cli/src/vote.rs b/cli/src/vote.rs index b29ecdd8f..44a6f2f5c 100644 --- a/cli/src/vote.rs +++ b/cli/src/vote.rs @@ -145,9 +145,10 @@ pub fn process_show_vote_account( let vote_account = rpc_client.get_account(vote_account_pubkey)?; if vote_account.owner != solana_vote_api::id() { - Err(WalletError::RpcRequestError( + return Err(WalletError::RpcRequestError( format!("{:?} is not a vote account", vote_account_pubkey).to_string(), - ))?; + ) + .into()); } let vote_state = VoteState::deserialize(&vote_account.data).map_err(|_| { @@ -218,9 +219,10 @@ pub fn process_uptime( let vote_account = rpc_client.get_account(vote_account_pubkey)?; if vote_account.owner != solana_vote_api::id() { - Err(WalletError::RpcRequestError( + return Err(WalletError::RpcRequestError( format!("{:?} is not a vote account", vote_account_pubkey).to_string(), - ))?; + ) + .into()); } let vote_state = VoteState::deserialize(&vote_account.data).map_err(|_| { diff --git a/cli/src/wallet.rs b/cli/src/wallet.rs index 25ecf8af6..5743862cf 100644 --- a/cli/src/wallet.rs +++ b/cli/src/wallet.rs @@ -423,7 +423,7 @@ fn check_account_for_multiple_fees( return Ok(()); } } - Err(WalletError::InsufficientFundsForFee)? + Err(WalletError::InsufficientFundsForFee.into()) } pub fn check_unique_pubkeys( @@ -462,9 +462,12 @@ fn process_airdrop( ); let previous_balance = match rpc_client.retry_get_balance(&config.keypair.pubkey(), 5)? { Some(lamports) => lamports, - None => Err(WalletError::RpcRequestError( - "Received result of an unexpected type".to_string(), - ))?, + None => { + return Err(WalletError::RpcRequestError( + "Received result of an unexpected type".to_string(), + ) + .into()) + } }; request_and_confirm_airdrop(&rpc_client, drone_addr, &config.keypair.pubkey(), lamports)?; @@ -486,7 +489,8 @@ fn process_balance( Some(lamports) => Ok(build_balance_message(lamports, use_lamports_unit)), None => Err(WalletError::RpcRequestError( "Received result of an unexpected type".to_string(), - ))?, + ) + .into()), } } @@ -502,10 +506,9 @@ fn process_confirm(rpc_client: &RpcClient, signature: &Signature) -> ProcessResu Ok("Not found".to_string()) } } - Err(err) => Err(WalletError::RpcRequestError(format!( - "Unable to confirm: {:?}", - err - )))?, + Err(err) => { + Err(WalletError::RpcRequestError(format!("Unable to confirm: {:?}", err)).into()) + } } } @@ -619,9 +622,10 @@ fn process_show_storage_account( let account = rpc_client.get_account(storage_account_pubkey)?; if account.owner != solana_storage_api::id() { - Err(WalletError::RpcRequestError( + return Err(WalletError::RpcRequestError( format!("{:?} is not a storage account", storage_account_pubkey).to_string(), - ))?; + ) + .into()); } use solana_storage_api::storage_contract::StorageContract; @@ -771,9 +775,10 @@ fn process_pay( let witness = if let Some(ref witness_vec) = *witnesses { witness_vec[0] } else { - Err(WalletError::BadParameter( + return Err(WalletError::BadParameter( "Could not parse required signature pubkey(s)".to_string(), - ))? + ) + .into()); }; let contract_state = Keypair::new(); @@ -1361,22 +1366,22 @@ pub fn log_instruction_custom_error(result: Result) -> P where E: 'static + std::error::Error + DecodeError + FromPrimitive, { - if result.is_err() { - let err = result.unwrap_err(); - if let ClientError::TransactionError(TransactionError::InstructionError( - _, - InstructionError::CustomError(code), - )) = err - { - if let Some(specific_error) = E::decode_custom_error_to_enum(code) { - error!("{}::{:?}", E::type_of(), specific_error); - Err(specific_error)? + match result { + Err(err) => { + if let ClientError::TransactionError(TransactionError::InstructionError( + _, + InstructionError::CustomError(code), + )) = err + { + if let Some(specific_error) = E::decode_custom_error_to_enum(code) { + error!("{}::{:?}", E::type_of(), specific_error); + return Err(specific_error.into()); + } } + error!("{:?}", err); + Err(err.into()) } - error!("{:?}", err); - Err(err)? - } else { - Ok(result.unwrap()) + Ok(sig) => Ok(sig), } } diff --git a/core/src/blocktree.rs b/core/src/blocktree.rs index 397d56b3f..b54532e20 100644 --- a/core/src/blocktree.rs +++ b/core/src/blocktree.rs @@ -266,7 +266,7 @@ impl Blocktree { "Error: {:?} while submitting write batch for slot {:?} retrying...", e, from_slot ); - Err(e)?; + return Err(e); } Ok(end) } diff --git a/core/src/cluster_info.rs b/core/src/cluster_info.rs index cc767dd02..a1361a1f7 100644 --- a/core/src/cluster_info.rs +++ b/core/src/cluster_info.rs @@ -809,7 +809,7 @@ impl ClusterInfo { // by a valid tvu port location let valid: Vec<_> = self.repair_peers(); if valid.is_empty() { - Err(ClusterInfoError::NoPeers)?; + return Err(ClusterInfoError::NoPeers.into()); } let n = thread_rng().gen::() % valid.len(); let addr = valid[n].gossip; // send the request to the peer's gossip port diff --git a/core/src/packet.rs b/core/src/packet.rs index adbacb70e..b2faac352 100644 --- a/core/src/packet.rs +++ b/core/src/packet.rs @@ -605,7 +605,7 @@ impl Blob { "error sending {} byte packet to {:?}: {:?}", p.meta.size, a, e ); - Err(e)?; + return Err(e.into()); } } } diff --git a/core/src/replay_stage.rs b/core/src/replay_stage.rs index 97bc20a17..b80846847 100644 --- a/core/src/replay_stage.rs +++ b/core/src/replay_stage.rs @@ -448,7 +448,7 @@ impl ReplayStage { trace!("new root {}", new_root); if let Err(e) = root_bank_sender.send(rooted_banks) { trace!("root_bank_sender failed: {:?}", e); - Err(e)?; + return Err(e.into()); } } Self::update_confidence_cache(bank.clone(), total_staked, lockouts_sender); diff --git a/core/src/replicator.rs b/core/src/replicator.rs index 12df37688..62a7c81e2 100644 --- a/core/src/replicator.rs +++ b/core/src/replicator.rs @@ -582,10 +582,9 @@ impl Replicator { ) -> Result<()> { // make sure replicator has some balance if client.poll_get_balance(&keypair.pubkey())? == 0 { - Err(io::Error::new( - io::ErrorKind::Other, - "keypair account has no balance", - ))? + return Err( + io::Error::new(io::ErrorKind::Other, "keypair account has no balance").into(), + ); } // check if the storage account exists @@ -705,10 +704,7 @@ impl Replicator { .as_u64() .unwrap()) } else { - Err(io::Error::new( - io::ErrorKind::Other, - "No RPC peers...".to_string(), - ))? + Err(io::Error::new(io::ErrorKind::Other, "No RPC peers...".to_string()).into()) } } @@ -889,10 +885,9 @@ impl Replicator { // check if all the slots in the segment are complete if !Self::segment_complete(start_slot, slots_per_segment, blocktree) { - Err(io::Error::new( - ErrorKind::Other, - "Unable to download the full segment", - ))? + return Err( + io::Error::new(ErrorKind::Other, "Unable to download the full segment").into(), + ); } Ok(start_slot) } diff --git a/core/src/shred.rs b/core/src/shred.rs index 4af26debe..179572da1 100644 --- a/core/src/shred.rs +++ b/core/src/shred.rs @@ -572,7 +572,7 @@ impl Shredder { shred_bufs.append(&mut pending_shreds); if shred_bufs.len() != fec_set_size { - Err(reed_solomon_erasure::Error::TooFewShardsPresent)?; + return Err(reed_solomon_erasure::Error::TooFewShardsPresent); } let session = Session::new(num_data, num_coding).unwrap(); @@ -623,7 +623,7 @@ impl Shredder { }; if num_data.saturating_add(first_index) != last_index.saturating_add(1) { - Err(reed_solomon_erasure::Error::TooFewDataShards)?; + return Err(reed_solomon_erasure::Error::TooFewDataShards); } shreds.iter().map(|shred| &shred.payload).collect() diff --git a/core/src/storage_stage.rs b/core/src/storage_stage.rs index d9d102af1..c13ea5fab 100644 --- a/core/src/storage_stage.rs +++ b/core/src/storage_stage.rs @@ -432,7 +432,7 @@ impl StorageStage { } Err(e) => { info!("error encrypting file: {:?}", e); - Err(e)?; + return Err(e.into()); } } } diff --git a/core/src/tvu.rs b/core/src/tvu.rs index 48b711229..394cf873c 100644 --- a/core/src/tvu.rs +++ b/core/src/tvu.rs @@ -158,11 +158,11 @@ impl Tvu { fork_confidence_cache, ); - let blockstream_service = if blockstream_unix_socket.is_some() { + let blockstream_service = if let Some(blockstream_unix_socket) = blockstream_unix_socket { let blockstream_service = BlockstreamService::new( blockstream_slot_receiver, blocktree.clone(), - blockstream_unix_socket.unwrap(), + blockstream_unix_socket, &exit, ); Some(blockstream_service) diff --git a/core/src/validator.rs b/core/src/validator.rs index 27f570226..949f1f13f 100644 --- a/core/src/validator.rs +++ b/core/src/validator.rs @@ -528,8 +528,8 @@ pub fn new_banks_from_blocktree( dev_halt_at_slot, ); - if snapshot_config.is_some() { - bank_forks.set_snapshot_config(snapshot_config.unwrap()); + if let Some(snapshot_config) = snapshot_config { + bank_forks.set_snapshot_config(snapshot_config); } ( diff --git a/core/src/window_service.rs b/core/src/window_service.rs index f1cd7a0c7..7383d9ffa 100644 --- a/core/src/window_service.rs +++ b/core/src/window_service.rs @@ -77,8 +77,7 @@ fn recv_window( leader_schedule_cache: &Arc, ) -> Result<()> where - F: Fn(&Shred, u64) -> bool, - F: Sync, + F: Fn(&Shred, u64) -> bool + Sync, { let timer = Duration::from_millis(200); let mut packets = r.recv_timeout(timer)?; diff --git a/gossip/src/main.rs b/gossip/src/main.rs index 410c29b03..99d7855dd 100644 --- a/gossip/src/main.rs +++ b/gossip/src/main.rs @@ -173,12 +173,14 @@ fn main() -> Result<(), Box> { } } } - if num_nodes_exactly.is_some() && nodes.len() > num_nodes_exactly.unwrap() { - eprintln!( - "Error: Extra nodes discovered. Expecting exactly {}", - num_nodes_exactly.unwrap() - ); - exit(1); + if let Some(num_nodes_exactly) = num_nodes_exactly { + if nodes.len() > num_nodes_exactly { + eprintln!( + "Error: Extra nodes discovered. Expecting exactly {}", + num_nodes_exactly + ); + exit(1); + } } } ("get-rpc-url", Some(matches)) => { diff --git a/programs/stake_api/src/stake_instruction.rs b/programs/stake_api/src/stake_instruction.rs index 339e5ebe6..707b6d77c 100644 --- a/programs/stake_api/src/stake_instruction.rs +++ b/programs/stake_api/src/stake_instruction.rs @@ -273,7 +273,7 @@ pub fn process_instruction( trace!("keyed_accounts: {:?}", keyed_accounts); if keyed_accounts.is_empty() { - Err(InstructionError::InvalidInstructionData)?; + return Err(InstructionError::InvalidInstructionData); } let (me, rest) = &mut keyed_accounts.split_at_mut(1); @@ -287,7 +287,7 @@ pub fn process_instruction( } StakeInstruction::DelegateStake => { if rest.len() < 3 { - Err(InstructionError::InvalidInstructionData)?; + return Err(InstructionError::InvalidInstructionData); } let vote = &rest[0]; @@ -300,7 +300,7 @@ pub fn process_instruction( } StakeInstruction::RedeemVoteCredits => { if rest.len() != 4 { - Err(InstructionError::InvalidInstructionData)?; + return Err(InstructionError::InvalidInstructionData); } let (vote, rest) = rest.split_at_mut(1); let vote = &mut vote[0]; @@ -316,7 +316,7 @@ pub fn process_instruction( } StakeInstruction::Withdraw(lamports) => { if rest.len() < 3 { - Err(InstructionError::InvalidInstructionData)?; + return Err(InstructionError::InvalidInstructionData); } let (to, rest) = &mut rest.split_at_mut(1); let mut to = &mut to[0]; @@ -331,7 +331,7 @@ pub fn process_instruction( } StakeInstruction::Deactivate => { if rest.len() < 2 { - Err(InstructionError::InvalidInstructionData)?; + return Err(InstructionError::InvalidInstructionData); } let (vote, rest) = rest.split_at_mut(1); let vote = &mut vote[0]; diff --git a/programs/stake_api/src/stake_state.rs b/programs/stake_api/src/stake_state.rs index 567c0e312..04a3b0191 100644 --- a/programs/stake_api/src/stake_state.rs +++ b/programs/stake_api/src/stake_state.rs @@ -614,7 +614,7 @@ impl<'a> StakeAccount for KeyedAccount<'a> { }; if lockup.slot > clock.slot && lockup.custodian != *to.unsigned_key() { - return Err(StakeError::LockupInForce)?; + return Err(StakeError::LockupInForce.into()); } if lamports > self.account.lamports { return Err(InstructionError::InsufficientFunds); diff --git a/runtime/src/accounts.rs b/runtime/src/accounts.rs index f18af54d9..2666d5354 100644 --- a/runtime/src/accounts.rs +++ b/runtime/src/accounts.rs @@ -277,8 +277,7 @@ impl Accounts { /// returns only the latest/current version of B for this fork fn scan_fork(&self, fork: Fork, func: F) -> Vec where - F: Fn(&StoredAccount) -> Option, - F: Send + Sync, + F: Fn(&StoredAccount) -> Option + Send + Sync, B: Send + Default, { let accumulator: Vec> = self.accounts_db.scan_account_storage( diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index f16f2a414..37744b2d6 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -593,8 +593,7 @@ impl AccountsDB { // PERF: Sequentially read each storage entry in parallel pub fn scan_account_storage(&self, fork_id: Fork, scan_func: F) -> Vec where - F: Fn(&StoredAccount, AppendVecId, &mut B) -> (), - F: Send + Sync, + F: Fn(&StoredAccount, AppendVecId, &mut B) -> () + Send + Sync, B: Send + Default, { let storage_maps: Vec> = self diff --git a/runtime/src/system_instruction_processor.rs b/runtime/src/system_instruction_processor.rs index 7c5bd64aa..62e4e376a 100644 --- a/runtime/src/system_instruction_processor.rs +++ b/runtime/src/system_instruction_processor.rs @@ -20,7 +20,7 @@ fn create_system_account( "CreateAccount: invalid account[from] owner {} ", &keyed_accounts[FROM_ACCOUNT_INDEX].account.owner ); - Err(SystemError::SourceNotSystemAccount)?; + return Err(SystemError::SourceNotSystemAccount); } if !keyed_accounts[TO_ACCOUNT_INDEX].account.data.is_empty() @@ -30,7 +30,7 @@ fn create_system_account( "CreateAccount: invalid argument; account {} already in use", keyed_accounts[TO_ACCOUNT_INDEX].unsigned_key() ); - Err(SystemError::AccountAlreadyInUse)?; + return Err(SystemError::AccountAlreadyInUse); } if sysvar::check_id(&program_id) { @@ -38,7 +38,7 @@ fn create_system_account( "CreateAccount: invalid argument; program id {} invalid", program_id ); - Err(SystemError::InvalidProgramId)?; + return Err(SystemError::InvalidProgramId); } if sysvar::is_sysvar_id(&keyed_accounts[TO_ACCOUNT_INDEX].unsigned_key()) { @@ -46,7 +46,7 @@ fn create_system_account( "CreateAccount: invalid argument; account id {} invalid", program_id ); - Err(SystemError::InvalidAccountId)?; + return Err(SystemError::InvalidAccountId); } if lamports > keyed_accounts[FROM_ACCOUNT_INDEX].account.lamports { @@ -54,7 +54,7 @@ fn create_system_account( "CreateAccount: insufficient lamports ({}, need {})", keyed_accounts[FROM_ACCOUNT_INDEX].account.lamports, lamports ); - Err(SystemError::ResultWithNegativeLamports)?; + return Err(SystemError::ResultWithNegativeLamports); } keyed_accounts[FROM_ACCOUNT_INDEX].account.lamports -= lamports; keyed_accounts[TO_ACCOUNT_INDEX].account.lamports += lamports; @@ -80,7 +80,7 @@ fn transfer_lamports( "Transfer: insufficient lamports ({}, need {})", keyed_accounts[FROM_ACCOUNT_INDEX].account.lamports, lamports ); - Err(SystemError::ResultWithNegativeLamports)?; + return Err(SystemError::ResultWithNegativeLamports); } keyed_accounts[FROM_ACCOUNT_INDEX].account.lamports -= lamports; keyed_accounts[TO_ACCOUNT_INDEX].account.lamports += lamports; @@ -99,7 +99,7 @@ pub fn process_instruction( // All system instructions require that accounts_keys[0] be a signer if keyed_accounts[FROM_ACCOUNT_INDEX].signer_key().is_none() { debug!("account[from] is unsigned"); - Err(InstructionError::MissingRequiredSignature)?; + return Err(InstructionError::MissingRequiredSignature); } match instruction { @@ -110,7 +110,7 @@ pub fn process_instruction( } => create_system_account(keyed_accounts, lamports, space, &program_id), SystemInstruction::Assign { program_id } => { if !system_program::check_id(&keyed_accounts[FROM_ACCOUNT_INDEX].account.owner) { - Err(InstructionError::IncorrectProgramId)?; + return Err(InstructionError::IncorrectProgramId); } assign_account_to_program(keyed_accounts, &program_id) }