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

perf: use ahash for reserved keys set #3001

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion core/src/banking_stage/immutable_deserialized_packet.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use {
super::packet_filter::PacketFilterFailure,
ahash::RandomState,
solana_compute_budget::compute_budget_limits::ComputeBudgetLimits,
solana_perf::packet::Packet,
solana_runtime_transaction::instructions_processor::process_compute_budget_instructions,
Expand Down Expand Up @@ -115,7 +116,7 @@ impl ImmutableDeserializedPacket {
&self,
votes_only: bool,
address_loader: impl AddressLoader,
reserved_account_keys: &HashSet<Pubkey>,
reserved_account_keys: &HashSet<Pubkey, RandomState>,
) -> Option<SanitizedTransaction> {
if votes_only && !self.is_simple_vote() {
return None;
Expand Down
1 change: 1 addition & 0 deletions ledger/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ license = { workspace = true }
edition = { workspace = true }

[dependencies]
ahash = { workspace = true }
assert_matches = { workspace = true }
bincode = { workspace = true }
bitflags = { workspace = true, features = ["serde"] }
Expand Down
4 changes: 3 additions & 1 deletion ledger/src/transaction_address_lookup_table_scanner.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use {
ahash::RandomState,
bincode::deserialize,
lazy_static::lazy_static,
solana_sdk::{
Expand All @@ -11,7 +12,8 @@ use {
};

lazy_static! {
static ref RESERVED_IDS_SET: HashSet<Pubkey> = ReservedAccountKeys::new_all_activated().active;
static ref RESERVED_IDS_SET: HashSet<Pubkey, RandomState> =
ReservedAccountKeys::new_all_activated().active;
}

pub struct ScannedLookupTableExtensions {
Expand Down
6 changes: 6 additions & 0 deletions programs/sbf/Cargo.lock

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

1 change: 1 addition & 0 deletions rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ license = { workspace = true }
edition = { workspace = true }

[dependencies]
ahash = { workspace = true }
base64 = { workspace = true }
bincode = { workspace = true }
bs58 = { workspace = true }
Expand Down
3 changes: 2 additions & 1 deletion rpc/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use {
optimistically_confirmed_bank_tracker::OptimisticallyConfirmedBank,
parsed_token_accounts::*, rpc_cache::LargestAccountsCache, rpc_health::*,
},
ahash::RandomState,
base64::{prelude::BASE64_STANDARD, Engine},
bincode::{config::Options, serialize},
crossbeam_channel::{unbounded, Receiver, Sender},
Expand Down Expand Up @@ -4209,7 +4210,7 @@ where
fn sanitize_transaction(
transaction: VersionedTransaction,
address_loader: impl AddressLoader,
reserved_account_keys: &HashSet<Pubkey>,
reserved_account_keys: &HashSet<Pubkey, RandomState>,
) -> Result<SanitizedTransaction> {
SanitizedTransaction::try_create(
transaction,
Expand Down
1 change: 1 addition & 0 deletions runtime-transaction/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ edition = { workspace = true }

[dependencies]
agave-transaction-view = { workspace = true }
ahash = { workspace = true }
log = { workspace = true }
solana-builtins-default-costs = { workspace = true }
solana-compute-budget = { workspace = true }
Expand Down
3 changes: 2 additions & 1 deletion runtime-transaction/src/runtime_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use {
compute_budget_instruction_details::*,
transaction_meta::{DynamicMeta, StaticMeta, TransactionMeta},
},
ahash::RandomState,
core::ops::Deref,
solana_compute_budget::compute_budget_limits::ComputeBudgetLimits,
solana_sdk::{
Expand Down Expand Up @@ -105,7 +106,7 @@ impl RuntimeTransaction<SanitizedTransaction> {
pub fn try_from(
statically_loaded_runtime_tx: RuntimeTransaction<SanitizedVersionedTransaction>,
address_loader: impl AddressLoader,
reserved_account_keys: &HashSet<Pubkey>,
reserved_account_keys: &HashSet<Pubkey, RandomState>,
) -> Result<Self> {
let hash = *statically_loaded_runtime_tx.message_hash();
let is_simple_vote_tx = statically_loaded_runtime_tx.is_simple_vote_tx();
Expand Down
1 change: 1 addition & 0 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ license = { workspace = true }
edition = { workspace = true }

[dependencies]
ahash = { workspace = true }
aquamarine = { workspace = true }
arrayref = { workspace = true }
base64 = { workspace = true }
Expand Down
3 changes: 2 additions & 1 deletion runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ use {
status_cache::{SlotDelta, StatusCache},
transaction_batch::{OwnedOrBorrowed, TransactionBatch},
},
ahash::RandomState,
byteorder::{ByteOrder, LittleEndian},
dashmap::{DashMap, DashSet},
log::*,
Expand Down Expand Up @@ -6272,7 +6273,7 @@ impl Bank {

/// Get a set of all actively reserved account keys that are not allowed to
/// be write-locked during transaction processing.
pub fn get_reserved_account_keys(&self) -> &HashSet<Pubkey> {
pub fn get_reserved_account_keys(&self) -> &HashSet<Pubkey, RandomState> {
&self.reserved_account_keys.active
}

Expand Down
1 change: 1 addition & 0 deletions sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ frozen-abi = [
]

[dependencies]
ahash = { workspace = true }
bincode = { workspace = true }
bitflags = { workspace = true, features = ["serde"] }
borsh = { workspace = true, optional = true }
Expand Down
1 change: 1 addition & 0 deletions sdk/program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ edition = { workspace = true }
rust-version = "1.79.0" # solana platform-tools rust version

[dependencies]
ahash = { workspace = true }
bincode = { workspace = true }
blake3 = { workspace = true, features = ["traits-preview"] }
borsh = { workspace = true, optional = true }
Expand Down
5 changes: 3 additions & 2 deletions sdk/program/src/message/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use {
pubkey::Pubkey,
system_instruction, system_program, sysvar,
},
ahash::RandomState,
solana_sanitize::{Sanitize, SanitizeError},
solana_short_vec as short_vec,
std::{collections::HashSet, convert::TryFrom, str::FromStr},
Expand Down Expand Up @@ -637,7 +638,7 @@ impl Message {
pub fn is_maybe_writable(
&self,
i: usize,
reserved_account_keys: Option<&HashSet<Pubkey>>,
reserved_account_keys: Option<&HashSet<Pubkey, RandomState>>,
) -> bool {
(self.is_writable_index(i))
&& !self.is_account_maybe_reserved(i, reserved_account_keys)
Expand All @@ -649,7 +650,7 @@ impl Message {
fn is_account_maybe_reserved(
&self,
key_index: usize,
reserved_account_keys: Option<&HashSet<Pubkey>>,
reserved_account_keys: Option<&HashSet<Pubkey, RandomState>>,
) -> bool {
let mut is_maybe_reserved = false;
if let Some(reserved_account_keys) = reserved_account_keys {
Expand Down
10 changes: 7 additions & 3 deletions sdk/program/src/message/sanitized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use {
solana_program::{system_instruction::SystemInstruction, system_program},
sysvar::instructions::{BorrowedAccountMeta, BorrowedInstruction},
},
ahash::RandomState,
solana_sanitize::{Sanitize, SanitizeError},
std::{borrow::Cow, collections::HashSet, convert::TryFrom},
thiserror::Error,
Expand All @@ -31,7 +32,10 @@ pub struct LegacyMessage<'a> {
}

impl<'a> LegacyMessage<'a> {
pub fn new(message: legacy::Message, reserved_account_keys: &HashSet<Pubkey>) -> Self {
pub fn new(
message: legacy::Message,
reserved_account_keys: &HashSet<Pubkey, RandomState>,
) -> Self {
let is_writable_account_cache = message
.account_keys
.iter()
Expand Down Expand Up @@ -109,7 +113,7 @@ impl SanitizedMessage {
pub fn try_new(
sanitized_msg: SanitizedVersionedMessage,
address_loader: impl AddressLoader,
reserved_account_keys: &HashSet<Pubkey>,
reserved_account_keys: &HashSet<Pubkey, RandomState>,
) -> Result<Self, SanitizeMessageError> {
Ok(match sanitized_msg.message {
VersionedMessage::Legacy(message) => {
Expand All @@ -130,7 +134,7 @@ impl SanitizedMessage {
/// Create a sanitized legacy message
pub fn try_from_legacy_message(
message: legacy::Message,
reserved_account_keys: &HashSet<Pubkey>,
reserved_account_keys: &HashSet<Pubkey, RandomState>,
) -> Result<Self, SanitizeMessageError> {
message.sanitize()?;
Ok(Self::Legacy(LegacyMessage::new(
Expand Down
3 changes: 2 additions & 1 deletion sdk/program/src/message/versions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use {
message::{legacy::Message as LegacyMessage, v0::MessageAddressTableLookup, MessageHeader},
pubkey::Pubkey,
},
ahash::RandomState,
serde::{
de::{self, Deserializer, SeqAccess, Unexpected, Visitor},
ser::{SerializeTuple, Serializer},
Expand Down Expand Up @@ -85,7 +86,7 @@ impl VersionedMessage {
pub fn is_maybe_writable(
&self,
index: usize,
reserved_account_keys: Option<&HashSet<Pubkey>>,
reserved_account_keys: Option<&HashSet<Pubkey, RandomState>>,
) -> bool {
match self {
Self::Legacy(message) => message.is_maybe_writable(index, reserved_account_keys),
Expand Down
12 changes: 8 additions & 4 deletions sdk/program/src/message/versions/v0/loaded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use {
message::{v0, AccountKeys},
pubkey::Pubkey,
},
ahash::RandomState,
std::{borrow::Cow, collections::HashSet},
};

Expand Down Expand Up @@ -58,7 +59,7 @@ impl<'a> LoadedMessage<'a> {
pub fn new(
message: v0::Message,
loaded_addresses: LoadedAddresses,
reserved_account_keys: &HashSet<Pubkey>,
reserved_account_keys: &HashSet<Pubkey, RandomState>,
) -> Self {
let mut loaded_message = Self {
message: Cow::Owned(message),
Expand All @@ -72,7 +73,7 @@ impl<'a> LoadedMessage<'a> {
pub fn new_borrowed(
message: &'a v0::Message,
loaded_addresses: &'a LoadedAddresses,
reserved_account_keys: &HashSet<Pubkey>,
reserved_account_keys: &HashSet<Pubkey, RandomState>,
) -> Self {
let mut loaded_message = Self {
message: Cow::Borrowed(message),
Expand All @@ -83,7 +84,10 @@ impl<'a> LoadedMessage<'a> {
loaded_message
}

fn set_is_writable_account_cache(&mut self, reserved_account_keys: &HashSet<Pubkey>) {
fn set_is_writable_account_cache(
&mut self,
reserved_account_keys: &HashSet<Pubkey, RandomState>,
) {
let is_writable_account_cache = self
.account_keys()
.iter()
Expand Down Expand Up @@ -138,7 +142,7 @@ impl<'a> LoadedMessage<'a> {
fn is_writable_internal(
&self,
key_index: usize,
reserved_account_keys: &HashSet<Pubkey>,
reserved_account_keys: &HashSet<Pubkey, RandomState>,
) -> bool {
if self.is_writable_index(key_index) {
if let Some(key) = self.account_keys().get(key_index) {
Expand Down
5 changes: 3 additions & 2 deletions sdk/program/src/message/versions/v0/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use {
},
pubkey::Pubkey,
},
ahash::RandomState,
solana_sanitize::SanitizeError,
solana_short_vec as short_vec,
std::collections::HashSet,
Expand Down Expand Up @@ -346,7 +347,7 @@ impl Message {
pub fn is_maybe_writable(
&self,
key_index: usize,
reserved_account_keys: Option<&HashSet<Pubkey>>,
reserved_account_keys: Option<&HashSet<Pubkey, RandomState>>,
) -> bool {
self.is_writable_index(key_index)
&& !self.is_account_maybe_reserved(key_index, reserved_account_keys)
Expand All @@ -363,7 +364,7 @@ impl Message {
fn is_account_maybe_reserved(
&self,
key_index: usize,
reserved_account_keys: Option<&HashSet<Pubkey>>,
reserved_account_keys: Option<&HashSet<Pubkey, RandomState>>,
) -> bool {
let mut is_maybe_reserved = false;
if let Some(reserved_account_keys) = reserved_account_keys {
Expand Down
Loading
Loading