Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rustfmt config #144

Merged
merged 1 commit into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,14 @@ jobs:
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}

- name: Rustup install nightly
run: rustup toolchain install nightly

- name: Rustup install rustfmt
run: rustup component add rustfmt --toolchain nightly

- name: Run cargo fmt
run: cargo fmt --all -- --check
run: cargo +nightly fmt --all -- --check

- name: Run cargo clippy
run: cargo clippy --all-targets -- -D warnings
17 changes: 9 additions & 8 deletions crates/litesvm/benches/banks_client_comparison.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
use std::{path::PathBuf, sync::Arc};

use criterion::{criterion_group, criterion_main, Criterion};
use litesvm::LiteSVM;
use {
solana_account::Account, solana_feature_set::FeatureSet, solana_keypair::Keypair,
solana_message::Message, solana_signer::Signer, solana_transaction::Transaction,
};
use {
criterion::{criterion_group, criterion_main, Criterion},
litesvm::LiteSVM,
solana_account::Account,
solana_feature_set::FeatureSet,
solana_instruction::{account_meta::AccountMeta, Instruction},
solana_keypair::Keypair,
solana_message::Message,
solana_pubkey::Pubkey,
solana_rent::Rent,
solana_signer::Signer,
solana_transaction::Transaction,
std::{path::PathBuf, sync::Arc},
};

fn read_counter_program() -> Vec<u8> {
Expand Down
17 changes: 9 additions & 8 deletions crates/litesvm/benches/max_perf.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
use std::path::PathBuf;

use criterion::{criterion_group, criterion_main, Criterion};
use litesvm::LiteSVM;
use {
solana_account::Account, solana_keypair::Keypair, solana_message::Message, solana_rent::Rent,
solana_signer::Signer, solana_transaction::Transaction,
};
use {
criterion::{criterion_group, criterion_main, Criterion},
litesvm::LiteSVM,
solana_account::Account,
solana_instruction::{account_meta::AccountMeta, Instruction},
solana_keypair::Keypair,
solana_message::Message,
solana_pubkey::Pubkey,
solana_rent::Rent,
solana_signer::Signer,
solana_transaction::Transaction,
std::path::PathBuf,
};

const NUM_GREETINGS: u8 = 255;
Expand Down
16 changes: 8 additions & 8 deletions crates/litesvm/benches/simple_bench.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use std::path::PathBuf;

use criterion::{criterion_group, criterion_main, Criterion};
use litesvm::LiteSVM;
use {
solana_account::Account, solana_keypair::Keypair, solana_message::Message,
solana_signer::Signer, solana_transaction::Transaction,
};
use {
criterion::{criterion_group, criterion_main, Criterion},
litesvm::LiteSVM,
solana_account::Account,
solana_instruction::{account_meta::AccountMeta, Instruction},
solana_keypair::Keypair,
solana_message::Message,
solana_pubkey::Pubkey,
solana_signer::Signer,
solana_transaction::Transaction,
std::path::PathBuf,
};

fn read_counter_program() -> Vec<u8> {
Expand Down
28 changes: 12 additions & 16 deletions crates/litesvm/src/accounts_db.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
use log::error;
use solana_program_runtime::{
loaded_programs::{LoadProgramMetrics, ProgramCacheEntry, ProgramCacheForTxBatch},
sysvar_cache::SysvarCache,
};
use solana_system_program::{get_system_account_kind, SystemAccountKind};
use std::{collections::HashMap, sync::Arc};
use {
crate::error::{InvalidSysvarDataError, LiteSVMError},
log::error,
solana_account::{state_traits::StateMut, AccountSharedData, ReadableAccount, WritableAccount},
solana_nonce as nonce,
solana_pubkey::Pubkey,
solana_sdk_ids::native_loader,
solana_transaction_error::TransactionError,
};
use {
solana_address_lookup_table_interface::{error::AddressLookupError, state::AddressLookupTable},
solana_clock::Clock,
solana_instruction::error::InstructionError,
Expand All @@ -22,20 +11,27 @@ use {
v0::{LoadedAddresses, MessageAddressTableLookup},
AddressLoader, AddressLoaderError,
},
solana_nonce as nonce,
solana_program_runtime::{
loaded_programs::{LoadProgramMetrics, ProgramCacheEntry, ProgramCacheForTxBatch},
sysvar_cache::SysvarCache,
},
solana_pubkey::Pubkey,
solana_sdk_ids::{
bpf_loader, bpf_loader_deprecated, bpf_loader_upgradeable, loader_v4,
bpf_loader, bpf_loader_deprecated, bpf_loader_upgradeable, loader_v4, native_loader,
sysvar::{
clock::ID as CLOCK_ID, epoch_rewards::ID as EPOCH_REWARDS_ID,
epoch_schedule::ID as EPOCH_SCHEDULE_ID, last_restart_slot::ID as LAST_RESTART_SLOT_ID,
rent::ID as RENT_ID, slot_hashes::ID as SLOT_HASHES_ID,
stake_history::ID as STAKE_HISTORY_ID,
},
},
solana_system_program::{get_system_account_kind, SystemAccountKind},
solana_sysvar::Sysvar,
solana_transaction_error::TransactionError,
std::{collections::HashMap, sync::Arc},
};

use crate::error::{InvalidSysvarDataError, LiteSVMError};

const FEES_ID: Pubkey = solana_pubkey::pubkey!("SysvarFees111111111111111111111111111111111");
const RECENT_BLOCKHASHES_ID: Pubkey =
solana_pubkey::pubkey!("SysvarRecentB1ockHashes11111111111111111111");
Expand Down
3 changes: 1 addition & 2 deletions crates/litesvm/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use solana_instruction::error::InstructionError;
use thiserror::Error;
use {solana_instruction::error::InstructionError, thiserror::Error};

#[derive(Error, Debug)]
pub enum InvalidSysvarDataError {
Expand Down
4 changes: 1 addition & 3 deletions crates/litesvm/src/format_logs.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use std::fmt::Write;

use ansi_term::Colour;
use {ansi_term::Colour, std::fmt::Write};

const PROGRAM_LOG: &str = "Program log:";

Expand Down
4 changes: 1 addition & 3 deletions crates/litesvm/src/history.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use crate::types::TransactionResult;
use indexmap::IndexMap;
use solana_signature::Signature;
use {crate::types::TransactionResult, indexmap::IndexMap, solana_signature::Signature};

#[derive(Clone)]
pub struct TransactionHistory(IndexMap<Signature, TransactionResult>);
Expand Down
69 changes: 36 additions & 33 deletions crates/litesvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,50 +253,54 @@ much easier.

*/

use itertools::Itertools;
use log::error;
use precompiles::load_precompiles;
#[cfg(feature = "nodejs-internal")]
use qualifier_attr::qualifiers;
use solana_bpf_loader_program::syscalls::create_program_runtime_environment_v1;
use solana_bpf_loader_program::syscalls::create_program_runtime_environment_v2;
use solana_builtins::BUILTINS;
use solana_compute_budget::compute_budget::ComputeBudget;
use solana_compute_budget::compute_budget_limits::ComputeBudgetLimits;
use solana_compute_budget_instruction::instructions_processor::process_compute_budget_instructions;
use solana_log_collector::LogCollector;
use solana_program_runtime::{
invoke_context::{BuiltinFunctionWithContext, EnvironmentConfig, InvokeContext},
loaded_programs::{LoadProgramMetrics, ProgramCacheEntry},
};
use solana_svm_transaction::svm_message::SVMMessage;
use solana_system_program::{get_system_account_kind, SystemAccountKind};
#[allow(deprecated)]
use solana_sysvar::recent_blockhashes::IterItem;
#[allow(deprecated)]
use solana_sysvar::{fees::Fees, recent_blockhashes::RecentBlockhashes};
use solana_timings::ExecuteTimings;
use std::{cell::RefCell, path::Path, rc::Rc, sync::Arc};
use types::SimulatedTransactionInfo;
use utils::{
construct_instructions_account,
inner_instructions::inner_instructions_list_from_instruction_trace,
};
use {
crate::{
accounts_db::AccountsDb,
error::LiteSVMError,
history::TransactionHistory,
message_processor::process_message,
spl::load_spl_programs,
types::{
ExecutionResult, FailedTransactionMetadata, TransactionMetadata, TransactionResult,
},
utils::{create_blockhash, rent::RentState},
},
itertools::Itertools,
log::error,
precompiles::load_precompiles,
solana_account::{Account, AccountSharedData, ReadableAccount, WritableAccount},
solana_bpf_loader_program::syscalls::{
create_program_runtime_environment_v1, create_program_runtime_environment_v2,
},
solana_builtins::BUILTINS,
solana_clock::Clock,
solana_compute_budget::{
compute_budget::ComputeBudget, compute_budget_limits::ComputeBudgetLimits,
},
solana_compute_budget_instruction::instructions_processor::process_compute_budget_instructions,
solana_epoch_rewards::EpochRewards,
solana_epoch_schedule::EpochSchedule,
solana_feature_set::FeatureSet,
solana_fee_structure::FeeStructure,
solana_hash::Hash,
solana_keypair::Keypair,
solana_last_restart_slot::LastRestartSlot,
solana_log_collector::LogCollector,
solana_message::{
inner_instruction::InnerInstructionsList, Message, SanitizedMessage, VersionedMessage,
},
solana_native_token::LAMPORTS_PER_SOL,
solana_nonce::{state::DurableNonce, NONCED_TX_MARKER_IX_INDEX},
solana_program_runtime::{
invoke_context::{BuiltinFunctionWithContext, EnvironmentConfig, InvokeContext},
loaded_programs::{LoadProgramMetrics, ProgramCacheEntry},
},
solana_pubkey::Pubkey,
solana_rent::Rent,
solana_reserved_account_keys::ReservedAccountKeys,
Expand All @@ -306,24 +310,23 @@ use {
solana_slot_hashes::SlotHashes,
solana_slot_history::SlotHistory,
solana_stake_interface::stake_history::StakeHistory,
solana_svm_transaction::svm_message::SVMMessage,
solana_system_program::{get_system_account_kind, SystemAccountKind},
solana_sysvar::Sysvar,
solana_sysvar_id::SysvarId,
solana_timings::ExecuteTimings,
solana_transaction::{
sanitized::{MessageHash, SanitizedTransaction},
versioned::VersionedTransaction,
},
solana_transaction_context::{ExecutionRecord, IndexOfAccount, TransactionContext},
solana_transaction_error::TransactionError,
};

use crate::{
accounts_db::AccountsDb,
error::LiteSVMError,
history::TransactionHistory,
message_processor::process_message,
spl::load_spl_programs,
types::{ExecutionResult, FailedTransactionMetadata, TransactionMetadata, TransactionResult},
utils::{create_blockhash, rent::RentState},
std::{cell::RefCell, path::Path, rc::Rc, sync::Arc},
types::SimulatedTransactionInfo,
utils::{
construct_instructions_account,
inner_instructions::inner_instructions_list_from_instruction_trace,
},
};

pub mod error;
Expand Down
3 changes: 1 addition & 2 deletions crates/litesvm/src/precompiles.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use {
crate::LiteSVM,
solana_account::{AccountSharedData, WritableAccount},
solana_precompiles::get_precompiles,
solana_sdk_ids::native_loader,
};

use crate::LiteSVM;

pub(crate) fn load_precompiles(svm: &mut LiteSVM) {
let mut account = AccountSharedData::default();
account.set_owner(native_loader::id());
Expand Down
4 changes: 1 addition & 3 deletions crates/litesvm/src/spl/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use solana_pubkey::pubkey;

use crate::LiteSVM;
use {crate::LiteSVM, solana_pubkey::pubkey};

pub fn load_spl_programs(svm: &mut LiteSVM) {
svm.add_program(
Expand Down
3 changes: 1 addition & 2 deletions crates/litesvm/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use {
crate::format_logs::format_logs,
solana_account::AccountSharedData,
solana_instruction::error::InstructionError,
solana_message::inner_instruction::InnerInstructionsList,
Expand All @@ -9,8 +10,6 @@ use {
solana_transaction_error::{TransactionError, TransactionResult as Result},
};

use crate::format_logs::format_logs;

#[derive(Debug, Default, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct TransactionMetadata {
Expand Down
6 changes: 4 additions & 2 deletions crates/litesvm/src/utils/inner_instructions.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use {
solana_instruction::TRANSACTION_LEVEL_STACK_HEIGHT,
solana_message::compiled_instruction::CompiledInstruction,
solana_message::inner_instruction::{InnerInstruction, InnerInstructionsList},
solana_message::{
compiled_instruction::CompiledInstruction,
inner_instruction::{InnerInstruction, InnerInstructionsList},
},
solana_transaction_context::TransactionContext,
};

Expand Down
3 changes: 1 addition & 2 deletions crates/litesvm/src/utils/serde_with_str.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use {
serde::{de, Deserializer, Serializer},
serde::{Deserialize, Serialize},
serde::{de, Deserialize, Deserializer, Serialize, Serializer},
std::str::FromStr,
};

Expand Down
9 changes: 4 additions & 5 deletions crates/litesvm/tests/blockhash.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
use litesvm::LiteSVM;
use {
litesvm::LiteSVM,
solana_account::{state_traits::StateMut, ReadableAccount},
solana_keypair::Keypair,
solana_message::Message,
solana_nonce::{
state::{Data, State as NonceState},
versions::Versions,
},
solana_pubkey::Pubkey,
solana_rent::Rent,
solana_signer::Signer,
solana_system_interface::instruction::advance_nonce_account,
solana_system_interface::instruction::{advance_nonce_account, transfer},
solana_transaction::Transaction,
solana_transaction_error::TransactionError,
};
use {
solana_message::Message, solana_pubkey::Pubkey, solana_system_interface::instruction::transfer,
};

fn data_from_state(state: &NonceState) -> &Data {
match state {
Expand Down
14 changes: 5 additions & 9 deletions crates/litesvm/tests/compute_budget.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
use litesvm::LiteSVM;
use solana_compute_budget::compute_budget::ComputeBudget;
use {
solana_compute_budget_interface::ComputeBudgetInstruction, solana_keypair::Keypair,
solana_signer::Signer, solana_transaction::Transaction,
solana_transaction_error::TransactionError,
};
use {
solana_instruction::error::InstructionError, solana_message::Message, solana_pubkey::Pubkey,
solana_system_interface::instruction::transfer,
litesvm::LiteSVM, solana_compute_budget::compute_budget::ComputeBudget,
solana_compute_budget_interface::ComputeBudgetInstruction,
solana_instruction::error::InstructionError, solana_keypair::Keypair, solana_message::Message,
solana_pubkey::Pubkey, solana_signer::Signer, solana_system_interface::instruction::transfer,
solana_transaction::Transaction, solana_transaction_error::TransactionError,
};

#[test_log::test]
Expand Down
Loading