Skip to content

Commit

Permalink
Add feature for tracking dynamic reserved account set
Browse files Browse the repository at this point in the history
  • Loading branch information
jstarry committed Jan 23, 2024
1 parent 7b18b81 commit a1ddd7b
Show file tree
Hide file tree
Showing 48 changed files with 714 additions and 303 deletions.
7 changes: 6 additions & 1 deletion accounts-db/src/nonce_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ mod tests {
instruction::Instruction,
message::Message,
nonce::{self, state::DurableNonce},
reserved_account_keys::ReservedAccountKeys,
signature::{keypair_from_seed, Signer},
system_instruction, system_program,
},
Expand All @@ -134,7 +135,11 @@ mod tests {
instructions: &[Instruction],
payer: Option<&Pubkey>,
) -> SanitizedMessage {
Message::new(instructions, payer).try_into().unwrap()
SanitizedMessage::try_from_legacy_message(
Message::new(instructions, payer),
&ReservedAccountKeys::empty(),
)
.unwrap()
}

#[test]
Expand Down
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 {
tpu_info::NullTpuInfo,
},
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 @@ -836,6 +836,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 @@ -2002,6 +2003,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 @@ -7,6 +7,7 @@ use {
feature_set,
hash::Hash,
message::Message,
pubkey::Pubkey,
sanitize::SanitizeError,
short_vec::decode_shortu16_len,
signature::Signature,
Expand All @@ -15,7 +16,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 @@ -107,6 +108,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 @@ -116,6 +118,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 @@ -313,7 +313,12 @@ impl SchedulerController {
.iter()
.filter_map(|packet| {
packet
.build_sanitized_transaction(feature_set, vote_only, bank.as_ref())
.build_sanitized_transaction(
feature_set,
vote_only,
bank.as_ref(),
&bank.reserved_account_keys,
)
.map(|tx| (tx, packet.priority_details()))
})
.inspect(|_| saturating_add_assign!(post_sanitization_count, 1))
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 @@ -298,6 +298,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 @@ -475,6 +476,7 @@ mod tests {
&Arc::new(FeatureSet::default()),
votes_only,
SimpleAddressLoader::Disabled,
&ReservedAccountKeys::empty(),
)
});
assert_eq!(2, txs.count());
Expand All @@ -485,6 +487,7 @@ mod tests {
&Arc::new(FeatureSet::default()),
votes_only,
SimpleAddressLoader::Disabled,
&ReservedAccountKeys::empty(),
)
});
assert_eq!(0, txs.count());
Expand All @@ -504,6 +507,7 @@ mod tests {
&Arc::new(FeatureSet::default()),
votes_only,
SimpleAddressLoader::Disabled,
&ReservedAccountKeys::empty(),
)
});
assert_eq!(3, txs.count());
Expand All @@ -514,6 +518,7 @@ mod tests {
&Arc::new(FeatureSet::default()),
votes_only,
SimpleAddressLoader::Disabled,
&ReservedAccountKeys::empty(),
)
});
assert_eq!(2, txs.count());
Expand All @@ -533,6 +538,7 @@ mod tests {
&Arc::new(FeatureSet::default()),
votes_only,
SimpleAddressLoader::Disabled,
&ReservedAccountKeys::empty(),
)
});
assert_eq!(3, txs.count());
Expand All @@ -543,6 +549,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 @@ -744,7 +748,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
12 changes: 9 additions & 3 deletions ledger-tool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,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 @@ -489,6 +490,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 @@ -500,6 +504,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 @@ -509,7 +514,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 @@ -2230,7 +2235,8 @@ fn main() {
if let Some((pubkey, account, slot)) = some_account_tuple
.filter(|(_, account, _)| Accounts::is_loadable(account.lamports()))
{
if !include_sysvars && solana_sdk::sysvar::is_sysvar_id(pubkey) {
if !include_sysvars && solana_sdk::sysvar::check_id(account.owner())
{
return;
}

Expand Down Expand Up @@ -2608,7 +2614,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
Loading

0 comments on commit a1ddd7b

Please sign in to comment.