Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Add feature for tracking dynamic reserved account set #34901

Closed
wants to merge 9 commits into from
Closed
6 changes: 4 additions & 2 deletions banks-server/src/banks_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ use {
},
solana_svm::transaction_results::TransactionExecutionResult,
std::{
convert::TryFrom,
io,
net::{Ipv4Addr, SocketAddr},
sync::{atomic::AtomicBool, Arc, RwLock},
Expand Down Expand Up @@ -179,6 +178,7 @@ fn simulate_transaction(
MessageHash::Compute,
Some(false), // is_simple_vote_tx
bank,
&bank.reserved_account_keys,
) {
Err(err) => {
return BanksTransactionResultWithSimulation {
Expand Down Expand Up @@ -333,6 +333,7 @@ impl Banks for BanksServer {
MessageHash::Compute,
Some(false), // is_simple_vote_tx
bank.as_ref(),
&bank.reserved_account_keys,
) {
Ok(tx) => tx,
Err(err) => return Some(Err(err)),
Expand Down Expand Up @@ -418,7 +419,8 @@ impl Banks for BanksServer {
commitment: CommitmentLevel,
) -> Option<u64> {
let bank = self.bank(commitment);
let sanitized_message = SanitizedMessage::try_from(message).ok()?;
let sanitized_message =
SanitizedMessage::try_from_legacy_message(message, &bank.reserved_account_keys).ok()?;
bank.get_fee_for_message(&sanitized_message)
}
}
Expand Down
2 changes: 2 additions & 0 deletions core/src/banking_stage/consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,7 @@ mod tests {
nonce_account::verify_nonce_account,
poh_config::PohConfig,
pubkey::Pubkey,
reserved_account_keys::ReservedAccountKeys,
signature::Keypair,
signer::Signer,
system_instruction, system_program, system_transaction,
Expand Down Expand Up @@ -2032,6 +2033,7 @@ mod tests {
MessageHash::Compute,
Some(false),
bank.as_ref(),
&ReservedAccountKeys::empty(),
)
.unwrap();

Expand Down
5 changes: 4 additions & 1 deletion core/src/banking_stage/immutable_deserialized_packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use {
feature_set,
hash::Hash,
message::Message,
pubkey::Pubkey,
sanitize::SanitizeError,
short_vec::decode_shortu16_len,
signature::Signature,
Expand All @@ -13,7 +14,7 @@ use {
VersionedTransaction,
},
},
std::{cmp::Ordering, mem::size_of, sync::Arc},
std::{cmp::Ordering, collections::HashSet, mem::size_of, sync::Arc},
thiserror::Error,
};

Expand Down Expand Up @@ -105,6 +106,7 @@ impl ImmutableDeserializedPacket {
feature_set: &Arc<feature_set::FeatureSet>,
votes_only: bool,
address_loader: impl AddressLoader,
reserved_account_keys: &HashSet<Pubkey>,
) -> Option<SanitizedTransaction> {
if votes_only && !self.is_simple_vote() {
return None;
Expand All @@ -114,6 +116,7 @@ impl ImmutableDeserializedPacket {
*self.message_hash(),
self.is_simple_vote(),
address_loader,
reserved_account_keys,
)
.ok()?;
tx.verify_precompiles(feature_set).ok()?;
Expand Down
1 change: 1 addition & 0 deletions core/src/banking_stage/latest_unprocessed_votes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ impl LatestUnprocessedVotes {
&bank.feature_set,
bank.vote_only_bank(),
bank.as_ref(),
&bank.reserved_account_keys,
)
{
if forward_packet_batches_by_accounts.try_add_packet(
Expand Down
1 change: 1 addition & 0 deletions core/src/banking_stage/read_write_account_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ mod tests {
MessageHash::Compute,
Some(false),
bank,
&bank.reserved_account_keys,
)
.unwrap()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,12 @@ impl SchedulerController {
let (transactions, fee_budget_limits_vec): (Vec<_>, Vec<_>) = chunk
.iter()
.filter_map(|packet| {
packet.build_sanitized_transaction(feature_set, vote_only, bank.as_ref())
packet.build_sanitized_transaction(
feature_set,
vote_only,
bank.as_ref(),
&bank.reserved_account_keys,
)
})
.inspect(|_| saturating_add_assign!(post_sanitization_count, 1))
.filter(|tx| {
Expand Down
7 changes: 7 additions & 0 deletions core/src/banking_stage/unprocessed_packet_batches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ mod tests {
solana_sdk::{
compute_budget::ComputeBudgetInstruction,
message::Message,
reserved_account_keys::ReservedAccountKeys,
signature::{Keypair, Signer},
system_instruction, system_transaction,
transaction::{SimpleAddressLoader, Transaction},
Expand Down Expand Up @@ -490,6 +491,7 @@ mod tests {
&Arc::new(FeatureSet::default()),
votes_only,
SimpleAddressLoader::Disabled,
&ReservedAccountKeys::empty(),
)
});
assert_eq!(2, txs.count());
Expand All @@ -500,6 +502,7 @@ mod tests {
&Arc::new(FeatureSet::default()),
votes_only,
SimpleAddressLoader::Disabled,
&ReservedAccountKeys::empty(),
)
});
assert_eq!(0, txs.count());
Expand All @@ -519,6 +522,7 @@ mod tests {
&Arc::new(FeatureSet::default()),
votes_only,
SimpleAddressLoader::Disabled,
&ReservedAccountKeys::empty(),
)
});
assert_eq!(3, txs.count());
Expand All @@ -529,6 +533,7 @@ mod tests {
&Arc::new(FeatureSet::default()),
votes_only,
SimpleAddressLoader::Disabled,
&ReservedAccountKeys::empty(),
)
});
assert_eq!(2, txs.count());
Expand All @@ -548,6 +553,7 @@ mod tests {
&Arc::new(FeatureSet::default()),
votes_only,
SimpleAddressLoader::Disabled,
&ReservedAccountKeys::empty(),
)
});
assert_eq!(3, txs.count());
Expand All @@ -558,6 +564,7 @@ mod tests {
&Arc::new(FeatureSet::default()),
votes_only,
SimpleAddressLoader::Disabled,
&ReservedAccountKeys::empty(),
)
});
assert_eq!(3, txs.count());
Expand Down
17 changes: 13 additions & 4 deletions core/src/banking_stage/unprocessed_transaction_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,13 @@ fn consume_scan_should_process_packet(
}

// Try to sanitize the packet
let (maybe_sanitized_transaction, sanitization_time_us) = measure_us!(
packet.build_sanitized_transaction(&bank.feature_set, bank.vote_only_bank(), bank)
);
let (maybe_sanitized_transaction, sanitization_time_us) = measure_us!(packet
.build_sanitized_transaction(
&bank.feature_set,
bank.vote_only_bank(),
bank,
&bank.reserved_account_keys,
));

payload
.slot_metrics_tracker
Expand Down Expand Up @@ -770,7 +774,12 @@ impl ThreadLocalUnprocessedPackets {
.enumerate()
.filter_map(|(packet_index, deserialized_packet)| {
deserialized_packet
.build_sanitized_transaction(&bank.feature_set, bank.vote_only_bank(), bank)
.build_sanitized_transaction(
&bank.feature_set,
bank.vote_only_bank(),
bank,
&bank.reserved_account_keys,
)
.map(|transaction| (transaction, packet_index))
})
.unzip();
Expand Down
2 changes: 2 additions & 0 deletions cost-model/src/cost_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ mod tests {
crate::transaction_cost::*,
solana_sdk::{
hash::Hash,
reserved_account_keys::ReservedAccountKeys,
signature::{Keypair, Signer},
system_transaction,
transaction::{
Expand Down Expand Up @@ -332,6 +333,7 @@ mod tests {
MessageHash::Compute,
Some(true),
SimpleAddressLoader::Disabled,
&ReservedAccountKeys::empty(),
)
.unwrap();

Expand Down
3 changes: 3 additions & 0 deletions cost-model/src/transaction_cost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ mod tests {
feature_set::FeatureSet,
hash::Hash,
message::SimpleAddressLoader,
reserved_account_keys::ReservedAccountKeys,
signer::keypair::Keypair,
transaction::{MessageHash, SanitizedTransaction, VersionedTransaction},
},
Expand Down Expand Up @@ -200,6 +201,7 @@ mod tests {
MessageHash::Compute,
Some(true),
SimpleAddressLoader::Disabled,
&ReservedAccountKeys::empty(),
)
.unwrap();

Expand All @@ -209,6 +211,7 @@ mod tests {
MessageHash::Compute,
Some(false),
SimpleAddressLoader::Disabled,
&ReservedAccountKeys::empty(),
)
.unwrap();

Expand Down
3 changes: 3 additions & 0 deletions entry/benches/entry_sigverify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use {
solana_perf::test_tx::test_tx,
solana_sdk::{
hash::Hash,
reserved_account_keys::ReservedAccountKeys,
transaction::{
Result, SanitizedTransaction, SimpleAddressLoader, TransactionVerificationMode,
VersionedTransaction,
Expand Down Expand Up @@ -40,6 +41,7 @@ fn bench_gpusigverify(bencher: &mut Bencher) {
message_hash,
None,
SimpleAddressLoader::Disabled,
&ReservedAccountKeys::empty(),
)
}?;

Expand Down Expand Up @@ -81,6 +83,7 @@ fn bench_cpusigverify(bencher: &mut Bencher) {
message_hash,
None,
SimpleAddressLoader::Disabled,
&ReservedAccountKeys::empty(),
)
}?;

Expand Down
2 changes: 2 additions & 0 deletions entry/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,7 @@ mod tests {
solana_sdk::{
hash::{hash, Hash},
pubkey::Pubkey,
reserved_account_keys::ReservedAccountKeys,
signature::{Keypair, Signer},
system_transaction,
transaction::{
Expand Down Expand Up @@ -1039,6 +1040,7 @@ mod tests {
message_hash,
None,
SimpleAddressLoader::Disabled,
&ReservedAccountKeys::empty(),
)
}?;

Expand Down
9 changes: 7 additions & 2 deletions ledger-tool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ use {
native_token::{lamports_to_sol, sol_to_lamports, Sol},
pubkey::Pubkey,
rent::Rent,
reserved_account_keys::ReservedAccountKeys,
shred_version::compute_shred_version,
stake::{self, state::StakeStateV2},
system_program,
Expand Down Expand Up @@ -460,6 +461,9 @@ fn compute_slot_cost(blockstore: &Blockstore, slot: Slot) -> Result<(), String>
let mut program_ids = HashMap::new();
let mut cost_tracker = CostTracker::default();

let feature_set = FeatureSet::all_enabled();
let reserved_account_keys = ReservedAccountKeys::active_and_inactive();

for entry in entries {
num_transactions += entry.transactions.len();
entry
Expand All @@ -471,6 +475,7 @@ fn compute_slot_cost(blockstore: &Blockstore, slot: Slot) -> Result<(), String>
MessageHash::Compute,
None,
SimpleAddressLoader::Disabled,
&reserved_account_keys,
)
.map_err(|err| {
warn!("Failed to compute cost of transaction: {:?}", err);
Expand All @@ -480,7 +485,7 @@ fn compute_slot_cost(blockstore: &Blockstore, slot: Slot) -> Result<(), String>
.for_each(|transaction| {
num_programs += transaction.message().instructions().len();

let tx_cost = CostModel::calculate_cost(&transaction, &FeatureSet::all_enabled());
let tx_cost = CostModel::calculate_cost(&transaction, &feature_set);
let result = cost_tracker.try_add(&tx_cost);
if result.is_err() {
println!(
Expand Down Expand Up @@ -2621,7 +2626,7 @@ fn main() {
for (pubkey, warped_account) in all_accounts {
// Don't output sysvars; it's always updated but not related to
// inflation.
if solana_sdk::sysvar::is_sysvar_id(&pubkey) {
if solana_sdk::sysvar::check_id(warped_account.owner()) {
continue;
}

Expand Down
12 changes: 6 additions & 6 deletions ledger-tool/src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,9 +643,9 @@ struct AccountsScanner {

impl AccountsScanner {
/// Returns true if this account should be included in the output
fn should_process_account(&self, account: &AccountSharedData, pubkey: &Pubkey) -> bool {
fn should_process_account(&self, account: &AccountSharedData) -> bool {
solana_accounts_db::accounts::Accounts::is_loadable(account.lamports())
&& (self.config.include_sysvars || !solana_sdk::sysvar::is_sysvar_id(pubkey))
&& (self.config.include_sysvars || !solana_sdk::sysvar::check_id(account.owner()))
}

fn maybe_output_account<S>(
Expand Down Expand Up @@ -688,8 +688,8 @@ impl AccountsScanner {
};

let scan_func = |account_tuple: Option<(&Pubkey, AccountSharedData, Slot)>| {
if let Some((pubkey, account, slot)) = account_tuple
.filter(|(pubkey, account, _)| self.should_process_account(account, pubkey))
if let Some((pubkey, account, slot)) =
account_tuple.filter(|(_, account, _)| self.should_process_account(account))
{
total_accounts_stats.accumulate_account(pubkey, &account, rent_collector);
self.maybe_output_account(
Expand All @@ -710,7 +710,7 @@ impl AccountsScanner {
if let Some((account, slot)) = self
.bank
.get_account_modified_slot_with_fixed_root(pubkey)
.filter(|(account, _)| self.should_process_account(account, pubkey))
.filter(|(account, _)| self.should_process_account(account))
{
total_accounts_stats.accumulate_account(pubkey, &account, rent_collector);
self.maybe_output_account(
Expand All @@ -727,7 +727,7 @@ impl AccountsScanner {
.get_program_accounts(program_pubkey, &ScanConfig::default())
.unwrap()
.iter()
.filter(|(pubkey, account)| self.should_process_account(account, pubkey))
.filter(|(_, account)| self.should_process_account(account))
.for_each(|(pubkey, account)| {
total_accounts_stats.accumulate_account(pubkey, account, rent_collector);
self.maybe_output_account(
Expand Down
Loading
Loading