Skip to content
Closed
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
3 changes: 1 addition & 2 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
/programs/loader-v4/ @anza-xyz/svm
/runtime-transaction/ @anza-xyz/tx-metadata
/svm-conformance/ @anza-xyz/svm
/svm-rent-collector/ @anza-xyz/svm
/svm-transaction/ @anza-xyz/svm
/svm/ @anza-xyz/svm
/svm/examples/Cargo.lock
/svm-callback/ @anza-xyz/svm
/transaction-context/ @anza-xyz/svm
/transaction-view/ @anza-xyz/tx-metadata
/transaction-view/ @anza-xyz/tx-metadata
17 changes: 0 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ members = [
"svm-callback",
"svm-conformance",
"svm-feature-set",
"svm-rent-collector",
"svm-transaction",
"syscalls",
"syscalls/gen-syscall-list",
Expand Down Expand Up @@ -544,7 +543,6 @@ solana-svm = { path = "svm", version = "=3.0.0" }
solana-svm-callback = { path = "svm-callback", version = "=3.0.0" }
solana-svm-conformance = { path = "svm-conformance", version = "=3.0.0" }
solana-svm-feature-set = { path = "svm-feature-set", version = "=3.0.0" }
solana-svm-rent-collector = { path = "svm-rent-collector", version = "=3.0.0" }
solana-svm-transaction = { path = "svm-transaction", version = "=3.0.0" }
solana-system-interface = "1.0"
solana-system-program = { path = "programs/system", version = "=3.0.0" }
Expand Down
2 changes: 1 addition & 1 deletion core/src/banking_stage/consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ impl Consumer {
&mut fee_payer_account,
0,
error_counters,
bank.rent_collector(),
&bank.rent_collector().rent,
fee,
)
}
Expand Down
1 change: 0 additions & 1 deletion runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ solana-stake-interface = { workspace = true }
solana-stake-program = { workspace = true }
solana-svm = { workspace = true }
solana-svm-callback = { workspace = true }
solana-svm-rent-collector = { workspace = true }
solana-svm-transaction = { workspace = true }
solana-system-interface = { workspace = true }
solana-system-program = { workspace = true, optional = true }
Expand Down
5 changes: 1 addition & 4 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ use {
epoch_stakes::{NodeVoteAccounts, VersionedEpochStakes},
inflation_rewards::points::InflationPointCalculationEvent,
installed_scheduler_pool::{BankWithScheduler, InstalledSchedulerRwLock},
rent_collector::RentCollectorWithMetrics,
runtime_config::RuntimeConfig,
snapshot_hash::SnapshotHash,
stake_account::StakeAccount,
Expand Down Expand Up @@ -3271,14 +3270,12 @@ impl Bank {

let (blockhash, blockhash_lamports_per_signature) =
self.last_blockhash_and_lamports_per_signature();
let rent_collector_with_metrics =
RentCollectorWithMetrics::new(self.rent_collector.clone());
let processing_environment = TransactionProcessingEnvironment {
blockhash,
blockhash_lamports_per_signature,
epoch_total_stake: self.get_current_epoch_total_stake(),
feature_set: self.feature_set.runtime_features(),
rent_collector: Some(&rent_collector_with_metrics),
rent: self.rent_collector.rent.clone(),
};

let sanitized_output = self
Expand Down
13 changes: 7 additions & 6 deletions runtime/src/bank/fee_distribution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use {
solana_pubkey::Pubkey,
solana_reward_info::{RewardInfo, RewardType},
solana_runtime_transaction::transaction_with_meta::TransactionWithMeta,
solana_svm_rent_collector::svm_rent_collector::SVMRentCollector,
solana_svm::rent_calculator::{get_account_rent_state, transition_allowed},
solana_system_interface::program as system_program,
std::{result::Result, sync::atomic::Ordering::Relaxed},
thiserror::Error,
Expand Down Expand Up @@ -153,16 +153,17 @@ impl Bank {
return Err(DepositFeeError::InvalidAccountOwner);
}

let recipient_pre_rent_state = self.rent_collector().get_account_rent_state(&account);
let recipient_pre_rent_state =
get_account_rent_state(&self.rent_collector().rent, &account);
let distribution = account.checked_add_lamports(fees);
if distribution.is_err() {
return Err(DepositFeeError::LamportOverflow);
}

let recipient_post_rent_state = self.rent_collector().get_account_rent_state(&account);
let rent_state_transition_allowed = self
.rent_collector()
.transition_allowed(&recipient_pre_rent_state, &recipient_post_rent_state);
let recipient_post_rent_state =
get_account_rent_state(&self.rent_collector().rent, &account);
let rent_state_transition_allowed =
transition_allowed(&recipient_pre_rent_state, &recipient_post_rent_state);
if !rent_state_transition_allowed {
return Err(DepositFeeError::InvalidRentPayingAccount);
}
Expand Down
1 change: 0 additions & 1 deletion runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ pub mod loader_utils;
pub mod non_circulating_supply;
pub mod prioritization_fee;
pub mod prioritization_fee_cache;
pub mod rent_collector;
pub mod root_bank_cache;
pub mod runtime_config;
pub mod serde_snapshot;
Expand Down
84 changes: 0 additions & 84 deletions runtime/src/rent_collector.rs

This file was deleted.

2 changes: 1 addition & 1 deletion scripts/patch-crates.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ update_solana_dependencies() {
solana-storage-bigtable
solana-storage-proto
solana-streamer
solana-svm-rent-collector
solana-svm-rent-calculator
solana-svm-transaction
solana-test-validator
solana-thin-client
Expand Down
11 changes: 3 additions & 8 deletions svm-rent-collector/Cargo.toml → svm-rent-calculator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "solana-svm-rent-collector"
description = "Solana SVM Rent Collector"
documentation = "https://docs.rs/solana-svm-rent-collector"
name = "solana-svm-rent-calculator"
description = "Solana SVM Rent Calculator"
documentation = "https://docs.rs/solana-svm-rent-calculator"
version = { workspace = true }
authors = { workspace = true }
repository = { workspace = true }
Expand All @@ -11,13 +11,8 @@ edition = { workspace = true }

[dependencies]
solana-account = { workspace = true }
solana-clock = { workspace = true }
solana-pubkey = { workspace = true }
solana-rent = { workspace = true }
solana-rent-collector = { workspace = true }
solana-sdk-ids = { workspace = true }
solana-transaction-context = { workspace = true }
solana-transaction-error = { workspace = true }

[dev-dependencies]
solana-epoch-schedule = { workspace = true }
6 changes: 6 additions & 0 deletions svm-rent-calculator/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//! Solana SVM Rent Calculator.
//!
//! Rent management for SVM.

pub mod rent_state;
pub mod svm_rent_calculator;
107 changes: 107 additions & 0 deletions svm-rent-calculator/src/svm_rent_calculator.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
//! Helpers for rent calculation within the Solana VM.

use {
crate::rent_state::RentState,
solana_account::{AccountSharedData, ReadableAccount},
solana_pubkey::Pubkey,
solana_rent::Rent,
solana_transaction_context::{IndexOfAccount, TransactionContext},
solana_transaction_error::{TransactionError, TransactionResult},
};

/// Check rent state transition for an account in a transaction.
///
/// This method has a default implementation that calls into
/// `check_rent_state_with_account`.
pub fn check_rent_state(
pre_rent_state: Option<&RentState>,
post_rent_state: Option<&RentState>,
transaction_context: &TransactionContext,
index: IndexOfAccount,
) -> TransactionResult<()> {
if let Some((pre_rent_state, post_rent_state)) = pre_rent_state.zip(post_rent_state) {
let expect_msg = "account must exist at TransactionContext index if rent-states are Some";
check_rent_state_with_account(
pre_rent_state,
post_rent_state,
transaction_context
.get_key_of_account_at_index(index)
.expect(expect_msg),
&transaction_context
.accounts()
.try_borrow(index)
.expect(expect_msg),
index,
)?;
}
Ok(())
}

/// Check rent state transition for an account directly.
///
/// This method has a default implementation that checks whether the
/// transition is allowed and returns an error if it is not. It also
/// verifies that the account is not the incinerator.
pub fn check_rent_state_with_account(
pre_rent_state: &RentState,
post_rent_state: &RentState,
address: &Pubkey,
_account_state: &AccountSharedData,
account_index: IndexOfAccount,
) -> TransactionResult<()> {
if !solana_sdk_ids::incinerator::check_id(address)
&& !transition_allowed(pre_rent_state, post_rent_state)
{
let account_index = account_index as u8;
Err(TransactionError::InsufficientFundsForRent { account_index })
} else {
Ok(())
}
}

/// Determine the rent state of an account.
///
/// This method has a default implementation that treats accounts with zero
/// lamports as uninitialized and uses the implemented `get_rent` to
/// determine whether an account is rent-exempt.
pub fn get_account_rent_state(rent: &Rent, account: &AccountSharedData) -> RentState {
if account.lamports() == 0 {
RentState::Uninitialized
} else if rent.is_exempt(account.lamports(), account.data().len()) {
RentState::RentExempt
} else {
RentState::RentPaying {
data_size: account.data().len(),
lamports: account.lamports(),
}
}
}

/// Check whether a transition from the pre_rent_state to the
/// post_rent_state is valid.
///
/// This method has a default implementation that allows transitions from
/// any state to `RentState::Uninitialized` or `RentState::RentExempt`.
/// Pre-state `RentState::RentPaying` can only transition to
/// `RentState::RentPaying` if the data size remains the same and the
/// account is not credited.
pub fn transition_allowed(pre_rent_state: &RentState, post_rent_state: &RentState) -> bool {
match post_rent_state {
RentState::Uninitialized | RentState::RentExempt => true,
RentState::RentPaying {
data_size: post_data_size,
lamports: post_lamports,
} => {
match pre_rent_state {
RentState::Uninitialized | RentState::RentExempt => false,
RentState::RentPaying {
data_size: pre_data_size,
lamports: pre_lamports,
} => {
// Cannot remain RentPaying if resized or credited.
post_data_size == pre_data_size && post_lamports <= pre_lamports
}
}
}
}
}
6 changes: 0 additions & 6 deletions svm-rent-collector/src/lib.rs

This file was deleted.

Loading
Loading