Skip to content

Commit

Permalink
FeatureSet: ahash (solana-labs#3756)
Browse files Browse the repository at this point in the history
  • Loading branch information
apfitzge authored Nov 25, 2024
1 parent a9dbf47 commit 7cb2b8a
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 30 deletions.
1 change: 1 addition & 0 deletions 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 programs/sbf/Cargo.lock

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

10 changes: 5 additions & 5 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ use {
verify_precompiles::verify_precompiles,
},
accounts_lt_hash::{CacheValue as AccountsLtHashCacheValue, Stats as AccountsLtHashStats},
ahash::AHashMap,
ahash::{AHashMap, AHashSet},
byteorder::{ByteOrder, LittleEndian},
dashmap::{DashMap, DashSet},
log::*,
Expand Down Expand Up @@ -6841,10 +6841,10 @@ impl Bank {

/// Compute the active feature set based on the current bank state,
/// and return it together with the set of newly activated features.
fn compute_active_feature_set(&self, include_pending: bool) -> (FeatureSet, HashSet<Pubkey>) {
fn compute_active_feature_set(&self, include_pending: bool) -> (FeatureSet, AHashSet<Pubkey>) {
let mut active = self.feature_set.active.clone();
let mut inactive = HashSet::new();
let mut pending = HashSet::new();
let mut inactive = AHashSet::new();
let mut pending = AHashSet::new();
let slot = self.slot();

for feature_id in &self.feature_set.inactive {
Expand Down Expand Up @@ -6878,7 +6878,7 @@ impl Bank {
fn apply_builtin_program_feature_transitions(
&mut self,
only_apply_transitions_for_new_features: bool,
new_feature_activations: &HashSet<Pubkey>,
new_feature_activations: &AHashSet<Pubkey>,
) {
for builtin in BUILTINS.iter() {
// The `builtin_is_bpf` flag is used to handle the case where a
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/bank/builtin_programs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ mod tests {
let only_apply_transitions_for_new_features = true;
bank.apply_builtin_program_feature_transitions(
only_apply_transitions_for_new_features,
&HashSet::new(),
&AHashSet::new(),
);
}

Expand Down
30 changes: 19 additions & 11 deletions sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ full = [
"dep:solana-seed-derivable",
"dep:solana-seed-phrase",
"dep:solana-signer",
"dep:solana-transaction-error"
"dep:solana-transaction-error",
]
borsh = [
"dep:borsh",
"solana-compute-budget-interface/borsh",
"solana-program/borsh",
"solana-secp256k1-recover/borsh"
"solana-secp256k1-recover/borsh",
]
dev-context-only-utils = [
"qualifier_attr",
Expand All @@ -74,7 +74,7 @@ frozen-abi = [
"solana-reward-info/frozen-abi",
"solana-short-vec/frozen-abi",
"solana-signature/frozen-abi",
"solana-transaction-error/frozen-abi"
"solana-transaction-error/frozen-abi",
]
# Enables the "vendored" feature of openssl inside of secp256r1-program
openssl-vendored = ["solana-precompiles/openssl-vendored"]
Expand Down Expand Up @@ -115,7 +115,9 @@ solana-bn254 = { workspace = true }
solana-cluster-type = { workspace = true, features = [
"serde",
], optional = true }
solana-commitment-config = { workspace = true, optional = true, features = ["serde"] }
solana-commitment-config = { workspace = true, optional = true, features = [
"serde",
] }
solana-compute-budget-interface = { workspace = true, optional = true, features = [
"serde",
] }
Expand All @@ -133,23 +135,29 @@ solana-frozen-abi-macro = { workspace = true, optional = true, features = [
] }
solana-inflation = { workspace = true, features = ["serde"] }
solana-instruction = { workspace = true }
solana-keypair = { workspace = true, optional = true, features = ["seed-derivable"] }
solana-keypair = { workspace = true, optional = true, features = [
"seed-derivable",
] }
solana-native-token = { workspace = true }
solana-packet = { workspace = true, features = ["bincode", "serde"] }
solana-precompile-error = { workspace = true, optional = true }
solana-precompiles = { workspace = true, optional = true }
solana-presigner = { workspace = true, optional = true }
solana-program = { workspace = true }
solana-program-memory = { workspace = true }
solana-pubkey = { workspace = true, default-features = false, features = ["std"] }
solana-pubkey = { workspace = true, default-features = false, features = [
"std",
] }
solana-quic-definitions = { workspace = true, optional = true }
solana-rent-debits = { workspace = true }
solana-reserved-account-keys = { workspace = true }
solana-reward-info = { workspace = true, features = ["serde"] }
solana-sanitize = { workspace = true }
solana-sdk-ids = { workspace = true }
solana-sdk-macro = { workspace = true }
solana-secp256k1-program = { workspace = true, optional = true, features = ["bincode"] }
solana-secp256k1-program = { workspace = true, optional = true, features = [
"bincode",
] }
solana-secp256k1-recover = { workspace = true }
solana-secp256r1-program = { workspace = true, default-features = false }
solana-seed-derivable = { workspace = true, optional = true }
Expand All @@ -165,10 +173,10 @@ solana-signature = { workspace = true, features = [
], optional = true }
solana-signer = { workspace = true, optional = true }
solana-time-utils = { workspace = true }
solana-transaction-context = { workspace = true, features = [
"bincode",
] }
solana-transaction-error = { workspace = true, features = ["serde"], optional = true }
solana-transaction-context = { workspace = true, features = ["bincode"] }
solana-transaction-error = { workspace = true, features = [
"serde",
], optional = true }
thiserror = { workspace = true }

[target.'cfg(target_arch = "wasm32")'.dependencies]
Expand Down
6 changes: 2 additions & 4 deletions sdk/feature-set/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 }
lazy_static = { workspace = true }
solana-epoch-schedule = { workspace = true }
solana-frozen-abi = { workspace = true, optional = true, features = [
Expand All @@ -23,10 +24,7 @@ solana-pubkey = { workspace = true }
solana-sha256-hasher = { workspace = true }

[features]
frozen-abi = [
"dep:solana-frozen-abi",
"dep:solana-frozen-abi-macro",
]
frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"]

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
Expand Down
18 changes: 9 additions & 9 deletions sdk/feature-set/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
#![cfg_attr(feature = "frozen-abi", feature(min_specialization))]

use {
ahash::{AHashMap, AHashSet},
lazy_static::lazy_static,
solana_epoch_schedule::EpochSchedule,
solana_hash::Hash,
solana_pubkey::Pubkey,
solana_sha256_hasher::Hasher,
std::collections::{HashMap, HashSet},
};

pub mod deprecate_rewards_sysvar {
Expand Down Expand Up @@ -894,7 +894,7 @@ pub mod migrate_stake_program_to_core_bpf {

lazy_static! {
/// Map of feature identifiers to user-visible description
pub static ref FEATURE_NAMES: HashMap<Pubkey, &'static str> = [
pub static ref FEATURE_NAMES: AHashMap<Pubkey, &'static str> = [
(secp256k1_program_enabled::id(), "secp256k1 program"),
(deprecate_rewards_sysvar::id(), "deprecate unused rewards sysvar"),
(pico_inflation::id(), "pico inflation"),
Expand Down Expand Up @@ -1136,7 +1136,7 @@ pub struct FullInflationFeaturePair {

lazy_static! {
/// Set of feature pairs that once enabled will trigger full inflation
pub static ref FULL_INFLATION_FEATURE_PAIRS: HashSet<FullInflationFeaturePair> = [
pub static ref FULL_INFLATION_FEATURE_PAIRS: AHashSet<FullInflationFeaturePair> = [
FullInflationFeaturePair {
vote_id: full_inflation::mainnet::certusone::vote::id(),
enable_id: full_inflation::mainnet::certusone::enable::id(),
Expand All @@ -1151,14 +1151,14 @@ lazy_static! {
#[cfg_attr(feature = "frozen-abi", derive(solana_frozen_abi_macro::AbiExample))]
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct FeatureSet {
pub active: HashMap<Pubkey, u64>,
pub inactive: HashSet<Pubkey>,
pub active: AHashMap<Pubkey, u64>,
pub inactive: AHashSet<Pubkey>,
}
impl Default for FeatureSet {
fn default() -> Self {
// All features disabled
Self {
active: HashMap::new(),
active: AHashMap::new(),
inactive: FEATURE_NAMES.keys().cloned().collect(),
}
}
Expand All @@ -1173,7 +1173,7 @@ impl FeatureSet {
}

/// List of enabled features that trigger full inflation
pub fn full_inflation_features_enabled(&self) -> HashSet<Pubkey> {
pub fn full_inflation_features_enabled(&self) -> AHashSet<Pubkey> {
let mut hash_set = FULL_INFLATION_FEATURE_PAIRS
.iter()
.filter_map(|pair| {
Expand All @@ -1183,7 +1183,7 @@ impl FeatureSet {
None
}
})
.collect::<HashSet<_>>();
.collect::<AHashSet<_>>();

if self.is_active(&full_inflation::devnet_and_testnet::id()) {
hash_set.insert(full_inflation::devnet_and_testnet::id());
Expand All @@ -1195,7 +1195,7 @@ impl FeatureSet {
pub fn all_enabled() -> Self {
Self {
active: FEATURE_NAMES.keys().cloned().map(|key| (key, 0)).collect(),
inactive: HashSet::new(),
inactive: AHashSet::new(),
}
}

Expand Down
1 change: 1 addition & 0 deletions svm/examples/Cargo.lock

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

0 comments on commit 7cb2b8a

Please sign in to comment.