Add rustfmt.toml and `cargo fmt` (#23238)

* fmt

* formatted

Co-authored-by: Lucas B <buffalu@jito.network>
This commit is contained in:
buffalu 2022-02-18 23:32:29 -06:00 committed by GitHub
parent 1add82aa9e
commit 70ebab2c82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
33 changed files with 127 additions and 108 deletions

View File

@ -5,8 +5,10 @@
//! but they are undocumented, may change over time, and are generally more //! but they are undocumented, may change over time, and are generally more
//! cumbersome to use. //! cumbersome to use.
pub use crate::error::BanksClientError; pub use {
pub use solana_banks_interface::{BanksClient as TarpcClient, TransactionStatus}; crate::error::BanksClientError,
solana_banks_interface::{BanksClient as TarpcClient, TransactionStatus},
};
use { use {
borsh::BorshDeserialize, borsh::BorshDeserialize,
futures::{future::join_all, Future, FutureExt, TryFutureExt}, futures::{future::join_all, Future, FutureExt, TryFutureExt},

View File

@ -9,7 +9,10 @@ use {
log::*, log::*,
rand::{thread_rng, Rng}, rand::{thread_rng, Rng},
solana_core::{sigverify::TransactionSigVerifier, sigverify_stage::SigVerifyStage}, solana_core::{sigverify::TransactionSigVerifier, sigverify_stage::SigVerifyStage},
solana_perf::{packet::to_packet_batches, packet::PacketBatch, test_tx::test_tx}, solana_perf::{
packet::{to_packet_batches, PacketBatch},
test_tx::test_tx,
},
solana_sdk::{ solana_sdk::{
hash::Hash, hash::Hash,
signature::{Keypair, Signer}, signature::{Keypair, Signer},

View File

@ -1,9 +1,9 @@
use crate::tower1_7_14::Tower1_7_14;
use { use {
crate::{ crate::{
heaviest_subtree_fork_choice::HeaviestSubtreeForkChoice, heaviest_subtree_fork_choice::HeaviestSubtreeForkChoice,
latest_validator_votes_for_frozen_banks::LatestValidatorVotesForFrozenBanks, latest_validator_votes_for_frozen_banks::LatestValidatorVotesForFrozenBanks,
progress_map::{LockoutIntervals, ProgressMap}, progress_map::{LockoutIntervals, ProgressMap},
tower1_7_14::Tower1_7_14,
tower_storage::{SavedTower, SavedTowerVersions, TowerStorage}, tower_storage::{SavedTower, SavedTowerVersions, TowerStorage},
}, },
chrono::prelude::*, chrono::prelude::*,

View File

@ -11,8 +11,10 @@ use {
crossbeam_channel::{Receiver, RecvTimeoutError, SendError, Sender}, crossbeam_channel::{Receiver, RecvTimeoutError, SendError, Sender},
itertools::Itertools, itertools::Itertools,
solana_measure::measure::Measure, solana_measure::measure::Measure,
solana_perf::packet::PacketBatch, solana_perf::{
solana_perf::sigverify::{count_valid_packets, shrink_batches, Deduper}, packet::PacketBatch,
sigverify::{count_valid_packets, shrink_batches, Deduper},
},
solana_sdk::timing, solana_sdk::timing,
solana_streamer::streamer::{self, PacketBatchReceiver, StreamerError}, solana_streamer::streamer::{self, PacketBatchReceiver, StreamerError},
std::{ std::{
@ -370,12 +372,15 @@ impl SigVerifyStage {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::sigverify::TransactionSigVerifier; use {
use crate::sigverify_stage::timing::duration_as_ms; super::*,
use crossbeam_channel::unbounded; crate::{sigverify::TransactionSigVerifier, sigverify_stage::timing::duration_as_ms},
use solana_perf::packet::to_packet_batches; crossbeam_channel::unbounded,
use solana_perf::test_tx::test_tx; solana_perf::{
use {super::*, solana_perf::packet::Packet}; packet::{to_packet_batches, Packet},
test_tx::test_tx,
},
};
fn count_non_discard(packet_batches: &[PacketBatch]) -> usize { fn count_non_discard(packet_batches: &[PacketBatch]) -> usize {
packet_batches packet_batches

View File

@ -1,11 +1,13 @@
use crate::consensus::{SwitchForkDecision, TowerError}; use {
use solana_sdk::{ crate::consensus::{SwitchForkDecision, TowerError},
clock::Slot, solana_sdk::{
hash::Hash, clock::Slot,
pubkey::Pubkey, hash::Hash,
signature::{Signature, Signer}, pubkey::Pubkey,
signature::{Signature, Signer},
},
solana_vote_program::vote_state::{BlockTimestamp, Vote, VoteState},
}; };
use solana_vote_program::vote_state::{BlockTimestamp, Vote, VoteState};
#[frozen_abi(digest = "7phMrqmBo2D3rXPdhBj8CpjRvvmx9qgpcU4cDGkL3W9q")] #[frozen_abi(digest = "7phMrqmBo2D3rXPdhBj8CpjRvvmx9qgpcU4cDGkL3W9q")]
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, AbiExample)] #[derive(Clone, Serialize, Deserialize, Debug, PartialEq, AbiExample)]

View File

@ -1,6 +1,8 @@
use { use {
crate::consensus::{Result, Tower, TowerError, TowerVersions}, crate::{
crate::tower1_7_14::SavedTower1_7_14, consensus::{Result, Tower, TowerError, TowerVersions},
tower1_7_14::SavedTower1_7_14,
},
solana_sdk::{ solana_sdk::{
pubkey::Pubkey, pubkey::Pubkey,
signature::{Signature, Signer}, signature::{Signature, Signer},

View File

@ -417,8 +417,7 @@ pub mod tests {
solana_runtime::bank::Bank, solana_runtime::bank::Bank,
solana_sdk::signature::{Keypair, Signer}, solana_sdk::signature::{Keypair, Signer},
solana_streamer::socket::SocketAddrSpace, solana_streamer::socket::SocketAddrSpace,
std::sync::atomic::AtomicU64, std::sync::atomic::{AtomicU64, Ordering},
std::sync::atomic::Ordering,
}; };
#[ignore] #[ignore]

View File

@ -271,8 +271,11 @@ fn main() {
#[cfg(test)] #[cfg(test)]
pub mod test { pub mod test {
use solana_local_cluster::{cluster::Cluster, local_cluster::LocalCluster}; use {
use {super::*, solana_sdk::timing::timestamp}; super::*,
solana_local_cluster::{cluster::Cluster, local_cluster::LocalCluster},
solana_sdk::timing::timestamp,
};
#[test] #[test]
fn test_dos() { fn test_dos() {

View File

@ -25,10 +25,13 @@ use {
short_vec::decode_shortu16_len, short_vec::decode_shortu16_len,
signature::Signature, signature::Signature,
}, },
std::hash::Hasher, std::{
std::sync::atomic::{AtomicBool, AtomicU64, Ordering}, convert::TryFrom,
std::time::{Duration, Instant}, hash::Hasher,
std::{convert::TryFrom, mem::size_of}, mem::size_of,
sync::atomic::{AtomicBool, AtomicU64, Ordering},
time::{Duration, Instant},
},
}; };
// Representing key tKeYE4wtowRb8yRroZShTipE18YVnqwXjsSAoNsFU6g // Representing key tKeYE4wtowRb8yRroZShTipE18YVnqwXjsSAoNsFU6g

View File

@ -1,7 +1,7 @@
use crate::invoke_context::InvokeContext;
#[allow(deprecated)] #[allow(deprecated)]
use solana_sdk::sysvar::{fees::Fees, recent_blockhashes::RecentBlockhashes}; use solana_sdk::sysvar::{fees::Fees, recent_blockhashes::RecentBlockhashes};
use { use {
crate::invoke_context::InvokeContext,
solana_sdk::{ solana_sdk::{
account::{AccountSharedData, ReadableAccount}, account::{AccountSharedData, ReadableAccount},
instruction::InstructionError, instruction::InstructionError,

View File

@ -10,8 +10,7 @@ use {
account::AccountSharedData, account::AccountSharedData,
clock::Slot, clock::Slot,
hash::Hash, hash::Hash,
instruction::Instruction, instruction::{Instruction, InstructionError},
instruction::InstructionError,
pubkey::Pubkey, pubkey::Pubkey,
signature::{Keypair, Signer}, signature::{Keypair, Signer},
slot_hashes::SlotHashes, slot_hashes::SlotHashes,

View File

@ -10,14 +10,12 @@ use {
solana_program_test::*, solana_program_test::*,
solana_sdk::{ solana_sdk::{
account::ReadableAccount, account::ReadableAccount,
instruction::Instruction, instruction::{Instruction, InstructionError},
instruction::InstructionError,
pubkey::{Pubkey, PUBKEY_BYTES}, pubkey::{Pubkey, PUBKEY_BYTES},
signature::{Keypair, Signer}, signature::{Keypair, Signer},
transaction::{Transaction, TransactionError}, transaction::{Transaction, TransactionError},
}, },
std::borrow::Cow, std::{borrow::Cow, result::Result},
std::result::Result,
}; };
mod common; mod common;

View File

@ -218,8 +218,7 @@ impl<'a> AddressLookupTable<'a> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use {super::*, solana_sdk::hash::Hash};
use solana_sdk::hash::Hash;
impl AddressLookupTable<'_> { impl AddressLookupTable<'_> {
fn new_for_tests(meta: LookupTableMeta, num_addresses: usize) -> Self { fn new_for_tests(meta: LookupTableMeta, num_addresses: usize) -> Self {

View File

@ -200,8 +200,7 @@ impl TestBroadcastReceiver {
} }
pub fn recv_timeout(&mut self, timeout: std::time::Duration) -> Result<String, String> { pub fn recv_timeout(&mut self, timeout: std::time::Duration) -> Result<String, String> {
use std::thread::sleep; use {std::thread::sleep, tokio::sync::broadcast::error::TryRecvError};
use tokio::sync::broadcast::error::TryRecvError;
let started = std::time::Instant::now(); let started = std::time::Instant::now();

View File

@ -1195,8 +1195,8 @@ pub(crate) mod tests {
}, },
serial_test::serial, serial_test::serial,
solana_client::rpc_config::{ solana_client::rpc_config::{
RpcAccountInfoConfig, RpcProgramAccountsConfig, RpcSignatureSubscribeConfig, RpcAccountInfoConfig, RpcBlockSubscribeConfig, RpcBlockSubscribeFilter,
RpcTransactionLogsFilter, {RpcBlockSubscribeConfig, RpcBlockSubscribeFilter}, RpcProgramAccountsConfig, RpcSignatureSubscribeConfig, RpcTransactionLogsFilter,
}, },
solana_runtime::{ solana_runtime::{
commitment::BlockCommitment, commitment::BlockCommitment,

View File

@ -245,8 +245,7 @@ pub struct SquashTiming {
type EpochCount = u64; type EpochCount = u64;
mod executor_cache { mod executor_cache {
use super::*; use {super::*, log};
use log;
#[derive(Debug, Default)] #[derive(Debug, Default)]
pub struct Stats { pub struct Stats {
@ -16162,8 +16161,10 @@ pub(crate) mod tests {
/// Test exceeding the accounts data budget by creating accounts in a loop /// Test exceeding the accounts data budget by creating accounts in a loop
#[test] #[test]
fn test_accounts_data_budget_exceeded() { fn test_accounts_data_budget_exceeded() {
use solana_program_runtime::accounts_data_meter::MAX_ACCOUNTS_DATA_LEN; use {
use solana_sdk::system_instruction::MAX_PERMITTED_DATA_LENGTH; solana_program_runtime::accounts_data_meter::MAX_ACCOUNTS_DATA_LEN,
solana_sdk::system_instruction::MAX_PERMITTED_DATA_LENGTH,
};
solana_logger::setup(); solana_logger::setup();
let (genesis_config, mint_keypair) = create_genesis_config(1_000_000_000_000); let (genesis_config, mint_keypair) = create_genesis_config(1_000_000_000_000);

View File

@ -3,8 +3,7 @@ use {
log::*, log::*,
solana_measure::measure::Measure, solana_measure::measure::Measure,
solana_sdk::clock::Slot, solana_sdk::clock::Slot,
std::ops::Range, std::ops::{Bound, Range, RangeBounds},
std::ops::{Bound, RangeBounds},
}; };
/// Provide access to SnapshotStorages sorted by slot /// Provide access to SnapshotStorages sorted by slot

View File

@ -27,8 +27,7 @@ type StakeHistoryInner = solana_sdk::stake_history::StakeHistory;
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use {super::*, solana_sdk::stake_history::StakeHistoryEntry};
use solana_sdk::stake_history::StakeHistoryEntry;
fn rand_stake_history_entry() -> StakeHistoryEntry { fn rand_stake_history_entry() -> StakeHistoryEntry {
StakeHistoryEntry { StakeHistoryEntry {

View File

@ -88,13 +88,17 @@ fn parse_vote_instruction_data(
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use solana_sdk::signature::{Keypair, Signer}; use {
use solana_vote_program::{ super::*,
vote_instruction, vote_state::Vote, vote_transaction::new_vote_transaction, solana_sdk::{
hash::hash,
signature::{Keypair, Signer},
},
solana_vote_program::{
vote_instruction, vote_state::Vote, vote_transaction::new_vote_transaction,
},
}; };
use {super::*, solana_sdk::hash::hash};
fn run_test_parse_vote_transaction(input_hash: Option<Hash>) { fn run_test_parse_vote_transaction(input_hash: Option<Hash>) {
let node_keypair = Keypair::new(); let node_keypair = Keypair::new();
let vote_keypair = Keypair::new(); let vote_keypair = Keypair::new();

2
rustfmt.toml Normal file
View File

@ -0,0 +1,2 @@
imports_granularity = "One"
group_imports = "One"

View File

@ -24,10 +24,10 @@ pub mod solana_client {
} }
pub mod rpc_client { pub mod rpc_client {
use super::super::solana_sdk::{ use super::{
hash::Hash, signature::Signature, transaction::Transaction, super::solana_sdk::{hash::Hash, signature::Signature, transaction::Transaction},
client_error::Result as ClientResult,
}; };
use super::client_error::Result as ClientResult;
pub struct RpcClient; pub struct RpcClient;
@ -63,12 +63,7 @@ pub mod solana_client {
/// This lets examples in solana-program appear to be written as client /// This lets examples in solana-program appear to be written as client
/// programs. /// programs.
pub mod solana_sdk { pub mod solana_sdk {
pub use crate::hash; pub use crate::{hash, instruction, message, nonce, pubkey, system_instruction};
pub use crate::instruction;
pub use crate::message;
pub use crate::nonce;
pub use crate::pubkey;
pub use crate::system_instruction;
pub mod signature { pub mod signature {
use crate::pubkey::Pubkey; use crate::pubkey::Pubkey;
@ -103,11 +98,10 @@ pub mod solana_sdk {
} }
pub mod transaction { pub mod transaction {
use super::signers::Signers; use {
use crate::hash::Hash; super::signers::Signers,
use crate::instruction::Instruction; crate::{hash::Hash, instruction::Instruction, message::Message, pubkey::Pubkey},
use crate::message::Message; };
use crate::pubkey::Pubkey;
pub struct Transaction { pub struct Transaction {
pub message: Message, pub message: Message,

View File

@ -2,13 +2,12 @@
//! //!
//! this account carries the Bank's most recent bank hashes for some N parents //! this account carries the Bank's most recent bank hashes for some N parents
//! //!
pub use crate::clock::Slot;
use { use {
crate::hash::Hash, crate::hash::Hash,
std::{iter::FromIterator, ops::Deref}, std::{iter::FromIterator, ops::Deref},
}; };
pub use crate::clock::Slot;
pub const MAX_ENTRIES: usize = 512; // about 2.5 minutes to get your vote in pub const MAX_ENTRIES: usize = 512; // about 2.5 minutes to get your vote in
// This is to allow tests with custom slot hash expiry to avoid having to generate // This is to allow tests with custom slot hash expiry to avoid having to generate

View File

@ -24,8 +24,10 @@ pub mod solana_client {
} }
pub mod rpc_client { pub mod rpc_client {
use super::client_error::Result as ClientResult; use {
use crate::{hash::Hash, signature::Signature, transaction::Transaction}; super::client_error::Result as ClientResult,
crate::{hash::Hash, signature::Signature, transaction::Transaction},
};
pub struct RpcClient; pub struct RpcClient;

View File

@ -1,15 +1,17 @@
//! Successors of instruction_context_context::StackFrame, KeyedAccount and AccountInfo //! Successors of instruction_context_context::StackFrame, KeyedAccount and AccountInfo
use crate::{ use {
account::{AccountSharedData, ReadableAccount, WritableAccount}, crate::{
instruction::InstructionError, account::{AccountSharedData, ReadableAccount, WritableAccount},
lamports::LamportsError, instruction::InstructionError,
pubkey::Pubkey, lamports::LamportsError,
}; pubkey::Pubkey,
use std::{ },
cell::{RefCell, RefMut}, std::{
collections::HashSet, cell::{RefCell, RefMut},
pin::Pin, collections::HashSet,
pin::Pin,
},
}; };
pub type TransactionAccount = (Pubkey, AccountSharedData); pub type TransactionAccount = (Pubkey, AccountSharedData);

View File

@ -2,11 +2,7 @@
#![cfg(target_arch = "wasm32")] #![cfg(target_arch = "wasm32")]
#![allow(non_snake_case)] #![allow(non_snake_case)]
use { use {
crate::{ crate::{hash::Hash, message::Message, signer::keypair::Keypair, transaction::Transaction},
hash::Hash,
signer::keypair::Keypair,
{message::Message, transaction::Transaction},
},
solana_program::{ solana_program::{
pubkey::Pubkey, pubkey::Pubkey,
wasm::{display_to_jsvalue, instructions::Instructions}, wasm::{display_to_jsvalue, instructions::Instructions},

View File

@ -256,10 +256,12 @@ pub fn spawn_server(
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::*; use {
use crossbeam_channel::unbounded; super::*,
use quinn::{ClientConfig, NewConnection}; crossbeam_channel::unbounded,
use std::{net::SocketAddr, time::Instant}; quinn::{ClientConfig, NewConnection},
std::{net::SocketAddr, time::Instant},
};
struct SkipServerVerification; struct SkipServerVerification;

View File

@ -1,6 +1,8 @@
//! Errors related to proving and verifying proofs. //! Errors related to proving and verifying proofs.
use crate::{range_proof::errors::RangeProofError, sigma_proofs::errors::*}; use {
use thiserror::Error; crate::{range_proof::errors::RangeProofError, sigma_proofs::errors::*},
thiserror::Error,
};
// TODO: clean up errors for encryption // TODO: clean up errors for encryption
#[derive(Error, Clone, Debug, Eq, PartialEq)] #[derive(Error, Clone, Debug, Eq, PartialEq)]

View File

@ -1,6 +1,5 @@
//! Errors related to proving and verifying range proofs. //! Errors related to proving and verifying range proofs.
use crate::errors::TranscriptError; use {crate::errors::TranscriptError, thiserror::Error};
use thiserror::Error;
#[derive(Error, Clone, Debug, Eq, PartialEq)] #[derive(Error, Clone, Debug, Eq, PartialEq)]
pub enum RangeProofError { pub enum RangeProofError {

View File

@ -448,8 +448,10 @@ impl CtxtCtxtEqualityProof {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::*; use {
use crate::encryption::{elgamal::ElGamalSecretKey, pedersen::Pedersen}; super::*,
crate::encryption::{elgamal::ElGamalSecretKey, pedersen::Pedersen},
};
#[test] #[test]
fn test_ciphertext_commitment_equality_proof_correctness() { fn test_ciphertext_commitment_equality_proof_correctness() {

View File

@ -1,6 +1,5 @@
//! Errors related to proving and verifying sigma proofs. //! Errors related to proving and verifying sigma proofs.
use crate::errors::TranscriptError; use {crate::errors::TranscriptError, thiserror::Error};
use thiserror::Error;
#[derive(Error, Clone, Debug, Eq, PartialEq)] #[derive(Error, Clone, Debug, Eq, PartialEq)]
pub enum EqualityProofError { pub enum EqualityProofError {

View File

@ -448,8 +448,7 @@ fn conditional_select_ristretto(
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::*; use {super::*, crate::encryption::pedersen::Pedersen};
use crate::encryption::pedersen::Pedersen;
#[test] #[test]
fn test_fee_above_max_proof() { fn test_fee_above_max_proof() {

View File

@ -298,8 +298,10 @@ impl AggregatedValidityProof {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::*; use {
use crate::encryption::{elgamal::ElGamalKeypair, pedersen::Pedersen}; super::*,
crate::encryption::{elgamal::ElGamalKeypair, pedersen::Pedersen},
};
#[test] #[test]
fn test_validity_proof_correctness() { fn test_validity_proof_correctness() {

View File

@ -166,10 +166,12 @@ impl ZeroBalanceProof {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::*; use {
use crate::encryption::{ super::*,
elgamal::{DecryptHandle, ElGamalKeypair, ElGamalSecretKey}, crate::encryption::{
pedersen::{Pedersen, PedersenCommitment, PedersenOpening}, elgamal::{DecryptHandle, ElGamalKeypair, ElGamalSecretKey},
pedersen::{Pedersen, PedersenCommitment, PedersenOpening},
},
}; };
#[test] #[test]